use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method hostSubstitution.
@ParameterizedTest
@MethodSource("hostSubstitutionSupplier")
public void hostSubstitution(Method method, String rawHost, Object[] arguments, String expectedUrl) {
HttpRequestMapper mapper = new HttpRequestMapper(rawHost, method, new JacksonSerder());
UrlBuilder urlBuilder = new UrlBuilder();
mapper.applySchemeAndHostMapping(arguments, urlBuilder);
assertEquals(expectedUrl, urlBuilder.toString());
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method pathSubstitution.
@ParameterizedTest
@MethodSource("pathSubstitutionSupplier")
public void pathSubstitution(Method method, Object[] arguments, String expectedPath) {
HttpRequestMapper mapper = new HttpRequestMapper("https://raw.host.com", method, new JacksonSerder());
assertEquals(expectedPath, mapper.applyPathMappings(arguments));
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method headerSubstitution.
@ParameterizedTest
@MethodSource("headerSubstitutionSupplier")
public void headerSubstitution(Method method, Object[] arguments, Map<String, String> expectedHeaders) {
HttpRequestMapper mapper = new HttpRequestMapper("https://raw.host.com", method, new JacksonSerder());
HttpHeaders actual = new HttpHeaders();
mapper.applyHeaderMappings(arguments, actual);
for (HttpHeader header : actual) {
assertEquals(expectedHeaders.get(header.getName()), header.getValue());
}
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method stringByteNoContentType.
@Test
public void stringByteNoContentType() throws NoSuchMethodException, IOException {
Class<StringByteNoContentTypeMethods> clazz = StringByteNoContentTypeMethods.class;
Method byteBodyMethod = clazz.getDeclaredMethod("byteBody", (new byte[0]).getClass(), Callback.class);
Method stringBodyMethod = clazz.getDeclaredMethod("stringBody", String.class, Callback.class);
HttpRequestMapper requestMapper = new HttpRequestMapper("https://raw.host.com", byteBodyMethod, new JacksonSerder());
byte[] bytesBody = new byte[2];
bytesBody[0] = 'A';
bytesBody[1] = 'B';
HttpRequest httpRequest = requestMapper.map(toObjectArray(bytesBody));
assertEquals("application/octet-stream", httpRequest.getHeaders().getValue("Content-Type"));
assertArrayEquals(bytesBody, httpRequest.getBody());
requestMapper = new HttpRequestMapper("https://raw.host.com", stringBodyMethod, new JacksonSerder());
httpRequest = requestMapper.map(toObjectArray("hello"));
assertEquals("application/octet-stream", httpRequest.getHeaders().getValue("Content-Type"));
assertEquals("hello", new String(httpRequest.getBody()));
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method dateTimeRfc1123EncodedContentMap.
@Test
public void dateTimeRfc1123EncodedContentMap() throws Throwable {
Class<DateTimeRfc1123EncodedContentMethods> clazz = DateTimeRfc1123EncodedContentMethods.class;
Method dateTimeRfc1123MapMethod = clazz.getDeclaredMethod("dateTimeRfc1123Map", Callback.class);
HttpResponseMapper mapperDateTimeRfc1123 = new HttpResponseMapper(dateTimeRfc1123MapMethod, extractCallbackType(dateTimeRfc1123MapMethod), logger);
JacksonSerder jacksonSerder = new JacksonSerder();
OffsetDateTime offsetDateTime0 = OffsetDateTime.parse("1980-01-01T10:00:00Z");
OffsetDateTime offsetDateTime1 = OffsetDateTime.parse("1981-01-01T10:00:00Z");
Map<String, String> wireDateTimeRfc1123Map = new HashMap<>();
wireDateTimeRfc1123Map.put("v0", new DateTimeRfc1123(offsetDateTime0).toString());
wireDateTimeRfc1123Map.put("v1", new DateTimeRfc1123(offsetDateTime1).toString());
String wireDateTimeRfc1123JsonMap = jacksonSerder.serialize(wireDateTimeRfc1123Map, SerdeEncoding.JSON);
MockHttpResponse httpResponseOffsetDateTimeMap = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireDateTimeRfc1123JsonMap.getBytes());
Response<Map<String, OffsetDateTime>> restResponseBase64OffsetDataTimeMap = (Response<Map<String, OffsetDateTime>>) mapperDateTimeRfc1123.map(httpResponseOffsetDateTimeMap, jacksonSerder);
Map<String, OffsetDateTime> dateTimeMapReceived = restResponseBase64OffsetDataTimeMap.getValue();
assertNotNull(dateTimeMapReceived);
assertEquals(2, dateTimeMapReceived.size());
assertEquals(0, dateTimeMapReceived.get("v0").compareTo(offsetDateTime0));
assertEquals(0, dateTimeMapReceived.get("v1").compareTo(offsetDateTime1));
}
Aggregations