Search in sources :

Example 66 with ZMailbox

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

the class TestMountpoint method testInvalidMountpoint.

/**
 * Tests {@link ZMailbox#getValidFolderIds(String)}.
 */
@Test
public void testInvalidMountpoint() throws Exception {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(REMOTE_USER_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
    String remoteFolderPath = "/" + NAME_PREFIX + "-testInvalidMountpoint-remote";
    ZFolder remoteFolder = TestUtil.createFolder(remoteMbox, remoteFolderPath);
    ZMountpoint mountpoint = TestUtil.createMountpoint(remoteMbox, remoteFolderPath, mbox, NAME_PREFIX + "-mountpoint");
    // Test valid mountpoint.
    Set<String> folderIds = new HashSet<String>();
    folderIds.add(mountpoint.getId());
    String inboxId = Integer.toString(Mailbox.ID_FOLDER_INBOX);
    folderIds.add(inboxId);
    String idString = mbox.getValidFolderIds(StringUtil.join(",", folderIds));
    List<String> returnedIds = Arrays.asList(idString.split(","));
    Assert.assertEquals("Number of return IDs from mbox.getValidFolderIds", 2, returnedIds.size());
    Assert.assertTrue("Returned IDs should contain ID of inbox", returnedIds.contains(inboxId));
    Assert.assertTrue("Returned IDs should contain ID of mountpoint", returnedIds.contains(mountpoint.getId()));
    Assert.assertEquals("Should be 1 comma in string returned by mbox.getValidFolderIds", 1, getNumCommas(idString));
    // Delete remote folder and confirm that the id is no longer returned.
    remoteMbox.deleteFolder(remoteFolder.getId());
    idString = mbox.getValidFolderIds(StringUtil.join(",", folderIds));
    returnedIds = Arrays.asList(idString.split(","));
    Assert.assertEquals("Number of return IDs from mbox.getValidFolderIds after mountpoint delete", 1, returnedIds.size());
    Assert.assertTrue("Returned IDs should contain ID of inbox after mp delete", returnedIds.contains(inboxId));
    Assert.assertEquals("Should no commas in string returned by mbox.getValidFolderIds after mp delete", 0, getNumCommas(idString));
}
Also used : ZMountpoint(com.zimbra.client.ZMountpoint) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 67 with ZMailbox

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

the class TestNoOp method testNoOpMany.

@Test
public void testNoOpMany() throws ServiceException {
    Set<Thread> threads = new HashSet<Thread>();
    final Set<Exception> exceptions = new HashSet<Exception>();
    for (int i = 0; i < THREAD_COUNT; i++) {
        Thread t = new Thread() {

            @Override
            public void run() {
                ZMailbox mbox = null;
                try {
                    mbox = TestUtil.getZMailbox(USER_NAME);
                } catch (ServiceException e) {
                    exceptions.add(e);
                    return;
                }
                for (int j = 0; j < LOOP_COUNT; j++) {
                    try {
                        mbox.noOp(1000);
                    } catch (ServiceException se) {
                        exceptions.add(se);
                    }
                }
            }
        };
        threads.add(t);
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        try {
            // note this test fails with normal timeout min limit in NoOp.java
            t.join(THREAD_TIMEOUT);
        } catch (InterruptedException e) {
        }
        Assert.assertFalse(t.isAlive());
    }
    if (!exceptions.isEmpty()) {
        for (Exception e : exceptions) {
            ZimbraLog.test.error("Exception during test", e);
        }
        Assert.fail(exceptions.size() + " exceptions during test");
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) ServiceException(com.zimbra.common.service.ServiceException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 68 with ZMailbox

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

the class TestLongSearchResultSets method testMessages.

@Test
public void testMessages() {
    try {
        Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT);
        long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
        int numMessages = 2257;
        int firstLimit = 100;
        int incLimit = 50;
        int offset = 0;
        ArrayList<String> expectedIds = new ArrayList<String>();
        for (int i = 0; i < numMessages; i++) {
            Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, String.format("this message contains a search string %s which we are searching for and a number %d and timestamp %d", SEARCH_STRING, i, timestamp), timestamp);
            expectedIds.add(Integer.toString(msg.getId()));
            timestamp += 1000;
            Thread.sleep(100);
        }
        Collections.reverse(expectedIds);
        Thread.sleep(100);
        ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT);
        ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
        searchParams.setSortBy(SearchSortBy.dateDesc);
        searchParams.setLimit(firstLimit);
        searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
        List<String> msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
        assertEquals(firstLimit, msgIds.size());
        int gotMessages = msgIds.size();
        List<String> seenIds = new ArrayList<String>();
        seenIds.addAll(msgIds);
        int recCount = 1;
        offset += firstLimit;
        while (gotMessages > 0) {
            searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
            searchParams.setSortBy(SearchSortBy.dateDesc);
            searchParams.setLimit(incLimit);
            searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
            searchParams.setOffset(offset);
            msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
            recCount++;
            gotMessages = msgIds.size();
            int resCount = 0;
            for (String szId : msgIds) {
                assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, szId, seenIds.indexOf(szId)), seenIds.contains(szId));
                seenIds.add(szId);
                resCount++;
            }
            // jetty sometimes crashes on Mac when bombarded with request without a timeout
            Thread.sleep(100);
            offset += incLimit;
        }
        for (int i = 0; i < expectedIds.size(); i++) {
            assertEquals("IDs at index " + i + " do not match", expectedIds.get(i), seenIds.get(i));
        }
        assertEquals("Returned incorrect number of messages", numMessages, seenIds.size());
    } catch (ServiceException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) Message(com.zimbra.cs.mailbox.Message) ServiceException(com.zimbra.common.service.ServiceException) ZSearchParams(com.zimbra.client.ZSearchParams) ArrayList(java.util.ArrayList) ServiceException(com.zimbra.common.service.ServiceException) Test(org.junit.Test)

Example 69 with ZMailbox

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

the class TestLongSearchResultSets method testConversations2.

@Test
public void testConversations2() {
    try {
        Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT2);
        long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
        int numMessages = 3207;
        int firstLimit = 100;
        int incLimit = 50;
        int offset = 0;
        ArrayList<String> expectedIds = new ArrayList<String>();
        for (int i = 0; i < numMessages; i++) {
            Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT2), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, String.format("this message contains a search string %s which we are searching for and a number %d and timestamp %d", SEARCH_STRING, i, timestamp), timestamp);
            expectedIds.add(Integer.toString(msg.getId()));
            timestamp += 1000;
            Thread.sleep(100);
        }
        Collections.reverse(expectedIds);
        Thread.sleep(100);
        ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT2);
        ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
        searchParams.setSortBy(SearchSortBy.dateDesc);
        searchParams.setLimit(firstLimit);
        searchParams.setTypes(ZSearchParams.TYPE_CONVERSATION);
        List<String> msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
        assertEquals(firstLimit, msgIds.size());
        int gotMessages = msgIds.size();
        List<String> seenIds = new ArrayList<String>();
        seenIds.addAll(msgIds);
        int recCount = 1;
        offset += firstLimit;
        while (gotMessages > 0) {
            searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
            searchParams.setSortBy(SearchSortBy.dateDesc);
            searchParams.setLimit(incLimit);
            searchParams.setTypes(ZSearchParams.TYPE_CONVERSATION);
            searchParams.setOffset(offset);
            msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
            recCount++;
            gotMessages = msgIds.size();
            int resCount = 0;
            for (String szId : msgIds) {
                assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, szId, seenIds.indexOf(szId)), seenIds.contains(szId));
                seenIds.add(szId);
                resCount++;
            }
            // jetty sometimes crashes on Mac when bombarded with request without a timeout
            Thread.sleep(100);
            offset += incLimit;
        }
        assertEquals("Returned incorrect number of conversations", numMessages, seenIds.size());
    } catch (ServiceException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) Message(com.zimbra.cs.mailbox.Message) ServiceException(com.zimbra.common.service.ServiceException) ZSearchParams(com.zimbra.client.ZSearchParams) ArrayList(java.util.ArrayList) ServiceException(com.zimbra.common.service.ServiceException) Test(org.junit.Test)

Example 70 with ZMailbox

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

the class TestMessageIntercept method testInterceptMultiValue.

/**
 * Confirms that legal intercept works with multiple interceptor addresses (bug 30961).
 */
public void testInterceptMultiValue() throws Exception {
    // Turn on legal intercept for recipient account.
    String interceptor1Address = TestUtil.getAddress(INTERCEPTOR1_NAME);
    String interceptor2Address = TestUtil.getAddress(INTERCEPTOR2_NAME);
    String senderAddress = TestUtil.getAddress(SENDER_NAME);
    String[] interceptorAddresses = new String[] { interceptor1Address, interceptor2Address };
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptAddress, interceptorAddresses);
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptSendHeadersOnly, LdapConstants.LDAP_FALSE);
    // Send message to recipient account.
    ZMailbox tappedMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    String tappedAddress = TestUtil.getAddress(RECIPIENT_NAME);
    String subject = NAME_PREFIX + " testIntercept-receive";
    TestUtil.addMessageLmtp(subject, tappedAddress, senderAddress);
    // Make sure both interceptor accounts intercepted it.
    ZMailbox interceptor1Mbox = TestUtil.getZMailbox(INTERCEPTOR1_NAME);
    ZMailbox interceptor2Mbox = TestUtil.getZMailbox(INTERCEPTOR2_NAME);
    ZMessage tappedMsg = TestUtil.getMessage(tappedMbox, "subject:\"" + subject + "\"");
    ZMessage interceptMsg1 = TestUtil.waitForMessage(interceptor1Mbox, "subject:\"" + subject + "\"");
    ZMessage interceptMsg2 = TestUtil.waitForMessage(interceptor2Mbox, "subject:\"" + subject + "\"");
    verifyInterceptMessage(interceptMsg1, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    verifyInterceptMessage(interceptMsg2, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    compareContent(tappedMbox, tappedMsg, interceptor1Mbox, interceptMsg1);
    compareContent(tappedMbox, tappedMsg, interceptor2Mbox, interceptMsg2);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox)

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