use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-beta-sdk-java by microsoftgraph.
the class CustomRequestTests method testCustomPut.
/**
* Test PUT with a custom request for both serialized and JSON content
*/
@Test
public void testCustomPut() {
DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
String str = "{ \"appActivityId\": \"/article?12345\", \"activitySourceHost\": \"https://www.contoso.com\", \"userTimezone\": \"Africa/Casablanca\"," + " \"appDisplayName\": \"Contoso, Ltd.\", \"activationUrl\": \"https://www.contoso.com/article?id=12345\", \"contentUrl\": \"https://www.contoso.com/article?id=12345\", " + "\"fallbackUrl\": \"https://www.contoso.com/article?id=12345\", \"contentInfo\": { \"@context\": \"https://schema.org\", \"@type\": \"Article\", \"author\": \"Jennifer Booth\", " + "\"name\": \"How to Tie a Reef Knot\" }, \"visualElements\": { \"attribution\": { \"iconUrl\": \"https://www.contoso.com/icon\", \"alternateText\": \"Contoso, Ltd.\", " + "\"addImageQuery\": false }, \"description\": \"How to Tie a Reef Knot. A step-by-step visual guide to the art of nautical knot-tying.\", \"backgroundColor\": \"#ff0000\"," + " \"displayText\": \"Contoso How-To: How to Tie a Reef Knot\", \"content\": { \"$schema\": \"https://adaptivecards.io/schemas/adaptive-card.json\", \"type\": \"AdaptiveCard\"," + " \"body\": [{ \"type\": \"TextBlock\", \"text\": \"Contoso MainPage\" }] } } }";
JsonObject response = testBase.graphClient.customRequest("/me/activities/%2Farticle%3F12346").buildRequest().put(JsonParser.parseString(str).getAsJsonObject()).getAsJsonObject();
UserActivity userActivity = serializer.deserializeObject(str, UserActivity.class);
UserActivity responseWithClass = testBase.graphClient.customRequest("/me/activities/2", UserActivity.class).buildRequest().put(userActivity);
assertNotNull(response);
assertNotNull(responseWithClass);
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-beta-sdk-java by microsoftgraph.
the class DefaultSerializerTests method testDriveDeserialization.
/**
* Make sure that deserializing a Drive also returns members from BaseDrive
*
* @throws Exception If there is an exception during the test
*/
@Test
public void testDriveDeserialization() throws Exception {
final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
String source = "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#drives/$entity\",\"id\":\"8bf6ae90006c4a4c\",\"driveType\":\"personal\",\"owner\":{\"user\":{\"displayName\":\"Peter\",\"id\":\"8bf6ae90006c4a4c\"}},\"quota\":{\"deleted\":1485718314,\"remaining\":983887466461,\"state\":\"normal\",\"total\":1142461300736,\"used\":158573834275}}";
Drive result = serializer.deserializeObject(source, Drive.class);
assertNotNull(result);
assertEquals("personal", result.driveType);
assertEquals(Long.valueOf(983887466461L), result.quota.remaining);
assertEquals("8bf6ae90006c4a4c", result.id);
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-beta-sdk-java by microsoftgraph.
the class DefaultSerializerTests method testRecurrenceRangeSerialization.
@Test
public void testRecurrenceRangeSerialization() throws Exception {
final String expected = "{\"endDate\":\"2016-05-25\",\"numberOfOccurrences\":4,\"recurrenceTimeZone\":\"PST\",\"startDate\":\"2016-04-25\",\"type\":\"endDate\"}";
final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
RecurrenceRange brr = new RecurrenceRange();
brr.type = RecurrenceRangeType.END_DATE;
brr.startDate = new DateOnly(2016, 4, 25);
brr.endDate = new DateOnly(2016, 5, 25);
brr.recurrenceTimeZone = "PST";
brr.numberOfOccurrences = 4;
String jsonOut = serializer.serializeObject(brr);
assertNotNull(jsonOut);
assertEquals(expected, jsonOut);
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-beta-sdk-java by microsoftgraph.
the class DefaultSerializerTests method testRecurrenceRangeDeserialization.
@Test
public void testRecurrenceRangeDeserialization() throws Exception {
final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
String source = "{\n" + " \"type\": \"noEnd\",\n" + " \"startDate\": \"2016-04-27\",\n" + " \"endDate\": \"0001-01-01\",\n" + " \"recurrenceTimeZone\": \"China Standard Time\",\n" + " \"numberOfOccurrences\": 0\n" + "}";
RecurrenceRange baseRecurrenceRange = serializer.deserializeObject(source, RecurrenceRange.class);
assertNotNull(source);
assertEquals(RecurrenceRangeType.NO_END, baseRecurrenceRange.type);
assertEquals("2016-04-27", baseRecurrenceRange.startDate.toString());
assertEquals("0001-01-01", baseRecurrenceRange.endDate.toString());
assertEquals("China Standard Time", baseRecurrenceRange.recurrenceTimeZone);
assertEquals(Integer.valueOf(0), baseRecurrenceRange.numberOfOccurrences);
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-beta-sdk-java by microsoftgraph.
the class DefaultSerializerTests method testResponseHeaders.
@Test
public void testResponseHeaders() throws Exception {
final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
User user = serializer.deserializeObject("{\"id\":\"1\"}", User.class, getResponseHeaders());
JsonElement responseHeaders = user.additionalDataManager().get("graphResponseHeaders");
assertNotNull(responseHeaders);
JsonElement responseHeader = responseHeaders.getAsJsonObject().get("header1");
assertNotNull(responseHeader);
assertEquals("value1", responseHeader.getAsJsonArray().get(0).getAsString());
}
Aggregations