Search in sources :

Example 1 with ContactInfo

use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.

the class TestCardDav method appleStyleGroup.

@Test
public void appleStyleGroup() throws ServiceException, IOException {
    String contactsFolderUrl = TestCalDav.getFolderUrl(dav1, "Contacts");
    HttpClient client = HttpClientBuilder.create().build();
    HttpPost postMethod = new HttpPost(contactsFolderUrl);
    TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
    postMethod.addHeader("Content-Type", "text/vcard");
    postMethod.setEntity(new ByteArrayEntity(rachelVcard.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
    HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
    postMethod = new HttpPost(contactsFolderUrl);
    TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
    postMethod.addHeader("Content-Type", "text/vcard");
    postMethod.setEntity(new ByteArrayEntity(blueGroupCreate.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
    HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
    exe.getNonNullHeaderValue("Location", "When creating Group");
    postMethod = new HttpPost(contactsFolderUrl);
    TestCalDav.addBasicAuthHeaderForUser(postMethod, dav1);
    postMethod.addHeader("Content-Type", "text/vcard");
    postMethod.setEntity(new ByteArrayEntity(parisVcard.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
    HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
    String url = String.format("%s%s", contactsFolderUrl, "F53A6F96-566F-46CC-8D48-A5263FAB5E38.vcf");
    HttpPut putMethod = new HttpPut(url);
    TestCalDav.addBasicAuthHeaderForUser(putMethod, dav1);
    putMethod.addHeader("Content-Type", "text/vcard");
    putMethod.setEntity(new ByteArrayEntity(blueGroupModify.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
    HttpMethodExecutor.execute(client, putMethod, HttpStatus.SC_NO_CONTENT);
    HttpGet getMethod = new HttpGet(url);
    TestCalDav.addBasicAuthHeaderForUser(getMethod, dav1);
    getMethod.addHeader("Content-Type", "text/vcard");
    exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
    String respBody = exe.getResponseAsString();
    String[] expecteds = { "X-ADDRESSBOOKSERVER-KIND:group", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:BE43F16D-336E-4C3E-BAE6-22B8F245A986", "X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:07139DE2-EA7B-46CB-A970-C4DF7F72D9AE" };
    for (String expected : expecteds) {
        assertTrue(String.format("GET should contain '%s'\nBODY=%s", expected, respBody), respBody.contains(expected));
    }
    // members are actually stored in a different way.  Make sure it isn't a fluke
    // that the GET response contained the correct members by checking that the members
    // appear where expected in a search hit.
    SearchRequest searchRequest = new SearchRequest();
    searchRequest.setSortBy("dateDesc");
    searchRequest.setLimit(8);
    searchRequest.setSearchTypes("contact");
    searchRequest.setQuery("in:Contacts");
    ZMailbox mbox = TestUtil.getZMailbox(DAV1);
    SearchResponse searchResp = mbox.invokeJaxb(searchRequest);
    assertNotNull("JAXB SearchResponse object", searchResp);
    List<SearchHit> hits = searchResp.getSearchHits();
    assertNotNull("JAXB SearchResponse hits", hits);
    assertEquals("JAXB SearchResponse hits", 3, hits.size());
    boolean seenGroup = false;
    for (SearchHit hit : hits) {
        ContactInfo contactInfo = (ContactInfo) hit;
        if ("BlueGroup".equals(contactInfo.getFileAs())) {
            seenGroup = true;
            assertEquals("Number of members of group in search hit", 2, contactInfo.getContactGroupMembers().size());
        }
        ZimbraLog.test.info("Hit %s class=%s", hit, hit.getClass().getName());
    }
    assertTrue("Seen group", seenGroup);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) SearchHit(com.zimbra.soap.type.SearchHit) HttpMethodExecutor(com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor) HttpGet(org.apache.http.client.methods.HttpGet) HttpPut(org.apache.http.client.methods.HttpPut) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) ZMailbox(com.zimbra.client.ZMailbox) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpClient(org.apache.http.client.HttpClient) ContactInfo(com.zimbra.soap.mail.type.ContactInfo) Test(org.junit.Test)

Example 2 with ContactInfo

use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.

the class TestGetContactsRequest method createContact.

public ContactInfo createContact(SoapTransport soapTrans, String fullName) throws ServiceException, IOException, HttpException {
    ContactSpec contactSpec = new ContactSpec();
    contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_fullName, fullName));
    CreateContactResponse resp = invokeJaxb(soapTrans, new CreateContactRequest(contactSpec));
    assertNotNull(String.format("CreateContactResponse when creating %s should not be null", fullName), resp);
    ContactInfo contact = resp.getContact();
    assertNotNull(String.format("CreateContactResponse/cn when creating %s should not be null", fullName), contact);
    return contact;
}
Also used : CreateContactRequest(com.zimbra.soap.mail.message.CreateContactRequest) ContactSpec(com.zimbra.soap.mail.type.ContactSpec) CreateContactResponse(com.zimbra.soap.mail.message.CreateContactResponse) ContactInfo(com.zimbra.soap.mail.type.ContactInfo)

Example 3 with ContactInfo

use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.

the class TestGetContactsRequest method testComaSeparatedIds.

@Test
public void testComaSeparatedIds() throws Exception {
    Element req = new JSONElement(MailConstants.GET_CONTACTS_REQUEST);
    req.addAttribute(MailConstants.A_SYNC, true);
    req.addNonUniqueElement(MailConstants.E_CONTACT).addAttribute(MailConstants.A_ID, String.format("%s,%s", ids.get(0), ids.get(1)));
    Element resp = transport.invoke(req);
    GetContactsResponse getContactsResp = JaxbUtil.elementToJaxb(resp);
    List<ContactInfo> contacts = getContactsResp.getContacts();
    assertEquals(2, contacts.size());
}
Also used : GetContactsResponse(com.zimbra.soap.mail.message.GetContactsResponse) JSONElement(com.zimbra.common.soap.Element.JSONElement) Element(com.zimbra.common.soap.Element) JSONElement(com.zimbra.common.soap.Element.JSONElement) ContactInfo(com.zimbra.soap.mail.type.ContactInfo) Test(org.junit.Test)

Example 4 with ContactInfo

use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.

the class TestGetContactsRequest method checkGetContactsMemberOf.

private void checkGetContactsMemberOf(SoapTransport soapTrans, GetContactsRequest getContactsReq, List<ContactInfo> groups, List<String> remIds, SoapProtocol proto) throws ServiceException, IOException, HttpException {
    GetContactsResponse getContactsResp;
    getContactsResp = invokeJaxb(soapTrans, getContactsReq, proto);
    List<ContactInfo> contacts = getContactsResp.getContacts();
    assertEquals("List of contacts returned when ask for contacts by ID", 2 + remIds.size(), contacts.size());
    checkMemberOf(contacts, ids.get(0), groups.get(0).getId(), groups.get(1).getId(), groups.get(2).getId());
    checkMemberOf(contacts, ids.get(1), groups.get(1).getId());
    checkMemberOf(contacts, remIds.get(0), remIds.get(4), remIds.get(5));
    getContactsReq.setIncludeMemberOf(false);
    getContactsResp = invokeJaxb(soapTrans, getContactsReq, proto);
    contacts = getContactsResp.getContacts();
    assertEquals("List of contacts returned when ask for contacts by ID without memberOf info", 2 + remIds.size(), contacts.size());
    checkMemberOf(contacts, ids.get(0));
    checkMemberOf(contacts, ids.get(1));
    checkMemberOf(contacts, remIds.get(0));
    // Back to what it should have been at the start
    getContactsReq.setIncludeMemberOf(true);
}
Also used : GetContactsResponse(com.zimbra.soap.mail.message.GetContactsResponse) ContactInfo(com.zimbra.soap.mail.type.ContactInfo)

Example 5 with ContactInfo

use of com.zimbra.soap.mail.type.ContactInfo in project zm-mailbox by Zimbra.

the class TestGetContactsRequest method createContactGroup.

public ContactInfo createContactGroup(SoapTransport soapTrans, String fullName, String... memberIds) throws ServiceException, IOException, HttpException {
    ContactSpec contactSpec = new ContactSpec();
    contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_fullName, fullName));
    contactSpec.addAttr(NewContactAttr.fromNameAndValue(ContactConstants.A_type, ContactConstants.TYPE_GROUP));
    for (String id : memberIds) {
        contactSpec.addContactGroupMember(NewContactGroupMember.createForTypeAndValue(ContactGroup.Member.Type.CONTACT_REF.getSoapEncoded(), id));
    }
    CreateContactResponse resp = invokeJaxb(soapTrans, new CreateContactRequest(contactSpec));
    assertNotNull(String.format("CreateContactResponse when creating ContactGroup %s should not be null", fullName), resp);
    ContactInfo contact = resp.getContact();
    assertNotNull(String.format("CreateContactResponse/cn when creating ContactGroup %s should not be null", fullName), contact);
    return contact;
}
Also used : CreateContactRequest(com.zimbra.soap.mail.message.CreateContactRequest) ContactSpec(com.zimbra.soap.mail.type.ContactSpec) CreateContactResponse(com.zimbra.soap.mail.message.CreateContactResponse) ContactInfo(com.zimbra.soap.mail.type.ContactInfo)

Aggregations

ContactInfo (com.zimbra.soap.mail.type.ContactInfo)8 Test (org.junit.Test)4 ZMailbox (com.zimbra.client.ZMailbox)3 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)3 SearchResponse (com.zimbra.soap.mail.message.SearchResponse)3 SearchHit (com.zimbra.soap.type.SearchHit)3 Account (com.zimbra.cs.account.Account)2 CreateContactRequest (com.zimbra.soap.mail.message.CreateContactRequest)2 CreateContactResponse (com.zimbra.soap.mail.message.CreateContactResponse)2 GetContactsResponse (com.zimbra.soap.mail.message.GetContactsResponse)2 ContactSpec (com.zimbra.soap.mail.type.ContactSpec)2 Element (com.zimbra.common.soap.Element)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 HttpMethodExecutor (com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor)1 GetContactsRequest (com.zimbra.soap.mail.message.GetContactsRequest)1 NewContactAttr (com.zimbra.soap.mail.type.NewContactAttr)1 ContactAttr (com.zimbra.soap.type.ContactAttr)1 Id (com.zimbra.soap.type.Id)1 Header (org.apache.commons.httpclient.Header)1 HttpClient (org.apache.commons.httpclient.HttpClient)1