use of com.zimbra.cs.imap.ImapPath 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);
}
use of com.zimbra.cs.imap.ImapPath 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()));
}
use of com.zimbra.cs.imap.ImapPath 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);
}
use of com.zimbra.cs.imap.ImapPath 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);
}
use of com.zimbra.cs.imap.ImapPath in project zm-mailbox by Zimbra.
the class TestImapServerListener method testGetListeners.
@Test
public void testGetListeners() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
assertNotNull("ImapServerListener instance should not be null", remoteListener);
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);
assertNotNull("ImapListener instance should not be null", session);
Set<ImapRemoteSession> sessions = remoteListener.getListeners(remoteAccount.getId(), i4folder.getId());
assertNotNull("getListeners should not return NULL before adding a listener", sessions);
assertTrue("expecting an empty list before adding a listener", sessions.isEmpty());
remoteListener.addListener(session);
// wait for waitset session to be created
QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
sessions = remoteListener.getListeners(remoteAccount.getId(), i4folder.getId());
assertNotNull("getListeners should not return NULL after adding a listener", sessions);
assertFalse("expecting a non empty list after adding a listener", sessions.isEmpty());
remoteListener.removeListener(session);
sessions = remoteListener.getListeners(remoteAccount.getId(), i4folder.getId());
assertNotNull("getListeners should not return NULL after removing a listener", sessions);
assertTrue("expecting an empty list after removing a listener", sessions.isEmpty());
assertNull("Should not have a waitset after removing last listener", remoteListener.getWSId());
}
Aggregations