Search in sources :

Example 6 with ParsedContact

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

the class ContactTest method tooLongSender.

@Test
public void tooLongSender() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, Strings.repeat("F", 129));
    Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    DbConnection conn = DbPool.getConnection(mbox);
    Assert.assertEquals(Strings.repeat("F", 128), 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, null);
    fields.put(ContactConstants.A_lastName, Strings.repeat("L", 129));
    mbox.modifyContact(null, contact.getId(), new ParsedContact(fields));
    Assert.assertEquals(Strings.repeat("L", 128), 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 7 with ParsedContact

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

the class ContactTest method testEncodeContact.

@Test
public void testEncodeContact() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_userCertificate, "{\"ZMVAL\":[\"Cert1149638887753217\"]}");
    Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    Element response = new Element.XMLElement(MailConstants.MODIFY_CONTACT_RESPONSE);
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    ToXML.encodeContact(response, new ItemIdFormatter(), new OperationContext(acct), contact, true, null);
    Assert.assertEquals(response.getElement("cn").getElement("a").getText(), "Cert1149638887753217");
}
Also used : Account(com.zimbra.cs.account.Account) ParsedContact(com.zimbra.cs.mime.ParsedContact) HashMap(java.util.HashMap) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Example 8 with ParsedContact

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

the class ContactAutoCompleteTest method reservedQueryTerm.

@Test
public void reservedQueryTerm() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, "not and or");
    fields.put(ContactConstants.A_lastName, "subject: from:");
    fields.put(ContactConstants.A_email, "test@zimbra.com");
    mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox));
    Assert.assertEquals(1, autocomplete.query("not", null, 100).entries.size());
    Assert.assertEquals(1, autocomplete.query("not and", null, 100).entries.size());
    Assert.assertEquals(1, autocomplete.query("not and or", null, 100).entries.size());
    Assert.assertEquals(1, autocomplete.query("subject:", null, 100).entries.size());
    Assert.assertEquals(1, autocomplete.query("subject: from:", null, 100).entries.size());
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 9 with ParsedContact

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

the class ContactAutoCompleteTest method spaceInFirstName.

@Test
public void spaceInFirstName() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, "First Second Third Forth");
    fields.put(ContactConstants.A_lastName, "Last");
    fields.put(ContactConstants.A_email, "test@zimbra.com");
    mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox));
    Assert.assertEquals(1, autocomplete.query("first second third forth", null, 100).entries.size());
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with ParsedContact

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

the class ContactAutoCompleteTest method lastNameFirstName.

@Test
public void lastNameFirstName() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, "First");
    fields.put(ContactConstants.A_lastName, "Last");
    fields.put(ContactConstants.A_email, "test@zimbra.com");
    mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox));
    Assert.assertEquals(1, autocomplete.query("first last", null, 100).entries.size());
    Assert.assertEquals(1, autocomplete.query("last first", null, 100).entries.size());
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) HashMap(java.util.HashMap) 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