Search in sources :

Example 26 with JacksonSerder

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));
}
Also used : HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) ArrayList(java.util.ArrayList) 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) OffsetDateTime(org.threeten.bp.OffsetDateTime) DateTimeRfc1123(com.azure.android.core.util.DateTimeRfc1123) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with JacksonSerder

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));
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 28 with JacksonSerder

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());
    }
}
Also used : HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) HttpHeader(com.azure.android.core.http.HttpHeader) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with JacksonSerder

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());
}
Also used : 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 30 with JacksonSerder

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));
}
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) UnixTime(com.azure.android.core.util.UnixTime) OffsetDateTime(org.threeten.bp.OffsetDateTime) 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