Search in sources :

Example 1 with ImapServerListener

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

the class TestImapServerListener method testNotifyNewFolder.

@Test
public void testNotifyNewFolder() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    ZFolder folder = TestUtil.createFolder(mboxStore, "/TestImapServerListenerTestNotifyNewFolder");
    ImapServerListener remoteListener = ImapServerListenerPool.getInstance().get(mboxStore);
    RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
    ImapCredentials creds = new ImapCredentials(remoteAccount);
    ImapPath path = new ImapPath(folder.getPath(), 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 - testNotifyNewFolder";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), "randomUserTestImapServerListener@yahoo.com");
    ZMessage msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox subject:\"%s\"", subject));
    mboxStore.moveMessage(msg.getId(), folder.getId());
    TestUtil.waitForMessage(mboxStore, String.format("in:%s subject:\"%s\"", folder.getName(), subject));
    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 : 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) 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) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 2 with ImapServerListener

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

the class TestImapServerListener method testDeleteAccount.

@Test
public void testDeleteAccount() 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
    String waitSetId = remoteListener.getWSId();
    QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, waitSetId, remoteServer);
    // delete account
    TestUtil.deleteAccount(REMOTE_USER_NAME);
    session.killSignal = new CountDownLatch(1);
    try {
        session.killSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    assertFalse("Expected 1st user's session to NOT be triggered", session.wasTriggered());
    assertTrue("Expected 1st user's session to be unregistered", session.wasUnregistered());
    // wait for ImapServerListener to create a new WaitSet
    int maxWait = 5000;
    while (maxWait > 0) {
        if (remoteListener.getWSId() == null) {
            break;
        } else {
            maxWait -= 500;
            Thread.sleep(500);
        }
    }
    assertNull("ImapServerListener should have deleted the waitset", remoteListener.getWSId());
}
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 3 with ImapServerListener

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

the class TestImapServerListener method testDestroyWaitset.

@Test
public void testDestroyWaitset() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    TestUtil.addMessage(mboxStore, "TestImapServerListener - testDestroyWaitset - 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
    String waitSetId = remoteListener.getWSId();
    TestUtil.waitForSessions(1, 1, 6000, waitSetId, remoteServer);
    // delete waitset
    ZimbraLog.test.debug("Destroying waitset %s", waitSetId);
    AdminDestroyWaitSetRequest destroyReq = new AdminDestroyWaitSetRequest(waitSetId);
    SoapTransport transport = TestUtil.getAdminSoapTransport(remoteServer);
    AdminDestroyWaitSetResponse destroyResp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(destroyReq)));
    Assert.assertNotNull("AdminDestroyWaitSetResponse should not be null", destroyResp);
    Assert.assertNotNull("AdminDestroyWaitSetResponse::waitSetId should not be null", destroyResp.getWaitSetId());
    Assert.assertEquals("AdminDestroyWaitSetResponse has wrong waitSetId", waitSetId, destroyResp.getWaitSetId());
    // wait for ImapServerListener to create a new WaitSet
    int maxWait = 5000;
    while (maxWait > 0) {
        if (remoteListener.getWSId() != null && !waitSetId.equalsIgnoreCase(remoteListener.getWSId())) {
            break;
        } else {
            maxWait -= 500;
            Thread.sleep(500);
        }
    }
    Assert.assertFalse("ImapServerListener should have created a new waitset", waitSetId.equalsIgnoreCase(remoteListener.getWSId()));
    // send a message
    session.doneSignal = new CountDownLatch(1);
    String subject = "TestImapServerListener - testDestroyWaitset - trigger message";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), TestUtil.getAddress("TestImapServerListener-testDestroyWaitset"));
    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 NOT be triggered", session.wasTriggered());
    assertFalse("ImapServerListener should have created a new waitset", remoteListener.getWSId().equalsIgnoreCase(waitSetId));
}
Also used : 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) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 4 with ImapServerListener

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

the class TestImapServerListener method testNotifyTagUntag.

@Test
public void testNotifyTagUntag() 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 - testNotifyTagUntag";
    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("testNotifyTagUntag", Color.blue);
    // tag
    session.doneSignal = new CountDownLatch(1);
    mboxStore.tagMessage(msg.getId(), tag.getId(), true);
    msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox tag:testNotifyTagUntag subject:\"%s\"", subject));
    assertTrue("Test message should have testNotifyTagUntag 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());
    // untag
    session.doneSignal = new CountDownLatch(1);
    mboxStore.tagMessage(msg.getId(), tag.getId(), false);
    msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox -tag:testNotifyTagUntag subject:\"%s\"", subject));
    assertFalse("Test message should NOT have testNotifyTagUntag tag after untagging", 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 untagging test message", 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 5 with ImapServerListener

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

the class TestImapServerListener method testNotifyDeleteItemFromInbox.

@Ignore("this is failing until WaitSetResponse can process deletes")
public void testNotifyDeleteItemFromInbox() 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);
    String subject = "TestImapServerListener - testNotifyDeleteItemFromInbox - trigger message";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), "randomUserTestImapServerListener@yahoo.com");
    ZMessage msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox subject:\"%s\"", subject));
    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);
    mboxStore.deleteMessage(msg.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", 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) 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) Ignore(org.junit.Ignore)

Aggregations

ImapServerListener (com.zimbra.cs.imap.ImapServerListener)12 ZMailbox (com.zimbra.client.ZMailbox)11 ServiceException (com.zimbra.common.service.ServiceException)10 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)10 ImapFolder (com.zimbra.cs.imap.ImapFolder)10 ImapHandler (com.zimbra.cs.imap.ImapHandler)10 ImapPath (com.zimbra.cs.imap.ImapPath)10 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)10 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 HttpException (org.apache.http.HttpException)10 Test (org.junit.Test)9 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)8 ZMessage (com.zimbra.client.ZMessage)5 ZFolder (com.zimbra.client.ZFolder)2 ZTag (com.zimbra.client.ZTag)2 SoapTransport (com.zimbra.common.soap.SoapTransport)1 Account (com.zimbra.cs.account.Account)1 ImapRemoteSession (com.zimbra.cs.imap.ImapRemoteSession)1 SomeAccountsWaitSet (com.zimbra.cs.session.SomeAccountsWaitSet)1