@Test public void testRemoveUserFromGroup() throws Exception { LdapGroup g1 = Utils.createTestGroup(CN); String[] usernames = {"U1_" + System.currentTimeMillis(), "U2_" + System.currentTimeMillis()}; if (HELPER.setGroup(g1)) { LOG.log(Level.INFO, "updated Group {0}", CN); } List<LdapUser> users = Utils.createTestUsers(usernames); for (LdapUser user : users) { g1.addUser(user); } HELPER.setGroup(g1); g1 = (LdapGroup) HELPER.getGroup(CN); int count = g1.getUsers().size(); LOG.log(Level.INFO, "user count Group {0} is {1}", new Object[] {CN, count}); g1.debug(); assertTrue(count > 1); g1.rmUser(users.get(0)); HELPER.setGroup(g1); g1 = (LdapGroup) HELPER.getGroup(CN); LOG.log(Level.INFO, "user count Group {0} is {1}", new Object[] {CN, g1.getUsers().size()}); g1.debug(); assertTrue(g1.getUsers().size() == (count - 1)); Utils.removeTestGroup(g1); Utils.removeTestUsers(users); }
@Test public void testGroupLoad() { LdapGroup group = (LdapGroup) HELPER.getGroup(HELPER.getAdminGroupIdentifiyer()); group.debug(); LOG.log(Level.INFO, "\nmembers: {0}\n", group.get(HELPER.getGroupMemberAttribut())); assertFalse(group.isNew()); assertFalse(group.isEmpty()); }
@BeforeClass public static void setUpClass() throws Exception { HELPER = Utils.getHelper(); CN = "G_" + System.currentTimeMillis(); testUser1 = HELPER.getUserTemplate("U_" + System.currentTimeMillis()); testUser1.set("cn", testUser1.getUid()); HELPER.setUser(testUser1); }
@Test public void testUpdateGroup() throws Exception { LdapGroup g1 = Utils.createTestGroup(CN); assertNull(g1.get("description")); g1.set("description", "Group " + CN); HELPER.setGroup(g1); g1 = (LdapGroup) HELPER.getGroup(CN); assertEquals(g1.get("description"), "Group " + CN); Utils.removeTestGroup(g1); }
@Test public void testAddUserToGroup() throws Exception { LdapGroup g1 = Utils.createTestGroup(CN); g1.addUser(testUser1); if (HELPER.setGroup(g1)) { LOG.log(Level.INFO, "updated Group {0}", CN); } g1 = (LdapGroup) HELPER.getGroup(CN); g1.debug(); Utils.removeTestGroup(g1); }
@Test public void testCreateGroup() throws Exception { Node g1 = HELPER.getGroup(CN); assertTrue(g1.isEmpty()); LdapGroup t1 = Utils.getTestGroup("test"); t1 = Utils.updatedGroup(t1, CN); if (HELPER.setGroup(t1)) { LOG.log(Level.INFO, "created Group {0}", CN); } g1 = HELPER.getGroup(CN); assertFalse(g1.isEmpty()); }
@Test public void testDeleteGroup() throws Exception { LdapGroup g1 = Utils.createTestGroup(CN); try { if (HELPER.rmGroup(g1)) { LOG.log(Level.INFO, "deleted Group {0}", CN); } } catch (Exception ex) { LOG.log(Level.SEVERE, "setGroup fails", ex); } g1 = (LdapGroup) HELPER.getGroup(CN); assertTrue(g1.isEmpty()); }
@Test public void testUpdateExistingGroup() throws Exception { LdapGroup g1 = (LdapGroup) HELPER.getGroup("users"); LOG.log(Level.INFO, "Group users description: {0}", g1.get("description")); String description = g1.get("description"); g1.set("description", description + CN); HELPER.setGroup(g1); g1 = (LdapGroup) HELPER.getGroup("users"); assertEquals(g1.get("description"), description + CN); g1.set("description", description); HELPER.setGroup(g1); g1 = (LdapGroup) HELPER.getGroup("users"); assertEquals(g1.get("description"), description); }
@Test public void testAddUsersToGroup() throws Exception { testUser2 = HELPER.getUserTemplate("U_" + System.currentTimeMillis()); testUser2.set("cn", testUser2.getUid()); HELPER.setUser(testUser2); LdapGroup g1 = Utils.createTestGroup(CN); g1.addUser(testUser1); g1.addUser(testUser2); HELPER.setGroup(g1); g1 = (LdapGroup) HELPER.getGroup(CN); LOG.log(Level.INFO, "user count Group {0} is {1}", new Object[] {CN, g1.getUsers().size()}); assertTrue(g1.getUsers().size() > 2); Utils.removeTestGroup(g1); }
@Test public void testUpdateEmptyGroup() throws Exception { LdapGroup g1 = Utils.createTestGroup(CN); int count = g1.getUsers().size(); LOG.log(Level.INFO, "user count Group {0} is {1}", new Object[] {CN, count}); g1.debug(); List<LdapUser> users = new ArrayList<LdapUser>(); for (LdapUser user : g1.getUsers()) { users.add(user); } for (LdapUser user : users) { g1.rmUser(user); } HELPER.setGroup(g1); g1 = (LdapGroup) HELPER.getGroup(CN); count = g1.getUsers().size(); LOG.log(Level.INFO, "user count Group {0} is {1}", new Object[] {CN, count}); g1.debug(); assertTrue(g1.getUsers().size() == 1); Utils.removeTestGroup(g1); }
@AfterClass public static void tearDownClass() throws Exception { HELPER.rmUser(testUser1); HELPER.rmUser(testUser2); }