44import static org .junit .Assert .assertNotNull ;
55import static org .junit .Assert .assertTrue ;
66
7+ import java .io .IOException ;
8+ import java .util .ArrayList ;
9+ import java .util .EnumSet ;
10+
711import com .google .gson .JsonElement ;
812import com .google .gson .JsonObject ;
913import com .google .gson .annotations .Expose ;
1014import com .google .gson .annotations .SerializedName ;
1115import com .microsoft .graph .callrecords .models .extensions .MediaStream ;
16+ import com .microsoft .graph .functional .TestBase ;
17+ import com .microsoft .graph .http .HttpMethod ;
1218import com .microsoft .graph .http .MockConnection ;
1319import com .microsoft .graph .logger .DefaultLogger ;
1420import com .microsoft .graph .models .extensions .Attachment ;
1723import com .microsoft .graph .models .extensions .FileAttachment ;
1824import com .microsoft .graph .models .extensions .RecurrenceRange ;
1925import com .microsoft .graph .models .extensions .User ;
26+ import com .microsoft .graph .models .extensions .UserGetMailTipsBody ;
27+ import com .microsoft .graph .models .generated .MailTipsType ;
2028import com .microsoft .graph .models .generated .RecurrenceRangeType ;
2129import com .microsoft .graph .requests .extensions .DriveItemDeltaCollectionResponse ;
2230import com .microsoft .graph .models .extensions .UploadSession ;
31+
32+ import org .junit .Assert ;
2333import org .junit .Test ;
2434
35+ import okhttp3 .Request ;
36+ import okio .Buffer ;
37+
2538public class DefaultSerializerTests {
2639
2740 /**
@@ -111,19 +124,19 @@ public void testRecurrenceRangeSerialization() throws Exception {
111124 assertNotNull (jsonOut );
112125 assertEquals (expected , jsonOut );
113126 }
114-
127+
115128 @ Test
116129 public void testResponseHeaders () throws Exception {
117130 MockConnection connection = new MockConnection (null );
118131 final DefaultSerializer serializer = new DefaultSerializer (new DefaultLogger ());
119132 User user = serializer .deserializeObject ("{\" id\" :\" 1\" }" , User .class , connection .getResponseHeaders ());
120-
133+
121134 JsonElement responseHeaders = user .additionalDataManager ().get ("graphResponseHeaders" );
122135 assertNotNull (responseHeaders );
123-
136+
124137 JsonElement responseHeader = responseHeaders .getAsJsonObject ().get ("header1" );
125138 assertNotNull (responseHeader );
126-
139+
127140 assertEquals ("value1" , responseHeader .getAsJsonArray ().get (0 ).getAsString ());
128141 }
129142
@@ -132,25 +145,25 @@ public void testDeserializeDerivedType() throws Exception {
132145 final DefaultSerializer serializer = new DefaultSerializer (new DefaultLogger ());
133146 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\" }" ;
134147 final Attachment result = serializer .deserializeObject (source , Attachment .class );
135-
148+
136149 assert (result instanceof FileAttachment );
137-
150+
138151 final FileAttachment fileAttachment = (FileAttachment ) result ;
139152 assertNotNull (fileAttachment .contentBytes );
140153 final JsonObject o = fileAttachment .getRawObject ();
141154 assertNotNull (o );
142155 assertEquals ("#microsoft.graph.fileAttachment" , o . get ("@odata.type" ).getAsString ());
143156 }
144-
157+
145158 @ Test
146159 public void testSerializerCanSerializeVoidWithoutEmittingWarning () {
147160 // Unfortunately does not assert for existence of Java 9 illegal access warnings
148- // which seem to written to the console without use of System.err/System.out (so cannot be captured AFAIK).
161+ // which seem to written to the console without use of System.err/System.out (so cannot be captured AFAIK).
149162 // @davidmoten
150163 final DefaultSerializer serializer = new DefaultSerializer (new DefaultLogger ());
151164 HasVoidMember t = new HasVoidMember ();
152165 String json = serializer .serializeObject (t );
153- // this line will emit a warning from Java 9 about illegal access to the constructor of Void
166+ // this line will emit a warning from Java 9 about illegal access to the constructor of Void
154167 // if gson TypeAdapterFactory is not handling Void properly
155168 HasVoidMember t2 = serializer .deserializeObject (json , HasVoidMember .class );
156169 assertEquals (t .x , t2 .x );
@@ -173,12 +186,28 @@ public void testDurationDeserialization() {
173186 assertNotNull (result );
174187 assertNotNull (result .maxRoundTripTime );
175188 }
176-
189+ @ Test
190+ public void testEnumActionParameterDeserialization () throws IOException {
191+ final ArrayList <String > users = new ArrayList <String >();
192+ 193+ final EnumSet <MailTipsType > mailtips = EnumSet .of (MailTipsType .MAILBOX_FULL_STATUS , MailTipsType .MAX_MESSAGE_SIZE );
194+ final UserGetMailTipsBody body = new UserGetMailTipsBody ();
195+ body .emailAddresses = users ;
196+ body .mailTipsOptions = mailtips ;
197+ final DefaultSerializer serializer = new DefaultSerializer (new DefaultLogger ());
198+ final String serialized = serializer .serializeObject (body );
199+ Assert .assertTrue ("result contains camelCasedValues" , serialized .contains ("mailboxFullStatus" ));
200+
201+ final UserGetMailTipsBody deserialized = serializer .deserializeObject (serialized , UserGetMailTipsBody .class );
202+
203+ Assert .assertEquals (2 , deserialized .mailTipsOptions .size ());
204+ }
205+
177206 public static final class HasVoidMember {
178207 @ SerializedName ("x" )
179208 @ Expose
180209 int x = 1 ;
181-
210+
182211 @ SerializedName ("y" )
183212 @ Expose
184213 Void y ;
0 commit comments