Skip to content

Commit 00940b3

Browse files
authored
Merge pull request #73 from contentstack/feat/DX-2979-global-field-impl
feat: implement Global Fields
2 parents b084b20 + 1237e3d commit 00940b3

15 files changed

+847
-53
lines changed

contentstack/src/androidTest/java/com/contentstack/sdk/AssetTestCase.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void test_C_Asset_fetch() throws Exception {
6969
public void onCompletion(ResponseType responseType, Error error) {
7070
assertEquals(BuildConfig.assetUID, asset.getAssetUid());
7171
assertEquals("image/jpeg", asset.getFileType());
72-
assertEquals("image1.jpg", asset.getFileName());
72+
assertEquals("phoenix2.jpg", asset.getFileName());
7373
latch.countDown();
7474
}
7575
});
@@ -84,7 +84,7 @@ public void test_E_AssetLibrary_includeCount_fetch() throws InterruptedException
8484
assetLibrary.fetchAll(new FetchAssetsCallback() {
8585
@Override
8686
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
87-
assertEquals(5, assetLibrary.getCount());
87+
assertEquals(6, assetLibrary.getCount());
8888
latch.countDown();
8989
}
9090
});
@@ -122,6 +122,22 @@ public void onCompletion(ResponseType responseType, Error error) {
122122
latch.await(5, TimeUnit.SECONDS);
123123
}
124124

125+
@Test
126+
public void test_include_branch() {
127+
final Asset asset = stack.asset(assetUid);
128+
asset.includeBranch();
129+
asset.fetch(new FetchResultCallback() {
130+
@Override
131+
public void onCompletion(ResponseType responseType, Error error) {
132+
if (error == null) {
133+
Log.d(TAG, asset.getAssetUid());
134+
assertEquals(assetUid, asset.getAssetUid());
135+
}
136+
}
137+
});
138+
}
139+
140+
125141
@Test
126142
public void test_AZURE_NA() throws Exception {
127143
Config config = new Config();

contentstack/src/androidTest/java/com/contentstack/sdk/EntryFindTest.java

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static junit.framework.TestCase.assertEquals;
44

55
import android.content.Context;
6+
import android.util.Log;
67

78
import androidx.test.core.app.ApplicationProvider;
89

@@ -13,6 +14,7 @@
1314
import org.junit.Test;
1415
import static org.junit.Assert.*;
1516

17+
import java.io.IOException;
1618
import java.text.ParseException;
1719
import java.text.SimpleDateFormat;
1820
import 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

Comments
 (0)