use of com.zimbra.cs.imap.RemoteImapMailboxStore 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.RemoteImapMailboxStore 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.RemoteImapMailboxStore 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.RemoteImapMailboxStore in project zm-mailbox by Zimbra.
the class TestRemoteImapMailboxStore method testSaveIMAPSubscriptions.
@Test
public void testSaveIMAPSubscriptions() throws Exception {
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
RemoteImapMailboxStore remoteStore = new RemoteImapMailboxStore(zmbox, TestUtil.getAccount(USER_NAME).getId());
// check that there are no subscriptions saved yet
Set<String> subs = remoteStore.listSubscriptions(null);
Assert.assertNull(subs);
String path = NAME_PREFIX + "_testPath";
Set<String> newSubs = new HashSet<String>();
newSubs.add(path);
// save subscriptions
remoteStore.saveSubscriptions(null, newSubs);
// verify that subscriptions were saved
subs = remoteStore.listSubscriptions(null);
Assert.assertNotNull(subs);
Assert.assertEquals(1, subs.size());
String sub = subs.iterator().next();
Assert.assertTrue(sub.equalsIgnoreCase(path));
}
use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.
the class TestRemoteImapMailboxStore method testGetCurrentModseq.
@Test
public void testGetCurrentModseq() throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
Folder folder = mbox.createFolder(null, NAME_PREFIX, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
int folderId = folder.getId();
ItemIdentifier folderIdent = folder.getFolderItemIdentifier();
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
RemoteImapMailboxStore remoteStore = new RemoteImapMailboxStore(zmbox, TestUtil.getAccount(USER_NAME).getId());
Assert.assertEquals("Before adding a message, remoteStore.getCurrentMODSEQ returns value different from folder.getImapMODSEQ", remoteStore.getCurrentMODSEQ(folderIdent), folder.getImapMODSEQ());
int oldModSeq = remoteStore.getCurrentMODSEQ(folderIdent);
// add a message to the folder
DeliveryOptions dopt = new DeliveryOptions().setFolderId(folderId).setFlags(Flag.BITMASK_UNREAD);
String message = TestUtil.getTestMessage(NAME_PREFIX, mbox.getAccount().getName(), "someone@zimbra.com", "nothing here", new Date(System.currentTimeMillis()));
ParsedMessage pm = new ParsedMessage(message.getBytes(), System.currentTimeMillis(), false);
mbox.addMessage(null, pm, dopt, null);
zmbox.noOp();
folder = mbox.getFolderById(null, folderId);
Assert.assertEquals("After adding a message, remoteStore.getCurrentMODSEQ returns value different from folder.getImapMODSEQ", remoteStore.getCurrentMODSEQ(folderIdent), folder.getImapMODSEQ());
Assert.assertFalse("Modseq should have changed after adding a message", remoteStore.getCurrentMODSEQ(folderIdent) == oldModSeq);
}
Aggregations