16
16
17
17
package org .springframework .web .service .invoker ;
18
18
19
+ import java .util .HashMap ;
19
20
import java .util .List ;
20
21
21
22
import org .junit .jupiter .api .Test ;
22
23
24
+ import org .springframework .core .convert .ConversionService ;
25
+ import org .springframework .core .convert .support .DefaultConversionService ;
23
26
import org .springframework .util .MultiValueMap ;
24
27
import org .springframework .web .bind .annotation .RequestParam ;
28
+ import org .springframework .web .service .annotation .GetExchange ;
25
29
import org .springframework .web .service .annotation .PostExchange ;
26
30
27
31
import static org .assertj .core .api .Assertions .assertThat ;
@@ -41,14 +45,14 @@ class RequestParamArgumentResolverTests {
41
45
42
46
private final TestExchangeAdapter client = new TestExchangeAdapter ();
43
47
44
- private final Service service =
45
- HttpServiceProxyFactory .builderFor (this .client ).build ().createClient (Service .class );
48
+ private final HttpServiceProxyFactory .Builder builder = HttpServiceProxyFactory .builderFor (this .client );
46
49
47
50
48
51
@ Test
49
52
@ SuppressWarnings ("unchecked" )
50
53
void requestParam () {
51
- this .service .postForm ("value 1" , "value 2" );
54
+ Service service = builder .build ().createClient (Service .class );
55
+ service .postForm ("value 1" , "value 2" );
52
56
53
57
Object body = this .client .getRequestValues ().getBodyValue ();
54
58
assertThat (body ).isInstanceOf (MultiValueMap .class );
@@ -57,12 +61,34 @@ void requestParam() {
57
61
.containsEntry ("param2" , List .of ("value 2" ));
58
62
}
59
63
64
+ @ Test
65
+ @ SuppressWarnings ("unchecked" )
66
+ void requestParamWithDisabledFormattingCollectionValue () {
67
+ ConversionService conversionService = new DefaultConversionService ();
68
+ boolean formatAsSingleValue = false ;
69
+ Service service = builder .customArgumentResolver (
70
+ new RequestParamArgumentResolver (conversionService , formatAsSingleValue ))
71
+ .build ()
72
+ .createClient (Service .class );
73
+ List <String > collectionParams = List .of ("1" , "2" , "3" );
74
+ service .getForm ("value 1" , collectionParams );
75
+
76
+ Object uriVariables = this .client .getRequestValues ().getUriVariables ();
77
+ assertThat (uriVariables ).isNotInstanceOf (MultiValueMap .class ).isInstanceOf (HashMap .class );
78
+ assertThat ((HashMap <String , String >) uriVariables ).hasSize (4 )
79
+ .containsEntry ("queryParam0" , "param1" )
80
+ .containsEntry ("queryParam0[0]" , "value 1" )
81
+ .containsEntry ("queryParam1" , "param2" )
82
+ .containsEntry ("queryParam1[0]" , String .join ("," , collectionParams ));
83
+ }
60
84
61
85
private interface Service {
62
86
63
87
@ PostExchange (contentType = "application/x-www-form-urlencoded" )
64
88
void postForm (@ RequestParam String param1 , @ RequestParam String param2 );
65
89
90
+ @ GetExchange
91
+ void getForm (@ RequestParam String param1 , @ RequestParam List <String > param2 );
66
92
}
67
93
68
94
}
0 commit comments