Search in sources :

Example 1 with MemberOf

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);
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) GuestAccount(com.zimbra.cs.account.GuestAccount) Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) MemberOf(com.zimbra.cs.account.Provisioning.MemberOf) GroupMembership(com.zimbra.cs.account.Provisioning.GroupMembership) Test(org.junit.Test)

Aggregations

Account (com.zimbra.cs.account.Account)1 DynamicGroup (com.zimbra.cs.account.DynamicGroup)1 Group (com.zimbra.cs.account.Group)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 GroupMembership (com.zimbra.cs.account.Provisioning.GroupMembership)1 MemberOf (com.zimbra.cs.account.Provisioning.MemberOf)1 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)1 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)1 Test (org.junit.Test)1