use of com.zimbra.cs.imap.ImapCredentials in project zm-mailbox by Zimbra.
the class SharedImapTests method imapPath.
@Test(timeout = 100000)
public void imapPath() throws IOException, ServiceException, MessagingException {
Account userAcct = TestUtil.getAccount(USER);
// Shuts up PMD complaint about missing asserts
assertNotNull("Account object for user", userAcct);
Account shareeAcct = TestUtil.createAccount(SHAREE);
ZMailbox shareeZmbox = TestUtil.getZMailbox(SHAREE);
ZMailbox zmbox = TestUtil.getZMailbox(USER);
/* create a few folders to ensure that the sharee account won't have the same folder IDs
* present as are used in the shared folders.
*/
for (int cnt = 0; cnt < 10; cnt++) {
TestUtil.createFolder(zmbox, "/toplevel-" + cnt);
}
String remFolder = String.format("/INBOX/%s-shared", testInfo.getMethodName());
String underRemFolder = String.format("%s/subFolder", remFolder);
String otherUserFolder = String.format("/home/%s%s", USER, remFolder);
String otherUserSubFolder = String.format("/home/%s%s", USER, underRemFolder);
ZFolder zfolder = TestUtil.createFolder(zmbox, remFolder);
ZFolder underZfolder = TestUtil.createFolder(zmbox, underRemFolder);
String mp = String.format("%s's %s-shared", USER, testInfo.getMethodName());
String subMp = String.format("%s/subFolder", mp);
TestUtil.createMountpoint(zmbox, remFolder, shareeZmbox, mp);
ImapCredentials creds = new ImapCredentials(shareeAcct);
checkImapPath("inbox", creds, "INBOX", false, /* usingReferent */
Integer.parseInt(ZFolder.ID_INBOX), shareeAcct.getId());
checkImapPath(mp, creds, mp, true, /* usingReferent */
zfolder.getFolderItemIdentifier().id, userAcct.getId());
checkImapPath(subMp, creds, subMp, true, /* usingReferent */
underZfolder.getFolderItemIdentifier().id, userAcct.getId());
checkImapPath(otherUserFolder, creds, otherUserFolder, false, /* usingReferent */
zfolder.getFolderItemIdentifier().id, userAcct.getId());
checkImapPath(otherUserSubFolder, creds, otherUserSubFolder, false, /* usingReferent */
underZfolder.getFolderItemIdentifier().id, userAcct.getId());
}
use of com.zimbra.cs.imap.ImapCredentials 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.ImapCredentials 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.ImapCredentials 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.ImapCredentials 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));
}
Aggregations