Search in sources :

Example 36 with DefaultSerializer

use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java by microsoftgraph.

the class CollectionPageSerializerTests method deltaLinkEndtoEndTest.

@Test
public void deltaLinkEndtoEndTest() throws Exception {
    final String jsonString = "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users\",\"@odata.deltaLink\":\"https://graph.microsoft.com/v1.0/users/delta?$deltatoken=iW6HI4gRQf_CNwkN_2YR_wZsbUvU92el3RLdsbOM_4ZSC9GlnuDQvR2Xy0DDbLeJHde01ChMf5TmFQhCNFFwoil_n6kD8qDh5afldOw_CAj71jPUSP5Fwi3_PqeWMhN3LdX6oFBE5T-RyeUJaXsP9b4DLxYnmOrlb9EyOd4LP-kffRADZDN30aTt402EhIx-s0UWAEkKuSEVw2C2QyzqWQFO_PrC5wRXXVi6DiQf715QDXkxDmpNkgcS_jzINs2u9HbZzIpj170ZOx52vE_3eaI150SAd8qXOg9DEFPc5KUwAeOyEruCnqGuN07TuOc7L8eXa96_R-snlCNjB4R7qOWXQcbhRejm0izYC8w7g3uu1l3cPdhZURDsioOlO1xQGTa_upsvqMiVZBaNgMzZlRvy3GZmNTW-zQA1PFfKgwaVpWB8DcvG2CagEXE_Run7zFav00LHlKc8mEpQnfzYrbNct_sgpBGdK7-alRFg_-x0gHqMuzIznmYn6mQ_Nh_e-s57wtHDNgTYAKKMjlJlOoHig2G3aTHc4zdg0zQ_LFTi1EiIxh5a1tZQuGhxp2-ky4_kfnl0qekJvkchqHquWMRm0iQ4Dja3VEFI7AIBxhNG4VBDibOm_HZd7Jtm9nxT_bCI5ji5aaaFMvy16Ei11sAWf9390ly9-HscR2zr2RHu1hReVxkVt-nUA-lhXmxWBrM64NJUae0JbF5s68QWCEBhWvGBYYclMjMvQfHG5R7yJ7Kosp_Afxg4Vna1cvCXuHLBe0RiCCMg88dnQreMiFC6rWRmltuJ8Ryk7u_ZFU_g0mPc904dhnJ5SfUJRnjQAkL-4I5LSDgGOR3Xk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um9xzAjq_NXkabHBU56GpHf0G8RpnRTabIqXx-bCgfLlF9wwpuupu7hINPNmdBJI1ZyqiWqeWG7KD47k7OBtPQ7Yuq.ElDr4hD2Tb9PoZex2ONMAModMdlpfXqklPlnRuLo5QA\",\"value\":[]}";
    final DefaultSerializer defaultSerializer = new DefaultSerializer(logger);
    final UserDeltaCollectionResponse response = defaultSerializer.deserializeObject(jsonString, UserDeltaCollectionResponse.class);
    final UserDeltaCollectionPage page = new UserDeltaCollectionPage(response, null);
    assertNotNull(page.deltaLink);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) UserDeltaCollectionPage(com.microsoft.graph.requests.UserDeltaCollectionPage) UserDeltaCollectionResponse(com.microsoft.graph.requests.UserDeltaCollectionResponse) Test(org.junit.jupiter.api.Test)

Example 37 with DefaultSerializer

use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-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)

Example 38 with DefaultSerializer

use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java by microsoftgraph.

the class DefaultSerializerTests method testDriveItemChildAdditionalDataDeserialization.

/**
 * Make sure that deserializing a DriveItems also deserializes child additionalData
 *
 * @throws Exception If there is an exception during the test
 */
@Test
public void testDriveItemChildAdditionalDataDeserialization() throws Exception {
    final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
    String source = "{\n" + "    \"@odata.context\": \"https://graph.microsoft.com/v1.0/$metadata#users('02008492-3fec-4ce4-bb54-980ad856856f')/drive/root/children\",\n" + "    \"value\": [\n" + "        {\n" + "            \"createdBy\": {\n" + "                \"user\": {\n" + "                    \"email\": \"the@email.com\",\n" + "                    \"id\": \"02008492-3fec-4ce4-bb54-980ad856856f\",\n" + "                    \"displayName\": \"John Doe\"\n" + "                }\n" + "            }\n" + "        }\n" + "    ]\n" + "}";
    DriveItemDeltaCollectionResponse result = serializer.deserializeObject(source, DriveItemDeltaCollectionResponse.class);
    assertNotNull(result);
    assertNotNull(result.value);
    assertEquals(1, result.value.size());
    assertNotNull(result.value.get(0));
    assertNotNull(result.value.get(0).createdBy);
    assertNotNull(result.value.get(0).createdBy.user);
    assertNotNull(result.value.get(0).createdBy.user.additionalDataManager());
    assertNotNull(result.value.get(0).createdBy.user.additionalDataManager().get("email"));
    assertEquals("the@email.com", result.value.get(0).createdBy.user.additionalDataManager().get("email").getAsString());
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) DriveItemDeltaCollectionResponse(com.microsoft.graph.requests.DriveItemDeltaCollectionResponse) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 39 with DefaultSerializer

use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java by microsoftgraph.

the class DefaultSerializerTests method testDeserializeDerivedType.

@Test
public void testDeserializeDerivedType() throws Exception {
    final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
    final String source = "{\"@odata.context\": \"/attachments/$entity\",\"@odata.type\": \"#microsoft.graph.fileAttachment\",\"id\": \"AAMkAGQ0MjBmNWVkLTYxZjUtNDRmYi05Y2NiLTBlYjIwNzJjNmM1NgBGAAAAAAC6ff7latYeQqu_gLrhSAIhBwCF7iGjpaOmRqVwbZc-xXzwAAAAAAEMAACF7iGjpaOmRqVwbZc-xXzwAABQStA0AAABEgAQAFbGmeisbjtLnQdp7kC_9Fk=\",\"lastModifiedDateTime\": \"2018-01-23T21:50:22Z\",\"name\": \"Test Book.xlsx\",\"contentType\": \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\"size\": 8457,\"isInline\": false,\"contentId\": null,\"contentLocation\": null,\"contentBytes\": \"bytedata\"}";
    final Attachment result = serializer.deserializeObject(source, Attachment.class);
    assert (result instanceof FileAttachment);
    final FileAttachment fileAttachment = (FileAttachment) result;
    assertNotNull(fileAttachment.contentBytes);
    assertEquals("#microsoft.graph.fileAttachment", fileAttachment.oDataType);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) FileAttachment(com.microsoft.graph.models.FileAttachment) Attachment(com.microsoft.graph.models.Attachment) FileAttachment(com.microsoft.graph.models.FileAttachment) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 40 with DefaultSerializer

use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-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)

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