use of com.zimbra.client.ZContact in project zm-mailbox by Zimbra.
the class TestZClient method testImapUIDForNonStandardContact.
@Test
public void testImapUIDForNonStandardContact() throws ServiceException {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Contact contact = TestUtil.createContactInDefaultFolder(mbox, "testzclient@example.com");
ItemIdentifier contactId = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), contact.getId());
Element reqEl = zmbox.newRequestElement(MailConstants.GET_CONTACTS_REQUEST);
// Specifically do NOT do reqEl.addAttribute(MailConstants.A_WANT_IMAP_UID, true);
reqEl.addNonUniqueElement(MailConstants.E_CONTACT).addAttribute(MailConstants.A_ID, contactId.id);
Element respEl = zmbox.invoke(reqEl);
ZContact zcontact = new ZContact(respEl.getElement(MailConstants.E_CONTACT), zmbox);
assertNotNull("ZContact object", zcontact);
// The IMAP UID should be gotten via a refetch of the contact - asking for the IMAP UID
assertEquals("Expected=ZContact ID Actual=ZContact IMAP UID", zcontact.getIdInMailbox(), zcontact.getImapUid());
assertEquals("IMAP UID Expected=Contact Actual=ZContact", contact.getImapUid(), zcontact.getImapUid());
assertEquals("ModifiedSequence Expected=Contact Actual=ZContact", contact.getModifiedSequence(), zcontact.getModifiedSequence());
}
use of com.zimbra.client.ZContact in project zm-mailbox by Zimbra.
the class TestZClient method testZMailboxGetItemById.
@Test
public void testZMailboxGetItemById() throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Integer id = Integer.valueOf(TestUtil.addMessage(zmbox, "testGetItemById test msg"));
ItemIdentifier msgItemId = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), id);
Contact contact = TestUtil.createContactInDefaultFolder(mbox, "testzclient@example.com");
ItemIdentifier contactId = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), contact.getId());
/* getting message using message id */
ZimbraMailItem mItemAsMsg = zmbox.getItemById((OpContext) null, msgItemId, MailItemType.MESSAGE);
assertNotNull("getItemById returned null when got with type MESSAGE", mItemAsMsg);
assertEquals("Different ID when got with type MESSAGE", id, Integer.valueOf(mItemAsMsg.getIdInMailbox()));
assertTrue(String.format("%s Not a ZMessage when got with type MESSAGE", mItemAsMsg.getClass().getName()), mItemAsMsg instanceof ZMessage);
/* getting item using message id */
mItemAsMsg = zmbox.getItemById((OpContext) null, msgItemId, MailItemType.UNKNOWN);
assertNotNull("getItemById returned null when got with type UNKNOWN", mItemAsMsg);
assertEquals("Different ID when got with type UNKNOWN", id, Integer.valueOf(mItemAsMsg.getIdInMailbox()));
assertTrue(String.format("%s Not a ZMessage when got with type UNKNOWN", mItemAsMsg.getClass().getName()), mItemAsMsg instanceof ZMessage);
/* getting contact using id of contact */
ZimbraMailItem mItemAsContact = zmbox.getItemById((OpContext) null, contactId, MailItemType.CONTACT);
assertNotNull("getItemById returned null when got with type CONTACT", mItemAsContact);
assertEquals("Different ID when got with type CONTACT", contactId.id, mItemAsContact.getIdInMailbox());
assertTrue(String.format("%s Not a ZContact when got with type CONTACT", mItemAsContact.getClass().getName()), mItemAsContact instanceof ZContact);
ZContact zContact = (ZContact) mItemAsContact;
assertEquals("Imap UID of ZContact should be same as Contact", contact.getImapUid(), zContact.getImapUid());
assertTrue(String.format("IMAP UID %s of ZContact not 0", zContact.getImapUid()), 0 != zContact.getImapUid());
/* getting message using contact id */
try {
zmbox.getItemById((OpContext) null, contactId, MailItemType.MESSAGE);
fail("ZClientNoSuchItemException was not thrown when getting contact as message");
} catch (ZClientException.ZClientNoSuchItemException zcnsie) {
}
/* getting message using non-existent id */
ItemIdentifier nonexistent = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), 9099);
try {
zmbox.getItemById((OpContext) null, nonexistent, MailItemType.UNKNOWN);
fail("ZClientNoSuchItemException was not thrown");
} catch (ZClientException.ZClientNoSuchItemException zcnsie) {
}
/* getting contact using id of message */
try {
zmbox.getItemById((OpContext) null, msgItemId, MailItemType.CONTACT);
fail("ZClientNoSuchItemException was not thrown");
} catch (ZClientException.ZClientNoSuchContactException zcnsce) {
}
/* getting document using id of message */
try {
zmbox.getItemById((OpContext) null, msgItemId, MailItemType.DOCUMENT);
fail("ZClientNoSuchItemException was not thrown");
} catch (ZClientException.ZClientNoSuchItemException zcnsce) {
}
}
use of com.zimbra.client.ZContact in project zm-mailbox by Zimbra.
the class TestZClient method testCreateAndModifyZContact.
@Test
public void testCreateAndModifyZContact() throws ServiceException {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Map<String, String> attrs = Maps.newHashMapWithExpectedSize(3);
attrs.put(ContactConstants.A_email, "fun@example.com");
attrs.put(ContactConstants.A_fullName, "Barney A. Rubble");
ZContact zcontact = zmbox.createContact(ZFolder.ID_CONTACTS, null, /* tags */
attrs);
assertNotNull("Newly created zcontact should not be null", zcontact);
assertEquals("Expected=ZContact ID Actual=ZContact IMAP UID", zcontact.getIdInMailbox(), zcontact.getImapUid());
Contact contact = mbox.getContactById(null, zcontact.getIdInMailbox());
assertNotNull("Contact object gotten by ID on newly created zcontact should not be null", zcontact);
assertEquals("IMAP UID Expected=Contact Actual=ZContact", contact.getImapUid(), zcontact.getImapUid());
assertEquals("ModifiedSequence Expected=Contact Actual=ZContact", contact.getModifiedSequence(), zcontact.getModifiedSequence());
int origModSeq = zcontact.getModifiedSequence();
attrs.put(ContactConstants.A_company, "Acme Inc.");
zcontact = zmbox.modifyContact(zcontact.getId(), true, /* i.e replace all */
attrs);
assertNotNull("Contact object from zmbox.modifyContact() should not be null", zcontact);
assertEquals("After Modify:Expected=ZContact ID Actual=ZContact IMAP UID", zcontact.getIdInMailbox(), zcontact.getImapUid());
contact = mbox.getContactById(null, zcontact.getIdInMailbox());
assertNotNull("After Modify:Contact object gotten by ID on newly modified zcontact should not be null", contact);
assertEquals("After Modify:IMAP UID:Expected=Contact Actual=ZContact", contact.getImapUid(), zcontact.getImapUid());
assertEquals("After Modify:ModifiedSequence Expected=Contact Actual=ZContact", contact.getModifiedSequence(), zcontact.getModifiedSequence());
assertTrue(String.format("After Contact modify, new modSeq=%s should be greater than old modSeq=%s", zcontact.getModifiedSequence(), origModSeq), zcontact.getModifiedSequence() > origModSeq);
List<ZContact> allZContacts = zmbox.getAllContacts(ZFolder.ID_CONTACTS, (ContactSortBy) null, true, /* sync */
null);
assertNotNull("zmbox.getAllContacts result should not be null", allZContacts);
assertEquals("zmbox.getAllContacts result should have 1 entry", 1, allZContacts.size());
zcontact = allZContacts.get(0);
assertEquals("GetAllContacts: IMAP UID Expected=Contact Actual=ZContact", contact.getImapUid(), zcontact.getImapUid());
assertEquals("GetAllContacts ModifiedSequence:Expected=Contact Actual=ZContact", contact.getModifiedSequence(), zcontact.getModifiedSequence());
}
use of com.zimbra.client.ZContact in project zm-mailbox by Zimbra.
the class TestUtil method deleteTestData.
/**
* Delete all messages, tags and folders in the user's mailbox whose subjects contain the given substring. For
* messages, the subject must contain subjectString as a separate word. Tags and folders can have the string
* anywhere in the name.
*/
public static void deleteTestData(String userName, String subjectSubstring) throws ServiceException {
ZMailbox mbox = getZMailbox(userName);
deleteMessages(mbox, "is:anywhere " + subjectSubstring);
// Workaround for bug 15160 (is:anywhere is busted)
deleteMessages(mbox, "in:trash " + subjectSubstring);
deleteMessages(mbox, "in:junk " + subjectSubstring);
deleteMessages(mbox, "in:sent " + subjectSubstring);
// Workaround for bug 31370
deleteMessages(mbox, "subject: " + subjectSubstring);
// Delete tags
for (ZTag tag : mbox.getAllTags()) {
if (tag.getName().contains(subjectSubstring)) {
mbox.deleteTag(tag.getId());
}
}
// Delete folders
for (ZFolder folder : mbox.getAllFolders()) {
if (folder.getName().contains(subjectSubstring)) {
mbox.deleteFolder(folder.getId());
}
}
// Delete contacts
for (ZContact contact : mbox.getAllContacts(null, ContactSortBy.nameAsc, false, null)) {
String fullName = contact.getAttrs().get("fullName");
if (fullName != null && fullName.contains(subjectSubstring)) {
mbox.deleteContact(contact.getId());
}
}
// Delete data sources
List<ZDataSource> dataSources = mbox.getAllDataSources();
for (ZDataSource ds : dataSources) {
if (ds.getName() != null && ds.getName().contains(subjectSubstring)) {
mbox.deleteDataSource(ds);
}
}
// Delete appointments
List<String> ids = search(mbox, subjectSubstring, ZSearchParams.TYPE_APPOINTMENT);
if (!ids.isEmpty()) {
mbox.deleteItem(StringUtil.join(",", ids), null);
}
// Delete documents
ids = search(mbox, subjectSubstring, ZSearchParams.TYPE_DOCUMENT);
if (!ids.isEmpty()) {
mbox.deleteItem(StringUtil.join(",", ids), null);
}
ZMailbox adminMbox = getZMailboxAsAdmin(userName);
adminMbox.emptyDumpster();
}
use of com.zimbra.client.ZContact in project zm-mailbox by Zimbra.
the class TestContacts method testMaxContacts.
/**
* Confirms that {@link Provisioning#A_zimbraContactMaxNumEntries} is enforced (bug 29627).
*/
@Test
public void testMaxContacts() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
List<ZContact> contacts = mbox.getAllContacts(null, ContactSortBy.nameAsc, false, null);
int max = contacts.size() + 2;
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraContactMaxNumEntries, Integer.toString(max));
Map<String, String> attrs = new HashMap<String, String>();
int i;
for (i = 1; i <= 10; i++) {
attrs.put("fullName", NAME_PREFIX + " testMaxContacts" + i);
try {
mbox.createContact(Integer.toString(Mailbox.ID_FOLDER_CONTACTS), null, attrs);
} catch (SoapFaultException e) {
assertEquals(MailServiceException.TOO_MANY_CONTACTS, e.getCode());
break;
}
}
assertEquals("Unexpected contact number", 3, i);
}
Aggregations