use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method voidBody.
@Test
public void voidBody() throws Throwable {
Class<VoidMethods> clazz = VoidMethods.class;
Method headMethod = clazz.getDeclaredMethod("noBody", Callback.class);
HttpResponseMapper mapper = new HttpResponseMapper(headMethod, extractCallbackType(headMethod), logger);
MockHttpResponse httpResponse = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), new byte[5]);
Response<Boolean> restResponse = (Response<Boolean>) mapper.map(httpResponse, new JacksonSerder());
assertNull(restResponse.getValue());
assertTrue(httpResponse.isClosed());
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method dateTimeRfc1123EncodedContent.
@Test
public void dateTimeRfc1123EncodedContent() throws Throwable {
Class<DateTimeRfc1123EncodedContentMethods> clazz = DateTimeRfc1123EncodedContentMethods.class;
Method dateTimeRfc1123Method = clazz.getDeclaredMethod("dateTimeRfc1123", Callback.class);
HttpResponseMapper mapperDateTimeRfc1123 = new HttpResponseMapper(dateTimeRfc1123Method, extractCallbackType(dateTimeRfc1123Method), logger);
JacksonSerder jacksonSerder = new JacksonSerder();
OffsetDateTime offsetDateTime = OffsetDateTime.parse("1980-01-01T10:00:00Z");
DateTimeRfc1123 dateTimeRfc1123 = new DateTimeRfc1123(offsetDateTime);
String wireDateTimeRfc1123JsonString = '"' + dateTimeRfc1123.toString() + '"';
MockHttpResponse httpResponseDateTimeRfc1123 = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireDateTimeRfc1123JsonString.getBytes());
Response<OffsetDateTime> restResponseBase64OffsetDataTime = (Response<OffsetDateTime>) mapperDateTimeRfc1123.map(httpResponseDateTimeRfc1123, jacksonSerder);
OffsetDateTime dateTimeReceived = restResponseBase64OffsetDataTime.getValue();
assertNotNull(dateTimeReceived);
assertEquals(0, dateTimeReceived.compareTo(offsetDateTime));
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method base64EncodedContentMap.
@Test
public void base64EncodedContentMap() throws Throwable {
Class<Base64EncodedContentMethods> clazz = Base64EncodedContentMethods.class;
Method base64UrlListMethod = clazz.getDeclaredMethod("base64UrlMap", Callback.class);
HttpResponseMapper mapperBase64List = new HttpResponseMapper(base64UrlListMethod, extractCallbackType(base64UrlListMethod), logger);
JacksonSerder jacksonSerder = new JacksonSerder();
final String value0ToEncode = "hello azure android";
final String value1ToEncode = "hello azure android again";
Map<String, String> base64EncodedBytesMap = new HashMap<>();
base64EncodedBytesMap.put("v0", Base64Url.encode(value0ToEncode.getBytes()).toString());
base64EncodedBytesMap.put("v1", Base64Url.encode(value1ToEncode.getBytes()).toString());
String wireBase64EncodedList = jacksonSerder.serialize(base64EncodedBytesMap, SerdeEncoding.JSON);
MockHttpResponse httpResponseBase64DecodedBytesMap = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireBase64EncodedList.getBytes());
Response<Map<String, byte[]>> restResponseBase64DecodedBytesMap = (Response<Map<String, byte[]>>) mapperBase64List.map(httpResponseBase64DecodedBytesMap, jacksonSerder);
Map<String, byte[]> decodedBytesList = restResponseBase64DecodedBytesMap.getValue();
assertNotNull(decodedBytesList);
assertEquals(2, decodedBytesList.size());
assertArrayEquals(value0ToEncode.getBytes(), decodedBytesList.get("v0"));
assertArrayEquals(value1ToEncode.getBytes(), decodedBytesList.get("v1"));
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method deserializePojo.
@Test
public void deserializePojo() throws Throwable {
Class<DeserializePojoMethods> clazz = DeserializePojoMethods.class;
Method getPersonMethod = clazz.getDeclaredMethod("getPerson", Callback.class);
HttpResponseMapper mapper = new HttpResponseMapper(getPersonMethod, extractCallbackType(getPersonMethod), logger);
Person person = new Person("John Doe", 40, OffsetDateTime.parse("1980-01-01T10:00:00Z"));
JacksonSerder jacksonSerder = new JacksonSerder();
String wirePerson = jacksonSerder.serialize(person, SerdeEncoding.JSON);
MockHttpResponse httpResponse = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wirePerson.getBytes());
Response<Person> restStreamResponse = (Response<Person>) mapper.map(httpResponse, jacksonSerder);
Person receivedPerson = restStreamResponse.getValue();
assertEquals(person.getName(), receivedPerson.getName());
assertEquals(person.getAge(), receivedPerson.getAge());
assertEquals(person.getDob(), receivedPerson.getDob());
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpResponseMapperTests method head.
@Test
public void head() throws Throwable {
Class<HeadMethods> clazz = HeadMethods.class;
Method headMethod = clazz.getDeclaredMethod("resourceExists", Callback.class);
HttpResponseMapper mapper = new HttpResponseMapper(headMethod, extractCallbackType(headMethod), logger);
MockHttpResponse httpResponse = new MockHttpResponse(HttpMethod.HEAD, "https://raw.host.com", 200, new HttpHeaders(), new byte[0]);
Response<Boolean> restResponse = (Response<Boolean>) mapper.map(httpResponse, new JacksonSerder());
assertTrue(restResponse.getValue());
assertTrue(httpResponse.isClosed());
httpResponse = new MockHttpResponse(HttpMethod.HEAD, "https://raw.host.com", 401, new HttpHeaders(), new byte[0]);
restResponse = (Response<Boolean>) mapper.map(httpResponse, new JacksonSerder());
assertFalse(restResponse.getValue());
assertTrue(httpResponse.isClosed());
}
Aggregations