33import static junit .framework .TestCase .assertEquals ;
44
55import android .content .Context ;
6+ import android .util .Log ;
67
78import androidx .test .core .app .ApplicationProvider ;
89
1314import org .junit .Test ;
1415import static org .junit .Assert .*;
1516
17+ import java .io .IOException ;
1618import java .text .ParseException ;
1719import java .text .SimpleDateFormat ;
1820import java .util .ArrayList ;
@@ -44,7 +46,7 @@ public void testFindEntry() throws InterruptedException {
4446 public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
4547 assertNull ("There should be no error" , error );
4648 assertNotNull ("Entry should have been fetched" , queryResult );
47- assertEquals ("source5 " , queryResult .getResultObjects ().get (0 ).getTitle ());
49+ assertEquals ("variant-base-product " , queryResult .getResultObjects ().get (0 ).getTitle ());
4850 // Unlock the latch to allow the test to proceed
4951 latch .countDown ();
5052 }
@@ -124,18 +126,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
124126 @ Test
125127 public void testFindLessThan () throws InterruptedException {
126128 final CountDownLatch latch = new CountDownLatch (1 );
127- final Query query = stack .contentType ("numbers_content_type" ).query ();
128- int value = 11 ;
129- query .lessThan ("num_field " , value );
129+ final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
130+ int value = 90 ;
131+ query .lessThan ("price " , value );
130132 query .find (new QueryResultsCallBack () {
131133 @ Override
132134 public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
133135 assertNull ("There should be no error" , error );
134136 assertNotNull ("Entry should have been fetched" , queryResult );
135137 List <Entry > entries = queryResult .getResultObjects ();
136138 for (int i = 0 ; i < entries .size (); i ++) {
137- Integer currNum = (int )entries .get (i ).get ("num_field " );
138- assertTrue ("Curr num_field should be less than the value" , currNum < value );
139+ Integer currNum = (int )entries .get (i ).get ("price " );
140+ assertTrue ("Curr price should be less than the value" , currNum < value );
139141 }
140142 latch .countDown ();
141143 }
@@ -147,18 +149,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
147149 @ Test
148150 public void testFindLessThanOrEqualTo () throws InterruptedException {
149151 final CountDownLatch latch = new CountDownLatch (1 );
150- final Query query = stack .contentType ("numbers_content_type" ).query ();
151- int value = 11 ;
152- query .lessThanOrEqualTo ("num_field " , value );
152+ final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
153+ int value = 90 ;
154+ query .lessThanOrEqualTo ("price " , value );
153155 query .find (new QueryResultsCallBack () {
154156 @ Override
155157 public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
156158 assertNull ("There should be no error" , error );
157159 assertNotNull ("Entry should have been fetched" , queryResult );
158160 List <Entry > entries = queryResult .getResultObjects ();
159161 for (int i = 0 ; i < entries .size (); i ++) {
160- Integer currNum = (int )entries .get (i ).get ("num_field " );
161- assertTrue ("Curr num_field should be less than or equal to the value" , currNum <= value );
162+ Integer currNum = (int )entries .get (i ).get ("price " );
163+ assertTrue ("Curr price should be less than or equal to the value" , currNum <= value );
162164 }
163165 latch .countDown ();
164166 }
@@ -170,18 +172,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
170172 @ Test
171173 public void testFindGreaterThan () throws InterruptedException {
172174 final CountDownLatch latch = new CountDownLatch (1 );
173- final Query query = stack .contentType ("numbers_content_type" ).query ();
174- int value = 11 ;
175- query .greaterThan ("num_field " , value );
175+ final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
176+ int value = 90 ;
177+ query .greaterThan ("price " , value );
176178 query .find (new QueryResultsCallBack () {
177179 @ Override
178180 public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
179181 assertNull ("There should be no error" , error );
180182 assertNotNull ("Entry should have been fetched" , queryResult );
181183 List <Entry > entries = queryResult .getResultObjects ();
182184 for (int i = 0 ; i < entries .size (); i ++) {
183- Integer currNum = (int )entries .get (i ).get ("num_field " );
184- assertTrue ("Curr num_field should be greater than the value" , currNum > value );
185+ Integer currNum = (int )entries .get (i ).get ("price " );
186+ assertTrue ("Curr price should be greater than the value" , currNum > value );
185187 }
186188 latch .countDown ();
187189 }
@@ -193,18 +195,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
193195 @ Test
194196 public void testFindGreaterThanOREqualTo () throws InterruptedException {
195197 final CountDownLatch latch = new CountDownLatch (1 );
196- final Query query = stack .contentType ("numbers_content_type" ).query ();
197- int value = 11 ;
198- query .greaterThanOrEqualTo ("num_field " , value );
198+ final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
199+ int value = 90 ;
200+ query .greaterThanOrEqualTo ("price " , value );
199201 query .find (new QueryResultsCallBack () {
200202 @ Override
201203 public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
202204 assertNull ("There should be no error" , error );
203205 assertNotNull ("Entry should have been fetched" , queryResult );
204206 List <Entry > entries = queryResult .getResultObjects ();
205207 for (int i = 0 ; i < entries .size (); i ++) {
206- Integer currNum = (int )entries .get (i ).get ("num_field " );
207- assertTrue ("Curr num_field should be greater than or equal to the value" , currNum >= value );
208+ Integer currNum = (int )entries .get (i ).get ("price " );
209+ assertTrue ("Curr price should be greater than or equal to the value" , currNum >= value );
208210 }
209211 latch .countDown ();
210212 }
@@ -217,7 +219,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
217219 public void testFindContainedIn () throws InterruptedException {
218220 final CountDownLatch latch = new CountDownLatch (1 );
219221 final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
220- String [] values = {"source1 " };
222+ String [] values = {"kids dress " };
221223 query .containedIn ("title" , values );
222224 query .find (new QueryResultsCallBack () {
223225 @ Override
@@ -240,7 +242,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
240242 public void testFindNotContainedIn () throws InterruptedException {
241243 final CountDownLatch latch = new CountDownLatch (1 );
242244 final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
243- String [] values = {"source1 " };
245+ String [] values = {"kids dress " };
244246 query .notContainedIn ("title" , values );
245247 query .find (new QueryResultsCallBack () {
246248 @ Override
@@ -306,10 +308,10 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
306308 @ Test
307309 public void testFindOr () throws InterruptedException {
308310 final CountDownLatch latch = new CountDownLatch (1 );
309- String [] values = {"source1 " };
310- String field = "boolean " ;
311+ String [] values = {"kids dress " };
312+ String field = "in_stock " ;
311313 final Query query1 = stack .contentType (CONTENT_TYPE_UID ).query ().containedIn ("title" , values );
312- final Query query2 = stack .contentType (CONTENT_TYPE_UID ).query ().where (field , true );
314+ final Query query2 = stack .contentType (CONTENT_TYPE_UID ).query ().where (field , 300 );
313315 final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
314316 ArrayList <Query > queryList = new ArrayList <>();
315317 queryList .add (query1 );
@@ -362,7 +364,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
362364 @ Test
363365 public void testFindIncludeReference () throws InterruptedException {
364366 final CountDownLatch latch = new CountDownLatch (1 );
365- String field = "reference " ;
367+ String field = "image " ;
366368 final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
367369 query .includeReference (field );
368370 query .find (new QueryResultsCallBack () {
@@ -373,15 +375,8 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
373375 List <Entry > entries = queryResult .getResultObjects ();
374376 for (int i = 0 ; i < entries .size (); i ++) {
375377 try {
376- JSONArray ref = (JSONArray )entries .get (i ).get (field );
377- // Convert JSONArray to List
378- List <String > list = new ArrayList <>();
379- for (int j = 0 ; j < ref .length (); j ++) {
380- JSONObject jsonObject = ref .getJSONObject (j ); // Get the first JSONObject
381- // Title is a mandatory field, so we can test against it being present
382- assertTrue ("One of or should be true" , jsonObject .has ("title" ));
383- }
384- } catch (JSONException e ) {
378+ Log .d ("Entry" , entries .get (i ).get (field ).toString ());
379+ } catch (Exception e ) {
385380 throw new RuntimeException (e );
386381 }
387382 }
0 commit comments