1616
1717import static org .junit .Assert .assertEquals ;
1818import static org .junit .Assert .assertNull ;
19+ import static org .junit .Assert .assertTrue ;
1920
21+ import com .google .appengine .api .datastore .EmbeddedEntity ;
2022import com .google .appengine .api .datastore .Entity ;
2123import com .google .appengine .tools .development .testing .LocalDatastoreServiceTestConfig ;
2224import com .google .appengine .tools .development .testing .LocalServiceTestHelper ;
25+ import com .google .gson .JsonArray ;
2326import com .google .gson .JsonObject ;
27+ import com .google .gson .JsonParser ;
28+ import java .util .ArrayList ;
2429import org .junit .After ;
2530import org .junit .Before ;
2631import org .junit .Test ;
@@ -75,6 +80,77 @@ public void toEntity_returnsTripEntityFromJsonMatchingTripName() {
7580 assertEquals ("\" My Milan Trip\" " , (String ) tripEntityConverted .getProperty ("tripName" ));
7681 }
7782
83+ @ Test
84+ public void toEntity_returnsTripEntityFromJsonMatchingSearchText () {
85+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
86+
87+ assertEquals ("\" Milano\" " , (String ) tripEntityConverted .getProperty ("searchText" ));
88+ }
89+
90+ @ Test
91+ public void toEntity_returnsTripEntityFromJsonMatchingIsOptimized () {
92+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
93+
94+ assertTrue ((Boolean ) tripEntityConverted .getProperty ("isOptimized" ));
95+ }
96+
97+ @ Test
98+ public void toEntity_returnsTripEntityFromJsonMatchingCenterLocation () {
99+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
100+ JsonObject centerLocation = new JsonObject ();
101+ centerLocation .addProperty ("lat" , 0 );
102+ centerLocation .addProperty ("lng" , 0 );
103+ JsonParser parser = new JsonParser ();
104+ JsonObject readLocation =
105+ (JsonObject ) parser .parse (tripEntityConverted .getProperty ("centerLocation" ).toString ());
106+ assertEquals (centerLocation , readLocation );
107+ }
108+
109+ @ Test
110+ public void toEntity_returnsTripEntityFromJsonMatchingAttractionName () {
111+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
112+ EmbeddedEntity readAttraction =
113+ (EmbeddedEntity ) ((ArrayList ) tripEntityConverted .getProperty ("attractions" )).get (0 );
114+
115+ assertEquals ("\" Milano Giuseppe\" " , readAttraction .getProperty ("name" ));
116+ }
117+
118+ @ Test
119+ public void toEntity_returnsTripEntityFromJsonMatchingAttractionPhotoUrl () {
120+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
121+ EmbeddedEntity readAttraction =
122+ (EmbeddedEntity ) ((ArrayList ) tripEntityConverted .getProperty ("attractions" )).get (0 );
123+
124+ assertEquals ("\" 2234f23f23r133fqfqef\" " , readAttraction .getProperty ("photoUrl" ));
125+ }
126+
127+ @ Test
128+ public void toEntity_returnsTripEntityFromJsonMatchingAttractionRouteIndex () {
129+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
130+ EmbeddedEntity readAttraction =
131+ (EmbeddedEntity ) ((ArrayList ) tripEntityConverted .getProperty ("attractions" )).get (0 );
132+
133+ assertEquals (0 , readAttraction .getProperty ("routeIndex" ));
134+ }
135+
136+ @ Test
137+ public void toEntity_returnsTripEntityFromJsonMatchingAttractionLat () {
138+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
139+ EmbeddedEntity readAttraction =
140+ (EmbeddedEntity ) ((ArrayList ) tripEntityConverted .getProperty ("attractions" )).get (0 );
141+
142+ assertEquals (1 , Integer .parseInt ((String ) readAttraction .getProperty ("lat" )));
143+ }
144+
145+ @ Test
146+ public void toEntity_returnsTripEntityFromJsonMatchingAttractionLng () {
147+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
148+ EmbeddedEntity readAttraction =
149+ (EmbeddedEntity ) ((ArrayList ) tripEntityConverted .getProperty ("attractions" )).get (0 );
150+
151+ assertEquals (1 , Integer .parseInt ((String ) readAttraction .getProperty ("lng" )));
152+ }
153+
78154 @ Test
79155 public void toJson_returnsTripJsonFromEntityMatchingSearchText () {
80156 Entity userEntity = UserCrud .createUser (EMAIL );
@@ -84,6 +160,89 @@ public void toJson_returnsTripJsonFromEntityMatchingSearchText() {
84160 assertEquals ("\" Milano\" " , tripDataJson .get ("searchText" ).getAsString ());
85161 }
86162
163+ @ Test
164+ public void toJson_returnsTripJsonFromEntityMatchingTripName () {
165+ Entity userEntity = UserCrud .createUser (EMAIL );
166+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
167+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
168+
169+ assertEquals ("\" My Milan Trip\" " , tripDataJson .get ("tripName" ).getAsString ());
170+ }
171+
172+ @ Test
173+ public void toJson_returnsTripJsonFromEntityMatchingIsOptimized () {
174+ Entity userEntity = UserCrud .createUser (EMAIL );
175+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
176+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
177+
178+ assertTrue (tripDataJson .get ("isOptimized" ).getAsBoolean ());
179+ }
180+
181+ @ Test
182+ public void toJson_returnsTripJsonFromEntityMatchingCenterLat () {
183+ Entity userEntity = UserCrud .createUser (EMAIL );
184+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
185+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
186+ assertEquals (0 , tripDataJson .get ("centerLat" ).getAsInt ());
187+ }
188+
189+ @ Test
190+ public void toJson_returnsTripJsonFromEntityMatchingCenterLng () {
191+ Entity userEntity = UserCrud .createUser (EMAIL );
192+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
193+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
194+ assertEquals (0 , tripDataJson .get ("centerLng" ).getAsInt ());
195+ }
196+
197+ // AttractionName , AttractionPhotoUrl, AttractionRouteIndex, AttractionLat,AttractionLng
198+ @ Test
199+ public void toJson_returnsTripJsonFromEntityMatchingAttractionName () {
200+ Entity userEntity = UserCrud .createUser (EMAIL );
201+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
202+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
203+ JsonArray attractions = (JsonArray ) tripDataJson .get ("attractions" );
204+ assertEquals (
205+ "\" \\ \" Milano Giuseppe\\ \" \" " , ((JsonObject ) attractions .get (0 )).get ("name" ).toString ());
206+ }
207+
208+ @ Test
209+ public void toJson_returnsTripJsonFromEntityMatchingAttractionPhotoUrl () {
210+ Entity userEntity = UserCrud .createUser (EMAIL );
211+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
212+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
213+ JsonArray attractions = (JsonArray ) tripDataJson .get ("attractions" );
214+ assertEquals (
215+ "\" \\ \" 2234f23f23r133fqfqef\\ \" \" " ,
216+ ((JsonObject ) attractions .get (0 )).get ("photoUrl" ).toString ());
217+ }
218+
219+ @ Test
220+ public void toJson_returnsTripJsonFromEntityMatchingAttractionRouteIndex () {
221+ Entity userEntity = UserCrud .createUser (EMAIL );
222+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
223+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
224+ JsonArray attractions = (JsonArray ) tripDataJson .get ("attractions" );
225+ assertEquals (0 , ((JsonObject ) attractions .get (0 )).get ("routeIndex" ).getAsInt ());
226+ }
227+
228+ @ Test
229+ public void toJson_returnsTripJsonFromEntityMatchingAttractionLat () {
230+ Entity userEntity = UserCrud .createUser (EMAIL );
231+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
232+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
233+ JsonArray attractions = (JsonArray ) tripDataJson .get ("attractions" );
234+ assertEquals (1 , ((JsonObject ) attractions .get (0 )).get ("lat" ).getAsInt ());
235+ }
236+
237+ @ Test
238+ public void toJson_returnsTripJsonFromEntityMatchingAttractionLng () {
239+ Entity userEntity = UserCrud .createUser (EMAIL );
240+ Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
241+ JsonObject tripDataJson = TripCrud .toJson (tripEntity );
242+ JsonArray attractions = (JsonArray ) tripDataJson .get ("attractions" );
243+ assertEquals (1 , ((JsonObject ) attractions .get (0 )).get ("lng" ).getAsInt ());
244+ }
245+
87246 @ Test
88247 public void updateTrip_returnsUpdatedTripNameForUpdatedEntity () {
89248 Entity userEntity = UserCrud .createUser (EMAIL );
0 commit comments