Search in sources :

Example 1 with HttpMethodExecutor

use of com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor 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 HttpMethodExecutor

use of com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor in project zm-mailbox by Zimbra.

the class TestCardDav method createInSharedAddressBook.

@Test(timeout = 100000)
public void createInSharedAddressBook() throws ServiceException, IOException {
    Account dav2 = TestUtil.createAccount(DAV2);
    assertNotNull("Test account object", dav2);
    shareContacts();
    String contactsFolderUrl = TestCalDav.getFolderUrl(dav1, sharedContactFolderName());
    HttpClient client = HttpClientBuilder.create().build();
    HttpPost 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 exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
    String location = exe.getNonNullHeaderValue("Location", "When creating VCARD in shared address book");
    String url = String.format("%s%s", contactsFolderUrl, location.substring(location.lastIndexOf('/') + 1));
    HttpGet getMethod = new HttpGet(url);
    TestCalDav.addBasicAuthHeaderForUser(getMethod, dav1);
    getMethod.addHeader("Content-Type", "text/vcard");
    exe = HttpMethodExecutor.execute(client, getMethod, HttpStatus.SC_OK);
}
Also used : Account(com.zimbra.cs.account.Account) HttpPost(org.apache.http.client.methods.HttpPost) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpMethodExecutor(com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) Test(org.junit.Test)

Example 3 with HttpMethodExecutor

use of com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor in project zm-mailbox by Zimbra.

the class TestCardDav method xBusyMacAttach.

@Test
public void xBusyMacAttach() 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(smallBusyMacAttach.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_VCARD)));
    HttpMethodExecutor exe = HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_CREATED);
    String location = exe.getNonNullHeaderValue("Location", "When creating VCARD");
    String url = String.format("%s%s", contactsFolderUrl, location.substring(location.lastIndexOf('/') + 1));
    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 = { "\r\nX-BUSYMAC-ATTACH;X-FILENAME=favicon.ico;ENCODING=B:AAABAAEAEBAAAAEAIABoBA\r\n", "\r\n AAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAABMLAAATCwAAAAAAAAAAAAAAAAAAw4cAY8\r\n", "\r\nX-BUSYMAC-MODIFIED-BY:Gren Elliot\r\n", "\r\nX-CUSTOM:one two three four five six seven eight nine ten eleven twelve t\r\n hirteen fourteen fifteen", "\r\nX-CUSTOM:Here are my simple\\Nmultiline\\Nnotes\r\n", "\r\nX-CUSTOM;TYPE=pref:semi-colon\\;seperated\\;\"stuff\"\\;here\r\n", "\r\nX-CUSTOM:comma\\,\"stuff\"\\,'there'\\,too\r\n", "\r\nX-HOBBY:my backslash\\\\ hobbies\r\n", "\r\nX-CREATED:2015-04-05T09:50:44Z\r\n" };
    for (String expected : expecteds) {
        assertTrue(String.format("GET should contain '%s'\nBODY=%s", expected, respBody), respBody.contains(expected));
    }
    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", 1, hits.size());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) ZMailbox(com.zimbra.client.ZMailbox) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) SearchHit(com.zimbra.soap.type.SearchHit) HttpMethodExecutor(com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Aggregations

HttpMethodExecutor (com.zimbra.qa.unittest.TestCalDav.HttpMethodExecutor)3 HttpClient (org.apache.http.client.HttpClient)3 HttpGet (org.apache.http.client.methods.HttpGet)3 HttpPost (org.apache.http.client.methods.HttpPost)3 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)3 Test (org.junit.Test)3 ZMailbox (com.zimbra.client.ZMailbox)2 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)2 SearchResponse (com.zimbra.soap.mail.message.SearchResponse)2 SearchHit (com.zimbra.soap.type.SearchHit)2 Account (com.zimbra.cs.account.Account)1 ContactInfo (com.zimbra.soap.mail.type.ContactInfo)1 HttpPut (org.apache.http.client.methods.HttpPut)1