@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(); userGroup.setName("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); }
@Test public void testAuthorityManagement() { // Try to get non-existent Authority authority = _userManager.getAuthority("nonexistentauthority"); assertNull(authority); // Clear DB as necessary authority = _userManager.getAuthority("authority"); if (authority != null) { _userManager.deleteAuthority(authority); } // Add authority = new Authority("regex"); _userManager.addAuthority(authority); // Update authority.setRegex("newregex"); _userManager.updateAuthority(authority); authority = _userManager.getAuthority("regex"); assertNull(authority); authority = _userManager.getAuthority("newregex"); assertNotNull(authority); assertEquals("newregex", authority.getRegex()); // Delete _userManager.deleteAuthority(authority); authority = _userManager.getAuthority("newregex"); assertNull(authority); }