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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations