Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,14 @@ private static Object getSanitizedValues(Object value) {
return null;
}
if (value.getClass().isArray()) {
if (((Object[]) value).length > 0 && ((Object[]) value)[0] instanceof ValuedEnum) {
if (((Object[]) value).length > 0) {
if (((Object[]) value)[0].getClass().isArray()) {
throw new IllegalArgumentException("multidimensional arrays are not supported");
}

final ArrayList<String> result = new ArrayList<>();
for (final Object item : (Object[]) value) {
result.add(((ValuedEnum) item).getValue());
result.add(getSanitizedValues(item).toString());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

class RequestInformationTest {
@Test
Expand Down Expand Up @@ -131,6 +132,29 @@ void SetsPathParametersOfPeriodAndDurationType() {
assertTrue(uriResult.toString().contains("seatingDuration='PT30M'"));
}


@Test
void SetsQueryParametersOfPeriodAndDurationTypedArray() throws IllegalStateException, URISyntaxException {
// Arrange as the request builders would
final RequestInformation requestInfo = new RequestInformation();
requestInfo.httpMethod = HttpMethod.GET;
requestInfo.urlTemplate = "http://localhost/{?periods}";

final GetQueryParameters queryParameters = new GetQueryParameters();
queryParameters.messageAges = new PeriodAndDuration[] {
PeriodAndDuration.parse("PT30M"),
PeriodAndDuration.parse("PT20M"),
PeriodAndDuration.parse("PT1H20M")
};

// Act
requestInfo.addQueryParameters(queryParameters);

// Assert
final URI uri = requestInfo.getUri();
assertEquals("http://localhost/?periods=PT30M,PT20M,PT1H20M", uri.toString());
}

@Test
void ExpandQueryParametersAfterPathParams() {
// Arrange as the request builders would
Expand Down Expand Up @@ -207,6 +231,26 @@ void SetsPathParametersOfBooleanType() {
assertTrue(uriResult.toString().contains("count=true"));
}

@Test
void SetsQueryParametersOfBooleanTypedArray() throws IllegalStateException, URISyntaxException {
// Arrange as the request builders would
final RequestInformation requestInfo = new RequestInformation();
requestInfo.httpMethod = HttpMethod.GET;
requestInfo.urlTemplate = "http://localhost/{?expandChildren}";

final GetQueryParameters queryParameters = new GetQueryParameters();
queryParameters.expandChildren = new Boolean[] {
true, false, true, true
};

// Act
requestInfo.addQueryParameters(queryParameters);

// Assert
final URI uri = requestInfo.getUri();
assertEquals("http://localhost/?expandChildren=true,false,true,true", uri.toString());
}

@Test
void SetsPathParametersOfUUIDType() {
// Arrange as the request builders would
Expand Down Expand Up @@ -239,6 +283,28 @@ void SetsQueryParametersOfUUIDType() {
assertTrue(uriResult.toString().contains("?id=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e"));
}

@Test
void SetsQueryParametersOfUUIDTypedArray() throws IllegalStateException, URISyntaxException {
// Arrange as the request builders would
final RequestInformation requestInfo = new RequestInformation();
requestInfo.httpMethod = HttpMethod.GET;
requestInfo.urlTemplate = "http://localhost/{?datasetIds}";

final GetQueryParameters queryParameters = new GetQueryParameters();
queryParameters.datasetIds = new UUID[] {
UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e"),
UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")
};

// Act
requestInfo.addQueryParameters(queryParameters);

// Assert
final URI uri = requestInfo.getUri();
assertEquals("http://localhost/?datasetIds=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e,a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e", uri.toString());
}


@Test
void SetsParsableContent() {
// Arrange as the request builders would
Expand Down Expand Up @@ -415,12 +481,25 @@ class GetQueryParameters implements QueryParameters {

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

@jakarta.annotation.Nullable public UUID[] datasetIds;

/** Per-dataset boolean indicating whether to resolve its child datasets */
@jakarta.annotation.Nullable public Boolean[] expandChildren;

/**
* Minimum message ages as duration, per dataset
*/
@jakarta.annotation.Nullable public PeriodAndDuration[] messageAges;

@jakarta.annotation.Nonnull public Map<String, Object> toQueryParameters() {
final Map<String, Object> allQueryParams = new HashMap();
final Map<String, Object> allQueryParams = new HashMap<>();
allQueryParams.put("%24select", select);
allQueryParams.put("%24search", search);
allQueryParams.put("dataset", dataset);
allQueryParams.put("datasets", datasets);
allQueryParams.put("datasetIds", datasetIds);
allQueryParams.put("expandChildren", expandChildren);
allQueryParams.put("periods", messageAges);
return allQueryParams;
}
}