Skip to content

Commit 6481c37

Browse files
committed
Added users cleanup on account testing to avoid "too many users" errors.
1 parent eac25a1 commit 6481c37

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractAccountApiTest.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ public void testDeleteSubAccount() throws Exception {
151151
@Test
152152
public void testGetUser() throws Exception {
153153
ApiResponse user = createUser();
154-
ApiResponse result = account.user(user.get("id").toString(), null);
154+
String id = user.get("id").toString();
155+
ApiResponse result = account.user(id, null);
155156
assertNotNull(result);
157+
deleteUser(id);
156158
}
157159

158160
@Test
@@ -171,6 +173,9 @@ public void testGetUsers() throws Exception {
171173

172174
assertTrue("User1 id should be in the result set", returnedIds.contains(id1));
173175
assertTrue("User2 id should be in the result set", returnedIds.contains(id2));
176+
deleteUser(id1);
177+
deleteUser(id2);
178+
174179
}
175180

176181
@Test
@@ -183,11 +188,12 @@ public void testCreateUser() throws Exception {
183188
@Test
184189
public void testUpdateUser() throws Exception {
185190
ApiResponse user = createUser(Account.Role.ADMIN);
186-
191+
String id = user.get("id").toString();
187192
String newName = randomLetters();
188-
ApiResponse result = account.updateUser(user.get("id").toString(), newName, null, null, null, null);
193+
ApiResponse result = account.updateUser(id, newName, null, null, null, null);
189194
assertNotNull(result);
190195
assertEquals(result.get("name"), newName);
196+
deleteUser(id);
191197
}
192198

193199
@Test
@@ -228,8 +234,10 @@ public void testDeleteUserGroup() throws Exception {
228234
public void testAddUserToUserGroup() throws Exception {
229235
ApiResponse user = createUser();
230236
ApiResponse group = createGroup();
231-
ApiResponse result = account.addUserToGroup(group.get("id").toString(), user.get("id").toString(), null);
237+
String userId = user.get("id").toString();
238+
ApiResponse result = account.addUserToGroup(group.get("id").toString(), userId, null);
232239
assertNotNull(result);
240+
deleteUser(userId);
233241
}
234242

235243
@Test
@@ -241,6 +249,7 @@ public void testRemoveUserFromUserGroup() throws Exception {
241249
account.addUserToGroup(groupId, userId, null);
242250
ApiResponse result = account.removeUserFromGroup(groupId, userId, null);
243251
assertNotNull(result);
252+
deleteUser(userId);
244253
}
245254

246255
@Test
@@ -271,6 +280,8 @@ public void testListUsersInGroup() throws Exception {
271280
ApiResponse result = account.userGroupUsers(groupId, null);
272281
assertNotNull(result);
273282
assertTrue(((List) result.get("users")).size() >= 2);
283+
deleteUser(user1Id);
284+
deleteUser(user2Id);
274285
}
275286

276287

@@ -280,7 +291,6 @@ private ApiResponse createGroup() throws Exception {
280291
ApiResponse userGroup = account.createUserGroup(name);
281292
createdGroupIds.add(userGroup.get("id").toString());
282293
return userGroup;
283-
284294
}
285295

286296
private ApiResponse createUser(Account.Role role) throws Exception {
@@ -313,7 +323,15 @@ private static String randomLetters() {
313323
for (int i = 0; i < 10; i++) {
314324
sb.append((char) ('a' + rand.nextInt('z' - 'a' + 1)));
315325
}
316-
317326
return sb.toString();
318327
}
328+
329+
private void deleteUser(String userId) {
330+
try {
331+
account.deleteUser(userId, null);
332+
createdUserIds.remove(userId);
333+
} catch (Exception e) {
334+
e.printStackTrace();
335+
}
336+
}
319337
}

0 commit comments

Comments
 (0)