Search in sources :

Example 26 with ParsedContact

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

the class ZimbraQueryTest method quick.

@Test
public void quick() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Contact contact = mbox.createContact(null, new ParsedContact(Collections.singletonMap(ContactConstants.A_email, "test1@zimbra.com")), Mailbox.ID_FOLDER_CONTACTS, null);
    MailboxTestUtil.index(mbox);
    mbox.createContact(null, new ParsedContact(Collections.singletonMap(ContactConstants.A_email, "test2@zimbra.com")), Mailbox.ID_FOLDER_CONTACTS, null);
    SearchParams params = new SearchParams();
    params.setQueryString("test");
    params.setSortBy(SortBy.NONE);
    params.setTypes(EnumSet.of(MailItem.Type.CONTACT));
    params.setQuick(true);
    ZimbraQuery query = new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    ZimbraQueryResults result = query.execute();
    Assert.assertTrue("Expected at least 1 result", result.hasNext());
    Assert.assertEquals("Result item ID not as expected", contact.getId(), result.getNext().getItemId());
    Assert.assertFalse("More hits than expected", result.hasNext());
    Closeables.closeQuietly(result);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Example 27 with ParsedContact

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

the class ContactAutoCompleteTest method rankingTestContactWithSameEmailDifferentDisplayName.

@Test
public void rankingTestContactWithSameEmailDifferentDisplayName() throws Exception {
    // Autocomplete should show same ranking for a email address present in difference contacts.
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, "Pal");
    fields.put(ContactConstants.A_lastName, "One");
    fields.put(ContactConstants.A_email, "testauto@zimbra.com");
    mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    Map<String, Object> fields1 = new HashMap<String, Object>();
    fields1.put(ContactConstants.A_email, "testauto@zimbra.com");
    mbox.createContact(null, new ParsedContact(fields1), Mailbox.ID_FOLDER_CONTACTS, null);
    ContactRankings.increment(mbox.getAccountId(), Collections.singleton(new InternetAddress("testauto@zimbra.com")));
    ContactRankings.increment(mbox.getAccountId(), Collections.singleton(new InternetAddress("testauto@zimbra.com")));
    ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox));
    AutoCompleteResult result = autocomplete.query("Pal", null, 10);
    Assert.assertEquals(1, result.entries.size());
    for (ContactEntry ce : result.entries) {
        Assert.assertEquals(2, ce.mRanking);
    }
    result.clear();
    result = autocomplete.query("testauto", null, 10);
    Assert.assertEquals(2, result.entries.size());
    for (ContactEntry ce : result.entries) {
        Assert.assertEquals(2, ce.mRanking);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) ParsedContact(com.zimbra.cs.mime.ParsedContact) AutoCompleteResult(com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult) HashMap(java.util.HashMap) ContactEntry(com.zimbra.cs.mailbox.ContactAutoComplete.ContactEntry) Test(org.junit.Test)

Example 28 with ParsedContact

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

the class ContactTest method locator.

/**
     * Confirms that locator is not set for contacts.
     */
@Test
public void locator() throws Exception {
    // Create contact.
    Map<String, String> attrs = Maps.newHashMap();
    attrs.put(ContactConstants.A_fullName, "Volume Id");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    mbox.createContact(null, new ParsedContact(attrs), Mailbox.ID_FOLDER_CONTACTS, null);
    // Check volume id in database.
    String sql = String.format("SELECT COUNT(*) FROM %s WHERE type = %d AND blob_digest IS NULL AND locator IS NOT NULL", DbMailItem.getMailItemTableName(mbox), MailItem.Type.CONTACT.toByte());
    DbResults results = DbUtil.executeQuery(sql);
    Assert.assertEquals("Found non-null locator values for contacts", 0, results.getInt(1));
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) DbResults(com.zimbra.cs.db.DbResults) Test(org.junit.Test)

Example 29 with ParsedContact

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

the class ContactTest method reanalyze.

@Test
public void reanalyze() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, "First1");
    fields.put(ContactConstants.A_lastName, "Last1");
    Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    DbConnection conn = DbPool.getConnection(mbox);
    Assert.assertEquals("Last1, First1", DbUtil.executeQuery(conn, "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?", mbox.getId(), contact.getId()).getString(1));
    fields.put(ContactConstants.A_firstName, "First2");
    fields.put(ContactConstants.A_lastName, "Last2");
    mbox.modifyContact(null, contact.getId(), new ParsedContact(fields));
    Assert.assertEquals("Last2, First2", DbUtil.executeQuery(conn, "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?", mbox.getId(), contact.getId()).getString(1));
    conn.closeQuietly();
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) HashMap(java.util.HashMap) DbConnection(com.zimbra.cs.db.DbPool.DbConnection) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Example 30 with ParsedContact

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

the class ContactTest method modifyInvalidImageAttachment.

/**
     * Tests Invalid image attachment (bug 71868).
     */
@Test
public void modifyInvalidImageAttachment() throws Exception {
    // Create a contact with an attachment.
    Map<String, String> attrs = new HashMap<String, String>();
    attrs.put("fullName", "Contact Initial Content");
    byte[] attachData = "attachment 1".getBytes();
    Attachment attachment1 = new Attachment(attachData, "image/png", "customField", "image.png");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Contact contact = mbox.createContact(null, new ParsedContact(attrs, Lists.newArrayList(attachment1)), Mailbox.ID_FOLDER_CONTACTS, null);
    Attachment attachment2 = new Attachment(attachData, "image/png", "image", "image2.png");
    try {
        ParsedContact pc = new ParsedContact(contact).modify(new ParsedContact.FieldDeltaList(), Lists.newArrayList(attachment2));
    } catch (ServiceException se) {
        Assert.assertEquals("check the INVALID_IMAGE exception", "mail.INVALID_IMAGE", se.getCode());
    }
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) Attachment(com.zimbra.cs.mailbox.Contact.Attachment) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Aggregations

ParsedContact (com.zimbra.cs.mime.ParsedContact)41 Test (org.junit.Test)24 HashMap (java.util.HashMap)23 Mailbox (com.zimbra.cs.mailbox.Mailbox)15 Contact (com.zimbra.cs.mailbox.Contact)12 OperationContext (com.zimbra.cs.mailbox.OperationContext)12 ItemId (com.zimbra.cs.service.util.ItemId)7 ServiceException (com.zimbra.common.service.ServiceException)6 Element (com.zimbra.common.soap.Element)6 ArrayList (java.util.ArrayList)6 Account (com.zimbra.cs.account.Account)5 Attachment (com.zimbra.cs.mailbox.Contact.Attachment)5 IOException (java.io.IOException)5 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 InputStream (java.io.InputStream)4 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)3 Member (com.zimbra.cs.mailbox.ContactGroup.Member)3 CreateContact (com.zimbra.cs.redolog.op.CreateContact)3 ModifyContact (com.zimbra.cs.redolog.op.ModifyContact)3 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)3