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