Search in sources :

Example 51 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestAccessKeyGrant method getZMailboxByKey.

private ZMailbox getZMailboxByKey() throws Exception {
    Map<String, String> authAttrs = new HashMap<String, String>();
    authAttrs.put(AUTH_K_ATTR, ACCESS_KEY);
    authAttrs.put(AUTH_H_ATTR, getAccountId(OWNER_NAME));
    ZAuthToken zat = new ZAuthToken(DUMMY_AUTH_PROVIDER, null, authAttrs);
    ZMailbox.Options options = new ZMailbox.Options(zat, TestUtil.getSoapUrl());
    return ZMailbox.getMailbox(options);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 52 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class SharedImapNotificationTests method testDeleteMessageBySubjectNotifications.

@Test
public void testDeleteMessageBySubjectNotifications() throws Exception {
    String folderName = "testDeleteMessageBySubjectNotifications-folder";
    String subject1 = "testDeleteMessageBySubjectNotifications-msg1";
    String subject2 = "testDeleteMessageBySubjectNotifications-msg2";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName);
    TestUtil.addMessage(zmbox, subject1, folder.getId(), null);
    TestUtil.addMessage(zmbox, subject2, folder.getId(), null);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
    assertEquals("Size of map returned by fetch 1", 2, mdMap.size());
    MailboxOperation deleteBySubject = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            TestUtil.deleteMessages(zmbox, "subject: " + subject2);
        }

        @Override
        protected String checkResult() throws Exception {
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE)");
            mdMap.entrySet().removeIf(e -> e.getValue().getEnvelope() == null || e.getValue().getEnvelope().getSubject() == null);
            if (mdMap.size() != 1) {
                return String.format("Size of map returned by fetch should be 1. Getting %d", mdMap.size());
            }
            return null;
        }
    };
    runOp(deleteBySubject, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 53 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class SharedImapNotificationTests method testDeleteFolderNotificationActiveFolder.

@Test
public void testDeleteFolderNotificationActiveFolder() throws Exception {
    String folderName = "TestRemoteImapNotifications-folder";
    String subject = "TestRemoteImapNotifications-testMessage";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName);
    TestUtil.addMessage(zmbox, subject, folder.getId(), null);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
    assertEquals("Size of map returned by initial fetch", 1, mdMap.size());
    MailboxOperation deleteFolder = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            zmbox.deleteFolder(folder.getId());
        }

        @Override
        protected String checkResult() throws Exception {
            try {
                connection.fetch("1:*", "(ENVELOPE BODY)");
                return "should not be able to connect; connection should be closed";
            }// connection is force closed
             catch (SocketException | CommandFailedException e) {
            }
            return null;
        }
    };
    runOp(deleteFolder, zmbox, folder);
}
Also used : SocketException(java.net.SocketException) ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZFolder(com.zimbra.client.ZFolder) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 54 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class SharedImapNotificationTests method testNotificationsEmptyActiveFolder.

@Test
public void testNotificationsEmptyActiveFolder() throws Exception {
    String folderName = "testNotificationsEmptyActiveFolder-folder";
    String subject1 = "testNotificationsEmptyActiveFolder-msg";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName);
    MailboxOperation addMessage = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            TestUtil.addMessage(zmbox, subject1, folder.getId(), null);
        }

        @Override
        protected String checkResult() throws Exception {
            try {
                Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
                if (mdMap.size() != 1) {
                    return String.format("Size of map returned by fetch should be 1. Getting %d", mdMap.size());
                }
            } catch (CommandFailedException cfe) {
                return cfe.getError();
            }
            return null;
        }
    };
    runOp(addMessage, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZFolder(com.zimbra.client.ZFolder) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 55 with ZMailbox

use of com.zimbra.client.ZMailbox 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)

Aggregations

ZMailbox (com.zimbra.client.ZMailbox)383 Test (org.junit.Test)288 ZFolder (com.zimbra.client.ZFolder)90 ZMessage (com.zimbra.client.ZMessage)82 Mailbox (com.zimbra.cs.mailbox.Mailbox)61 Account (com.zimbra.cs.account.Account)60 ServiceException (com.zimbra.common.service.ServiceException)55 ArrayList (java.util.ArrayList)38 IOException (java.io.IOException)35 MessageData (com.zimbra.cs.mailclient.imap.MessageData)28 ZMountpoint (com.zimbra.client.ZMountpoint)26 Message (com.zimbra.cs.mailbox.Message)24 HashMap (java.util.HashMap)23 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)21 ZTag (com.zimbra.client.ZTag)21 SoapFaultException (com.zimbra.common.soap.SoapFaultException)21 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)21 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)20 HttpClient (org.apache.http.client.HttpClient)19 ZSearchParams (com.zimbra.client.ZSearchParams)18