use of com.zimbra.cs.imap.ImapPath in project zm-mailbox by Zimbra.
the class ImapCommandThrottleTest method copy.
@Test
public void copy() {
String destFolder = "destFolder";
String sequenceSet = "10:20";
CopyCommand copy = new CopyCommand(sequenceSet, new ImapPath(destFolder, null));
Assert.assertTrue("same obj", copy.isDuplicate(copy));
CopyCommand copy2 = new CopyCommand(sequenceSet, new ImapPath(destFolder, null));
Assert.assertTrue("diff obj same fields", copy.isDuplicate(copy2));
CopyCommand copy3 = new CopyCommand(sequenceSet, new ImapPath(destFolder + "foo", null));
Assert.assertFalse("diff dest path", copy.isDuplicate(copy3));
CopyCommand copy4 = new CopyCommand("20:30", new ImapPath(destFolder + "foo", null));
Assert.assertFalse("diff dest path", copy.isDuplicate(copy4));
}
use of com.zimbra.cs.imap.ImapPath in project zm-mailbox by Zimbra.
the class ImapCommandThrottleTest method append.
@Test
public void append() throws IOException {
String path = "testPath";
AppendCommand append = new AppendCommand(new ImapPath(path, null), makeAppends());
Assert.assertTrue("same obj", append.isDuplicate(append));
AppendCommand append2 = new AppendCommand(new ImapPath(path, null), makeAppends());
Assert.assertTrue("diff obj same params", append.isDuplicate(append2));
AppendCommand append3 = new AppendCommand(new ImapPath(path + "foo", null), makeAppends());
Assert.assertFalse("different path", append.isDuplicate(append3));
List<AppendMessage> appends = makeAppends();
appends.remove(0);
AppendCommand append4 = new AppendCommand(new ImapPath(path, null), appends);
Assert.assertFalse("different length appends", append.isDuplicate(append4));
appends = makeAppends();
AppendMessage appendMsg = appends.remove(0);
List<Part> parts = new ArrayList<Part>();
AppendMessage appendMsg2 = new AppendMessage(appendMsg.getPersistentFlagNames(), appendMsg.getDate(), parts);
parts.add(makeAppendPart(appendMsg2, 215, (byte) 215));
appends.add(0, appendMsg2);
AppendCommand append5 = new AppendCommand(new ImapPath(path, null), appends);
Assert.assertFalse("different append parts", append.isDuplicate(append5));
parts = new ArrayList<Part>();
appendMsg2 = new AppendMessage(appendMsg.getPersistentFlagNames(), new Date(), parts);
parts.add(makeAppendPart(appendMsg2, 123, (byte) 99));
appends.remove(0);
appends.add(0, appendMsg2);
AppendCommand append6 = new AppendCommand(new ImapPath(path, null), appends);
Assert.assertFalse("different date", append.isDuplicate(append6));
parts = new ArrayList<Part>();
List<String> flagNames = new ArrayList<String>();
flagNames.add("F1");
flagNames.add("F3");
appendMsg2 = new AppendMessage(flagNames, appendMsg.getDate(), parts);
parts.add(makeAppendPart(appendMsg2, 123, (byte) 99));
appends.remove(0);
appends.add(0, appendMsg2);
AppendCommand append7 = new AppendCommand(new ImapPath(path, null), appends);
Assert.assertFalse("different flag names", append.isDuplicate(append7));
}
use of com.zimbra.cs.imap.ImapPath in project zm-mailbox by Zimbra.
the class TestImapServerListener method testRegisterUnregister.
@Test
public void testRegisterUnregister() throws ServiceException, IOException, HttpException {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
assertNotNull("ImapServerListener instance should not be null", remoteListener);
RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
assertNotNull("ImapMailboxStore instance should not be null", imapStore);
ImapCredentials creds = new ImapCredentials(remoteAccount);
ImapPath path = new ImapPath("INBOX", creds);
assertNotNull("ImapPath instance should not be null", path);
byte params = 0;
ImapHandler handler = new MockImapHandler().setCredentials(creds);
ImapFolder i4folder = new ImapFolder(path, params, handler);
assertNotNull("ImapFolder instance should not be null", i4folder);
assertNotNull("ImapFolder.getCredentials() should not return null", i4folder.getCredentials());
assertNotNull("ImapFolder.getPath() should not return null", i4folder.getPath());
MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
assertNotNull("ImapListener instance should not be null", session);
assertFalse("Expecting ImapServerListener::isListeningOn to return false before calling addListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNull("Should not have a waitset before registering first listener", remoteListener.getWSId());
remoteListener.addListener(session);
assertTrue("Expecting ImapServerListener::isListeningOn to return true after calling addListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNotNull("Should have a waitset after registering first listener", remoteListener.getWSId());
QueryWaitSetRequest req = new QueryWaitSetRequest(remoteListener.getWSId());
SoapTransport transport = TestUtil.getAdminSoapTransport(remoteServer);
QueryWaitSetResponse resp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(req)));
assertNotNull(resp);
List<WaitSetInfo> wsInfoList = resp.getWaitsets();
assertNotNull(wsInfoList);
assertFalse(wsInfoList.isEmpty());
assertEquals(1, wsInfoList.size());
WaitSetInfo wsInfo = wsInfoList.get(0);
assertNotNull(wsInfo);
assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
remoteListener.removeListener(session);
assertFalse("Expecting ImapServerListener::isListeningOn to return false after calling removeListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNull("Should not have a waitset after removing last listener", remoteListener.getWSId());
}
use of com.zimbra.cs.imap.ImapPath in project zm-mailbox by Zimbra.
the class TestImapServerListener method testNotifyWrongFolder.
@Test
public void testNotifyWrongFolder() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
ZFolder folder = TestUtil.createFolder(mboxStore, "/TestImapServerListener-testNotifyNewFolder");
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);
session.doneSignal = new CountDownLatch(1);
remoteListener.addListener(session);
// wait for waitset session to be created
QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
TestUtil.addMessage(mboxStore, "TestImapServerListener - testNotifyWrongFolder", folder.getId());
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertFalse("Expected session to not be triggered", session.wasTriggered());
remoteListener.removeListener(session);
}
use of com.zimbra.cs.imap.ImapPath in project zm-mailbox by Zimbra.
the class TestImapServerListener method testShutdown.
@Test
public void testShutdown() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
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);
assertNotNull("Should have a waitset after addig a listener", remoteListener.getWSId());
remoteListener.shutdown();
assertNull("Should not have a waitset after shutting down ImapServerListener", remoteListener.getWSId());
}
Aggregations