Search in sources :

Example 11 with RemoteImapMailboxStore

use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.

the class TestImapServerListener method testNotifyRenameTag.

@Test
public void testNotifyRenameTag() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    ImapServerListener remoteListener = ImapServerListenerPool.getInstance().get(mboxStore);
    RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
    ImapCredentials creds = new ImapCredentials(remoteAccount);
    ImapPath path = new ImapPath("INBOX", creds);
    byte params = 0;
    ImapHandler handler = new MockImapHandler().setCredentials(creds);
    ImapFolder i4folder = new ImapFolder(path, params, handler);
    MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
    remoteListener.addListener(session);
    // wait for waitset session to be created
    QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
    session.doneSignal = new CountDownLatch(1);
    String subject = "TestImapServerListener - testNotifyRenameTag";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), "randomUserTestImapServerListener@yahoo.com");
    ZMessage msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox subject:\"%s\"", subject));
    assertTrue("New message should have UNREAD flag", msg.isUnread());
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    assertTrue("Expected session to be triggered after delivering the test message", session.wasTriggered());
    ZTag tag = mboxStore.createTag("testNotifyTag", Color.blue);
    // tag
    session.doneSignal = new CountDownLatch(1);
    mboxStore.tagMessage(msg.getId(), tag.getId(), true);
    msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox tag:testNotifyTag subject:\"%s\"", subject));
    assertTrue("Test message should have testNotifyTag tag after tagging", msg.getTagIds().contains(tag.getId()));
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    assertTrue("Expected session to be triggered after tagging test message", session.wasTriggered());
    // rename tag
    session.doneSignal = new CountDownLatch(1);
    mboxStore.renameTag(tag.getId(), "testNotifyRenamedTag");
    msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox tag:testNotifyRenamedTag subject:\"%s\"", subject));
    assertTrue("Test message should have testNotifyRenamedTag tag after renaming the tag", msg.getTagIds().contains(tag.getId()));
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    assertTrue("Expected session to be triggered after renaming the tag", session.wasTriggered());
    remoteListener.removeListener(session);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ZTag(com.zimbra.client.ZTag) ImapPath(com.zimbra.cs.imap.ImapPath) CountDownLatch(java.util.concurrent.CountDownLatch) HttpException(org.apache.http.HttpException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 12 with RemoteImapMailboxStore

use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.

the class TestImapServerListener method testDeleteOneOutOfTwoAccounts.

@Test
public void testDeleteOneOutOfTwoAccounts() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    // first account
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    TestUtil.addMessage(mboxStore, "TestImapServerListener - testNotify - init message 1", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    ImapServerListener remoteListener = ImapServerListenerPool.getInstance().get(mboxStore);
    RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
    ImapCredentials creds = new ImapCredentials(remoteAccount);
    ImapPath path = new ImapPath("INBOX", creds);
    byte params = 0;
    ImapHandler handler = new MockImapHandler().setCredentials(creds);
    ImapFolder i4folder = new ImapFolder(path, params, handler);
    MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
    remoteListener.addListener(session);
    // second account (will be deleted)
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraMailHost, remoteServer.getServiceHostname());
    Account remoteAccount2 = TestUtil.createAccount(REMOTE_USER_NAME2, attrs);
    ZMailbox mboxStore2 = TestUtil.getZMailbox(REMOTE_USER_NAME2);
    ZimbraLog.test.debug("Created 2d account " + REMOTE_USER_NAME2 + " with ID " + remoteAccount2.getId());
    TestUtil.addMessage(mboxStore2, "TestImapServerListener - testNotify - init message 2", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    ImapServerListener remoteListener2 = ImapServerListenerPool.getInstance().get(mboxStore2);
    assertEquals("Should be getting the same ImapServerListener for both accounts on the same server", remoteListener2, remoteListener);
    RemoteImapMailboxStore imapStore2 = new RemoteImapMailboxStore(mboxStore2);
    ImapCredentials creds2 = new ImapCredentials(remoteAccount2);
    ImapPath path2 = new ImapPath("INBOX", creds2);
    params = 0;
    ImapHandler handler2 = new MockImapHandler().setCredentials(creds2);
    ImapFolder i4folder2 = new ImapFolder(path2, params, handler2);
    MockImapListener session2 = new MockImapListener(imapStore2, i4folder2, handler2);
    remoteListener2.addListener(session2);
    // wait for waitset sessions to be created
    String waitSetId = remoteListener.getWSId();
    assertTrue("Both listener references should be pointing to the same listener with the same waitset", waitSetId.equalsIgnoreCase(remoteListener2.getWSId()));
    TestUtil.waitForSessions(2, 2, 6000, waitSetId, remoteServer);
    // delete the 2d account
    ZimbraLog.test.debug("Deleting " + REMOTE_USER_NAME2);
    TestUtil.deleteAccount(REMOTE_USER_NAME2);
    session2.killSignal = new CountDownLatch(1);
    // send a message to the 1st account
    session.doneSignal = new CountDownLatch(1);
    String subject = "TestImapServerListener - testDeleteOneOutOfTwoAccounts - trigger message";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), TestUtil.getAddress("TestImapServerListener-testDeleteOneOutOfTwoAccounts"));
    TestUtil.waitForMessages(mboxStore, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
    // the 2d account's session should be killed
    try {
        session2.killSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    // the 1st accounts session should be triggered
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    ZimbraLog.test.debug("Checking triggers");
    assertTrue("Expected the 1st account's session to be triggered", session.wasTriggered());
    assertFalse("Expected the 2d account's session to NOT be triggered", session2.wasTriggered());
    assertTrue("Expected the 2d account's session to be unregistered", session2.wasUnregistered());
    assertFalse("Expected the 1st account's session to NOT be unregistered", session.wasUnregistered());
    assertNotNull("ImapServerListener should NOT have deleted the waitset", remoteListener.getWSId());
    assertTrue("Waitset ID should have remained the same", waitSetId.equalsIgnoreCase(remoteListener.getWSId()));
}
Also used : Account(com.zimbra.cs.account.Account) ImapFolder(com.zimbra.cs.imap.ImapFolder) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) CountDownLatch(java.util.concurrent.CountDownLatch) HttpException(org.apache.http.HttpException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 13 with RemoteImapMailboxStore

use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.

the class TestImapServerListener method testNotifyInbox.

@Test
public void testNotifyInbox() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    TestUtil.addMessage(mboxStore, "TestImapServerListener - testNotify - init message", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    ImapServerListener remoteListener = ImapServerListenerPool.getInstance().get(mboxStore);
    RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
    ImapCredentials creds = new ImapCredentials(remoteAccount);
    ImapPath path = new ImapPath("INBOX", creds);
    byte params = 0;
    ImapHandler handler = new MockImapHandler().setCredentials(creds);
    ImapFolder i4folder = new ImapFolder(path, params, handler);
    MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
    remoteListener.addListener(session);
    // wait for waitset session to be created
    QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
    session.doneSignal = new CountDownLatch(1);
    String subject = "TestImapServerListener - testNotifyInbox - trigger message";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), "randomUserTestImapServerListener@yahoo.com");
    TestUtil.waitForMessages(mboxStore, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    assertTrue("Expected session to be triggered", session.wasTriggered());
    remoteListener.removeListener(session);
}
Also used : ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) CountDownLatch(java.util.concurrent.CountDownLatch) HttpException(org.apache.http.HttpException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 14 with RemoteImapMailboxStore

use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.

the class TestRemoteImapMailboxStore method testSaveIMAPSubscriptions.

@Test
public void testSaveIMAPSubscriptions() throws Exception {
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    RemoteImapMailboxStore remoteStore = new RemoteImapMailboxStore(zmbox, TestUtil.getAccount(USER_NAME).getId());
    // check that there are no subscriptions saved yet
    Set<String> subs = remoteStore.listSubscriptions(null);
    Assert.assertNull(subs);
    String path = NAME_PREFIX + "_testPath";
    Set<String> newSubs = new HashSet<String>();
    newSubs.add(path);
    // save subscriptions
    remoteStore.saveSubscriptions(null, newSubs);
    // verify that subscriptions were saved
    subs = remoteStore.listSubscriptions(null);
    Assert.assertNotNull(subs);
    Assert.assertEquals(1, subs.size());
    String sub = subs.iterator().next();
    Assert.assertTrue(sub.equalsIgnoreCase(path));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with RemoteImapMailboxStore

use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.

the class TestRemoteImapMailboxStore method testGetCurrentModseq.

@Test
public void testGetCurrentModseq() throws Exception {
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    Folder folder = mbox.createFolder(null, NAME_PREFIX, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    int folderId = folder.getId();
    ItemIdentifier folderIdent = folder.getFolderItemIdentifier();
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    RemoteImapMailboxStore remoteStore = new RemoteImapMailboxStore(zmbox, TestUtil.getAccount(USER_NAME).getId());
    Assert.assertEquals("Before adding a message, remoteStore.getCurrentMODSEQ returns value different from folder.getImapMODSEQ", remoteStore.getCurrentMODSEQ(folderIdent), folder.getImapMODSEQ());
    int oldModSeq = remoteStore.getCurrentMODSEQ(folderIdent);
    // add a message to the folder
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(folderId).setFlags(Flag.BITMASK_UNREAD);
    String message = TestUtil.getTestMessage(NAME_PREFIX, mbox.getAccount().getName(), "someone@zimbra.com", "nothing here", new Date(System.currentTimeMillis()));
    ParsedMessage pm = new ParsedMessage(message.getBytes(), System.currentTimeMillis(), false);
    mbox.addMessage(null, pm, dopt, null);
    zmbox.noOp();
    folder = mbox.getFolderById(null, folderId);
    Assert.assertEquals("After adding a message, remoteStore.getCurrentMODSEQ returns value different from folder.getImapMODSEQ", remoteStore.getCurrentMODSEQ(folderIdent), folder.getImapMODSEQ());
    Assert.assertFalse("Modseq should have changed after adding a message", remoteStore.getCurrentMODSEQ(folderIdent) == oldModSeq);
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Folder(com.zimbra.cs.mailbox.Folder) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)20 Test (org.junit.Test)19 ZMailbox (com.zimbra.client.ZMailbox)16 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)14 ImapFolder (com.zimbra.cs.imap.ImapFolder)14 ImapHandler (com.zimbra.cs.imap.ImapHandler)14 ImapPath (com.zimbra.cs.imap.ImapPath)14 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)12 ServiceException (com.zimbra.common.service.ServiceException)10 ImapServerListener (com.zimbra.cs.imap.ImapServerListener)10 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 HttpException (org.apache.http.HttpException)10 ZMessage (com.zimbra.client.ZMessage)5 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 ZFolder (com.zimbra.client.ZFolder)2 ZTag (com.zimbra.client.ZTag)2 ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 Account (com.zimbra.cs.account.Account)2