Search in sources :

Example 6 with HttpHeaders

use of com.azure.android.core.http.HttpHeaders in project azure-sdk-for-android by Azure.

the class HttpResponseMapperTests method unixTimeEncodedContentList.

@Test
public void unixTimeEncodedContentList() throws Throwable {
    Class<UnixTimeEncodedContentMethods> clazz = UnixTimeEncodedContentMethods.class;
    Method unixTimeListMethod = clazz.getDeclaredMethod("unixTimeList", Callback.class);
    HttpResponseMapper mapperUnixTime = new HttpResponseMapper(unixTimeListMethod, extractCallbackType(unixTimeListMethod), logger);
    JacksonSerder jacksonSerder = new JacksonSerder();
    OffsetDateTime offsetDateTime0 = OffsetDateTime.parse("1980-01-01T10:00:00Z");
    OffsetDateTime offsetDateTime1 = OffsetDateTime.parse("1981-01-01T10:00:00Z");
    List<Integer> wireUnixTimeList = new ArrayList<>();
    wireUnixTimeList.add(Integer.parseInt(new UnixTime(offsetDateTime0).toString()));
    wireUnixTimeList.add(Integer.parseInt(new UnixTime(offsetDateTime1).toString()));
    String wireUnixTimeJsonList = jacksonSerder.serialize(wireUnixTimeList, SerdeEncoding.JSON);
    MockHttpResponse httpResponseOffsetDateTimeList = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireUnixTimeJsonList.getBytes());
    Response<List<OffsetDateTime>> restResponseBase64OffsetDataTimeList = (Response<List<OffsetDateTime>>) mapperUnixTime.map(httpResponseOffsetDateTimeList, jacksonSerder);
    List<OffsetDateTime> dateTimeListReceived = restResponseBase64OffsetDataTimeList.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) UnixTime(com.azure.android.core.util.UnixTime) OffsetDateTime(org.threeten.bp.OffsetDateTime) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with HttpHeaders

use of com.azure.android.core.http.HttpHeaders in project azure-sdk-for-android by Azure.

the class HttpResponseMapperTests method streamAndBytes.

@Test
public void streamAndBytes() throws Throwable {
    byte[] wireBytes = new byte[20];
    new Random().nextBytes(wireBytes);
    Class<StreamAndBytesMethods> clazz = StreamAndBytesMethods.class;
    final Method photoStreamMethod = clazz.getDeclaredMethod("photoStream", Callback.class);
    HttpResponseMapper mapper1 = new HttpResponseMapper(photoStreamMethod, extractCallbackType(photoStreamMethod), logger);
    MockHttpResponse httpResponse1 = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireBytes);
    Response<InputStream> restStreamResponse = (Response<InputStream>) mapper1.map(httpResponse1, new JacksonSerder());
    InputStream photoStream = restStreamResponse.getValue();
    assertNotNull(photoStream);
    assertFalse(httpResponse1.isClosed());
    assertArrayEquals(wireBytes, streamToBytes(photoStream));
    final Method photoBytesMethod = clazz.getDeclaredMethod("photoBytes", Callback.class);
    HttpResponseMapper mapper2 = new HttpResponseMapper(photoBytesMethod, extractCallbackType(photoBytesMethod), logger);
    MockHttpResponse httpResponse2 = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireBytes);
    Response<byte[]> restBytesResponse = (Response<byte[]>) mapper2.map(httpResponse2, new JacksonSerder());
    byte[] photoBytes = restBytesResponse.getValue();
    assertNotNull(photoBytes);
    assertFalse(httpResponse2.isClosed());
    assertArrayEquals(wireBytes, photoBytes);
}
Also used : HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) 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) Random(java.util.Random) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with HttpHeaders

use of com.azure.android.core.http.HttpHeaders in project azure-sdk-for-android by Azure.

the class HttpResponseMapperTests method unixTimeEncodedContentMap.

@Test
public void unixTimeEncodedContentMap() throws Throwable {
    Class<UnixTimeEncodedContentMethods> clazz = UnixTimeEncodedContentMethods.class;
    Method unixTimeMapMethod = clazz.getDeclaredMethod("unixTimeMap", Callback.class);
    HttpResponseMapper mapperDateTimeRfc1123 = new HttpResponseMapper(unixTimeMapMethod, extractCallbackType(unixTimeMapMethod), 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, Integer> wireUnixTimeMap = new HashMap<>();
    wireUnixTimeMap.put("v0", Integer.parseInt(new UnixTime(offsetDateTime0).toString()));
    wireUnixTimeMap.put("v1", Integer.parseInt(new UnixTime(offsetDateTime1).toString()));
    String wireDateTimeRfc1123JsonMap = jacksonSerder.serialize(wireUnixTimeMap, SerdeEncoding.JSON);
    MockHttpResponse httpResponseDateTimeOffsetMap = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireDateTimeRfc1123JsonMap.getBytes());
    Response<Map<String, OffsetDateTime>> restResponseOffsetDataTimeMap = (Response<Map<String, OffsetDateTime>>) mapperDateTimeRfc1123.map(httpResponseDateTimeOffsetMap, jacksonSerder);
    Map<String, OffsetDateTime> dateTimeMapReceived = restResponseOffsetDataTimeMap.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) UnixTime(com.azure.android.core.util.UnixTime) OffsetDateTime(org.threeten.bp.OffsetDateTime) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with HttpHeaders

use of com.azure.android.core.http.HttpHeaders 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 10 with HttpHeaders

use of com.azure.android.core.http.HttpHeaders 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)

Aggregations

HttpHeaders (com.azure.android.core.http.HttpHeaders)37 Test (org.junit.jupiter.api.Test)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 HttpResponse (com.azure.android.core.http.HttpResponse)20 JacksonSerder (com.azure.android.core.serde.jackson.JacksonSerder)17 HttpMethod (com.azure.android.core.http.HttpMethod)16 Method (java.lang.reflect.Method)16 PagedResponse (com.azure.android.core.rest.util.paging.PagedResponse)13 CountDownLatch (java.util.concurrent.CountDownLatch)9 HashMap (java.util.HashMap)7 HttpRequest (com.azure.android.core.http.HttpRequest)6 HttpBinJSON (com.azure.android.core.test.implementation.entities.HttpBinJSON)6 Map (java.util.Map)6 OffsetDateTime (org.threeten.bp.OffsetDateTime)6 Response (com.azure.android.core.rest.Response)5 StreamResponse (com.azure.android.core.rest.StreamResponse)5 List (java.util.List)5 HttpCallback (com.azure.android.core.http.HttpCallback)4 HttpHeader (com.azure.android.core.http.HttpHeader)4 HttpPipeline (com.azure.android.core.http.HttpPipeline)4