use of com.zimbra.cs.account.Provisioning.MemberOf in project zm-mailbox by Zimbra.
the class TestLdapProvDynamicGroup method getGroupMembership.
/*
* Test Provisioning.getGroupMembership
*/
@Test
public void getGroupMembership() throws Exception {
Group group = createDynamicGroup(genGroupNameLocalPart());
Group otherDynamicGroup = createDynamicGroup(genGroupNameLocalPart("other-dynamic"));
Group otherStaticGroup = provUtil.createDistributionList(genGroupNameLocalPart("other-static"), domain);
Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
String externalAddr = "user@external.com";
GuestAccount guestAcct = new GuestAccount(externalAddr, null);
prov.addGroupMembers(group, new String[] { acct.getName(), externalAddr });
prov.addGroupMembers(otherDynamicGroup, new String[] { acct.getName(), externalAddr });
prov.addGroupMembers(otherStaticGroup, new String[] { acct.getName(), externalAddr });
Set<String> expectedMemberOf = Sets.newHashSet(Verify.makeResultStr(group.getId(), Boolean.FALSE), Verify.makeResultStr(otherDynamicGroup.getId(), Boolean.FALSE), Verify.makeResultStr(otherStaticGroup.getId(), Boolean.FALSE));
Set<String> expectedIds = Sets.newHashSet(Verify.makeResultStr(group.getId()), Verify.makeResultStr(otherDynamicGroup.getId()), Verify.makeResultStr(otherStaticGroup.getId()));
/*
* verify membership for acct
*/
GroupMembership membership = prov.getGroupMembership(acct, false);
List<MemberOf> memberOfList = membership.memberOf();
List<String> groupIdList = membership.groupIds();
Set<String> actualMemberOf = Sets.newHashSet();
for (MemberOf memberOf : memberOfList) {
actualMemberOf.add(Verify.makeResultStr(memberOf.getId(), memberOf.isAdminGroup()));
}
Set<String> actualIds = Sets.newHashSet();
for (String id : groupIdList) {
actualIds.add(Verify.makeResultStr(id));
}
Verify.verifyEquals(expectedMemberOf, actualMemberOf);
Verify.verifyEquals(expectedIds, actualIds);
/*
* verify membership for guest acct
*/
membership = prov.getGroupMembership(guestAcct, false);
memberOfList = membership.memberOf();
groupIdList = membership.groupIds();
actualMemberOf = Sets.newHashSet();
for (MemberOf memberOf : memberOfList) {
actualMemberOf.add(Verify.makeResultStr(memberOf.getId(), memberOf.isAdminGroup()));
}
actualIds = Sets.newHashSet();
for (String id : groupIdList) {
actualIds.add(Verify.makeResultStr(id));
}
Verify.verifyEquals(expectedMemberOf, actualMemberOf);
Verify.verifyEquals(expectedIds, actualIds);
}
Aggregations