1515import static java .util .Collections .singletonMap ;
1616import static junit .framework .TestCase .assertTrue ;
1717import static org .junit .Assert .*;
18+ import static org .junit .Assume .assumeTrue ;
1819
1920public abstract class AbstractAccountApiTest extends MockableTest {
2021 private static Random rand = new Random ();
@@ -35,12 +36,14 @@ public static void setUpClass() {
3536
3637 @ Before
3738 public void setUp () throws Exception {
39+ assumeCloudinaryAccountURLExist ();
3840 System .out .println ("Running " + this .getClass ().getName () + "." + currentTest .getMethodName ());
3941 this .account = new Account (new Cloudinary ());
4042 }
4143
4244 @ AfterClass
4345 public static void tearDownClass () {
46+ assumeCloudinaryAccountURLExist ();
4447 System .out .println ("Start TearDownClass" );
4548 Account account = new Account (new Cloudinary ());
4649 for (String createdSubAccountId : createdSubAccountIds ) {
@@ -71,6 +74,7 @@ public static void tearDownClass() {
7174
7275 @ Test
7376 public void testPassingCredentialsThroughOptions () throws Exception {
77+ assumeCloudinaryAccountURLExist ();
7478 int exceptions = 0 ;
7579
7680 Map <String , Object > map = singletonMap ("provisioning_api_secret" , new Object ()) ;
@@ -104,13 +108,15 @@ public void testPassingCredentialsThroughOptions() throws Exception {
104108 // Sub accounts tests
105109 @ Test
106110 public void testGetSubAccount () throws Exception {
111+ assumeCloudinaryAccountURLExist ();
107112 ApiResponse accountResponse = createSubAccount ();
108113 ApiResponse account = this .account .subAccount (accountResponse .get ("id" ).toString (), null );
109114 assertNotNull (account );
110115 }
111116
112117 @ Test
113118 public void testGetSubAccounts () throws Exception {
119+ assumeCloudinaryAccountURLExist ();
114120 createSubAccount ();
115121 ApiResponse accounts = account .subAccounts (null , null , null , null );
116122 assertNotNull (accounts );
@@ -119,6 +125,7 @@ public void testGetSubAccounts() throws Exception {
119125
120126 @ Test
121127 public void testCreateSubAccount () throws Exception {
128+ assumeCloudinaryAccountURLExist ();
122129 ApiResponse result = createSubAccount ();
123130 assertNotNull (result );
124131
@@ -135,6 +142,7 @@ public void testCreateSubAccount() throws Exception {
135142
136143 @ Test
137144 public void testUpdateSubAccount () throws Exception {
145+ assumeCloudinaryAccountURLExist ();
138146 ApiResponse subAccount = createSubAccount ();
139147 String newCloudName = randomLetters ();
140148 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 {
144152
145153 @ Test
146154 public void testDeleteSubAccount () throws Exception {
155+ assumeCloudinaryAccountURLExist ();
147156 ApiResponse createResult = createSubAccount ();
148157 String id = createResult .get ("id" ).toString ();
149158 ApiResponse result = account .deleteSubAccount (id , null );
@@ -155,6 +164,7 @@ public void testDeleteSubAccount() throws Exception {
155164 // Users test
156165 @ Test
157166 public void testGetUser () throws Exception {
167+ assumeCloudinaryAccountURLExist ();
158168 ApiResponse user = createUser ();
159169 String userId = user .get ("id" ).toString ();
160170 ApiResponse result = account .user (userId , null );
@@ -165,6 +175,7 @@ public void testGetUser() throws Exception {
165175
166176 @ Test
167177 public void testGetUsers () throws Exception {
178+ assumeCloudinaryAccountURLExist ();
168179 String user1Id = createUser (Account .Role .MASTER_ADMIN ).get ("id" ).toString ();
169180 String user2Id = createUser (Account .Role .MASTER_ADMIN ).get ("id" ).toString ();
170181 ApiResponse result = account .users (null , Arrays .asList (user1Id , user2Id ), null , null , null );
@@ -185,6 +196,7 @@ public void testGetUsers() throws Exception {
185196
186197 @ Test
187198 public void testGetPendingUsers () throws Exception {
199+ assumeCloudinaryAccountURLExist ();
188200 String id = createUser (Account .Role .BILLING ).get ("id" ).toString ();
189201
190202 ApiResponse pending = account .users (true , Collections .singletonList (id ), null , null , null );
@@ -199,6 +211,7 @@ public void testGetPendingUsers() throws Exception {
199211
200212 @ Test
201213 public void testGetUsersByPrefix () throws Exception {
214+ assumeCloudinaryAccountURLExist ();
202215 final long timeMillis = System .currentTimeMillis ();
203216 final String userName = String .format ("SDK TEST Get Users By Prefix %d" , timeMillis );
204217 final String userEmail =
String .
format (
"sdk-test-get-users-by-prefix+%[email protected] " ,
timeMillis );
@@ -217,6 +230,7 @@ public void testGetUsersByPrefix() throws Exception {
217230
218231 @ Test
219232 public void testGetUsersBySubAccountIds () throws Exception {
233+ assumeCloudinaryAccountURLExist ();
220234 ApiResponse subAccount = createSubAccount ();
221235 final String subAccountId = subAccount .get ("id" ).toString ();
222236
@@ -235,41 +249,47 @@ public void testGetUsersBySubAccountIds() throws Exception {
235249
236250 @ Test
237251 public void testGetUsersThrowsWhenSubAccountIdDoesntExist () throws Exception {
252+ assumeCloudinaryAccountURLExist ();
238253 final String subAccountId = randomLetters ();
239254 expectedException .expectMessage ("Cannot find sub account with id " + subAccountId );
240255 account .users (true , null , null , subAccountId , null );
241256 }
242257
243258 @ Test
244259 public void testCreateUser () throws Exception {
260+ assumeCloudinaryAccountURLExist ();
245261 ApiResponse createResult = createSubAccount ();
246262 ApiResponse result = createUser (Collections .singletonList (createResult .get ("id" ).toString ()));
247263 assertNotNull (result );
248264 }
249265
250266 @ Test
251267 public void testCreateUserWithOptions () throws Exception {
268+ assumeCloudinaryAccountURLExist ();
252269 ApiResponse createResult = createSubAccount ();
253270 ApiResponse result = createUser (Collections .singletonList (createResult .get ("id" ).toString ()), ObjectUtils .emptyMap ());
254271 assertNotNull (result );
255272 }
256273
257274 @ Test
258275 public void testCreateUserEnabled () throws Exception {
276+ assumeCloudinaryAccountURLExist ();
259277 ApiResponse createResult = createSubAccount ();
260278 ApiResponse result = createUser (Collections .singletonList (createResult .get ("id" ).toString ()), true );
261279 assertTrue ((Boolean ) result .get ("enabled" ));
262280 }
263281
264282 @ Test
265283 public void testCreateUserDisabled () throws Exception {
284+ assumeCloudinaryAccountURLExist ();
266285 ApiResponse createResult = createSubAccount ();
267286 ApiResponse result = createUser (Collections .singletonList (createResult .get ("id" ).toString ()), false );
268287 assertFalse ((Boolean ) result .get ("enabled" ));
269288 }
270289
271290 @ Test
272291 public void testUpdateUser () throws Exception {
292+ assumeCloudinaryAccountURLExist ();
273293 ApiResponse user = createUser (Account .Role .ADMIN );
274294 String userId = user .get ("id" ).toString ();
275295 String newName = randomLetters ();
@@ -282,6 +302,7 @@ public void testUpdateUser() throws Exception {
282302
283303 @ Test
284304 public void testUpdateUserEnabled () throws Exception {
305+ assumeCloudinaryAccountURLExist ();
285306 ApiResponse user = createUser (Account .Role .ADMIN );
286307 String userId = user .get ("id" ).toString ();
287308 String newName = randomLetters ();
@@ -294,6 +315,7 @@ public void testUpdateUserEnabled() throws Exception {
294315
295316 @ Test
296317 public void testUpdateUserDisabled () throws Exception {
318+ assumeCloudinaryAccountURLExist ();
297319 ApiResponse user = createUser (Account .Role .ADMIN );
298320 String userId = user .get ("id" ).toString ();
299321 String newName = randomLetters ();
@@ -306,6 +328,7 @@ public void testUpdateUserDisabled() throws Exception {
306328
307329 @ Test
308330 public void testDeleteUser () throws Exception {
331+ assumeCloudinaryAccountURLExist ();
309332 ApiResponse user = createUser (Collections .<String >emptyList ());
310333 String id = user .get ("id" ).toString ();
311334 ApiResponse result = account .deleteUser (id , null );
@@ -316,12 +339,14 @@ public void testDeleteUser() throws Exception {
316339 // groups
317340 @ Test
318341 public void testCreateUserGroup () throws Exception {
342+ assumeCloudinaryAccountURLExist ();
319343 ApiResponse group = createGroup ();
320344 assertNotNull (group );
321345 }
322346
323347 @ Test
324348 public void testUpdateUserGroup () throws Exception {
349+ assumeCloudinaryAccountURLExist ();
325350 ApiResponse group = createGroup ();
326351 String newName = randomLetters ();
327352 ApiResponse result = account .updateUserGroup (group .get ("id" ).toString (), newName , null );
@@ -330,6 +355,7 @@ public void testUpdateUserGroup() throws Exception {
330355
331356 @ Test
332357 public void testDeleteUserGroup () throws Exception {
358+ assumeCloudinaryAccountURLExist ();
333359 ApiResponse group = createGroup ();
334360 String id = group .get ("id" ).toString ();
335361 ApiResponse result = account .deleteUserGroup (id , null );
@@ -340,6 +366,7 @@ public void testDeleteUserGroup() throws Exception {
340366
341367 @ Test
342368 public void testAddUserToUserGroup () throws Exception {
369+ assumeCloudinaryAccountURLExist ();
343370 ApiResponse user = createUser ();
344371 ApiResponse group = createGroup ();
345372 String userId = user .get ("id" ).toString ();
@@ -350,6 +377,7 @@ public void testAddUserToUserGroup() throws Exception {
350377
351378 @ Test
352379 public void testRemoveUserFromUserGroup () throws Exception {
380+ assumeCloudinaryAccountURLExist ();
353381 ApiResponse user = createUser (Account .Role .MEDIA_LIBRARY_ADMIN );
354382 ApiResponse group = createGroup ();
355383 String groupId = group .get ("id" ).toString ();
@@ -362,6 +390,7 @@ public void testRemoveUserFromUserGroup() throws Exception {
362390
363391 @ Test
364392 public void testListUserGroups () throws Exception {
393+ assumeCloudinaryAccountURLExist ();
365394 createGroup ();
366395 ApiResponse result = account .userGroups ();
367396 assertNotNull (result );
@@ -370,13 +399,15 @@ public void testListUserGroups() throws Exception {
370399
371400 @ Test
372401 public void testListUserGroup () throws Exception {
402+ assumeCloudinaryAccountURLExist ();
373403 ApiResponse group = createGroup ();
374404 ApiResponse result = account .userGroup (group .get ("id" ).toString (), null );
375405 assertNotNull (result );
376406 }
377407
378408 @ Test
379409 public void testListUsersInGroup () throws Exception {
410+ assumeCloudinaryAccountURLExist ();
380411 ApiResponse user1 = createUser ();
381412 ApiResponse user2 = createUser ();
382413 ApiResponse group = createGroup ();
@@ -395,58 +426,69 @@ public void testListUsersInGroup() throws Exception {
395426
396427 // Helpers
397428 private ApiResponse createGroup () throws Exception {
429+ assumeCloudinaryAccountURLExist ();
398430 String name = randomLetters ();
399431 ApiResponse userGroup = account .createUserGroup (name );
400432 createdGroupIds .add (userGroup .get ("id" ).toString ());
401433 return userGroup ;
402434 }
403435
404436 private ApiResponse createUser () throws Exception {
437+ assumeCloudinaryAccountURLExist ();
405438 return createUser (Collections .<String >emptyList ());
406439 }
407440
408441 private ApiResponse createUser (Account .Role role ) throws Exception {
442+ assumeCloudinaryAccountURLExist ();
409443 return createUser (Collections .<String >emptyList (), role );
410444 }
411445
412446 private ApiResponse createUser (List <String > subAccountsIds ) throws Exception {
447+ assumeCloudinaryAccountURLExist ();
413448 return createUser (subAccountsIds , Account .Role .BILLING );
414449 }
415450
416451 private ApiResponse createUser (List <String > subAccountsIds , Map <String , Object > options ) throws Exception {
452+ assumeCloudinaryAccountURLExist ();
417453 return createUser (subAccountsIds , Account .Role .BILLING , options );
418454 }
419455
420456 private ApiResponse createUser (List <String > subAccountsIds , Boolean enabled ) throws Exception {
457+ assumeCloudinaryAccountURLExist ();
421458 return createUser (subAccountsIds , Account .Role .BILLING , enabled );
422459 }
423460
424461 private ApiResponse createUser (List <String > subAccountsIds , Account .Role role ) throws Exception {
462+ assumeCloudinaryAccountURLExist ();
425463 String email = "sdk+" + SDK_TEST_TAG + randomLetters () + "@cloudinary.com" ;
426464 return createUser ("TestName" , email , role , subAccountsIds );
427465 }
428466
429467 private ApiResponse createUser (List <String > subAccountsIds , Account .Role role , Map <String , Object > options ) throws Exception {
468+ assumeCloudinaryAccountURLExist ();
430469 String email = "sdk+" + SDK_TEST_TAG + randomLetters () + "@cloudinary.com" ;
431470 ApiResponse user = account .createUser ("TestUserJava" +new Date ().toString (), email , role , null , subAccountsIds , options );
432471 createdUserIds .add (user .get ("id" ).toString ());
433472 return user ;
434473 }
435474
436475 private ApiResponse createUser (List <String > subAccountsIds , Account .Role role , Boolean enabled ) throws Exception {
476+ assumeCloudinaryAccountURLExist ();
437477 String email = "sdk+" + SDK_TEST_TAG + randomLetters () + "@cloudinary.com" ;
438478 ApiResponse user = account .createUser ("TestUserJava" +new Date ().toString (), email , role , enabled , subAccountsIds , null );
439479 createdUserIds .add (user .get ("id" ).toString ());
440480 return user ;
441481 }
442482
443483 private ApiResponse createUser (final String name , String email , Account .Role role , List <String > subAccountsIds ) throws Exception {
484+ assumeCloudinaryAccountURLExist ();
444485 ApiResponse user = account .createUser (name , email , role , subAccountsIds , null );
445486 createdUserIds .add (user .get ("id" ).toString ());
446487 return user ;
447488 }
448489
449490 private void deleteUser (String userId ){
491+ assumeCloudinaryAccountURLExist ();
450492 try {
451493 account .deleteUser (userId , null );
452494 createdUserIds .remove (userId );
@@ -457,12 +499,14 @@ private void deleteUser(String userId){
457499
458500
459501 private ApiResponse createSubAccount () throws Exception {
502+ assumeCloudinaryAccountURLExist ();
460503 ApiResponse subAccount = account .createSubAccount (randomLetters (), null , emptyMap (), true , null );
461504 createdSubAccountIds .add (subAccount .get ("id" ).toString ());
462505 return subAccount ;
463506 }
464507
465508 private static String randomLetters () {
509+ assumeCloudinaryAccountURLExist ();
466510 StringBuilder sb = new StringBuilder ();
467511 for (int i = 0 ; i < 10 ; i ++) {
468512 sb .append ((char ) ('a' + rand .nextInt ('z' - 'a' + 1 )));
0 commit comments