Skip to content

Commit ce5673e

Browse files
committed
- adds a unit test for properties wwrong casing
1 parent af2f106 commit ce5673e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/test/java/com/microsoft/graph/serializer/DefaultSerializerTests.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
56

67
import com.google.gson.JsonElement;
78
import com.google.gson.JsonObject;
@@ -17,6 +18,7 @@
1718
import com.microsoft.graph.models.extensions.User;
1819
import com.microsoft.graph.models.generated.RecurrenceRangeType;
1920
import com.microsoft.graph.requests.extensions.DriveItemDeltaCollectionResponse;
21+
import com.microsoft.graph.models.extensions.UploadSession;
2022
import org.junit.Test;
2123

2224
public class DefaultSerializerTests {
@@ -127,14 +129,14 @@ public void testResponseHeaders() throws Exception {
127129
@Test
128130
public void testDeserializeDerivedType() throws Exception {
129131
final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
130-
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\"}";
131-
Attachment result = serializer.deserializeObject(source, Attachment.class);
132+
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\"}";
133+
final Attachment result = serializer.deserializeObject(source, Attachment.class);
132134

133135
assert(result instanceof FileAttachment);
134136

135-
FileAttachment fileAttachment = (FileAttachment) result;
137+
final FileAttachment fileAttachment = (FileAttachment) result;
136138
assertNotNull(fileAttachment.contentBytes);
137-
JsonObject o = fileAttachment.getRawObject();
139+
final JsonObject o = fileAttachment.getRawObject();
138140
assertNotNull(o);
139141
assertEquals("#microsoft.graph.fileAttachment", o. get("@odata.type").getAsString());
140142
}
@@ -153,6 +155,15 @@ public void testSerializerCanSerializeVoidWithoutEmittingWarning() {
153155
assertEquals(t.x, t2.x);
154156
assertEquals(t.y, t2.y);
155157
}
158+
@Test
159+
public void testDeserializerWhenCasingRespondedByServiceIsWrong() {
160+
final DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());
161+
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\"]}";
162+
final UploadSession result = serializer.deserializeObject(source, UploadSession.class);
163+
assertNotNull(result);
164+
assertNotNull(result.nextExpectedRanges);
165+
assertTrue(result.nextExpectedRanges.size() > 0);
166+
}
156167

157168
public static final class HasVoidMember {
158169
@SerializedName("x")

0 commit comments

Comments
 (0)