Search in sources :

Example 11 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse in project zm-mailbox by Zimbra.

the class TestImapServerListener method testShutdown.

@Test
public void testShutdown() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    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);
    assertNotNull("Should have a waitset after addig a listener", remoteListener.getWSId());
    remoteListener.shutdown();
    assertNull("Should not have a waitset after shutting down ImapServerListener", 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) Test(org.junit.Test)

Example 12 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse 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 13 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse 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 QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method testDestroyWaitset.

@Test
public void testDestroyWaitset() throws Exception {
    ZimbraLog.test.info("Starting testDestroyWaitset");
    String user1Name = "testDestroyWaitset_user1";
    acc1 = TestUtil.createAccount(user1Name);
    ZMailbox mbox = TestUtil.getZMailbox(user1Name);
    Set<String> accountIds = new HashSet<String>();
    accountIds.add(mbox.getAccountId());
    String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
    AdminCreateWaitSetResponse resp = createAdminWaitSet(accountIds, adminAuthToken, false);
    assertNotNull(resp);
    waitSetId = resp.getWaitSetId();
    assertNotNull(waitSetId);
    QueryWaitSetRequest qwsReq = new QueryWaitSetRequest(waitSetId);
    QueryWaitSetResponse qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
    validateQueryWaitSetResponse(qwsResp, acc1.getId(), null, null, false);
    AdminDestroyWaitSetRequest destroyReq = new AdminDestroyWaitSetRequest(waitSetId);
    AdminDestroyWaitSetResponse destroyResp = (AdminDestroyWaitSetResponse) sendReq(destroyReq, adminAuthToken, TestUtil.getAdminSoapUrl());
    assertNotNull("AdminDestroyWaitSetResponse should not be null", destroyResp);
    assertNotNull("AdminDestroyWaitSetResponse::waitSetId should not be null", destroyResp.getWaitSetId());
    assertEquals("AdminDestroyWaitSetResponse has wrong waitSetId", waitSetId, destroyResp.getWaitSetId());
    qwsReq = new QueryWaitSetRequest(waitSetId);
    Element faultResp = sendReqExpectedToFail(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
    assertNotNull("should return Element", faultResp);
    try {
        TestUtil.getAdminSoapTransport().extractBodyElement(faultResp);
        fail("Should thrown SoapFaultException");
    } catch (SoapFaultException sfe) {
        assertEquals("Expecting admin.NO_SUCH_WAITSET", AdminServiceException.NO_SUCH_WAITSET, sfe.getCode());
    } catch (SoapParseException spe) {
        fail("Should not be throwing SoapParseException. " + spe.getMessage());
    }
    waitSetId = null;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) Element(com.zimbra.common.soap.Element) SoapParseException(com.zimbra.common.soap.SoapParseException) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) SoapFaultException(com.zimbra.common.soap.SoapFaultException) HashSet(java.util.HashSet) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) Test(org.junit.Test)

Example 15 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse in project zm-mailbox by Zimbra.

the class TestImapServerListener method testNotifyReadUnread.

@Test
public void testNotifyReadUnread() 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 - testNotifyReadUnread";
    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());
    // mark read
    session.doneSignal = new CountDownLatch(1);
    mboxStore.markMessageRead(msg.getId(), true);
    msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox is:read subject:\"%s\"", subject));
    assertFalse("New message should NOT 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 marking test message READ", session.wasTriggered());
    // mark unread
    session.doneSignal = new CountDownLatch(1);
    mboxStore.markMessageRead(msg.getId(), false);
    msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox is:unread 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 marking test message UREAD", 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) Test(org.junit.Test)

Aggregations

QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)16 Test (org.junit.Test)13 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)12 ImapFolder (com.zimbra.cs.imap.ImapFolder)12 ImapHandler (com.zimbra.cs.imap.ImapHandler)12 ImapPath (com.zimbra.cs.imap.ImapPath)12 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)12 ZMailbox (com.zimbra.client.ZMailbox)10 ServiceException (com.zimbra.common.service.ServiceException)8 ImapServerListener (com.zimbra.cs.imap.ImapServerListener)8 IOException (java.io.IOException)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 HttpException (org.apache.http.HttpException)8 ZMessage (com.zimbra.client.ZMessage)5 QueryWaitSetRequest (com.zimbra.soap.admin.message.QueryWaitSetRequest)5 ZFolder (com.zimbra.client.ZFolder)3 WaitSetInfo (com.zimbra.soap.admin.type.WaitSetInfo)3 ZTag (com.zimbra.client.ZTag)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 ImapRemoteSession (com.zimbra.cs.imap.ImapRemoteSession)2