//1. create a gatekeeper and assign test@example.com as developer
MockGateKeeper mockGateKeeper = new MockGateKeeper();
mockGateKeeper.allowRoleToUser("test@example.com", Role.DEVELOPER);
AdminAPI api = new AdminAPI();
api.setGateKeeper(mockGateKeeper);
//2. add a role and ensure it is present
User user = UserServiceFactory.getUserService().getCurrentUser();
String role = "testdummy_" + UUID.randomUUID();
APIResponse resp = api.addRole(role, user);
assertTrue(resp.statusCode == Status.SUCCESS);
List<RoleProp> roles = (List<RoleProp>) api.getAllRoles().object;
assertTrue("added role should be present",
isRolePresent(roles, role.toUpperCase()));
//3. rename a role and ensure the entity in datastore is updated
String newRole = role + "_new";
resp = api.renameRole(role, newRole, user);
assertTrue(resp.statusCode == Status.SUCCESS);
roles = (List<RoleProp>) api.getAllRoles().object;
assertTrue("new role should be present",
isRolePresent(roles, newRole.toUpperCase()));
assertTrue("old role should not be present",
(false == isRolePresent(roles, role.toUpperCase())));
//4. delete the role and ensure it is deleted from datastore
resp = api.deleteRole(newRole, user);
assertTrue("deletion should be success",
resp.statusCode == Status.SUCCESS);
roles = (List<RoleProp>) api.getAllRoles().object;
assertTrue("role after deletion should not be present",
(false == isRolePresent(roles, newRole.toUpperCase())));
}