Search in sources :

Example 1 with JacksonSerder

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

Example 2 with JacksonSerder

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

Example 3 with JacksonSerder

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());
    }
}
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 4 with JacksonSerder

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()));
}
Also used : HttpRequest(com.azure.android.core.http.HttpRequest) 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 5 with JacksonSerder

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