use of com.zimbra.cs.imap.ImapRemoteSession 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.ImapRemoteSession in project zm-mailbox by Zimbra.
the class TestImapNotificationsViaMailbox method runOp.
@Override
protected void runOp(MailboxOperation op, ZMailbox zmbox, ZFolder folder) throws Exception {
ImapServerListener listener = ImapServerListenerPool.getInstance().get(zmbox);
Set<ImapRemoteSession> sessions = listener.getListeners(zmbox.getAccountId(), Integer.valueOf(folder.getId()));
assertFalse(String.format("Folder %s does not have any IMAP listeners", folder.getPath()), sessions.isEmpty());
ImapRemoteSession session = sessions.iterator().next();
ZMailbox imapzmbox = (ZMailbox) session.getMailbox();
op.run(imapzmbox);
String failure = op.checkResult();
assertNull(failure, failure);
}
use of com.zimbra.cs.imap.ImapRemoteSession 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