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