Search in sources :

Example 41 with DefaultSerializer

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);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) JsonObject(com.google.gson.JsonObject) UserActivity(com.microsoft.graph.models.UserActivity) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 42 with DefaultSerializer

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);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) Drive(com.microsoft.graph.models.Drive) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 43 with DefaultSerializer

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);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) RecurrenceRange(com.microsoft.graph.models.RecurrenceRange) DateOnly(com.microsoft.graph.core.DateOnly) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 44 with DefaultSerializer

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);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) RecurrenceRange(com.microsoft.graph.models.RecurrenceRange) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 45 with DefaultSerializer

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());
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) User(com.microsoft.graph.models.User) JsonElement(com.google.gson.JsonElement) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultSerializer (com.microsoft.graph.serializer.DefaultSerializer)59 Test (org.junit.jupiter.api.Test)54 DefaultLogger (com.microsoft.graph.logger.DefaultLogger)32 IHttpRequest (com.microsoft.graph.http.IHttpRequest)6 URL (java.net.URL)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ILogger (com.microsoft.graph.logger.ILogger)5 JsonElement (com.google.gson.JsonElement)4 MediaStream (com.microsoft.graph.callrecords.models.MediaStream)4 GraphErrorResponse (com.microsoft.graph.http.GraphErrorResponse)4 PlannerChecklistItem (com.microsoft.graph.models.PlannerChecklistItem)4 PlannerTaskDetails (com.microsoft.graph.models.PlannerTaskDetails)4 RecurrenceRange (com.microsoft.graph.models.RecurrenceRange)4 User (com.microsoft.graph.models.User)4 ISerializer (com.microsoft.graph.serializer.ISerializer)4 GraphServiceException (com.microsoft.graph.http.GraphServiceException)3 OkHttpClient (okhttp3.OkHttpClient)3 Request (okhttp3.Request)3 JsonObject (com.google.gson.JsonObject)2 DateOnly (com.microsoft.graph.core.DateOnly)2