|
21 | 21 | import java.util.ArrayList; |
22 | 22 | import java.util.HashMap; |
23 | 23 | import java.util.Map; |
| 24 | +import java.util.UUID; |
24 | 25 |
|
25 | 26 | class RequestInformationTest { |
26 | 27 | @Test |
@@ -50,6 +51,27 @@ void BuildsUrlOnProvidedBaseUrl() { |
50 | 51 | assertEquals("http://localhost/users", result.toString()); |
51 | 52 | } |
52 | 53 |
|
| 54 | + @Test |
| 55 | + void ThrowsIllegalArgumentWhenMultidimensionalQueryParameterIsSet() { |
| 56 | + // Arrange as the request builders would |
| 57 | + final RequestInformation requestInfo = new RequestInformation(); |
| 58 | + requestInfo.httpMethod = HttpMethod.GET; |
| 59 | + requestInfo.urlTemplate = "{+baseurl}/users{?datasetIds}"; |
| 60 | + final GetQueryParameters queryParameters = new GetQueryParameters(); |
| 61 | + queryParameters.parallelDatasetIds = |
| 62 | + new UUID[][] { |
| 63 | + {UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")}, |
| 64 | + {UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")} |
| 65 | + }; |
| 66 | + |
| 67 | + // Assert |
| 68 | + var exception = |
| 69 | + assertThrows( |
| 70 | + IllegalArgumentException.class, |
| 71 | + () -> requestInfo.addQueryParameters(queryParameters)); |
| 72 | + assertTrue(exception.getMessage().contains("multidimensional arrays are not supported")); |
| 73 | + } |
| 74 | + |
53 | 75 | @Test |
54 | 76 | void SetsPathParametersOfDateTimeOffsetType() { |
55 | 77 | // Arrange as the request builders would |
@@ -131,6 +153,30 @@ void SetsPathParametersOfPeriodAndDurationType() { |
131 | 153 | assertTrue(uriResult.toString().contains("seatingDuration='PT30M'")); |
132 | 154 | } |
133 | 155 |
|
| 156 | + @Test |
| 157 | + void SetsQueryParametersOfPeriodAndDurationTypedArray() |
| 158 | + throws IllegalStateException, URISyntaxException { |
| 159 | + // Arrange as the request builders would |
| 160 | + final RequestInformation requestInfo = new RequestInformation(); |
| 161 | + requestInfo.httpMethod = HttpMethod.GET; |
| 162 | + requestInfo.urlTemplate = "http://localhost/{?periods}"; |
| 163 | + |
| 164 | + final GetQueryParameters queryParameters = new GetQueryParameters(); |
| 165 | + queryParameters.messageAges = |
| 166 | + new PeriodAndDuration[] { |
| 167 | + PeriodAndDuration.parse("PT30M"), |
| 168 | + PeriodAndDuration.parse("PT20M"), |
| 169 | + PeriodAndDuration.parse("PT1H20M") |
| 170 | + }; |
| 171 | + |
| 172 | + // Act |
| 173 | + requestInfo.addQueryParameters(queryParameters); |
| 174 | + |
| 175 | + // Assert |
| 176 | + final URI uri = requestInfo.getUri(); |
| 177 | + assertEquals("http://localhost/?periods=PT30M,PT20M,PT1H20M", uri.toString()); |
| 178 | + } |
| 179 | + |
134 | 180 | @Test |
135 | 181 | void ExpandQueryParametersAfterPathParams() { |
136 | 182 | // Arrange as the request builders would |
@@ -207,6 +253,24 @@ void SetsPathParametersOfBooleanType() { |
207 | 253 | assertTrue(uriResult.toString().contains("count=true")); |
208 | 254 | } |
209 | 255 |
|
| 256 | + @Test |
| 257 | + void SetsQueryParametersOfBooleanTypedArray() throws IllegalStateException, URISyntaxException { |
| 258 | + // Arrange as the request builders would |
| 259 | + final RequestInformation requestInfo = new RequestInformation(); |
| 260 | + requestInfo.httpMethod = HttpMethod.GET; |
| 261 | + requestInfo.urlTemplate = "http://localhost/{?expandChildren}"; |
| 262 | + |
| 263 | + final GetQueryParameters queryParameters = new GetQueryParameters(); |
| 264 | + queryParameters.expandChildren = new Boolean[] {true, false, true, true}; |
| 265 | + |
| 266 | + // Act |
| 267 | + requestInfo.addQueryParameters(queryParameters); |
| 268 | + |
| 269 | + // Assert |
| 270 | + final URI uri = requestInfo.getUri(); |
| 271 | + assertEquals("http://localhost/?expandChildren=true,false,true,true", uri.toString()); |
| 272 | + } |
| 273 | + |
210 | 274 | @Test |
211 | 275 | void SetsPathParametersOfUUIDType() { |
212 | 276 | // Arrange as the request builders would |
@@ -239,6 +303,30 @@ void SetsQueryParametersOfUUIDType() { |
239 | 303 | assertTrue(uriResult.toString().contains("?id=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")); |
240 | 304 | } |
241 | 305 |
|
| 306 | + @Test |
| 307 | + void SetsQueryParametersOfUUIDTypedArray() throws IllegalStateException, URISyntaxException { |
| 308 | + // Arrange as the request builders would |
| 309 | + final RequestInformation requestInfo = new RequestInformation(); |
| 310 | + requestInfo.httpMethod = HttpMethod.GET; |
| 311 | + requestInfo.urlTemplate = "http://localhost/{?datasetIds}"; |
| 312 | + |
| 313 | + final GetQueryParameters queryParameters = new GetQueryParameters(); |
| 314 | + queryParameters.datasetIds = |
| 315 | + new UUID[] { |
| 316 | + UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e"), |
| 317 | + UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e") |
| 318 | + }; |
| 319 | + |
| 320 | + // Act |
| 321 | + requestInfo.addQueryParameters(queryParameters); |
| 322 | + |
| 323 | + // Assert |
| 324 | + final URI uri = requestInfo.getUri(); |
| 325 | + assertEquals( |
| 326 | + "http://localhost/?datasetIds=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e,a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e", |
| 327 | + uri.toString()); |
| 328 | + } |
| 329 | + |
242 | 330 | @Test |
243 | 331 | void SetsParsableContent() { |
244 | 332 | // Arrange as the request builders would |
@@ -415,12 +503,31 @@ class GetQueryParameters implements QueryParameters { |
415 | 503 |
|
416 | 504 | @jakarta.annotation.Nullable public TestEnum[] datasets; |
417 | 505 |
|
| 506 | + @jakarta.annotation.Nullable public UUID[] datasetIds; |
| 507 | + |
| 508 | + /** |
| 509 | + * Search by dataset ids in parallel (or something like that) |
| 510 | + */ |
| 511 | + @jakarta.annotation.Nullable public UUID[][] parallelDatasetIds; |
| 512 | + |
| 513 | + /** Per-dataset boolean indicating whether to resolve its child datasets */ |
| 514 | + @jakarta.annotation.Nullable public Boolean[] expandChildren; |
| 515 | + |
| 516 | + /** |
| 517 | + * Minimum message ages as duration, per dataset |
| 518 | + */ |
| 519 | + @jakarta.annotation.Nullable public PeriodAndDuration[] messageAges; |
| 520 | + |
418 | 521 | @jakarta.annotation.Nonnull public Map<String, Object> toQueryParameters() { |
419 | | - final Map<String, Object> allQueryParams = new HashMap(); |
| 522 | + final Map<String, Object> allQueryParams = new HashMap<>(); |
420 | 523 | allQueryParams.put("%24select", select); |
421 | 524 | allQueryParams.put("%24search", search); |
422 | 525 | allQueryParams.put("dataset", dataset); |
423 | 526 | allQueryParams.put("datasets", datasets); |
| 527 | + allQueryParams.put("datasetIds", datasetIds); |
| 528 | + allQueryParams.put("parallelDatasetIds", parallelDatasetIds); |
| 529 | + allQueryParams.put("expandChildren", expandChildren); |
| 530 | + allQueryParams.put("periods", messageAges); |
424 | 531 | return allQueryParams; |
425 | 532 | } |
426 | 533 | } |
0 commit comments