3
3
import static junit .framework .TestCase .assertEquals ;
4
4
5
5
import android .content .Context ;
6
+ import android .util .Log ;
6
7
7
8
import androidx .test .core .app .ApplicationProvider ;
8
9
13
14
import org .junit .Test ;
14
15
import static org .junit .Assert .*;
15
16
17
+ import java .io .IOException ;
16
18
import java .text .ParseException ;
17
19
import java .text .SimpleDateFormat ;
18
20
import java .util .ArrayList ;
@@ -44,7 +46,7 @@ public void testFindEntry() throws InterruptedException {
44
46
public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
45
47
assertNull ("There should be no error" , error );
46
48
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 ());
48
50
// Unlock the latch to allow the test to proceed
49
51
latch .countDown ();
50
52
}
@@ -124,18 +126,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
124
126
@ Test
125
127
public void testFindLessThan () throws InterruptedException {
126
128
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 );
130
132
query .find (new QueryResultsCallBack () {
131
133
@ Override
132
134
public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
133
135
assertNull ("There should be no error" , error );
134
136
assertNotNull ("Entry should have been fetched" , queryResult );
135
137
List <Entry > entries = queryResult .getResultObjects ();
136
138
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 );
139
141
}
140
142
latch .countDown ();
141
143
}
@@ -147,18 +149,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
147
149
@ Test
148
150
public void testFindLessThanOrEqualTo () throws InterruptedException {
149
151
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 );
153
155
query .find (new QueryResultsCallBack () {
154
156
@ Override
155
157
public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
156
158
assertNull ("There should be no error" , error );
157
159
assertNotNull ("Entry should have been fetched" , queryResult );
158
160
List <Entry > entries = queryResult .getResultObjects ();
159
161
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 );
162
164
}
163
165
latch .countDown ();
164
166
}
@@ -170,18 +172,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
170
172
@ Test
171
173
public void testFindGreaterThan () throws InterruptedException {
172
174
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 );
176
178
query .find (new QueryResultsCallBack () {
177
179
@ Override
178
180
public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
179
181
assertNull ("There should be no error" , error );
180
182
assertNotNull ("Entry should have been fetched" , queryResult );
181
183
List <Entry > entries = queryResult .getResultObjects ();
182
184
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 );
185
187
}
186
188
latch .countDown ();
187
189
}
@@ -193,18 +195,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
193
195
@ Test
194
196
public void testFindGreaterThanOREqualTo () throws InterruptedException {
195
197
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 );
199
201
query .find (new QueryResultsCallBack () {
200
202
@ Override
201
203
public void onCompletion (ResponseType responseType , QueryResult queryResult , Error error ) {
202
204
assertNull ("There should be no error" , error );
203
205
assertNotNull ("Entry should have been fetched" , queryResult );
204
206
List <Entry > entries = queryResult .getResultObjects ();
205
207
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 );
208
210
}
209
211
latch .countDown ();
210
212
}
@@ -217,7 +219,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
217
219
public void testFindContainedIn () throws InterruptedException {
218
220
final CountDownLatch latch = new CountDownLatch (1 );
219
221
final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
220
- String [] values = {"source1 " };
222
+ String [] values = {"kids dress " };
221
223
query .containedIn ("title" , values );
222
224
query .find (new QueryResultsCallBack () {
223
225
@ Override
@@ -240,7 +242,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
240
242
public void testFindNotContainedIn () throws InterruptedException {
241
243
final CountDownLatch latch = new CountDownLatch (1 );
242
244
final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
243
- String [] values = {"source1 " };
245
+ String [] values = {"kids dress " };
244
246
query .notContainedIn ("title" , values );
245
247
query .find (new QueryResultsCallBack () {
246
248
@ Override
@@ -306,10 +308,10 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
306
308
@ Test
307
309
public void testFindOr () throws InterruptedException {
308
310
final CountDownLatch latch = new CountDownLatch (1 );
309
- String [] values = {"source1 " };
310
- String field = "boolean " ;
311
+ String [] values = {"kids dress " };
312
+ String field = "in_stock " ;
311
313
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 );
313
315
final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
314
316
ArrayList <Query > queryList = new ArrayList <>();
315
317
queryList .add (query1 );
@@ -362,7 +364,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
362
364
@ Test
363
365
public void testFindIncludeReference () throws InterruptedException {
364
366
final CountDownLatch latch = new CountDownLatch (1 );
365
- String field = "reference " ;
367
+ String field = "image " ;
366
368
final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
367
369
query .includeReference (field );
368
370
query .find (new QueryResultsCallBack () {
@@ -373,15 +375,8 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
373
375
List <Entry > entries = queryResult .getResultObjects ();
374
376
for (int i = 0 ; i < entries .size (); i ++) {
375
377
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 ) {
385
380
throw new RuntimeException (e );
386
381
}
387
382
}
0 commit comments