Search in sources :

Example 11 with JacksonSerder

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());
}
Also used : HttpResponse(com.azure.android.core.http.HttpResponse) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) Method(java.lang.reflect.Method) HttpMethod(com.azure.android.core.http.HttpMethod) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with JacksonSerder

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));
}
Also used : HttpResponse(com.azure.android.core.http.HttpResponse) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) OffsetDateTime(org.threeten.bp.OffsetDateTime) DateTimeRfc1123(com.azure.android.core.util.DateTimeRfc1123) Method(java.lang.reflect.Method) HttpMethod(com.azure.android.core.http.HttpMethod) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with JacksonSerder

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"));
}
Also used : HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) HttpMethod(com.azure.android.core.http.HttpMethod) HttpResponse(com.azure.android.core.http.HttpResponse) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with JacksonSerder

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());
}
Also used : HttpResponse(com.azure.android.core.http.HttpResponse) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) Method(java.lang.reflect.Method) HttpMethod(com.azure.android.core.http.HttpMethod) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with JacksonSerder

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());
}
Also used : HttpResponse(com.azure.android.core.http.HttpResponse) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) Method(java.lang.reflect.Method) HttpMethod(com.azure.android.core.http.HttpMethod) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

JacksonSerder (com.azure.android.core.serde.jackson.JacksonSerder)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 Test (org.junit.jupiter.api.Test)23 Method (java.lang.reflect.Method)20 HttpMethod (com.azure.android.core.http.HttpMethod)18 HttpHeaders (com.azure.android.core.http.HttpHeaders)17 HttpResponse (com.azure.android.core.http.HttpResponse)16 PagedResponse (com.azure.android.core.rest.util.paging.PagedResponse)13 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 OffsetDateTime (org.threeten.bp.OffsetDateTime)6 HttpPipeline (com.azure.android.core.http.HttpPipeline)3 HttpPipelineBuilder (com.azure.android.core.http.HttpPipelineBuilder)3 HttpRequest (com.azure.android.core.http.HttpRequest)3 UrlBuilder (com.azure.android.core.http.util.UrlBuilder)3 DateTimeRfc1123 (com.azure.android.core.util.DateTimeRfc1123)3 UnixTime (com.azure.android.core.util.UnixTime)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3