15
15
import static java .util .Collections .singletonMap ;
16
16
import static junit .framework .TestCase .assertTrue ;
17
17
import static org .junit .Assert .*;
18
+ import static org .junit .Assume .assumeTrue ;
18
19
19
20
public abstract class AbstractAccountApiTest extends MockableTest {
20
21
private static Random rand = new Random ();
@@ -35,12 +36,14 @@ public static void setUpClass() {
35
36
36
37
@ Before
37
38
public void setUp () throws Exception {
39
+ assumeCloudinaryAccountURLExist ();
38
40
System .out .println ("Running " + this .getClass ().getName () + "." + currentTest .getMethodName ());
39
41
this .account = new Account (new Cloudinary ());
40
42
}
41
43
42
44
@ AfterClass
43
45
public static void tearDownClass () {
46
+ assumeCloudinaryAccountURLExist ();
44
47
System .out .println ("Start TearDownClass" );
45
48
Account account = new Account (new Cloudinary ());
46
49
for (String createdSubAccountId : createdSubAccountIds ) {
@@ -71,6 +74,7 @@ public static void tearDownClass() {
71
74
72
75
@ Test
73
76
public void testPassingCredentialsThroughOptions () throws Exception {
77
+ assumeCloudinaryAccountURLExist ();
74
78
int exceptions = 0 ;
75
79
76
80
Map <String , Object > map = singletonMap ("provisioning_api_secret" , new Object ()) ;
@@ -104,13 +108,15 @@ public void testPassingCredentialsThroughOptions() throws Exception {
104
108
// Sub accounts tests
105
109
@ Test
106
110
public void testGetSubAccount () throws Exception {
111
+ assumeCloudinaryAccountURLExist ();
107
112
ApiResponse accountResponse = createSubAccount ();
108
113
ApiResponse account = this .account .subAccount (accountResponse .get ("id" ).toString (), null );
109
114
assertNotNull (account );
110
115
}
111
116
112
117
@ Test
113
118
public void testGetSubAccounts () throws Exception {
119
+ assumeCloudinaryAccountURLExist ();
114
120
createSubAccount ();
115
121
ApiResponse accounts = account .subAccounts (null , null , null , null );
116
122
assertNotNull (accounts );
@@ -119,6 +125,7 @@ public void testGetSubAccounts() throws Exception {
119
125
120
126
@ Test
121
127
public void testCreateSubAccount () throws Exception {
128
+ assumeCloudinaryAccountURLExist ();
122
129
ApiResponse result = createSubAccount ();
123
130
assertNotNull (result );
124
131
@@ -135,6 +142,7 @@ public void testCreateSubAccount() throws Exception {
135
142
136
143
@ Test
137
144
public void testUpdateSubAccount () throws Exception {
145
+ assumeCloudinaryAccountURLExist ();
138
146
ApiResponse subAccount = createSubAccount ();
139
147
String newCloudName = randomLetters ();
140
148
ApiResponse result = account .updateSubAccount (subAccount .get ("id" ).toString (), null , newCloudName , Collections .<String , String >emptyMap (), null , null );
@@ -144,6 +152,7 @@ public void testUpdateSubAccount() throws Exception {
144
152
145
153
@ Test
146
154
public void testDeleteSubAccount () throws Exception {
155
+ assumeCloudinaryAccountURLExist ();
147
156
ApiResponse createResult = createSubAccount ();
148
157
String id = createResult .get ("id" ).toString ();
149
158
ApiResponse result = account .deleteSubAccount (id , null );
@@ -155,6 +164,7 @@ public void testDeleteSubAccount() throws Exception {
155
164
// Users test
156
165
@ Test
157
166
public void testGetUser () throws Exception {
167
+ assumeCloudinaryAccountURLExist ();
158
168
ApiResponse user = createUser ();
159
169
String userId = user .get ("id" ).toString ();
160
170
ApiResponse result = account .user (userId , null );
@@ -165,6 +175,7 @@ public void testGetUser() throws Exception {
165
175
166
176
@ Test
167
177
public void testGetUsers () throws Exception {
178
+ assumeCloudinaryAccountURLExist ();
168
179
String user1Id = createUser (Account .Role .MASTER_ADMIN ).get ("id" ).toString ();
169
180
String user2Id = createUser (Account .Role .MASTER_ADMIN ).get ("id" ).toString ();
170
181
ApiResponse result = account .users (null , Arrays .asList (user1Id , user2Id ), null , null , null );
@@ -185,6 +196,7 @@ public void testGetUsers() throws Exception {
185
196
186
197
@ Test
187
198
public void testGetPendingUsers () throws Exception {
199
+ assumeCloudinaryAccountURLExist ();
188
200
String id = createUser (Account .Role .BILLING ).get ("id" ).toString ();
189
201
190
202
ApiResponse pending = account .users (true , Collections .singletonList (id ), null , null , null );
@@ -199,6 +211,7 @@ public void testGetPendingUsers() throws Exception {
199
211
200
212
@ Test
201
213
public void testGetUsersByPrefix () throws Exception {
214
+ assumeCloudinaryAccountURLExist ();
202
215
final long timeMillis = System .currentTimeMillis ();
203
216
final String userName = String .format ("SDK TEST Get Users By Prefix %d" , timeMillis );
204
217
final String userEmail =
String .
format (
"sdk-test-get-users-by-prefix+%[email protected] " ,
timeMillis );
@@ -217,6 +230,7 @@ public void testGetUsersByPrefix() throws Exception {
217
230
218
231
@ Test
219
232
public void testGetUsersBySubAccountIds () throws Exception {
233
+ assumeCloudinaryAccountURLExist ();
220
234
ApiResponse subAccount = createSubAccount ();
221
235
final String subAccountId = subAccount .get ("id" ).toString ();
222
236
@@ -235,41 +249,47 @@ public void testGetUsersBySubAccountIds() throws Exception {
235
249
236
250
@ Test
237
251
public void testGetUsersThrowsWhenSubAccountIdDoesntExist () throws Exception {
252
+ assumeCloudinaryAccountURLExist ();
238
253
final String subAccountId = randomLetters ();
239
254
expectedException .expectMessage ("Cannot find sub account with id " + subAccountId );
240
255
account .users (true , null , null , subAccountId , null );
241
256
}
242
257
243
258
@ Test
244
259
public void testCreateUser () throws Exception {
260
+ assumeCloudinaryAccountURLExist ();
245
261
ApiResponse createResult = createSubAccount ();
246
262
ApiResponse result = createUser (Collections .singletonList (createResult .get ("id" ).toString ()));
247
263
assertNotNull (result );
248
264
}
249
265
250
266
@ Test
251
267
public void testCreateUserWithOptions () throws Exception {
268
+ assumeCloudinaryAccountURLExist ();
252
269
ApiResponse createResult = createSubAccount ();
253
270
ApiResponse result = createUser (Collections .singletonList (createResult .get ("id" ).toString ()), ObjectUtils .emptyMap ());
254
271
assertNotNull (result );
255
272
}
256
273
257
274
@ Test
258
275
public void testCreateUserEnabled () throws Exception {
276
+ assumeCloudinaryAccountURLExist ();
259
277
ApiResponse createResult = createSubAccount ();
260
278
ApiResponse result = createUser (Collections .singletonList (createResult .get ("id" ).toString ()), true );
261
279
assertTrue ((Boolean ) result .get ("enabled" ));
262
280
}
263
281
264
282
@ Test
265
283
public void testCreateUserDisabled () throws Exception {
284
+ assumeCloudinaryAccountURLExist ();
266
285
ApiResponse createResult = createSubAccount ();
267
286
ApiResponse result = createUser (Collections .singletonList (createResult .get ("id" ).toString ()), false );
268
287
assertFalse ((Boolean ) result .get ("enabled" ));
269
288
}
270
289
271
290
@ Test
272
291
public void testUpdateUser () throws Exception {
292
+ assumeCloudinaryAccountURLExist ();
273
293
ApiResponse user = createUser (Account .Role .ADMIN );
274
294
String userId = user .get ("id" ).toString ();
275
295
String newName = randomLetters ();
@@ -282,6 +302,7 @@ public void testUpdateUser() throws Exception {
282
302
283
303
@ Test
284
304
public void testUpdateUserEnabled () throws Exception {
305
+ assumeCloudinaryAccountURLExist ();
285
306
ApiResponse user = createUser (Account .Role .ADMIN );
286
307
String userId = user .get ("id" ).toString ();
287
308
String newName = randomLetters ();
@@ -294,6 +315,7 @@ public void testUpdateUserEnabled() throws Exception {
294
315
295
316
@ Test
296
317
public void testUpdateUserDisabled () throws Exception {
318
+ assumeCloudinaryAccountURLExist ();
297
319
ApiResponse user = createUser (Account .Role .ADMIN );
298
320
String userId = user .get ("id" ).toString ();
299
321
String newName = randomLetters ();
@@ -306,6 +328,7 @@ public void testUpdateUserDisabled() throws Exception {
306
328
307
329
@ Test
308
330
public void testDeleteUser () throws Exception {
331
+ assumeCloudinaryAccountURLExist ();
309
332
ApiResponse user = createUser (Collections .<String >emptyList ());
310
333
String id = user .get ("id" ).toString ();
311
334
ApiResponse result = account .deleteUser (id , null );
@@ -316,12 +339,14 @@ public void testDeleteUser() throws Exception {
316
339
// groups
317
340
@ Test
318
341
public void testCreateUserGroup () throws Exception {
342
+ assumeCloudinaryAccountURLExist ();
319
343
ApiResponse group = createGroup ();
320
344
assertNotNull (group );
321
345
}
322
346
323
347
@ Test
324
348
public void testUpdateUserGroup () throws Exception {
349
+ assumeCloudinaryAccountURLExist ();
325
350
ApiResponse group = createGroup ();
326
351
String newName = randomLetters ();
327
352
ApiResponse result = account .updateUserGroup (group .get ("id" ).toString (), newName , null );
@@ -330,6 +355,7 @@ public void testUpdateUserGroup() throws Exception {
330
355
331
356
@ Test
332
357
public void testDeleteUserGroup () throws Exception {
358
+ assumeCloudinaryAccountURLExist ();
333
359
ApiResponse group = createGroup ();
334
360
String id = group .get ("id" ).toString ();
335
361
ApiResponse result = account .deleteUserGroup (id , null );
@@ -340,6 +366,7 @@ public void testDeleteUserGroup() throws Exception {
340
366
341
367
@ Test
342
368
public void testAddUserToUserGroup () throws Exception {
369
+ assumeCloudinaryAccountURLExist ();
343
370
ApiResponse user = createUser ();
344
371
ApiResponse group = createGroup ();
345
372
String userId = user .get ("id" ).toString ();
@@ -350,6 +377,7 @@ public void testAddUserToUserGroup() throws Exception {
350
377
351
378
@ Test
352
379
public void testRemoveUserFromUserGroup () throws Exception {
380
+ assumeCloudinaryAccountURLExist ();
353
381
ApiResponse user = createUser (Account .Role .MEDIA_LIBRARY_ADMIN );
354
382
ApiResponse group = createGroup ();
355
383
String groupId = group .get ("id" ).toString ();
@@ -362,6 +390,7 @@ public void testRemoveUserFromUserGroup() throws Exception {
362
390
363
391
@ Test
364
392
public void testListUserGroups () throws Exception {
393
+ assumeCloudinaryAccountURLExist ();
365
394
createGroup ();
366
395
ApiResponse result = account .userGroups ();
367
396
assertNotNull (result );
@@ -370,13 +399,15 @@ public void testListUserGroups() throws Exception {
370
399
371
400
@ Test
372
401
public void testListUserGroup () throws Exception {
402
+ assumeCloudinaryAccountURLExist ();
373
403
ApiResponse group = createGroup ();
374
404
ApiResponse result = account .userGroup (group .get ("id" ).toString (), null );
375
405
assertNotNull (result );
376
406
}
377
407
378
408
@ Test
379
409
public void testListUsersInGroup () throws Exception {
410
+ assumeCloudinaryAccountURLExist ();
380
411
ApiResponse user1 = createUser ();
381
412
ApiResponse user2 = createUser ();
382
413
ApiResponse group = createGroup ();
@@ -395,58 +426,69 @@ public void testListUsersInGroup() throws Exception {
395
426
396
427
// Helpers
397
428
private ApiResponse createGroup () throws Exception {
429
+ assumeCloudinaryAccountURLExist ();
398
430
String name = randomLetters ();
399
431
ApiResponse userGroup = account .createUserGroup (name );
400
432
createdGroupIds .add (userGroup .get ("id" ).toString ());
401
433
return userGroup ;
402
434
}
403
435
404
436
private ApiResponse createUser () throws Exception {
437
+ assumeCloudinaryAccountURLExist ();
405
438
return createUser (Collections .<String >emptyList ());
406
439
}
407
440
408
441
private ApiResponse createUser (Account .Role role ) throws Exception {
442
+ assumeCloudinaryAccountURLExist ();
409
443
return createUser (Collections .<String >emptyList (), role );
410
444
}
411
445
412
446
private ApiResponse createUser (List <String > subAccountsIds ) throws Exception {
447
+ assumeCloudinaryAccountURLExist ();
413
448
return createUser (subAccountsIds , Account .Role .BILLING );
414
449
}
415
450
416
451
private ApiResponse createUser (List <String > subAccountsIds , Map <String , Object > options ) throws Exception {
452
+ assumeCloudinaryAccountURLExist ();
417
453
return createUser (subAccountsIds , Account .Role .BILLING , options );
418
454
}
419
455
420
456
private ApiResponse createUser (List <String > subAccountsIds , Boolean enabled ) throws Exception {
457
+ assumeCloudinaryAccountURLExist ();
421
458
return createUser (subAccountsIds , Account .Role .BILLING , enabled );
422
459
}
423
460
424
461
private ApiResponse createUser (List <String > subAccountsIds , Account .Role role ) throws Exception {
462
+ assumeCloudinaryAccountURLExist ();
425
463
String email = "sdk+" + SDK_TEST_TAG + randomLetters () + "@cloudinary.com" ;
426
464
return createUser ("TestName" , email , role , subAccountsIds );
427
465
}
428
466
429
467
private ApiResponse createUser (List <String > subAccountsIds , Account .Role role , Map <String , Object > options ) throws Exception {
468
+ assumeCloudinaryAccountURLExist ();
430
469
String email = "sdk+" + SDK_TEST_TAG + randomLetters () + "@cloudinary.com" ;
431
470
ApiResponse user = account .createUser ("TestUserJava" +new Date ().toString (), email , role , null , subAccountsIds , options );
432
471
createdUserIds .add (user .get ("id" ).toString ());
433
472
return user ;
434
473
}
435
474
436
475
private ApiResponse createUser (List <String > subAccountsIds , Account .Role role , Boolean enabled ) throws Exception {
476
+ assumeCloudinaryAccountURLExist ();
437
477
String email = "sdk+" + SDK_TEST_TAG + randomLetters () + "@cloudinary.com" ;
438
478
ApiResponse user = account .createUser ("TestUserJava" +new Date ().toString (), email , role , enabled , subAccountsIds , null );
439
479
createdUserIds .add (user .get ("id" ).toString ());
440
480
return user ;
441
481
}
442
482
443
483
private ApiResponse createUser (final String name , String email , Account .Role role , List <String > subAccountsIds ) throws Exception {
484
+ assumeCloudinaryAccountURLExist ();
444
485
ApiResponse user = account .createUser (name , email , role , subAccountsIds , null );
445
486
createdUserIds .add (user .get ("id" ).toString ());
446
487
return user ;
447
488
}
448
489
449
490
private void deleteUser (String userId ){
491
+ assumeCloudinaryAccountURLExist ();
450
492
try {
451
493
account .deleteUser (userId , null );
452
494
createdUserIds .remove (userId );
@@ -457,12 +499,14 @@ private void deleteUser(String userId){
457
499
458
500
459
501
private ApiResponse createSubAccount () throws Exception {
502
+ assumeCloudinaryAccountURLExist ();
460
503
ApiResponse subAccount = account .createSubAccount (randomLetters (), null , emptyMap (), true , null );
461
504
createdSubAccountIds .add (subAccount .get ("id" ).toString ());
462
505
return subAccount ;
463
506
}
464
507
465
508
private static String randomLetters () {
509
+ assumeCloudinaryAccountURLExist ();
466
510
StringBuilder sb = new StringBuilder ();
467
511
for (int i = 0 ; i < 10 ; i ++) {
468
512
sb .append ((char ) ('a' + rand .nextInt ('z' - 'a' + 1 )));
0 commit comments