use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method dateTimeRfc1123EncodedContentList.
@Test
public void dateTimeRfc1123EncodedContentList() throws Throwable {
Class<DateTimeRfc1123EncodedContentMethods> clazz = DateTimeRfc1123EncodedContentMethods.class;
Method dateTimeRfc1123ListMethod = clazz.getDeclaredMethod("dateTimeRfc1123List", Callback.class);
HttpResponseMapper mapperDateTimeRfc1123 = new HttpResponseMapper(dateTimeRfc1123ListMethod, extractCallbackType(dateTimeRfc1123ListMethod), logger);
JacksonSerder jacksonSerder = new JacksonSerder();
OffsetDateTime offsetDateTime0 = OffsetDateTime.parse("1980-01-01T10:00:00Z");
OffsetDateTime offsetDateTime1 = OffsetDateTime.parse("1981-01-01T10:00:00Z");
List<String> wireDateTimeRfc1123List = new ArrayList<>();
wireDateTimeRfc1123List.add(new DateTimeRfc1123(offsetDateTime0).toString());
wireDateTimeRfc1123List.add(new DateTimeRfc1123(offsetDateTime1).toString());
String wireDateTimeRfc1123JsonList = jacksonSerder.serialize(wireDateTimeRfc1123List, SerdeEncoding.JSON);
MockHttpResponse httpResponseDateTimeRfc1123 = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireDateTimeRfc1123JsonList.getBytes());
Response<List<OffsetDateTime>> httpResponseOffsetDateTimeList = (Response<List<OffsetDateTime>>) mapperDateTimeRfc1123.map(httpResponseDateTimeRfc1123, jacksonSerder);
List<OffsetDateTime> dateTimeListReceived = httpResponseOffsetDateTimeList.getValue();
assertNotNull(dateTimeListReceived);
assertEquals(2, dateTimeListReceived.size());
assertEquals(0, dateTimeListReceived.get(0).compareTo(offsetDateTime0));
assertEquals(0, dateTimeListReceived.get(1).compareTo(offsetDateTime1));
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method httpMethod.
@ParameterizedTest
@MethodSource("httpMethodSupplier")
public void httpMethod(Method method, HttpMethod expectedMethod, String expectedRelativePath, String expectedFullyQualifiedName) {
HttpRequestMapper mapper = new HttpRequestMapper("https://raw.host.com", method, new JacksonSerder());
assertEquals(expectedMethod, mapper.getHttpMethod());
assertEquals(expectedRelativePath, mapper.applyPathMappings(null));
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method headers.
@ParameterizedTest
@MethodSource("headersSupplier")
public void headers(Method method, HttpHeaders expectedHeaders) {
HttpRequestMapper mapper = new HttpRequestMapper("https://raw.host.com", method, new JacksonSerder());
HttpHeaders actual = new HttpHeaders();
mapper.applyHeaderMappings(null, actual);
for (HttpHeader header : actual) {
assertEquals(expectedHeaders.getValue(header.getName()), header.getValue());
}
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method knownError.
@Test
public void knownError() throws Throwable {
Class<KnownErrorMethods> clazz = KnownErrorMethods.class;
Method getError409Method = clazz.getDeclaredMethod("getError409", Callback.class);
HttpResponseMapper mapper = new HttpResponseMapper(getError409Method, extractCallbackType(getError409Method), logger);
ErrorData409 errorData409 = new ErrorData409(677, "retry after 10 sec");
JacksonSerder jacksonSerder = new JacksonSerder();
String wireErrorData409 = jacksonSerder.serialize(errorData409, SerdeEncoding.JSON);
MockHttpResponse httpResponse = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 409, new HttpHeaders(), wireErrorData409.getBytes());
Retry409Exception ex = null;
try {
mapper.map(httpResponse, jacksonSerder);
} catch (Retry409Exception e) {
ex = e;
}
assertNotNull(ex);
assertNotNull(ex.getValue());
ErrorData409 receivedErrorData409 = ex.getValue();
assertEquals(errorData409.getCode(), receivedErrorData409.getCode());
assertEquals(errorData409.getMessage(), receivedErrorData409.getMessage());
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method unixTimeEncodedContent.
@Test
public void unixTimeEncodedContent() throws Throwable {
Class<UnixTimeEncodedContentMethods> clazz = UnixTimeEncodedContentMethods.class;
Method unixTimeMethod = clazz.getDeclaredMethod("unixTime", Callback.class);
HttpResponseMapper mapperUnixTime = new HttpResponseMapper(unixTimeMethod, extractCallbackType(unixTimeMethod), logger);
JacksonSerder jacksonSerder = new JacksonSerder();
OffsetDateTime offsetDateTime = OffsetDateTime.parse("1980-01-01T10:00:00Z");
UnixTime unixTime = new UnixTime(offsetDateTime);
String wireUnixTimeJsonNumber = unixTime.toString();
MockHttpResponse httpResponseUnixTime = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireUnixTimeJsonNumber.getBytes());
Response<OffsetDateTime> restResponseUnixTime = (Response<OffsetDateTime>) mapperUnixTime.map(httpResponseUnixTime, jacksonSerder);
OffsetDateTime dateTimeReceived = restResponseUnixTime.getValue();
assertNotNull(dateTimeReceived);
assertEquals(0, dateTimeReceived.compareTo(offsetDateTime));
}
Aggregations