}
@Test
public void testUserGroupManagement() {
// Try to get non-existent
UserGroup userGroup = _userManager.getUserGroup("nonexistentusergroup");
assertNull(userGroup);
// Clear DB as necessary
userGroup = _userManager.getUserGroup("testusergroup");
if (userGroup != null) {
_userManager.deleteUserGroup(userGroup);
}
// Add
userGroup = new UserGroup(null, "testusergroup");
Authority authority = _userManager.getAuthority("testauthority");
if (authority == null) {
authority = new Authority("testauthority");
_userManager.addAuthority(authority);
}
userGroup.getAuthorities().add(authority);
User user = _userManager.getUser("testuser");
if (user == null) {
user = getTestUser();
_userManager.addUser(user);
}
_userManager.addUserGroup(userGroup);
// Update
Authority additionalAuthority = _userManager.getAuthority("additionalauthority");
if (additionalAuthority == null) {
additionalAuthority = new Authority("additionalauthority");
_userManager.addAuthority(additionalAuthority);
}
userGroup.getAuthorities().add(additionalAuthority);
_userManager.updateUserGroup(userGroup);
userGroup = _userManager.getUserGroup("testusergroup");
assertNotNull(userGroup);
assertTrue(userGroup.getAuthorities().contains(additionalAuthority));
// Delete
_userManager.deleteUserGroup(userGroup);
userGroup = _userManager.getUserGroup("testusergroup");
assertNull(userGroup);