Skip to content

Commit 455e8fe

Browse files
authored
Merge pull request #81 from contentstack/fix/DX-1599-entrytestcase
Fix testcases
2 parents 17d387a + a6072dd commit 455e8fe

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

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

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.ArrayList;
1414
import java.util.concurrent.CountDownLatch;
15+
import java.util.concurrent.TimeUnit;
1516

1617
import static junit.framework.TestCase.*;
1718

@@ -73,34 +74,41 @@ public void tearDown() {
7374

7475

7576
@Test
76-
public void test_01_findAllEntries() {
77+
public void test_01_findAllEntries() throws InterruptedException {
78+
final CountDownLatch latch = new CountDownLatch(1);
7779
final Query query = stack.contentType(CONTENT_TYPE_UID).query();
7880
query.find(new QueryResultsCallBack() {
7981
@Override
8082
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
8183
if (error == null) {
8284
entryUID = queryresult.getResultObjects().get(15).getUid();
8385
}
86+
latch.countDown();
8487
}
8588
});
89+
latch.await();
8690
}
8791

8892
@Test
89-
public void test_02_only_fetch() {
93+
public void test_02_only_fetch() throws InterruptedException {
94+
final CountDownLatch latch = new CountDownLatch(1);
9095
final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
9196
entry.only(new String[]{"price"});
9297
entry.fetch(new EntryResultCallBack() {
9398
@Override
9499
public void onCompletion(ResponseType responseType, Error error) {
95100
if (error == null) {
96-
assertEquals(786, entry.toJSON().opt("price"));
101+
assertEquals(89, entry.toJSON().opt("price"));
97102
}
103+
latch.countDown();
98104
}
99105
});
106+
latch.await();
100107
}
101108

102109
@Test
103-
public void test_03_except_fetch() {
110+
public void test_03_except_fetch() throws InterruptedException {
111+
final CountDownLatch latch = new CountDownLatch(1);
104112
final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
105113
entry.except(new String[]{"title"});
106114
entry.fetch(new EntryResultCallBack() {
@@ -111,12 +119,15 @@ public void onCompletion(ResponseType responseType, Error error) {
111119
} else {
112120
Log.e(TAG, error.getErrorMessage());
113121
}
122+
latch.countDown();
114123
}
115124
});
125+
latch.await();
116126
}
117127

118128
@Test
119-
public void test_04_includeReference_fetch() {
129+
public void test_04_includeReference_fetch() throws InterruptedException {
130+
final CountDownLatch latch = new CountDownLatch(1);
120131
final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
121132
entry.includeReference("category");
122133
entry.fetch(new EntryResultCallBack() {
@@ -133,14 +144,17 @@ public void onCompletion(ResponseType responseType, Error error) {
133144
} catch (Exception e) {
134145
Log.e(TAG, e.getLocalizedMessage());
135146
}
147+
latch.countDown();
136148

137149
}
138150
}
139151
});
152+
latch.await();
140153
}
141154

142155
@Test
143-
public void test_05_includeReferenceOnly_fetch() {
156+
public void test_05_includeReferenceOnly_fetch() throws InterruptedException {
157+
final CountDownLatch latch = new CountDownLatch(1);
144158
final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
145159
ArrayList<String> strings = new ArrayList<>();
146160
strings.add("title");
@@ -151,16 +165,19 @@ public void test_05_includeReferenceOnly_fetch() {
151165
@Override
152166
public void onCompletion(ResponseType responseType, Error error) {
153167
if (error == null) {
154-
assertEquals("laptop", entry.toJSON().optString("title"));
168+
assertEquals("entry_lt8", entry.toJSON().optString("title"));
155169
}
170+
latch.countDown();
156171
}
157172
});
173+
latch.await();
158174

159175
}
160176

161177

162178
@Test
163179
public void test_06_includeReferenceExcept_fetch() throws InterruptedException {
180+
final CountDownLatch latch = new CountDownLatch(1);
164181
final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
165182
ArrayList<String> strings = new ArrayList<>();
166183
strings.add("color");
@@ -184,6 +201,7 @@ public void onCompletion(ResponseType responseType, Error error) {
184201

185202
@Test
186203
public void test_07_getMarkdown_fetch() throws InterruptedException {
204+
final CountDownLatch latch = new CountDownLatch(1);
187205

188206
final Entry entry = stack.contentType("user").entry(entryUID);
189207
entry.fetch(new EntryResultCallBack() {
@@ -202,6 +220,7 @@ public void onCompletion(ResponseType responseType, Error error) {
202220

203221
@Test
204222
public void test_08_get() throws InterruptedException {
223+
final CountDownLatch latch = new CountDownLatch(1);
205224
final Entry entry = stack.contentType("user").entry(entryUID);
206225
entry.fetch(new EntryResultCallBack() {
207226
@Override
@@ -219,6 +238,7 @@ public void onCompletion(ResponseType responseType, Error error) {
219238

220239
@Test
221240
public void test_09_getParam() throws InterruptedException {
241+
final CountDownLatch latch = new CountDownLatch(1);
222242
final Entry entry = stack.contentType("user").entry(entryUID);
223243
entry.addParam("include_dimensions", "true");
224244
entry.fetch(new EntryResultCallBack() {
@@ -237,6 +257,7 @@ public void onCompletion(ResponseType responseType, Error error) {
237257

238258
@Test
239259
public void test_10_IncludeReferenceContentTypeUID() throws InterruptedException {
260+
final CountDownLatch latch = new CountDownLatch(1);
240261
final Entry entry = stack.contentType("user").entry(entryUID);
241262
entry.includeReferenceContentTypeUID();
242263
entry.fetch(new EntryResultCallBack() {
@@ -266,6 +287,7 @@ public void onCompletion(ResponseType responseType, Error error) {
266287

267288
@Test
268289
public void test_11_Locale() throws InterruptedException {
290+
final CountDownLatch latch = new CountDownLatch(1);
269291
final Entry entry = stack.contentType("user").entry(entryUID);
270292
entry.fetch(new EntryResultCallBack() {
271293
@Override
@@ -305,6 +327,7 @@ public void onCompletion(ResponseType responseType, Error error) {
305327

306328
@Test
307329
public void test_13_entry_include_embedded_items_unit_test() throws InterruptedException {
330+
final CountDownLatch latch = new CountDownLatch(1);
308331

309332
final Entry entry = stack.contentType("user").entry(entryUID);
310333
entry.includeEmbeddedItems().fetch(new EntryResultCallBack() {
@@ -323,25 +346,31 @@ public void onCompletion(ResponseType responseType, Error error) {
323346
}
324347

325348
@Test
326-
public void VariantsTestSingleUid(){
349+
public void VariantsTestSingleUid() throws InterruptedException {
350+
final CountDownLatch latch = new CountDownLatch(1);
327351
final Entry entry = stack.contentType("product").entry(variantEntryUID).variants(variantUID);
328352
entry.fetch(new EntryResultCallBack() {
329353
@Override
330354
public void onCompletion(ResponseType responseType, Error error) {
331355
// assertEquals(variantUID, entry.getHeaders().get("x-cs-variant-uid"));
332356
System.out.println(entry.toJSON());
357+
latch.countDown();
333358
}
334359
});
360+
latch.await();
335361
}
336362
@Test
337-
public void VariantsTestArray(){
363+
public void VariantsTestArray() throws InterruptedException {
364+
final CountDownLatch latch = new CountDownLatch(1);
338365
final Entry entry = stack.contentType("product").entry(variantEntryUID).variants(variantsUID);
339366
entry.fetch(new EntryResultCallBack() {
340367
@Override
341368
public void onCompletion(ResponseType responseType, Error error) {
342369
System.out.println(entry.toJSON());
370+
latch.countDown();
343371
}
344372
});
373+
latch.await();
345374
}
346375

347376
}

0 commit comments

Comments
 (0)