2424import com .google .appengine .tools .development .testing .LocalServiceTestHelper ;
2525import com .google .gson .JsonArray ;
2626import com .google .gson .JsonObject ;
27- import com .google .gson .JsonParser ;
2827import java .util .ArrayList ;
2928import org .junit .After ;
3029import org .junit .Before ;
@@ -37,9 +36,9 @@ public class TripCrudTest {
3736 private static final LocalServiceTestHelper DATASTORE_SERVICE_HELPER =
3837 new LocalServiceTestHelper (new LocalDatastoreServiceTestConfig ());
3938 private static final String TRIP_DATA =
40- "{\" isOptimized\" :true,\" searchText\" :\" Milano\" ,\" tripName\" :\" My Milan Trip\" ,\" centerLocation \" :{ \" lat \" : 0,\" lng \" :0} ,\" attractions\" :[{\" name\" :\" Milano Giuseppe\" ,\" photoUrl\" :\" 2234f23f23r133fqfqef\" ,\" routeIndex\" :0,\" lat\" :1,\" lng\" :1}]}" ;
39+ "{\" isOptimized\" :true,\" searchText\" :\" Milano\" ,\" tripName\" :\" My Milan Trip\" ,\" centerLng \" :0,\" centerLat \" :0,\" attractions\" :[{\" name\" :\" Milano Giuseppe\" ,\" photoUrl\" :\" 2234f23f23r133fqfqef\" ,\" routeIndex\" :0,\" lat\" :1,\" lng\" :1}]}" ;
4140 private static final String TRIP_DATA_2 =
42- "{\" isOptimized\" :true,\" searchText\" :\" Milano\" ,\" tripName\" :\" My Awesome Milan Trip\" ,\" centerLocation \" :{ \" lat \" : 0,\" lng \" :0} ,\" attractions\" :[{\" name\" :\" Milano Giuseppe\" ,\" photoUrl\" :\" 2234f23f23r133fqfqef\" ,\" routeIndex\" :0,\" lat\" :1,\" lng\" :1}]}" ;
41+ "{\" isOptimized\" :true,\" searchText\" :\" Milano\" ,\" tripName\" :\" My Awesome Milan Trip\" ,\" centerLng \" :0,\" centerLat \" :0,\" attractions\" :[{\" name\" :\" Milano Giuseppe\" ,\" photoUrl\" :\" 2234f23f23r133fqfqef\" ,\" routeIndex\" :0,\" lat\" :1,\" lng\" :1}]}" ;
4342 private static final String BAD_TRIP_DATA = "{\" isOptimized\" :true,\" searchText\" :\" Milano\" }" ;
4443
4544 private static final String EMAIL = "testEMAIL@gmail.com" ;
@@ -77,14 +76,14 @@ public void readTrip_noTripFound() {
7776 public void toEntity_returnsTripEntityFromJsonMatchingTripName () {
7877 Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
7978
80- assertEquals ("\" My Milan Trip\" " , (String ) tripEntityConverted .getProperty ("tripName" ));
79+ assertEquals ("My Milan Trip" , (String ) tripEntityConverted .getProperty ("tripName" ));
8180 }
8281
8382 @ Test
8483 public void toEntity_returnsTripEntityFromJsonMatchingSearchText () {
8584 Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
8685
87- assertEquals ("\" Milano\" " , (String ) tripEntityConverted .getProperty ("searchText" ));
86+ assertEquals ("Milano" , (String ) tripEntityConverted .getProperty ("searchText" ));
8887 }
8988
9089 @ Test
@@ -95,15 +94,17 @@ public void toEntity_returnsTripEntityFromJsonMatchingIsOptimized() {
9594 }
9695
9796 @ Test
98- public void toEntity_returnsTripEntityFromJsonMatchingCenterLocation () {
97+ public void toEntity_returnsTripEntityFromJsonMatchingCenterLat () {
9998 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 );
99+
100+ assertEquals (0 , tripEntityConverted .getProperty ("centerLat" ));
101+ }
102+
103+ @ Test
104+ public void toEntity_returnsTripEntityFromJsonMatchingCenterLng () {
105+ Entity tripEntityConverted = TripCrud .toEntity (TRIP_DATA , null , null );
106+
107+ assertEquals (0 , tripEntityConverted .getProperty ("centerLng" ));
107108 }
108109
109110 @ Test
@@ -112,7 +113,7 @@ public void toEntity_returnsTripEntityFromJsonMatchingAttractionName() {
112113 EmbeddedEntity readAttraction =
113114 (EmbeddedEntity ) ((ArrayList ) tripEntityConverted .getProperty ("attractions" )).get (0 );
114115
115- assertEquals ("\" Milano Giuseppe\" " , readAttraction .getProperty ("name" ));
116+ assertEquals ("Milano Giuseppe" , readAttraction .getProperty ("name" ));
116117 }
117118
118119 @ Test
@@ -121,7 +122,7 @@ public void toEntity_returnsTripEntityFromJsonMatchingAttractionPhotoUrl() {
121122 EmbeddedEntity readAttraction =
122123 (EmbeddedEntity ) ((ArrayList ) tripEntityConverted .getProperty ("attractions" )).get (0 );
123124
124- assertEquals ("\" 2234f23f23r133fqfqef\" " , readAttraction .getProperty ("photoUrl" ));
125+ assertEquals ("2234f23f23r133fqfqef" , readAttraction .getProperty ("photoUrl" ));
125126 }
126127
127128 @ Test
@@ -157,7 +158,7 @@ public void toJson_returnsTripJsonFromEntityMatchingSearchText() {
157158 Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
158159 JsonObject tripDataJson = TripCrud .toJson (tripEntity );
159160
160- assertEquals ("\" Milano\" " , tripDataJson .get ("searchText" ).getAsString ());
161+ assertEquals ("Milano" , tripDataJson .get ("searchText" ).getAsString ());
161162 }
162163
163164 @ Test
@@ -166,7 +167,7 @@ public void toJson_returnsTripJsonFromEntityMatchingTripName() {
166167 Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
167168 JsonObject tripDataJson = TripCrud .toJson (tripEntity );
168169
169- assertEquals ("\" My Milan Trip\" " , tripDataJson .get ("tripName" ).getAsString ());
170+ assertEquals ("My Milan Trip" , tripDataJson .get ("tripName" ).getAsString ());
170171 }
171172
172173 @ Test
@@ -194,15 +195,13 @@ public void toJson_returnsTripJsonFromEntityMatchingCenterLng() {
194195 assertEquals (0 , tripDataJson .get ("centerLng" ).getAsInt ());
195196 }
196197
197- // AttractionName , AttractionPhotoUrl, AttractionRouteIndex, AttractionLat,AttractionLng
198198 @ Test
199199 public void toJson_returnsTripJsonFromEntityMatchingAttractionName () {
200200 Entity userEntity = UserCrud .createUser (EMAIL );
201201 Entity tripEntity = TripCrud .createTrip (EMAIL , TRIP_DATA );
202202 JsonObject tripDataJson = TripCrud .toJson (tripEntity );
203203 JsonArray attractions = (JsonArray ) tripDataJson .get ("attractions" );
204- assertEquals (
205- "\" \\ \" Milano Giuseppe\\ \" \" " , ((JsonObject ) attractions .get (0 )).get ("name" ).toString ());
204+ assertEquals ("Milano Giuseppe" , ((JsonObject ) attractions .get (0 )).get ("name" ).getAsString ());
206205 }
207206
208207 @ Test
@@ -212,8 +211,7 @@ public void toJson_returnsTripJsonFromEntityMatchingAttractionPhotoUrl() {
212211 JsonObject tripDataJson = TripCrud .toJson (tripEntity );
213212 JsonArray attractions = (JsonArray ) tripDataJson .get ("attractions" );
214213 assertEquals (
215- "\" \\ \" 2234f23f23r133fqfqef\\ \" \" " ,
216- ((JsonObject ) attractions .get (0 )).get ("photoUrl" ).toString ());
214+ "2234f23f23r133fqfqef" , ((JsonObject ) attractions .get (0 )).get ("photoUrl" ).getAsString ());
217215 }
218216
219217 @ Test
@@ -250,7 +248,7 @@ public void updateTrip_returnsUpdatedTripNameForUpdatedEntity() {
250248 TripCrud .updateTrip (tripEntity .getKey ().getId (), TRIP_DATA_2 );
251249 Entity tripFound = TripCrud .readTrip (tripEntity .getKey ().getId ());
252250
253- assertEquals ("\" My Awesome Milan Trip\" " , (String ) tripFound .getProperty ("tripName" ));
251+ assertEquals ("My Awesome Milan Trip" , (String ) tripFound .getProperty ("tripName" ));
254252 }
255253
256254 @ Test
0 commit comments