@@ -38,6 +38,7 @@ public void setUp() throws Exception {
3838
3939 @ AfterClass
4040 public static void tearDownClass () {
41+ System .out .println ("Start TearDownClass" );
4142 Account account = new Account (new Cloudinary ());
4243 for (String createdSubAccountId : createdSubAccountIds ) {
4344 try {
@@ -62,6 +63,7 @@ public static void tearDownClass() {
6263 e .printStackTrace ();
6364 }
6465 }
66+ System .out .println ("### Deleted - SubAccounts:" +createdSubAccountIds .size ()+", Users:" +createdUserIds .size ()+ ", UserGroups:" +createdGroupIds .size ());
6567 }
6668
6769 @ Test
@@ -151,16 +153,18 @@ public void testDeleteSubAccount() throws Exception {
151153 @ Test
152154 public void testGetUser () throws Exception {
153155 ApiResponse user = createUser ();
154- String id = user .get ("id" ).toString ();
155- ApiResponse result = account .user (id , null );
156+ String userId = user .get ("id" ).toString ();
157+ ApiResponse result = account .user (userId , null );
158+
156159 assertNotNull (result );
160+ deleteUser (userId );
157161 }
158162
159163 @ Test
160164 public void testGetUsers () throws Exception {
161- String id1 = createUser (Account .Role .MASTER_ADMIN ).get ("id" ).toString ();
162- String id2 = createUser (Account .Role .MASTER_ADMIN ).get ("id" ).toString ();
163- ApiResponse result = account .users (null , Arrays .asList (id1 , id2 ), null , null , null );
165+ String user1Id = createUser (Account .Role .MASTER_ADMIN ).get ("id" ).toString ();
166+ String user2Id = createUser (Account .Role .MASTER_ADMIN ).get ("id" ).toString ();
167+ ApiResponse result = account .users (null , Arrays .asList (user1Id , user2Id ), null , null , null );
164168 assertNotNull (result );
165169 final ArrayList users = (ArrayList ) result .get ("users" );
166170 ArrayList <String > returnedIds = new ArrayList <String >(2 );
@@ -170,8 +174,10 @@ public void testGetUsers() throws Exception {
170174 returnedIds .add (((Map ) users .get (0 )).get ("id" ).toString ());
171175 returnedIds .add (((Map ) users .get (1 )).get ("id" ).toString ());
172176
173- assertTrue ("User1 id should be in the result set" , returnedIds .contains (id1 ));
174- assertTrue ("User2 id should be in the result set" , returnedIds .contains (id2 ));
177+ assertTrue ("User1 id should be in the result set" , returnedIds .contains (user1Id ));
178+ assertTrue ("User2 id should be in the result set" , returnedIds .contains (user2Id ));
179+ deleteUser (user1Id );
180+ deleteUser (user2Id );
175181 }
176182
177183 @ Test
@@ -184,11 +190,13 @@ public void testCreateUser() throws Exception {
184190 @ Test
185191 public void testUpdateUser () throws Exception {
186192 ApiResponse user = createUser (Account .Role .ADMIN );
187- String id = user .get ("id" ).toString ();
193+ String userId = user .get ("id" ).toString ();
188194 String newName = randomLetters ();
189- ApiResponse result = account .updateUser (id , newName , null , null , null , null );
195+ ApiResponse result = account .updateUser (userId , newName , null , null , null , null );
196+
190197 assertNotNull (result );
191198 assertEquals (result .get ("name" ), newName );
199+ deleteUser (userId );
192200 }
193201
194202 @ Test
@@ -232,6 +240,7 @@ public void testAddUserToUserGroup() throws Exception {
232240 String userId = user .get ("id" ).toString ();
233241 ApiResponse result = account .addUserToGroup (group .get ("id" ).toString (), userId , null );
234242 assertNotNull (result );
243+ deleteUser (userId );
235244 }
236245
237246 @ Test
@@ -243,6 +252,7 @@ public void testRemoveUserFromUserGroup() throws Exception {
243252 account .addUserToGroup (groupId , userId , null );
244253 ApiResponse result = account .removeUserFromGroup (groupId , userId , null );
245254 assertNotNull (result );
255+ deleteUser (userId );
246256 }
247257
248258 @ Test
@@ -273,6 +283,8 @@ public void testListUsersInGroup() throws Exception {
273283 ApiResponse result = account .userGroupUsers (groupId , null );
274284 assertNotNull (result );
275285 assertTrue (((List ) result .get ("users" )).size () >= 2 );
286+ deleteUser (user1Id );
287+ deleteUser (user2Id );
276288 }
277289
278290
@@ -298,11 +310,21 @@ private ApiResponse createUser(List<String> subAccountsIds) throws Exception {
298310
299311 private ApiResponse createUser (List <String > subAccountsIds , Account .Role role ) throws Exception {
300312 String email = String .format ("%s@%s.com" , randomLetters (), randomLetters ());
301- ApiResponse user = account .createUser ("TestName" , email , role , subAccountsIds , null );
313+ ApiResponse user = account .createUser ("TestUserJava" + new Date (). toString () , email , role , subAccountsIds , null );
302314 createdUserIds .add (user .get ("id" ).toString ());
303315 return user ;
304316 }
305317
318+ private void deleteUser (String userId ){
319+ try {
320+ account .deleteUser (userId , null );
321+ createdUserIds .remove (userId );
322+ } catch (Exception e ) {
323+ e .printStackTrace ();
324+ }
325+ }
326+
327+
306328 private ApiResponse createSubAccount () throws Exception {
307329 ApiResponse subAccount = account .createSubAccount (randomLetters (), null , emptyMap (), true , null );
308330 createdSubAccountIds .add (subAccount .get ("id" ).toString ());
0 commit comments