16
16
17
17
package org .springframework .web .reactive .function .server ;
18
18
19
+ import java .util .Map ;
20
+
19
21
import org .junit .Test ;
20
22
import reactor .core .publisher .Mono ;
21
23
24
+ import org .springframework .http .HttpMethod ;
22
25
import org .springframework .http .HttpStatus ;
23
26
import org .springframework .http .ResponseEntity ;
24
27
import org .springframework .web .client .RestTemplate ;
25
28
26
29
import static org .junit .Assert .*;
27
- import static org .springframework .web .reactive .function .server .RequestPredicates .*;
28
- import static org .springframework .web .reactive .function .server .RouterFunctions .*;
30
+ import static org .springframework .web .reactive .function .server .RequestPredicates .GET ;
31
+ import static org .springframework .web .reactive .function .server .RequestPredicates .all ;
32
+ import static org .springframework .web .reactive .function .server .RequestPredicates .method ;
33
+ import static org .springframework .web .reactive .function .server .RequestPredicates .path ;
34
+ import static org .springframework .web .reactive .function .server .RouterFunctions .nest ;
35
+ import static org .springframework .web .reactive .function .server .RouterFunctions .route ;
29
36
30
37
/**
31
38
* @author Arjen Poutsma
@@ -45,7 +52,8 @@ protected RouterFunction<?> routerFunction() {
45
52
route (GET ("/bar" ), nestedHandler ::variables ).and (
46
53
nest (GET ("/{bar}" ),
47
54
route (GET ("/{baz}" ), nestedHandler ::variables ))))
48
- .andRoute (GET ("/{qux}/quux" ), nestedHandler ::variables );
55
+ .andRoute (path ("/{qux}/quux" ).and (method (HttpMethod .GET )), nestedHandler ::variables )
56
+ .andRoute (all (), nestedHandler ::variables );
49
57
}
50
58
51
59
@@ -89,7 +97,7 @@ public void parentVariables() {
89
97
90
98
// SPR 16692
91
99
@ Test
92
- public void removeFailedPathVariables () {
100
+ public void removeFailedNestedPathVariables () {
93
101
ResponseEntity <String > result =
94
102
restTemplate .getForEntity ("http://localhost:" + port + "/qux/quux" , String .class );
95
103
@@ -98,6 +106,17 @@ public void removeFailedPathVariables() {
98
106
99
107
}
100
108
109
+ // SPR 17210
110
+ @ Test
111
+ public void removeFailedPathVariablesAnd () {
112
+ ResponseEntity <String > result =
113
+ restTemplate .postForEntity ("http://localhost:" + port + "/qux/quux" , "" , String .class );
114
+
115
+ assertEquals (HttpStatus .OK , result .getStatusCode ());
116
+ assertEquals ("{}" , result .getBody ());
117
+
118
+ }
119
+
101
120
102
121
private static class NestedHandler {
103
122
@@ -109,11 +128,15 @@ public Mono<ServerResponse> baz(ServerRequest request) {
109
128
return ServerResponse .ok ().syncBody ("baz" );
110
129
}
111
130
131
+ @ SuppressWarnings ("unchecked" )
112
132
public Mono <ServerResponse > variables (ServerRequest request ) {
113
- assertEquals (request .pathVariables (),
114
- request .attributes ().get (RouterFunctions .URI_TEMPLATE_VARIABLES_ATTRIBUTE ));
133
+ Map <String , String > pathVariables = request .pathVariables ();
134
+ Map <String , String > attributePathVariables =
135
+ (Map <String , String >) request .attributes ().get (RouterFunctions .URI_TEMPLATE_VARIABLES_ATTRIBUTE );
136
+ assertTrue ( (pathVariables .equals (attributePathVariables ))
137
+ || (pathVariables .isEmpty () && (attributePathVariables == null )));
115
138
116
- Mono <String > responseBody = Mono .just (request . pathVariables () .toString ());
139
+ Mono <String > responseBody = Mono .just (pathVariables .toString ());
117
140
return ServerResponse .ok ().body (responseBody , String .class );
118
141
}
119
142
0 commit comments