16
16
17
17
import static com .github .tomakehurst .wiremock .client .WireMock .equalTo ;
18
18
import static com .github .tomakehurst .wiremock .client .WireMock .havingExactly ;
19
+ import static com .github .tomakehurst .wiremock .client .WireMock .matching ;
19
20
20
21
/**
21
22
* Stub with query parameters split from request url.
26
27
*/
27
28
public class SplitPathAndQueryParamsStubMappingTransformer extends StubMappingTransformer {
28
29
30
+ private boolean parametersMatchAnything = false ;
31
+
32
+ public SplitPathAndQueryParamsStubMappingTransformer () {
33
+ }
34
+
35
+ public SplitPathAndQueryParamsStubMappingTransformer (boolean parametersMatchAnything ) {
36
+ this .parametersMatchAnything = parametersMatchAnything ;
37
+ }
38
+
29
39
@ Override
30
40
public StubMapping transform (StubMapping stubMapping , FileSource files , Parameters parameters ) {
31
41
String path = Urls .getPath (stubMapping .getRequest ().getUrl ());
@@ -36,14 +46,18 @@ public StubMapping transform(StubMapping stubMapping, FileSource files, Paramete
36
46
37
47
queryParameterMap .forEach ((key , queryParameter ) ->
38
48
{
39
- if (queryParameter . isSingleValued () ) {
40
- mappingBuilder .withQueryParam (key , equalTo ( queryParameter . firstValue () ));
49
+ if (parametersMatchAnything ) {
50
+ mappingBuilder .withQueryParam (key , matching ( "^(.*)$" ));
41
51
} else {
42
- // https://wiremock.org/docs/request-matching/#matching-headerquery-parameter-containing-multiple-values
43
- MultiValuePattern havingExactly = havingExactly (queryParameter .values ().stream ()
44
- .map (WireMock ::equalTo )
45
- .toArray (StringValuePattern []::new ));
46
- mappingBuilder .withQueryParam (key , havingExactly );
52
+ if (queryParameter .isSingleValued ()) {
53
+ mappingBuilder .withQueryParam (key , equalTo (queryParameter .firstValue ()));
54
+ } else {
55
+ // https://wiremock.org/docs/request-matching/#matching-headerquery-parameter-containing-multiple-values
56
+ MultiValuePattern havingExactly = havingExactly (queryParameter .values ().stream ()
57
+ .map (WireMock ::equalTo )
58
+ .toArray (StringValuePattern []::new ));
59
+ mappingBuilder .withQueryParam (key , havingExactly );
60
+ }
47
61
}
48
62
}
49
63
);
0 commit comments