Skip to content

Commit dc032e4

Browse files
authored
Revert "feat: implement Global Fields "
1 parent 00940b3 commit dc032e4

15 files changed

+53
-847
lines changed

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

Lines changed: 2 additions & 18 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("phoenix2.jpg", asset.getFileName());
72+
assertEquals("image1.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(6, assetLibrary.getCount());
87+
assertEquals(5, assetLibrary.getCount());
8888
latch.countDown();
8989
}
9090
});
@@ -122,22 +122,6 @@ 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-
141125
@Test
142126
public void test_AZURE_NA() throws Exception {
143127
Config config = new Config();

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

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

55
import android.content.Context;
6-
import android.util.Log;
76

87
import androidx.test.core.app.ApplicationProvider;
98

@@ -14,7 +13,6 @@
1413
import org.junit.Test;
1514
import static org.junit.Assert.*;
1615

17-
import java.io.IOException;
1816
import java.text.ParseException;
1917
import java.text.SimpleDateFormat;
2018
import java.util.ArrayList;
@@ -46,7 +44,7 @@ public void testFindEntry() throws InterruptedException {
4644
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
4745
assertNull("There should be no error", error);
4846
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());
5048
// Unlock the latch to allow the test to proceed
5149
latch.countDown();
5250
}
@@ -126,18 +124,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
126124
@Test
127125
public void testFindLessThan() throws InterruptedException {
128126
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);
132130
query.find(new QueryResultsCallBack() {
133131
@Override
134132
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
135133
assertNull("There should be no error", error);
136134
assertNotNull("Entry should have been fetched", queryResult);
137135
List<Entry> entries = queryResult.getResultObjects();
138136
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);
141139
}
142140
latch.countDown();
143141
}
@@ -149,18 +147,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
149147
@Test
150148
public void testFindLessThanOrEqualTo() throws InterruptedException {
151149
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);
155153
query.find(new QueryResultsCallBack() {
156154
@Override
157155
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
158156
assertNull("There should be no error", error);
159157
assertNotNull("Entry should have been fetched", queryResult);
160158
List<Entry> entries = queryResult.getResultObjects();
161159
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);
164162
}
165163
latch.countDown();
166164
}
@@ -172,18 +170,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
172170
@Test
173171
public void testFindGreaterThan() throws InterruptedException {
174172
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);
178176
query.find(new QueryResultsCallBack() {
179177
@Override
180178
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
181179
assertNull("There should be no error", error);
182180
assertNotNull("Entry should have been fetched", queryResult);
183181
List<Entry> entries = queryResult.getResultObjects();
184182
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);
187185
}
188186
latch.countDown();
189187
}
@@ -195,18 +193,18 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
195193
@Test
196194
public void testFindGreaterThanOREqualTo() throws InterruptedException {
197195
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);
201199
query.find(new QueryResultsCallBack() {
202200
@Override
203201
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
204202
assertNull("There should be no error", error);
205203
assertNotNull("Entry should have been fetched", queryResult);
206204
List<Entry> entries = queryResult.getResultObjects();
207205
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);
210208
}
211209
latch.countDown();
212210
}
@@ -219,7 +217,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
219217
public void testFindContainedIn() throws InterruptedException {
220218
final CountDownLatch latch = new CountDownLatch(1);
221219
final Query query = stack.contentType(CONTENT_TYPE_UID).query();
222-
String[] values = {"kids dress"};
220+
String[] values = {"source1"};
223221
query.containedIn("title", values);
224222
query.find(new QueryResultsCallBack() {
225223
@Override
@@ -242,7 +240,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
242240
public void testFindNotContainedIn() throws InterruptedException {
243241
final CountDownLatch latch = new CountDownLatch(1);
244242
final Query query = stack.contentType(CONTENT_TYPE_UID).query();
245-
String[] values = {"kids dress"};
243+
String[] values = {"source1"};
246244
query.notContainedIn("title", values);
247245
query.find(new QueryResultsCallBack() {
248246
@Override
@@ -308,10 +306,10 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
308306
@Test
309307
public void testFindOr() throws InterruptedException {
310308
final CountDownLatch latch = new CountDownLatch(1);
311-
String[] values = {"kids dress"};
312-
String field = "in_stock";
309+
String[] values = {"source1"};
310+
String field = "boolean";
313311
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);
315313
final Query query = stack.contentType(CONTENT_TYPE_UID).query();
316314
ArrayList<Query> queryList = new ArrayList<>();
317315
queryList.add(query1);
@@ -364,7 +362,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
364362
@Test
365363
public void testFindIncludeReference() throws InterruptedException {
366364
final CountDownLatch latch = new CountDownLatch(1);
367-
String field = "image";
365+
String field = "reference";
368366
final Query query = stack.contentType(CONTENT_TYPE_UID).query();
369367
query.includeReference(field);
370368
query.find(new QueryResultsCallBack() {
@@ -375,8 +373,15 @@ public void onCompletion(ResponseType responseType, QueryResult queryResult, Err
375373
List<Entry> entries = queryResult.getResultObjects();
376374
for (int i = 0; i < entries.size(); i++) {
377375
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) {
380385
throw new RuntimeException(e);
381386
}
382387
}

0 commit comments

Comments
 (0)