use of com.azure.android.core.util.UnixTime 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.util.UnixTime 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.util.UnixTime in project azure-sdk-for-android by Azure.
the class HttpResponseMapper method decodeContent.
private Object decodeContent(final Object encodedContent, final Type encodedType, final Type decodeType) {
if (decodeType == byte[].class) {
if (encodedType == Base64Url.class) {
return ((Base64Url) encodedContent).decodedBytes();
}
} else if (decodeType == OffsetDateTime.class) {
if (encodedType == DateTimeRfc1123.class) {
return ((DateTimeRfc1123) encodedContent).getDateTime();
} else if (encodedType == UnixTime.class) {
return ((UnixTime) encodedContent).getDateTime();
}
} else if (TypeUtil.isTypeOrSubTypeOf(decodeType, List.class)) {
final Type decodeElementType = TypeUtil.getTypeArgument(decodeType);
@SuppressWarnings("unchecked") final List<Object> list = (List<Object>) encodedContent;
final int size = list.size();
for (int i = 0; i < size; ++i) {
final Object encodedElement = list.get(i);
final Object decodedElement = decodeContent(encodedElement, encodedType, decodeElementType);
if (encodedElement != decodedElement) {
list.set(i, decodedElement);
}
}
return list;
} else if (TypeUtil.isTypeOrSubTypeOf(decodeType, Map.class)) {
final Type decodeValueType = TypeUtil.getTypeArguments(decodeType)[1];
@SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) encodedContent;
final Set<Map.Entry<String, Object>> encodedEntries = map.entrySet();
for (Map.Entry<String, Object> encodedEntry : encodedEntries) {
final Object encodedValue = encodedEntry.getValue();
final Object decodedValue = decodeContent(encodedValue, encodedType, decodeValueType);
if (encodedValue != decodedValue) {
map.put(encodedEntry.getKey(), decodedValue);
}
}
return map;
}
return encodedContent;
}
use of com.azure.android.core.util.UnixTime 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));
}
Aggregations