22
33import static org .junit .Assert .assertEquals ;
44
5+ import java .nio .charset .StandardCharsets ;
56import java .util .ArrayList ;
67import java .util .Arrays ;
78
@@ -31,7 +32,7 @@ public void setUp() {
3132
3233 @ Test
3334 public void testAttachmentCollectionPageSerialization () throws Exception {
34- String expectedString = "[{\" contentBytes\" :\" data \" ,\" name\" :\" document.pdf\" ,\" @odata.type\" :\" #microsoft.graph.fileAttachment\" ,\" id\" :\" 54321\" },{\" item\" :{\" end\" :{\" dateTime\" :\" 2018-11-18T07:30:26.544Z\" ,\" timeZone\" :\" UTC\" },\" start\" :{\" dateTime\" :\" 2018-10-16T06:15:26.544Z\" ,\" timeZone\" :\" UTC\" },\" subject\" :\" Test Event Subject\" ,\" @odata.type\" :\" microsoft.graph.event\" ,\" id\" :\" 1234\" },\" name\" :\" Holiday event\" ,\" @odata.type\" :\" #microsoft.graph.itemAttachment\" },{\" item\" :{\" displayName\" :\" displayname\" ,\" mobilePhone\" :\" 123456890\" ,\" @odata.type\" :\" microsoft.graph.contact\" },\" name\" :\" Attachment name\" ,\" @odata.type\" :\" #microsoft.graph.itemAttachment\" }]" ;
35+ String expectedString = "[{\" contentBytes\" :\" ZGF0YQ== \" ,\" name\" :\" document.pdf\" ,\" @odata.type\" :\" #microsoft.graph.fileAttachment\" ,\" id\" :\" 54321\" },{\" item\" :{\" end\" :{\" dateTime\" :\" 2018-11-18T07:30:26.544Z\" ,\" timeZone\" :\" UTC\" },\" start\" :{\" dateTime\" :\" 2018-10-16T06:15:26.544Z\" ,\" timeZone\" :\" UTC\" },\" subject\" :\" Test Event Subject\" ,\" @odata.type\" :\" microsoft.graph.event\" ,\" id\" :\" 1234\" },\" name\" :\" Holiday event\" ,\" @odata.type\" :\" #microsoft.graph.itemAttachment\" },{\" item\" :{\" displayName\" :\" displayname\" ,\" mobilePhone\" :\" 123456890\" ,\" @odata.type\" :\" microsoft.graph.contact\" },\" name\" :\" Attachment name\" ,\" @odata.type\" :\" #microsoft.graph.itemAttachment\" }]" ;
3536 AttachmentCollectionResponse response = new AttachmentCollectionResponse ();
3637 response .value = Arrays .asList (getFileAttachment (),getItemAttachmentWithEvent (),getItemAttachmentWithContact ());
3738 AttachmentCollectionPage attachmentCollectionPage = new AttachmentCollectionPage (response , null );
@@ -42,7 +43,7 @@ public void testAttachmentCollectionPageSerialization() throws Exception {
4243
4344 @ Test
4445 public void testAttachmentCollectionPageDeserialization () throws Exception {
45- String jsonString = "[{\" contentBytes\" :\" data \" ,\" name\" :\" document.pdf\" ,\" @odata.type\" :\" #microsoft.graph.fileAttachment\" ,\" id\" :\" 54321\" },{\" @odata.type\" :\" #microsoft.graph.itemAttachment\" ,\" name\" :\" Holiday event\" ,\" id\" :null,\" isInline\" :null,\" size\" :null,\" item\" :{\" subject\" :\" Test Event Subject\" ,\" start\" :{\" dateTime\" :\" 2018-10-16T06:15:26.544Z\" ,\" timeZone\" :\" UTC\" },\" end\" :{\" dateTime\" :\" 2018-11-18T07:30:26.544Z\" ,\" timeZone\" :\" UTC\" },\" @odata.type\" :\" microsoft.graph.event\" ,\" id\" :\" 1234\" }},{\" @odata.type\" :\" #microsoft.graph.itemAttachment\" ,\" name\" :\" Attachment name\" ,\" id\" :null,\" isInline\" :null,\" size\" :null,\" item\" :{\" displayName\" :\" displayname\" ,\" mobilePhone\" :\" 123456890\" ,\" @odata.type\" :\" microsoft.graph.contact\" }}]" ;
46+ String jsonString = "[{\" contentBytes\" :\" ZGF0YQ== \" ,\" name\" :\" document.pdf\" ,\" @odata.type\" :\" #microsoft.graph.fileAttachment\" ,\" id\" :\" 54321\" },{\" @odata.type\" :\" #microsoft.graph.itemAttachment\" ,\" name\" :\" Holiday event\" ,\" id\" :null,\" isInline\" :null,\" size\" :null,\" item\" :{\" subject\" :\" Test Event Subject\" ,\" start\" :{\" dateTime\" :\" 2018-10-16T06:15:26.544Z\" ,\" timeZone\" :\" UTC\" },\" end\" :{\" dateTime\" :\" 2018-11-18T07:30:26.544Z\" ,\" timeZone\" :\" UTC\" },\" @odata.type\" :\" microsoft.graph.event\" ,\" id\" :\" 1234\" }},{\" @odata.type\" :\" #microsoft.graph.itemAttachment\" ,\" name\" :\" Attachment name\" ,\" id\" :null,\" isInline\" :null,\" size\" :null,\" item\" :{\" displayName\" :\" displayname\" ,\" mobilePhone\" :\" 123456890\" ,\" @odata.type\" :\" microsoft.graph.contact\" }}]" ;
4647 JsonElement jsonElement = JsonParser .parseString (jsonString );
4748 AttachmentCollectionPage attachmentCollectionPage = AttachmentCollectionPageSerializer .deserialize (jsonElement , logger );
4849 for (Attachment attachment : attachmentCollectionPage .getCurrentPage ()) {
@@ -71,7 +72,7 @@ else if(itemAttachment.item instanceof Contact) {
7172 private FileAttachment getFileAttachment () throws Exception {
7273 FileAttachment fileAttachment = new FileAttachment ();
7374 fileAttachment .name = "document.pdf" ;
74- fileAttachment .contentBytes = ByteArraySerializer . deserialize ( "data" );
75+ fileAttachment .contentBytes = "data" . getBytes ( StandardCharsets . UTF_8 );
7576 fileAttachment .oDataType = "#microsoft.graph.fileAttachment" ;
7677 fileAttachment .id ="54321" ;
7778 return fileAttachment ;
0 commit comments