Search in sources :

Example 11 with ImapPath

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));
}
Also used : CopyCommand(com.zimbra.cs.imap.CopyCommand) ImapPath(com.zimbra.cs.imap.ImapPath) Test(org.junit.Test)

Example 12 with ImapPath

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));
}
Also used : AppendCommand(com.zimbra.cs.imap.AppendCommand) Part(com.zimbra.cs.imap.AppendMessage.Part) AppendMessage(com.zimbra.cs.imap.AppendMessage) ArrayList(java.util.ArrayList) ImapPath(com.zimbra.cs.imap.ImapPath) Date(java.util.Date) Test(org.junit.Test)

Example 13 with ImapPath

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());
}
Also used : ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 14 with ImapPath

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);
}
Also used : ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) CountDownLatch(java.util.concurrent.CountDownLatch) HttpException(org.apache.http.HttpException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 15 with ImapPath

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());
}
Also used : ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) Test(org.junit.Test)

Aggregations

ImapPath (com.zimbra.cs.imap.ImapPath)20 Test (org.junit.Test)18 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)14 ImapFolder (com.zimbra.cs.imap.ImapFolder)14 ImapHandler (com.zimbra.cs.imap.ImapHandler)14 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)14 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)12 ZMailbox (com.zimbra.client.ZMailbox)10 ServiceException (com.zimbra.common.service.ServiceException)10 ImapServerListener (com.zimbra.cs.imap.ImapServerListener)10 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 HttpException (org.apache.http.HttpException)10 ZMessage (com.zimbra.client.ZMessage)5 ZFolder (com.zimbra.client.ZFolder)2 ZTag (com.zimbra.client.ZTag)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 ImapRemoteSession (com.zimbra.cs.imap.ImapRemoteSession)2 QResyncInfo (com.zimbra.cs.imap.QResyncInfo)2 SelectCommand (com.zimbra.cs.imap.SelectCommand)2