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));
}
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);
}
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));
}
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());
}
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));
}
Aggregations