Search in sources :

Example 21 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.

the class TestContactGroup method derefGal.

@Test
public void derefGal() throws Exception {
    Account account = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user1"));
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    // TODO
    OperationContext octxt = null;
    Account galMember = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user2"));
    LdapAccount ldapAccount = (LdapAccount) galMember;
    String dn = ldapAccount.getDN();
    String email = galMember.getName();
    ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.GAL_REF, dn), new MemberData(Member.Type.INLINE, "aaa@test.com"), new MemberData(Member.Type.INLINE, "zzz@test.com") });
    contactGroup.derefAllMembers(mbox, octxt);
    boolean gotGalRefMember = false;
    String prevMemberKey = null;
    for (Member member : contactGroup.getDerefedMembers()) {
        String memberKey = member.getDerefedKey();
        if (prevMemberKey != null) {
            assertTrue(prevMemberKey.compareTo(memberKey) < 0);
        }
        prevMemberKey = memberKey;
        Member.Type type = member.getType();
        if (type == Member.Type.GAL_REF) {
            assertEquals(email, memberKey);
            gotGalRefMember = true;
        }
    // System.out.println(memberKey);
    }
    List<String> emailAddrs = contactGroup.getEmailAddresses(false, mbox, octxt, false);
    assertEquals(3, emailAddrs.size());
    assertTrue(emailAddrs.contains(email));
    assertTrue(emailAddrs.contains("aaa@test.com"));
    assertTrue(emailAddrs.contains("zzz@test.com"));
    assertTrue(gotGalRefMember);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 22 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.

the class TestContactGroup method removeNonExistingMember.

@Test
public void removeNonExistingMember() throws Exception {
    ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, CONTACT_REF_VALUE), new MemberData(Member.Type.GAL_REF, GAL_REF_VALUE), new MemberData(Member.Type.INLINE, INLINE_VALUE) });
    boolean caughtException = false;
    try {
        contactGroup.removeMember(Member.Type.INLINE, "not there");
    } catch (ServiceException e) {
        if (e.getMessage().startsWith("invalid request: no such member:")) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    // verify members are untouched
    contactGroup = reEncode(contactGroup);
    List<Member> members = contactGroup.getMembers();
    assertEquals(3, members.size());
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 23 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.

the class TestContactGroup method addMember.

@Test
public void addMember() throws Exception {
    ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, CONTACT_REF_VALUE), new MemberData(Member.Type.GAL_REF, GAL_REF_VALUE), new MemberData(Member.Type.INLINE, INLINE_VALUE) });
    MemberData memberToAdd = new MemberData(Member.Type.INLINE, "added");
    Member addedMember = contactGroup.addMember(memberToAdd.type, memberToAdd.value);
    contactGroup = reEncode(contactGroup);
    List<Member> members = contactGroup.getMembers();
    assertEquals(4, members.size());
    Member newMember = members.get(3);
    assertEquals(memberToAdd.type, newMember.getType());
    assertEquals(memberToAdd.value, newMember.getValue());
}
Also used : ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 24 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.

the class TestContactGroup method insertOrder.

@Test
public void insertOrder() throws Exception {
    int NUM_MEMBERS = 5;
    ContactGroup contactGroup = createContactGroup(new MemberData[0]);
    for (int i = 1; i <= NUM_MEMBERS; i++) {
        MemberData memberData = new MemberData(Member.Type.INLINE, "" + i);
        contactGroup.addMember(memberData.type, memberData.value);
    }
    contactGroup = reEncode(contactGroup);
    List<Member> members = contactGroup.getMembers();
    Member firstMember = members.get(0);
    // delete
    contactGroup.removeMember(firstMember.getType(), firstMember.getValue());
    // then re-add
    contactGroup.addMember(firstMember.getType(), firstMember.getValue());
    contactGroup = reEncode(contactGroup);
    members = contactGroup.getMembers();
    // verify the member is now at the end and other member shifted up
    for (int i = 0; i < NUM_MEMBERS - 1; i++) {
        Member member = members.get(i);
        assertEquals(Member.Type.INLINE, member.getType());
        assertEquals("" + (i + 2), member.getValue());
    }
    Member lastMember = members.get(NUM_MEMBERS - 1);
    assertEquals(firstMember.getType(), lastMember.getType());
    assertEquals(firstMember.getValue(), lastMember.getValue());
}
Also used : ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Example 25 with ContactGroup

use of com.zimbra.cs.mailbox.ContactGroup in project zm-mailbox by Zimbra.

the class TestContactGroup method deleteAllMembers.

@Test
public void deleteAllMembers() throws Exception {
    ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, CONTACT_REF_VALUE), new MemberData(Member.Type.GAL_REF, GAL_REF_VALUE), new MemberData(Member.Type.INLINE, INLINE_VALUE) });
    contactGroup.removeAllMembers();
    contactGroup = reEncode(contactGroup);
    List<Member> members = contactGroup.getMembers();
    assertEquals(0, members.size());
}
Also used : ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ContactRefMember(com.zimbra.cs.mailbox.ContactGroup.ContactRefMember) GalRefMember(com.zimbra.cs.mailbox.ContactGroup.GalRefMember) Member(com.zimbra.cs.mailbox.ContactGroup.Member) InlineMember(com.zimbra.cs.mailbox.ContactGroup.InlineMember) Test(org.junit.Test)

Aggregations

ContactGroup (com.zimbra.cs.mailbox.ContactGroup)25 Member (com.zimbra.cs.mailbox.ContactGroup.Member)16 Test (org.junit.Test)13 ContactRefMember (com.zimbra.cs.mailbox.ContactGroup.ContactRefMember)12 GalRefMember (com.zimbra.cs.mailbox.ContactGroup.GalRefMember)12 InlineMember (com.zimbra.cs.mailbox.ContactGroup.InlineMember)12 Contact (com.zimbra.cs.mailbox.Contact)9 HashMap (java.util.HashMap)8 ServiceException (com.zimbra.common.service.ServiceException)7 Account (com.zimbra.cs.account.Account)5 Mailbox (com.zimbra.cs.mailbox.Mailbox)5 ItemId (com.zimbra.cs.service.util.ItemId)5 ArrayList (java.util.ArrayList)5 ZMailbox (com.zimbra.client.ZMailbox)4 Element (com.zimbra.common.soap.Element)4 OperationContext (com.zimbra.cs.mailbox.OperationContext)4 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)3 Attachment (com.zimbra.cs.mailbox.Contact.Attachment)3 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)2 VCardParamsAndValue (com.zimbra.cs.mailbox.VCardParamsAndValue)2