Search in sources :

Example 6 with ZContact

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());
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) Element(com.zimbra.common.soap.Element) ZContact(com.zimbra.client.ZContact) Contact(com.zimbra.cs.mailbox.Contact) ZContact(com.zimbra.client.ZContact) Test(org.junit.Test)

Example 7 with ZContact

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) {
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZimbraMailItem(com.zimbra.common.mailbox.ZimbraMailItem) ZClientException(com.zimbra.common.zclient.ZClientException) ZContact(com.zimbra.client.ZContact) Contact(com.zimbra.cs.mailbox.Contact) OpContext(com.zimbra.common.mailbox.OpContext) ZContact(com.zimbra.client.ZContact) Test(org.junit.Test)

Example 8 with ZContact

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());
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZMountpoint(com.zimbra.client.ZMountpoint) ZContact(com.zimbra.client.ZContact) ZContact(com.zimbra.client.ZContact) Contact(com.zimbra.cs.mailbox.Contact) Test(org.junit.Test)

Example 9 with ZContact

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();
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZTag(com.zimbra.client.ZTag) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource) ZContact(com.zimbra.client.ZContact)

Example 10 with ZContact

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);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ZContact(com.zimbra.client.ZContact) Test(org.junit.Test)

Aggregations

ZContact (com.zimbra.client.ZContact)12 ZMailbox (com.zimbra.client.ZMailbox)11 Test (org.junit.Test)9 Contact (com.zimbra.cs.mailbox.Contact)7 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 HashMap (java.util.HashMap)4 ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)3 ZFolder (com.zimbra.client.ZFolder)2 ZAttachmentInfo (com.zimbra.client.ZMailbox.ZAttachmentInfo)2 ZMountpoint (com.zimbra.client.ZMountpoint)2 Element (com.zimbra.common.soap.Element)2 Account (com.zimbra.cs.account.Account)2 ZDataSource (com.zimbra.client.ZDataSource)1 ZSearchGalResult (com.zimbra.client.ZMailbox.ZSearchGalResult)1 ZMessage (com.zimbra.client.ZMessage)1 ZTag (com.zimbra.client.ZTag)1 ZAuthToken (com.zimbra.common.auth.ZAuthToken)1 OpContext (com.zimbra.common.mailbox.OpContext)1 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)1 ServiceException (com.zimbra.common.service.ServiceException)1