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());
}
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);
}
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());
}
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));
}
}
Aggregations