DN groupDN = DN.decode("cn=Test Group of Unique Names,ou=Groups,o=test");
DN user1DN = DN.decode("uid=user.1,ou=People,o=test");
DN user2DN = DN.decode("uid=user.2,ou=People,o=test");
DN user3DN = DN.decode("uid=user.3,ou=People,o=test");
Group groupInstance = groupManager.getGroupInstance(groupDN);
assertNotNull(groupInstance);
assertEquals(groupInstance.getGroupDN(), groupDN);
assertTrue(groupInstance.isMember(user1DN));
assertTrue(groupInstance.isMember(user2DN));
assertFalse(groupInstance.isMember(user3DN));
MemberList memberList = groupInstance.getMembers();
while (memberList.hasMoreMembers())
{
DN memberDN = memberList.nextMemberDN();
assertTrue(memberDN.equals(user1DN) || memberDN.equals(user2DN));
}
SearchFilter filter = SearchFilter.createFilterFromString("(uid=user.1)");
memberList = groupInstance.getMembers(DN.decode("o=test"),
SearchScope.WHOLE_SUBTREE, filter);
assertTrue(memberList.hasMoreMembers());
DN memberDN = memberList.nextMemberDN();
assertTrue(memberDN.equals(user1DN));
assertFalse(memberList.hasMoreMembers());
filter = SearchFilter.createFilterFromString("(uid=user.3)");
memberList = groupInstance.getMembers(DN.decode("o=test"),
SearchScope.WHOLE_SUBTREE, filter);
assertFalse(memberList.hasMoreMembers());
// Modify the group and make sure the group manager gets updated
// accordingly.
LinkedList<Modification> mods = new LinkedList<Modification>();
Attribute a2 = Attributes.create("uniquemember", "uid=user.2,ou=People,o=test");
Attribute a3 = Attributes.create("uniquemember", "uid=user.3,ou=People,o=test");
mods.add(new Modification(ModificationType.DELETE, a2));
mods.add(new Modification(ModificationType.ADD, a3));
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
ModifyOperation modifyOperation = conn.processModify(groupDN, mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
groupInstance = groupManager.getGroupInstance(groupDN);
assertNotNull(groupInstance);
assertEquals(groupInstance.getGroupDN(), groupDN);
assertTrue(groupInstance.isMember(user1DN));
assertFalse(groupInstance.isMember(user2DN));
assertTrue(groupInstance.isMember(user3DN));
// Delete the group and make sure the group manager gets updated
// accordingly.
DeleteOperation deleteOperation = conn.processDelete(groupDN);