|
21 | 21 | import org.apache.hc.core5.http.Method; |
22 | 22 | import org.apache.hc.core5.http.ParseException; |
23 | 23 | import org.apache.hc.core5.http.io.entity.EntityUtils; |
24 | | -import org.apache.hc.core5.http.message.BasicNameValuePair; |
25 | 24 | import org.apache.hc.core5.net.URIBuilder; |
26 | 25 | import org.awaitility.core.ConditionTimeoutException; |
27 | 26 | import org.awaitility.pollinterval.FixedPollInterval; |
|
41 | 40 | import java.security.SecureRandom; |
42 | 41 | import java.security.cert.X509Certificate; |
43 | 42 | import java.time.Duration; |
| 43 | +import java.util.List; |
44 | 44 | import java.util.Map; |
45 | 45 | import java.util.concurrent.TimeUnit; |
46 | 46 | import java.util.concurrent.atomic.AtomicReference; |
47 | 47 | import java.util.function.Consumer; |
48 | | -import java.util.stream.Collectors; |
49 | 48 |
|
50 | 49 | import static com.cucumber.tutorial.util.PlainHttpResponseUtils.from; |
51 | 50 | import static org.awaitility.Awaitility.await; |
@@ -81,32 +80,38 @@ protected URI uri(String path) { |
81 | 80 | } |
82 | 81 |
|
83 | 82 | protected URI uri(String path, Map<String, Object> pathParams) { |
84 | | - return uri(path, pathParams, null); |
| 83 | + return uri(path, pathParams, (Map<String, String>) null); |
85 | 84 | } |
86 | 85 |
|
87 | 86 | protected URI uri(String path, Map<String, Object> pathParams, Map<String, String> nonEmptyQueryParams) { |
88 | 87 | return uri(path, pathParams, nonEmptyQueryParams, null); |
89 | 88 | } |
90 | 89 |
|
91 | 90 | protected URI uri(String path, Map<String, Object> pathParams, Map<String, String> nonEmptyQueryParams, Map<String, String> rawQueryParams) { |
92 | | - return uri(address(), path, pathParams, nonEmptyQueryParams, rawQueryParams); |
| 91 | + return uri(address(), path, pathParams, |
| 92 | + nonEmptyQueryParams != null ? List.of(nonEmptyQueryParams) : null, rawQueryParams != null ? List.of(rawQueryParams) : null); |
93 | 93 | } |
94 | 94 |
|
95 | | - public static URI uri(String address, String path, Map<String, Object> pathParams, Map<String, String> nonEmptyQueryParams, Map<String, String> rawQueryParams) { |
| 95 | + protected URI uri(String path, Map<String, Object> pathParams, List<Map<String, String>> rawQueryParams) { |
| 96 | + return uri(address(), path, pathParams, null, rawQueryParams); |
| 97 | + } |
| 98 | + |
| 99 | + public static URI uri(String address, String path, Map<String, Object> pathParams, |
| 100 | + List<Map<String, String>> nonEmptyQueryParamsList, List<Map<String, String>> rawQueryParamsList) { |
96 | 101 | URIBuilder uriBuilder; |
97 | 102 | try { |
98 | 103 | uriBuilder = new URIBuilder(address); |
99 | 104 | if (path != null) { |
100 | 105 | uriBuilder.appendPath(StringFormat.replaceProps(path, pathParams)); |
101 | 106 | } |
102 | | - if (nonEmptyQueryParams != null) { |
103 | | - uriBuilder.addParameters(nonEmptyQueryParams.entrySet().stream() |
104 | | - .filter(e -> e.getValue() != null && !e.getValue().isEmpty()) |
105 | | - .map(param -> new BasicNameValuePair(param.getKey(), param.getValue())).collect(Collectors.toList())); |
| 107 | + if (nonEmptyQueryParamsList != null) { |
| 108 | + nonEmptyQueryParamsList |
| 109 | + .forEach(queryParam -> |
| 110 | + queryParam.entrySet().stream().filter(e -> e.getValue() != null && !e.getValue().isEmpty()) |
| 111 | + .forEach(entry -> uriBuilder.addParameter(entry.getKey(), entry.getValue()))); |
106 | 112 | } |
107 | | - if (rawQueryParams != null) { |
108 | | - uriBuilder.addParameters(rawQueryParams.entrySet().stream() |
109 | | - .map(param -> new BasicNameValuePair(param.getKey(), param.getValue())).collect(Collectors.toList())); |
| 113 | + if (rawQueryParamsList != null) { |
| 114 | + rawQueryParamsList.forEach(queryParam -> queryParam.forEach(uriBuilder::addParameter)); |
110 | 115 | } |
111 | 116 | return uriBuilder.build(); |
112 | 117 | } catch (URISyntaxException e) { |
|
0 commit comments