10
10
11
11
import java .util .List ;
12
12
import java .util .concurrent .CountDownLatch ;
13
+ import java .util .concurrent .TimeUnit ;
13
14
14
15
import static junit .framework .Assert .assertTrue ;
15
16
import static junit .framework .TestCase .assertEquals ;
@@ -26,7 +27,6 @@ public class AssetTestCase {
26
27
private static Stack stack ;
27
28
private static CountDownLatch latch ;
28
29
29
-
30
30
@ BeforeClass
31
31
public static void oneTimeSetUp () throws Exception {
32
32
Context appContext = ApplicationProvider .getApplicationContext ();
@@ -39,125 +39,93 @@ public static void oneTimeSetUp() throws Exception {
39
39
stack = Contentstack .stack (appContext , DEFAULT_API_KEY , DEFAULT_DELIVERY_TOKEN , DEFAULT_ENV , config );
40
40
}
41
41
42
-
43
- @ Test ()
44
- public void test_A_getAllAssetsToSetAssetUID () {
45
- final AssetLibrary assetLibrary = stack .assetLibrary ();
46
- assetLibrary .fetchAll (new FetchAssetsCallback () {
47
- @ Override
48
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
49
- if (error == null ) {
50
- Log .d (TAG , "response: " + assets .get (0 ).getAssetUid ());
51
- assetUid = assets .get (0 ).getAssetUid ();
52
- Log .e (assetUid , assetUid );
53
- }
54
- }
55
- });
56
-
57
- }
58
-
59
42
@ Test
60
- public void test_B_VerifyAssetUID () {
43
+ public void test_B_VerifyAssetUID () throws InterruptedException {
44
+ final CountDownLatch latch = new CountDownLatch (1 );
61
45
final Asset asset = stack .asset (assetUid );
62
46
asset .fetch (new FetchResultCallback () {
63
47
@ Override
64
48
public void onCompletion (ResponseType responseType , Error error ) {
65
- if ( error == null ) {
66
- // Success Block.
67
- Log . d ( TAG , "response: " + asset .getAssetUid ());
68
- assertEquals ( assetUid , asset . getAssetUid ());
69
- }
49
+ // Success Block.
50
+ Log . d ( TAG , "response: " + asset . getAssetUid ());
51
+ assertEquals ( assetUid , asset .getAssetUid ());
52
+ // Unlock the latch to allow the test to proceed
53
+ latch . countDown ();
70
54
}
71
55
});
56
+ latch .await (5 , TimeUnit .SECONDS );
57
+ assertEquals ("Query was not completed in time" , 0 , latch .getCount ());
72
58
}
73
59
74
60
@ Test
75
- public void test_C_Asset_fetch () {
61
+ public void test_C_Asset_fetch () throws Exception {
62
+ Config config = new Config ();
63
+ Context appContext = ApplicationProvider .getApplicationContext ();
64
+ stack = Contentstack .stack (appContext , BuildConfig .APIKey , BuildConfig .deliveryToken , BuildConfig .environment , config );
65
+ final CountDownLatch latch = new CountDownLatch (1 );
76
66
final Asset asset = stack .asset (assetUid );
77
67
asset .fetch (new FetchResultCallback () {
78
68
@ Override
79
69
public void onCompletion (ResponseType responseType , Error error ) {
80
- if (error == null ) {
81
- assertEquals (BuildConfig .assetUID , asset .getAssetUid ());
82
- assertEquals ("image/jpeg" , asset .getFileType ());
83
- assertEquals ("phoenix2.jpg" , asset .getFileName ());
84
- assertEquals ("482141" , asset .getFileSize ());
85
- } else {
86
- assertEquals (105 , error .getErrorCode ());
87
- }
70
+ assertEquals (BuildConfig .assetUID , asset .getAssetUid ());
71
+ assertEquals ("image/jpeg" , asset .getFileType ());
72
+ assertEquals ("phoenix2.jpg" , asset .getFileName ());
73
+ latch .countDown ();
88
74
}
89
75
});
76
+ latch .await (5 , TimeUnit .SECONDS );
90
77
}
91
78
92
79
@ Test
93
- public void test_D_AssetLibrary_fetch () {
80
+ public void test_E_AssetLibrary_includeCount_fetch () throws InterruptedException {
81
+ final CountDownLatch latch = new CountDownLatch (1 );
94
82
final AssetLibrary assetLibrary = stack .assetLibrary ();
83
+ assetLibrary .includeCount ();
95
84
assetLibrary .fetchAll (new FetchAssetsCallback () {
96
85
@ Override
97
86
public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
98
- if (error == null ) {
99
- assets .forEach (asset -> {
100
- Log .d (TAG , "----Test--Asset-D--Success----" + asset .toJSON ());
101
- Log .d (TAG , "----Test--Asset-D--Success----" + asset .getFileType ());
102
- Log .d (TAG , "----Test--Asset-D--Success----" + asset .getCreatedBy ());
103
- Log .d (TAG , "----Test--Asset-D--Success----" + asset .getUpdatedBy ());
104
- Log .d (TAG , "----Test--Asset-D--Success----" + asset .getFileName ());
105
- Log .d (TAG , "----Test--Asset-D--Success----" + asset .getFileSize ());
106
- Log .d (TAG , "----Test--Asset-D--Success----" + asset .getAssetUid ());
107
- Log .d (TAG , "----Test--Asset-D--Success----" + asset .getUrl ());
108
- });
109
- }
87
+ assertEquals (6 , assetLibrary .getCount ());
88
+ latch .countDown ();
110
89
}
111
90
});
91
+ latch .await (5 , TimeUnit .SECONDS );
112
92
}
113
93
114
94
@ Test
115
- public void test_E_AssetLibrary_includeCount_fetch () {
116
- final AssetLibrary assetLibrary = stack .assetLibrary ();
117
- assetLibrary .includeCount ();
118
- assetLibrary .fetchAll (new FetchAssetsCallback () {
95
+ public void test_G_Include_Dimension () throws InterruptedException {
96
+ final CountDownLatch latch = new CountDownLatch (1 );
97
+ final Asset asset = stack .asset (assetUid );
98
+ asset .includeDimension ();
99
+ asset .fetch (new FetchResultCallback () {
119
100
@ Override
120
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
121
- if (error == null ) {
122
- assertEquals (16 , assetLibrary .getCount ());
123
- }
101
+ public void onCompletion (ResponseType responseType , Error error ) {
102
+ assertEquals (assetUid , asset .getAssetUid ());
103
+ latch .countDown ();
124
104
}
125
105
});
106
+ latch .await (5 , TimeUnit .SECONDS );
126
107
}
127
108
128
- @ Test
129
- public void test_F_AssetLibrary_includeRelativeUrl_fetch () {
130
- final AssetLibrary assetLibrary = stack .assetLibrary ();
131
- assetLibrary .includeRelativeUrl ();
132
- assetLibrary .fetchAll (new FetchAssetsCallback () {
133
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
134
- if (error == null ) {
135
- assertTrue (assets .get (0 ).getUrl ().contains ("phoenix2.jpg" ));
136
- }
137
- }
138
- });
139
- }
140
109
141
110
@ Test
142
- public void test_G_Include_Dimension () {
111
+ public void test_H_include_fallback () throws InterruptedException {
112
+ final CountDownLatch latch = new CountDownLatch (1 );
143
113
final Asset asset = stack .asset (assetUid );
144
- asset .includeDimension ();
114
+ asset .includeFallback ();
145
115
asset .fetch (new FetchResultCallback () {
146
116
@ Override
147
117
public void onCompletion (ResponseType responseType , Error error ) {
148
- if (error == null ) {
149
- Log .d (TAG , asset .getAssetUid ());
150
- assertEquals (assetUid , asset .getAssetUid ());
151
- }
118
+ assertEquals (assetUid , asset .getAssetUid ());
119
+ latch .countDown ();
152
120
}
153
121
});
122
+ latch .await (5 , TimeUnit .SECONDS );
154
123
}
155
124
156
-
157
125
@ Test
158
- public void test_H_include_fallback () {
126
+ public void test_include_branch () {
159
127
final Asset asset = stack .asset (assetUid );
160
- asset .includeFallback ();
128
+ asset .includeBranch ();
161
129
asset .fetch (new FetchResultCallback () {
162
130
@ Override
163
131
public void onCompletion (ResponseType responseType , Error error ) {
@@ -169,6 +137,7 @@ public void onCompletion(ResponseType responseType, Error error) {
169
137
});
170
138
}
171
139
140
+
172
141
@ Test
173
142
public void test_AZURE_NA () throws Exception {
174
143
Config config = new Config ();
@@ -196,74 +165,17 @@ public void test_GCP_NA() throws Exception {
196
165
}
197
166
198
167
@ Test
199
- public void test_I_fetch_asset_by_title () {
200
- final AssetLibrary assetLibrary = stack .assetLibrary ().where ("title" , "iot-icon.png" );
201
- assetLibrary .fetchAll (new FetchAssetsCallback () {
202
- @ Override
203
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
204
- if (error == null ) {
205
- for (Asset asset : assets ) {
206
- Log .d ("RESULT:" , "resp" + asset .json );
207
- }
208
- }
209
- }
210
- });
211
- }
212
-
213
- @ Test
214
- public void test_J_fetch_asset_by_tags () {
215
- final AssetLibrary assetLibrary = stack .assetLibrary ().where ("tags" ,"tag1" );
216
- assetLibrary .fetchAll (new FetchAssetsCallback () {
217
- @ Override
218
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
219
- if (error == null ) {
220
- for ( Asset asset : assets ){
221
- Log .d ("RESULT:" , "resp" + asset .json );
222
- }
223
- assertTrue (assets .size ()>0 );
224
- }
225
- }
226
- });
227
- }
228
-
229
- @ Test
230
- public void test_K_fetch_asset_by_description () {
231
- final AssetLibrary assetLibrary = stack .assetLibrary ().where ("description" ,"Page1" );
232
- assetLibrary .fetchAll (new FetchAssetsCallback () {
233
- @ Override
234
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
235
- for (Asset asset : assets ){
236
- Log .d ("RESULT:" , "resp" + asset .toJSON ());
237
- }
238
- assertTrue (assets .size ()>0 );
239
- }
240
- });
241
- }
242
-
243
- @ Test
244
- public void test_L_fetch_asset_invalid () {
245
- final AssetLibrary assetLibrary = stack .assetLibrary ().where ("title" ,null );
246
- assetLibrary .fetchAll (new FetchAssetsCallback () {
247
- @ Override
248
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
249
- Log .e ("RESULT:" , "ERROR:" + error .errorMessage );
250
- }
251
- });
252
-
253
- }
254
-
255
- @ Test
256
- public void test_M_fetch_asset_empty_title () {
168
+ public void test_M_fetch_asset_empty_title () throws InterruptedException {
169
+ final CountDownLatch latch = new CountDownLatch (1 );
257
170
final AssetLibrary assetLibrary = stack .assetLibrary ().where ("title" ,"" );
258
171
assetLibrary .fetchAll (new FetchAssetsCallback () {
259
172
@ Override
260
173
public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
261
- for (Asset asset : assets ){
262
- Log .d ("RESULT:" , "resp: " + asset .toJSON ());
263
- }
264
174
assertEquals (0 , assets .size ());
175
+ latch .countDown ();
265
176
}
266
177
});
178
+ latch .await (5 , TimeUnit .SECONDS );
267
179
}
268
180
269
181
}
0 commit comments