Skip to content

Commit 4ecee97

Browse files
committed
test: add a few sanity checks for arrays of special types
1 parent 96f9f31 commit 4ecee97

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import java.util.HashMap;
2323
import java.util.Map;
24+
import java.util.UUID;
2425

2526
class RequestInformationTest {
2627
@Test
@@ -131,6 +132,29 @@ void SetsPathParametersOfPeriodAndDurationType() {
131132
assertTrue(uriResult.toString().contains("seatingDuration='PT30M'"));
132133
}
133134

135+
136+
@Test
137+
void SetsQueryParametersOfPeriodAndDurationTypedArray() throws IllegalStateException, URISyntaxException {
138+
// Arrange as the request builders would
139+
final RequestInformation requestInfo = new RequestInformation();
140+
requestInfo.httpMethod = HttpMethod.GET;
141+
requestInfo.urlTemplate = "http://localhost/{?periods}";
142+
143+
final GetQueryParameters queryParameters = new GetQueryParameters();
144+
queryParameters.messageAges = new PeriodAndDuration[] {
145+
PeriodAndDuration.parse("PT30M"),
146+
PeriodAndDuration.parse("PT20M"),
147+
PeriodAndDuration.parse("PT1H20M")
148+
};
149+
150+
// Act
151+
requestInfo.addQueryParameters(queryParameters);
152+
153+
// Assert
154+
final URI uri = requestInfo.getUri();
155+
assertEquals("http://localhost/?periods=PT30M,PT20M,PT1H20M", uri.toString());
156+
}
157+
134158
@Test
135159
void ExpandQueryParametersAfterPathParams() {
136160
// Arrange as the request builders would
@@ -207,6 +231,26 @@ void SetsPathParametersOfBooleanType() {
207231
assertTrue(uriResult.toString().contains("count=true"));
208232
}
209233

234+
@Test
235+
void SetsQueryParametersOfBooleanTypedArray() throws IllegalStateException, URISyntaxException {
236+
// Arrange as the request builders would
237+
final RequestInformation requestInfo = new RequestInformation();
238+
requestInfo.httpMethod = HttpMethod.GET;
239+
requestInfo.urlTemplate = "http://localhost/{?expandChildren}";
240+
241+
final GetQueryParameters queryParameters = new GetQueryParameters();
242+
queryParameters.expandChildren = new Boolean[] {
243+
true, false, true, true
244+
};
245+
246+
// Act
247+
requestInfo.addQueryParameters(queryParameters);
248+
249+
// Assert
250+
final URI uri = requestInfo.getUri();
251+
assertEquals("http://localhost/?expandChildren=true,false,true,true", uri.toString());
252+
}
253+
210254
@Test
211255
void SetsPathParametersOfUUIDType() {
212256
// Arrange as the request builders would
@@ -239,6 +283,28 @@ void SetsQueryParametersOfUUIDType() {
239283
assertTrue(uriResult.toString().contains("?id=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e"));
240284
}
241285

286+
@Test
287+
void SetsQueryParametersOfUUIDTypedArray() throws IllegalStateException, URISyntaxException {
288+
// Arrange as the request builders would
289+
final RequestInformation requestInfo = new RequestInformation();
290+
requestInfo.httpMethod = HttpMethod.GET;
291+
requestInfo.urlTemplate = "http://localhost/{?datasetIds}";
292+
293+
final GetQueryParameters queryParameters = new GetQueryParameters();
294+
queryParameters.datasetIds = new UUID[] {
295+
UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e"),
296+
UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")
297+
};
298+
299+
// Act
300+
requestInfo.addQueryParameters(queryParameters);
301+
302+
// Assert
303+
final URI uri = requestInfo.getUri();
304+
assertEquals("http://localhost/?datasetIds=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e,a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e", uri.toString());
305+
}
306+
307+
242308
@Test
243309
void SetsParsableContent() {
244310
// Arrange as the request builders would
@@ -415,12 +481,25 @@ class GetQueryParameters implements QueryParameters {
415481

416482
@jakarta.annotation.Nullable public TestEnum[] datasets;
417483

484+
@jakarta.annotation.Nullable public UUID[] datasetIds;
485+
486+
/** Per-dataset boolean indicating whether to resolve its child datasets */
487+
@jakarta.annotation.Nullable public Boolean[] expandChildren;
488+
489+
/**
490+
* Minimum message ages as duration, per dataset
491+
*/
492+
@jakarta.annotation.Nullable public PeriodAndDuration[] messageAges;
493+
418494
@jakarta.annotation.Nonnull public Map<String, Object> toQueryParameters() {
419-
final Map<String, Object> allQueryParams = new HashMap();
495+
final Map<String, Object> allQueryParams = new HashMap<>();
420496
allQueryParams.put("%24select", select);
421497
allQueryParams.put("%24search", search);
422498
allQueryParams.put("dataset", dataset);
423499
allQueryParams.put("datasets", datasets);
500+
allQueryParams.put("datasetIds", datasetIds);
501+
allQueryParams.put("expandChildren", expandChildren);
502+
allQueryParams.put("periods", messageAges);
424503
return allQueryParams;
425504
}
426505
}

0 commit comments

Comments
 (0)