use of com.zimbra.cs.imap.ImapHandler in project zm-mailbox by Zimbra.
the class TestImapServerListener method testRemoveFolderInterest.
@Test
public void testRemoveFolderInterest() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
ImapCredentials creds = new ImapCredentials(remoteAccount);
// add listener on INBOX
ImapPath path = new ImapPath("INBOX", creds);
byte params = 0;
ImapHandler handler = new MockImapHandler().setCredentials(creds);
ImapFolder i4folder = new ImapFolder(path, params, handler);
MockImapListener inboxSession = new MockImapListener(imapStore, i4folder, handler);
remoteListener.addListener(inboxSession);
// check created waitset
QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
assertNotNull(resp);
List<WaitSetInfo> wsInfoList = resp.getWaitsets();
assertFalse(wsInfoList.isEmpty());
assertEquals(1, wsInfoList.size());
WaitSetInfo wsInfo = wsInfoList.get(0);
assertNotNull(wsInfo);
assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
List<SessionForWaitSet> sessions = wsInfo.getSessions();
assertNotNull(sessions);
assertEquals("expected to find 1 session after adding a listener for INBOX", 1, sessions.size());
SessionForWaitSet s = sessions.get(0);
Set<Integer> folders = s.getWaitSetSession().getFolderInterestsAsSet();
assertNotNull("folder interests cannot be NULL", folders);
assertEquals("should have one folder interest", 1, folders.size());
assertTrue("folder interests should contain INBOX", folders.contains(Mailbox.ID_FOLDER_INBOX));
// add listener on DRAFTS
path = new ImapPath("DRAFTS", creds);
params = 0;
i4folder = new ImapFolder(path, params, handler);
ImapRemoteSession draftsSession = (ImapRemoteSession) imapStore.createListener(i4folder, handler);
remoteListener.addListener(draftsSession);
// check that waitset was updated
resp = TestUtil.waitForSessions(1, 2, 6000, remoteListener.getWSId(), remoteServer);
assertNotNull(resp);
wsInfoList = resp.getWaitsets();
assertFalse(wsInfoList.isEmpty());
wsInfo = wsInfoList.get(0);
assertNotNull(wsInfo);
assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
sessions = wsInfo.getSessions();
assertNotNull(sessions);
assertEquals("expected to find 1 session after adding a listener for DRAFTS", 1, sessions.size());
s = sessions.get(0);
folders = s.getWaitSetSession().getFolderInterestsAsSet();
assertNotNull("folder interests cannot be NULL", folders);
assertEquals("should have two folder interests", 2, folders.size());
assertTrue("folder interests should contain DRAFTS", folders.contains(Mailbox.ID_FOLDER_DRAFTS));
assertTrue("folder interests should contain INBOX", folders.contains(Mailbox.ID_FOLDER_INBOX));
remoteListener.removeListener(inboxSession);
// check that waitset was updated after removing a listener
resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
assertNotNull(resp);
wsInfoList = resp.getWaitsets();
assertFalse(wsInfoList.isEmpty());
wsInfo = wsInfoList.get(0);
assertNotNull(wsInfo);
assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
sessions = wsInfo.getSessions();
assertNotNull(sessions);
assertEquals("expected to find 1 session after removing listener for inbox", 1, sessions.size());
s = sessions.get(0);
folders = s.getWaitSetSession().getFolderInterestsAsSet();
assertNotNull("folder interests cannot be NULL", folders);
assertEquals("should have one folder interest after removing a listener", 1, folders.size());
assertTrue("folder interests should contain DRAFTS after removing INBOX listener", folders.contains(Mailbox.ID_FOLDER_DRAFTS));
}
use of com.zimbra.cs.imap.ImapHandler 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);
}
use of com.zimbra.cs.imap.ImapHandler 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());
}
use of com.zimbra.cs.imap.ImapHandler 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));
}
use of com.zimbra.cs.imap.ImapHandler 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);
}
Aggregations