Search in sources :

Example 21 with DefaultSerializer

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

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

the class DefaultSerializerTests method testDoubleDeserialization.

@Test
public void testDoubleDeserialization() {
    final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
    final String source = " [{\"streamId\": \"12976\",\"startDateTime\": null,\"endDateTime\": null,\"streamDirection\": \"callerToCallee\",\"averageAudioDegradation\": null,\"averageJitter\": null,\"maxJitter\": null,\"averagePacketLossRate\": null,\"maxPacketLossRate\": null,\"averageRatioOfConcealedSamples\": null,\"maxRatioOfConcealedSamples\": null,\"averageRoundTripTime\": null,\"maxRoundTripTime\": null,\"packetUtilization\": 0,\"averageBandwidthEstimate\": null,\"wasMediaBypassed\": null,\"postForwardErrorCorrectionPacketLossRate\": null,\"averageVideoFrameLossPercentage\": null,\"averageReceivedFrameRate\": null,\"lowFrameRateRatio\": null,\"averageVideoPacketLossRate\": null,\"averageVideoFrameRate\": null,\"lowVideoProcessingCapabilityRatio\": null,\"averageAudioNetworkJitter\": null,\"maxAudioNetworkJitter\": null},{\"streamId\": \"3303\",\"startDateTime\": null,\"endDateTime\": null,\"streamDirection\": \"calleeToCaller\",\"averageAudioDegradation\": null,\"averageJitter\": \"PT0S\",\"maxJitter\": \"PT0S\",\"averagePacketLossRate\": 0,\"maxPacketLossRate\": 0,\"averageRatioOfConcealedSamples\": null,\"maxRatioOfConcealedSamples\": null,\"averageRoundTripTime\": \"PT0.02S\",\"maxRoundTripTime\": \"PT0.02S\",\"packetUtilization\": 1184,\"averageBandwidthEstimate\": null,\"wasMediaBypassed\": null,\"postForwardErrorCorrectionPacketLossRate\": 0,\"averageVideoFrameLossPercentage\": 0,\"averageReceivedFrameRate\": null,\"lowFrameRateRatio\": 0,\"averageVideoPacketLossRate\": null,\"averageVideoFrameRate\": 25.6,\"lowVideoProcessingCapabilityRatio\": null,\"averageAudioNetworkJitter\": null,\"maxAudioNetworkJitter\": null}]";
    final MediaStream[] result = serializer.deserializeObject(source, MediaStream[].class);
    assertNotNull(result);
    assertNotNull(result[0]);
    assertNotNull(result[1]);
    assertNull(result[0].averagePacketLossRate);
    assertEquals(0f, result[1].averagePacketLossRate, 0f);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) MediaStream(com.microsoft.graph.callrecords.models.MediaStream) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 23 with DefaultSerializer

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

the class DefaultSerializerTests method testEnumActionParameterDeserialization.

@Test
public void testEnumActionParameterDeserialization() throws IOException {
    final ArrayList<String> users = new ArrayList<String>();
    users.add("michael@chambele.onmicrosoft.com");
    final EnumSet<MailTipsType> mailtips = EnumSet.of(MailTipsType.MAILBOX_FULL_STATUS, MailTipsType.MAX_MESSAGE_SIZE);
    final UserGetMailTipsParameterSet body = UserGetMailTipsParameterSet.newBuilder().withEmailAddresses(users).withMailTipsOptions(mailtips).build();
    final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
    final String serialized = serializer.serializeObject(body);
    assertTrue(serialized.contains("mailboxFullStatus"), "result contains camelCasedValues");
    final UserGetMailTipsParameterSet deserialized = serializer.deserializeObject(serialized, UserGetMailTipsParameterSet.class);
    assertEquals(2, deserialized.mailTipsOptions.size());
}
Also used : UserGetMailTipsParameterSet(com.microsoft.graph.models.UserGetMailTipsParameterSet) DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) ArrayList(java.util.ArrayList) MailTipsType(com.microsoft.graph.models.MailTipsType) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 24 with DefaultSerializer

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

the class DefaultSerializerTests method testDeserializerWhenCasingRespondedByServiceIsWrong.

@Test
public void testDeserializerWhenCasingRespondedByServiceIsWrong() {
    final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
    final String source = "{\"@odata.context\": \"https://outlook.office.com/api/v2.0/$metadata#Users('e45f52f5-f2dd-4359-abc5-e74f2960b831')/Messages/AAMkAGQ0MjBmNWVkLTYxZjUtNDRmYi05Y2NiLTBlYjIwNzJjNmM1NgBGAAAAAAC6ff7latYeQqu_gLrhSAIhBwCF7iGjpaOmRqVwbZc-xXzwAAAAAAEMAACF7iGjpaOmRqVwbZc-xXzwAABQStA0AAABEgAQAFbGmeisbjtLnQdp7kC_9Fk=/AttachmentSessions/$entity\",\"ExpirationDateTime\": \"2020-10-06T14:23:42.1027521Z\",\"NextExpectedRanges\": [\"5242880\"]}";
    final UploadSession result = serializer.deserializeObject(source, UploadSession.class);
    assertNotNull(result);
    assertNotNull(result.nextExpectedRanges);
    assertTrue(result.nextExpectedRanges.size() > 0);
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) UploadSession(com.microsoft.graph.models.UploadSession) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.jupiter.api.Test)

Example 25 with DefaultSerializer

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

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