Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for LocalDate and OffsetDateTime in RequestInformation #1586

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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 @@ -20,6 +20,7 @@
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -473,6 +474,10 @@ private static Object getSanitizedValues(Object value) {
return ((ValuedEnum) value).getValue();
} else if (value instanceof UUID) {
return value.toString();
} else if (value instanceof OffsetDateTime) {
return ((OffsetDateTime) value).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
} else if (value instanceof LocalDate) {
return ((LocalDate) value).format(DateTimeFormatter.ISO_LOCAL_DATE);
} else {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
Expand Down Expand Up @@ -73,6 +74,23 @@ void SetsPathParametersOfDateTimeOffsetType() {
assertTrue(uriResult.toString().contains("toDateTime='2022-08-02T00%3A00%3A00Z'"));
}

@Test
void SetsPathParametersOfLocalDateType() {
final RequestInformation requestInfo = new RequestInformation();
requestInfo.httpMethod = HttpMethod.GET;
requestInfo.urlTemplate = "http://localhost/getCalendarView(startLocalDate='{startLocalDate}',endLocalDate='{endLocalDate}')";

final LocalDate startLocalDate = LocalDate.of(2022, 8, 1);
final LocalDate endLocalDate = LocalDate.of(2022, 8, 2);

requestInfo.pathParameters.put("startLocalDate", startLocalDate);
requestInfo.pathParameters.put("endLocalDate", endLocalDate);

var uriResult = assertDoesNotThrow(() -> requestInfo.getUri());
assertTrue(uriResult.toString().contains("startLocalDate='2022-08-01'"));
assertTrue(uriResult.toString().contains("endLocalDate='2022-08-02'"));
}

@Test
void ExpandQueryParametersAfterPathParams() {
// Arrange as the request builders would
Expand Down