Search in sources :

Example 56 with DefaultSerializer

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

the class BatchResponseContentTest method testInvalidBatchResponseContentWithMalformedResponse.

@Test
public void testInvalidBatchResponseContentWithMalformedResponse() {
    String invalidResponsebody = "{responses: [] }";
    BatchResponseContent batchresponse = new DefaultSerializer(mock(ILogger.class)).deserializeObject(invalidResponsebody, BatchResponseContent.class);
    assertTrue(batchresponse.responses.isEmpty());
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) Test(org.junit.jupiter.api.Test)

Example 57 with DefaultSerializer

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

the class BatchResponseContentTest method testGetBatchResponseContentByID.

@Test
public void testGetBatchResponseContentByID() throws IOException {
    String responsebody = "{\"responses\": [{\"id\": \"1\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\"businessPhones\":[\"8006427676\"],\"displayName\":\"MOD Administrator\",\"givenName\":\"MOD\",\"jobTitle\":null,\"mail\":\"admin@M365x751487.OnMicrosoft.com\",\"mobilePhone\":\"425-882-1032\",\"officeLocation\":null,\"preferredLanguage\":\"en-US\",\"surname\":\"Administrator\",\"userPrincipalName\":\"admin@M365x751487.onmicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\"}},{\"id\": \"2\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-store, no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#drives/$entity\",\"createdDateTime\":\"2019-01-12T09:05:38Z\",\"description\":\"\",\"id\":\"b!nlu9o5I9g0y8gsHXfUM_bPTZ0oM_wVNArHM5R4-VkHLlnxx5SpqHRJledwfICP9f\",\"lastModifiedDateTime\":\"2019-03-06T06:59:04Z\",\"name\":\"OneDrive\",\"webUrl\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents\",\"driveType\":\"business\",\"createdBy\":{\"user\":{\"displayName\":\"System Account\"}},\"lastModifiedBy\":{\"user\":{\"displayName\":\"System Account\"}},\"owner\":{\"user\":{\"email\":\"admin@M365x751487.OnMicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"quota\":{\"deleted\":0,\"remaining\":1099509670098,\"state\":\"normal\",\"total\":1099511627776,\"used\":30324}}},{\"id\": \"3\",\"status\":201,\"headers\" : {\"Location\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"Preference-Applied\":\"odata.include-annotations=*\",\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c')/onenote/notebooks/$entity\",\"id\":\"1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"self\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"createdDateTime\":\"2019-03-06T08:08:09Z\",\"displayName\":\"My Notebook -442293399\",\"lastModifiedDateTime\":\"2019-03-06T08:08:09Z\",\"isDefault\":false,\"userRole\":\"Owner\",\"isShared\":false,\"sectionsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sections\",\"sectionGroupsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sectionGroups\",\"createdBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"lastModifiedBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"links\":{\"oneNoteClientUrl\":{\"href\":\"onenote:https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"},\"oneNoteWebUrl\":{\"href\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"}}}}]}";
    BatchResponseContent batchresponse = new DefaultSerializer(mock(ILogger.class)).deserializeObject(responsebody, BatchResponseContent.class);
    BatchResponseStep<?> response = batchresponse.getResponseById("1");
    assertTrue(response != null);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) Test(org.junit.jupiter.api.Test)

Example 58 with DefaultSerializer

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

the class BaseClientTests method testCustomRequest.

@Test
public void testCustomRequest() {
    baseClient.setHttpProvider(new CoreHttpProvider(new DefaultSerializer(mLogger), mLogger, new OkHttpClient.Builder().build()));
    final CustomRequestBuilder<JsonElement> simpleRequestBuilder = baseClient.customRequest("");
    assertNotNull(simpleRequestBuilder);
    final CustomRequestBuilder<String> stringRequestBuilder = baseClient.customRequest("", String.class);
    assertNotNull(stringRequestBuilder);
    final CustomRequest<String> abs = stringRequestBuilder.buildRequest();
    abs.setHttpMethod(HttpMethod.POST);
    final Request nat = abs.getHttpRequest("somestring");
    assertEquals("\"somestring\"", getStringFromRequestBody(nat));
    assertEquals("application", nat.body().contentType().type());
    assertEquals("json", nat.body().contentType().subtype());
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) OkHttpClient(okhttp3.OkHttpClient) JsonElement(com.google.gson.JsonElement) Request(okhttp3.Request) CustomRequest(com.microsoft.graph.http.CustomRequest) CoreHttpProvider(com.microsoft.graph.http.CoreHttpProvider) Test(org.junit.jupiter.api.Test)

Example 59 with DefaultSerializer

use of com.microsoft.graph.serializer.DefaultSerializer in project java-spring-webhooks-sample by microsoftgraph.

the class ListenController method processNewChannelMessageNotification.

/**
 * Processes a new channel message notification by decrypting the included resource data
 *
 * @param notification the new channel message notification
 * @param subscription the matching subscription record
 */
private void processNewChannelMessageNotification(@NonNull final ChangeNotification notification, @NonNull final SubscriptionRecord subscription) {
    Objects.requireNonNull(notification);
    Objects.requireNonNull(subscription);
    // Decrypt the encrypted key from the notification
    final var decryptedKey = certificateStore.getEncryptionKey(notification.encryptedContent.dataKey);
    // Validate the signature
    if (certificateStore.isDataSignatureValid(decryptedKey, notification.encryptedContent.data, notification.encryptedContent.dataSignature)) {
        // Decrypt the data using the decrypted key
        final var decryptedData = certificateStore.getDecryptedData(decryptedKey, notification.encryptedContent.data);
        // Deserialize the decrypted JSON into a ChatMessage
        final var serializer = new DefaultSerializer(new DefaultLogger());
        final var chatMessage = serializer.deserializeObject(decryptedData, ChatMessage.class);
        // Send the information to subscribed clients
        socketIONamespace.getRoomOperations(subscription.subscriptionId).sendEvent("notificationReceived", new NewChatMessageNotification(chatMessage));
    }
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) DefaultLogger(com.microsoft.graph.logger.DefaultLogger)

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