Search in sources :

Example 1 with DefaultLogger

use of com.microsoft.graph.logger.DefaultLogger in project msgraph-sdk-java by microsoftgraph.

the class DefaultClientConfig method getLogger.

/**
 * Gets the logger
 *
 * @return the logger
 */
public ILogger getLogger() {
    if (logger == null) {
        logger = new DefaultLogger();
        logger.logDebug("Created DefaultLogger");
    }
    return logger;
}
Also used : DefaultLogger(com.microsoft.graph.logger.DefaultLogger)

Example 2 with DefaultLogger

use of com.microsoft.graph.logger.DefaultLogger in project msgraph-sdk-java by microsoftgraph.

the class DefaultSeralizerTests method testRecurrenceRangeSerialization.

@Test
public void testRecurrenceRangeSerialization() throws Exception {
    final String expected = "{\"type\":\"endDate\",\"startDate\":\"2016-04-25\",\"endDate\":\"2016-05-25\",\"recurrenceTimeZone\":\"PST\",\"numberOfOccurrences\":4}";
    final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
    BaseRecurrenceRange brr = new BaseRecurrenceRange();
    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 : BaseRecurrenceRange(com.microsoft.graph.models.generated.BaseRecurrenceRange) DateOnly(com.microsoft.graph.models.extensions.DateOnly) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.Test)

Example 3 with DefaultLogger

use of com.microsoft.graph.logger.DefaultLogger in project msgraph-sdk-java by microsoftgraph.

the class DefaultSeralizerTests 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 : Drive(com.microsoft.graph.models.extensions.Drive) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.Test)

Example 4 with DefaultLogger

use of com.microsoft.graph.logger.DefaultLogger in project msgraph-sdk-java by microsoftgraph.

the class DefaultSeralizerTests method testDeserializeDerivedType.

@Test
public void testDeserializeDerivedType() throws Exception {
    final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
    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\"}";
    Attachment result = serializer.deserializeObject(source, Attachment.class);
    assert (result instanceof FileAttachment);
    FileAttachment fileAttachment = (FileAttachment) result;
    assertNotNull(fileAttachment.contentBytes);
    JsonObject o = fileAttachment.getRawObject();
    assertNotNull(o);
    assertEquals("#microsoft.graph.fileAttachment", o.get("@odata.type").getAsString());
}
Also used : FileAttachment(com.microsoft.graph.models.extensions.FileAttachment) JsonObject(com.google.gson.JsonObject) Attachment(com.microsoft.graph.models.extensions.Attachment) FileAttachment(com.microsoft.graph.models.extensions.FileAttachment) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.Test)

Example 5 with DefaultLogger

use of com.microsoft.graph.logger.DefaultLogger in project msgraph-sdk-java by microsoftgraph.

the class DefaultSeralizerTests method testResponseHeaders.

@Test
public void testResponseHeaders() throws Exception {
    MockConnection connection = new MockConnection(null);
    final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
    User user = serializer.deserializeObject("{\"id\":\"1\"}", User.class, connection.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 : User(com.microsoft.graph.models.extensions.User) JsonElement(com.google.gson.JsonElement) MockConnection(com.microsoft.graph.http.MockConnection) DefaultLogger(com.microsoft.graph.logger.DefaultLogger) Test(org.junit.Test)

Aggregations

DefaultLogger (com.microsoft.graph.logger.DefaultLogger)8 Test (org.junit.Test)7 BaseRecurrenceRange (com.microsoft.graph.models.generated.BaseRecurrenceRange)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 MockAuthenticationProvider (com.microsoft.graph.authentication.MockAuthenticationProvider)1 MockConnection (com.microsoft.graph.http.MockConnection)1 ILogger (com.microsoft.graph.logger.ILogger)1 Attachment (com.microsoft.graph.models.extensions.Attachment)1 DateOnly (com.microsoft.graph.models.extensions.DateOnly)1 Drive (com.microsoft.graph.models.extensions.Drive)1 FileAttachment (com.microsoft.graph.models.extensions.FileAttachment)1 User (com.microsoft.graph.models.extensions.User)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1