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 ();
@@ -40,94 +40,86 @@ public static void oneTimeSetUp() throws Exception {
40
40
}
41
41
42
42
@ Test
43
- public void test_B_VerifyAssetUID () {
43
+ public void test_B_VerifyAssetUID () throws InterruptedException {
44
+ final CountDownLatch latch = new CountDownLatch (1 );
44
45
final Asset asset = stack .asset (assetUid );
45
46
asset .fetch (new FetchResultCallback () {
46
47
@ Override
47
48
public void onCompletion (ResponseType responseType , Error error ) {
48
- if ( error == null ) {
49
- // Success Block.
50
- Log . d ( TAG , "response: " + asset .getAssetUid ());
51
- assertEquals ( assetUid , asset . getAssetUid ());
52
- }
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 ();
53
54
}
54
55
});
56
+ latch .await (5 , TimeUnit .SECONDS );
57
+ assertEquals ("Query was not completed in time" , 0 , latch .getCount ());
55
58
}
56
59
57
60
@ Test
58
- 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 );
59
66
final Asset asset = stack .asset (assetUid );
60
67
asset .fetch (new FetchResultCallback () {
61
68
@ Override
62
69
public void onCompletion (ResponseType responseType , Error error ) {
63
- if (error == null ) {
64
- assertEquals (BuildConfig .assetUID , asset .getAssetUid ());
65
- assertEquals ("image/jpeg" , asset .getFileType ());
66
- assertEquals ("phoenix2.jpg" , asset .getFileName ());
67
- assertEquals ("482141" , asset .getFileSize ());
68
- } else {
69
- assertEquals (105 , error .getErrorCode ());
70
- }
70
+ assertEquals (BuildConfig .assetUID , asset .getAssetUid ());
71
+ assertEquals ("image/jpeg" , asset .getFileType ());
72
+ assertEquals ("image1.jpg" , asset .getFileName ());
73
+ latch .countDown ();
71
74
}
72
75
});
76
+ latch .await (5 , TimeUnit .SECONDS );
73
77
}
74
78
75
79
@ Test
76
- public void test_E_AssetLibrary_includeCount_fetch () {
80
+ public void test_E_AssetLibrary_includeCount_fetch () throws InterruptedException {
81
+ final CountDownLatch latch = new CountDownLatch (1 );
77
82
final AssetLibrary assetLibrary = stack .assetLibrary ();
78
83
assetLibrary .includeCount ();
79
84
assetLibrary .fetchAll (new FetchAssetsCallback () {
80
85
@ Override
81
86
public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
82
- if (error == null ) {
83
- assertEquals (16 , assetLibrary .getCount ());
84
- }
85
- }
86
- });
87
- }
88
-
89
- @ Test
90
- public void test_F_AssetLibrary_includeRelativeUrl_fetch () {
91
- final AssetLibrary assetLibrary = stack .assetLibrary ();
92
- assetLibrary .includeRelativeUrl ();
93
- assetLibrary .fetchAll (new FetchAssetsCallback () {
94
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
95
- if (error == null ) {
96
- assertTrue (assets .get (0 ).getUrl ().contains ("phoenix2.jpg" ));
97
- }
87
+ assertEquals (5 , assetLibrary .getCount ());
88
+ latch .countDown ();
98
89
}
99
90
});
91
+ latch .await (5 , TimeUnit .SECONDS );
100
92
}
101
93
102
94
@ Test
103
- public void test_G_Include_Dimension () {
95
+ public void test_G_Include_Dimension () throws InterruptedException {
96
+ final CountDownLatch latch = new CountDownLatch (1 );
104
97
final Asset asset = stack .asset (assetUid );
105
98
asset .includeDimension ();
106
99
asset .fetch (new FetchResultCallback () {
107
100
@ Override
108
101
public void onCompletion (ResponseType responseType , Error error ) {
109
- if (error == null ) {
110
- Log .d (TAG , asset .getAssetUid ());
111
- assertEquals (assetUid , asset .getAssetUid ());
112
- }
102
+ assertEquals (assetUid , asset .getAssetUid ());
103
+ latch .countDown ();
113
104
}
114
105
});
106
+ latch .await (5 , TimeUnit .SECONDS );
115
107
}
116
108
117
109
118
110
@ Test
119
- public void test_H_include_fallback () {
111
+ public void test_H_include_fallback () throws InterruptedException {
112
+ final CountDownLatch latch = new CountDownLatch (1 );
120
113
final Asset asset = stack .asset (assetUid );
121
114
asset .includeFallback ();
122
115
asset .fetch (new FetchResultCallback () {
123
116
@ Override
124
117
public void onCompletion (ResponseType responseType , Error error ) {
125
- if (error == null ) {
126
- Log .d (TAG , asset .getAssetUid ());
127
- assertEquals (assetUid , asset .getAssetUid ());
128
- }
118
+ assertEquals (assetUid , asset .getAssetUid ());
119
+ latch .countDown ();
129
120
}
130
121
});
122
+ latch .await (5 , TimeUnit .SECONDS );
131
123
}
132
124
133
125
@ Test
@@ -157,47 +149,17 @@ public void test_GCP_NA() throws Exception {
157
149
}
158
150
159
151
@ Test
160
- public void test_J_fetch_asset_by_tags () {
161
- final AssetLibrary assetLibrary = stack .assetLibrary ().where ("tags" ,"tag1" );
162
- assetLibrary .fetchAll (new FetchAssetsCallback () {
163
- @ Override
164
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
165
- if (error == null ) {
166
- for ( Asset asset : assets ){
167
- Log .d ("RESULT:" , "resp" + asset .json );
168
- }
169
- assertTrue (assets .size ()>0 );
170
- }
171
- }
172
- });
173
- }
174
-
175
- @ Test
176
- public void test_K_fetch_asset_by_description () {
177
- final AssetLibrary assetLibrary = stack .assetLibrary ().where ("description" ,"Page1" );
178
- assetLibrary .fetchAll (new FetchAssetsCallback () {
179
- @ Override
180
- public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
181
- for (Asset asset : assets ){
182
- Log .d ("RESULT:" , "resp" + asset .toJSON ());
183
- }
184
- assertTrue (assets .size ()>0 );
185
- }
186
- });
187
- }
188
-
189
- @ Test
190
- public void test_M_fetch_asset_empty_title () {
152
+ public void test_M_fetch_asset_empty_title () throws InterruptedException {
153
+ final CountDownLatch latch = new CountDownLatch (1 );
191
154
final AssetLibrary assetLibrary = stack .assetLibrary ().where ("title" ,"" );
192
155
assetLibrary .fetchAll (new FetchAssetsCallback () {
193
156
@ Override
194
157
public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
195
- for (Asset asset : assets ){
196
- Log .d ("RESULT:" , "resp: " + asset .toJSON ());
197
- }
198
158
assertEquals (0 , assets .size ());
159
+ latch .countDown ();
199
160
}
200
161
});
162
+ latch .await (5 , TimeUnit .SECONDS );
201
163
}
202
164
203
165
}
0 commit comments