use of com.zimbra.cs.imap.ImapHandler 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);
}
use of com.zimbra.cs.imap.ImapHandler in project zm-mailbox by Zimbra.
the class TestImapServerListener method testRegisterUnregister.
@Test
public void testRegisterUnregister() throws ServiceException, IOException, HttpException {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
assertNotNull("ImapServerListener instance should not be null", remoteListener);
RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
assertNotNull("ImapMailboxStore instance should not be null", imapStore);
ImapCredentials creds = new ImapCredentials(remoteAccount);
ImapPath path = new ImapPath("INBOX", creds);
assertNotNull("ImapPath instance should not be null", path);
byte params = 0;
ImapHandler handler = new MockImapHandler().setCredentials(creds);
ImapFolder i4folder = new ImapFolder(path, params, handler);
assertNotNull("ImapFolder instance should not be null", i4folder);
assertNotNull("ImapFolder.getCredentials() should not return null", i4folder.getCredentials());
assertNotNull("ImapFolder.getPath() should not return null", i4folder.getPath());
MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
assertNotNull("ImapListener instance should not be null", session);
assertFalse("Expecting ImapServerListener::isListeningOn to return false before calling addListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNull("Should not have a waitset before registering first listener", remoteListener.getWSId());
remoteListener.addListener(session);
assertTrue("Expecting ImapServerListener::isListeningOn to return true after calling addListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNotNull("Should have a waitset after registering first listener", remoteListener.getWSId());
QueryWaitSetRequest req = new QueryWaitSetRequest(remoteListener.getWSId());
SoapTransport transport = TestUtil.getAdminSoapTransport(remoteServer);
QueryWaitSetResponse resp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(req)));
assertNotNull(resp);
List<WaitSetInfo> wsInfoList = resp.getWaitsets();
assertNotNull(wsInfoList);
assertFalse(wsInfoList.isEmpty());
assertEquals(1, wsInfoList.size());
WaitSetInfo wsInfo = wsInfoList.get(0);
assertNotNull(wsInfo);
assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
remoteListener.removeListener(session);
assertFalse("Expecting ImapServerListener::isListeningOn to return false after calling removeListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNull("Should not have a waitset after removing last listener", remoteListener.getWSId());
}
use of com.zimbra.cs.imap.ImapHandler in project zm-mailbox by Zimbra.
the class TestImapServerListener method testNotifyWrongFolder.
@Test
public void testNotifyWrongFolder() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
ZFolder folder = TestUtil.createFolder(mboxStore, "/TestImapServerListener-testNotifyNewFolder");
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);
session.doneSignal = new CountDownLatch(1);
remoteListener.addListener(session);
// wait for waitset session to be created
QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
TestUtil.addMessage(mboxStore, "TestImapServerListener - testNotifyWrongFolder", folder.getId());
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertFalse("Expected session to not be triggered", session.wasTriggered());
remoteListener.removeListener(session);
}
use of com.zimbra.cs.imap.ImapHandler 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());
}
use of com.zimbra.cs.imap.ImapHandler 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);
}
Aggregations