Search in sources :

Example 1 with CreateWaitSetResponse

use of com.zimbra.soap.mail.message.CreateWaitSetResponse in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method testWaitSetRequest.

@Test
public void testWaitSetRequest() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String authToken = mbox.getAuthToken().getValue();
    CreateWaitSetRequest req = new CreateWaitSetRequest("all");
    WaitSetAddSpec add = new WaitSetAddSpec();
    add.setId(mbox.getAccountInfo(false).getId());
    req.addAccount(add);
    DocumentResult dr = new DocumentResult();
    marshaller.marshal(req, dr);
    Document doc = dr.getDocument();
    ZimbraLog.test.info(doc.getRootElement().asXML());
    CreateWaitSetResponse createResp = (CreateWaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "CreateWaitSetRequest");
    String waitSetId = createResp.getWaitSetId();
    Assert.assertNotNull(waitSetId);
    WaitSetRequest waitSet = new com.zimbra.soap.mail.message.WaitSetRequest(waitSetId, "0");
    dr = new DocumentResult();
    marshaller.marshal(waitSet, dr);
    doc = dr.getDocument();
    WaitSetResponse wsResp = (WaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
    Assert.assertEquals("0", wsResp.getSeqNo());
    String subject = NAME_PREFIX + " test wait set request 1";
    TestUtil.addMessageLmtp(subject, USER_NAME, "user999@example.com");
    try {
        Thread.sleep(500);
    } catch (Exception e) {
    }
    wsResp = (WaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
    Assert.assertFalse(wsResp.getSeqNo().equals("0"));
}
Also used : WaitSetRequest(com.zimbra.soap.mail.message.WaitSetRequest) CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) ZMailbox(com.zimbra.client.ZMailbox) WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) WaitSetResponse(com.zimbra.soap.mail.message.WaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) DocumentResult(org.dom4j.io.DocumentResult) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) Document(org.dom4j.Document) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException) HttpException(org.apache.commons.httpclient.HttpException) CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) Test(org.junit.Test)

Example 2 with CreateWaitSetResponse

use of com.zimbra.soap.mail.message.CreateWaitSetResponse in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method testSyncWaitSetRequest.

@Test
public void testSyncWaitSetRequest() throws Exception {
    String user1Name = "testSyncWaitSetRequest_user1";
    acc1 = TestUtil.createAccount(user1Name);
    ZMailbox mbox = TestUtil.getZMailbox(user1Name);
    String authToken = mbox.getAuthToken().getValue();
    CreateWaitSetResponse resp = createWaitSet(mbox.getAccountInfo(false).getId(), authToken);
    assertNotNull(resp);
    waitSetId = resp.getWaitSetId();
    int seq = resp.getSequence();
    WaitSetRequest waitSet = new WaitSetRequest(waitSetId, Integer.toString(seq));
    WaitSetResponse wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
    assertEquals("0", wsResp.getSeqNo());
    String subject = NAME_PREFIX + " test wait set request 1";
    TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
    // try { Thread.sleep(500); } catch (Exception e) {}
    TestUtil.waitForMessages(mbox, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
    wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
    assertFalse(wsResp.getSeqNo().equals("0"));
    List<AccountWithModifications> accounts = wsResp.getSignalledAccounts();
    assertEquals("should have signaled 1 account", 1, accounts.size());
    assertEquals(String.format("Shold have signaled account %s", acc1.getId()), acc1.getId(), accounts.get(0).getId());
    assertNull("Should not return folder notifications unless 'expand' is set to 'true'", accounts.get(0).getPendingFolderModifications());
}
Also used : CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) WaitSetRequest(com.zimbra.soap.mail.message.WaitSetRequest) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) AdminWaitSetRequest(com.zimbra.soap.admin.message.AdminWaitSetRequest) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest) ZMailbox(com.zimbra.client.ZMailbox) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) WaitSetResponse(com.zimbra.soap.mail.message.WaitSetResponse) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) AdminWaitSetResponse(com.zimbra.soap.admin.message.AdminWaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) AccountWithModifications(com.zimbra.soap.type.AccountWithModifications) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) Test(org.junit.Test)

Example 3 with CreateWaitSetResponse

use of com.zimbra.soap.mail.message.CreateWaitSetResponse in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method testFolderInterestSyncWaitSetRequest.

@Test
public void testFolderInterestSyncWaitSetRequest() throws Exception {
    String user1Name = "testFISyncWaitSetRequest_user1";
    acc1 = TestUtil.createAccount(user1Name);
    ZMailbox mbox = TestUtil.getZMailbox(user1Name);
    String acctId = mbox.getAccountId();
    String authToken = mbox.getAuthToken().getValue();
    ZimbraLog.test.info("GREN 1");
    String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
    ZimbraLog.test.info("GREN 2");
    ZFolder myFolder = TestUtil.createFolder(mbox, "funFolder");
    Set<Integer> folderInterest = Sets.newHashSet();
    folderInterest.add(myFolder.getFolderIdInOwnerMailbox());
    /* initially only interested in funFolder */
    CreateWaitSetResponse resp = createWaitSet(acctId, authToken, folderInterest);
    assertNotNull(resp);
    waitSetId = resp.getWaitSetId();
    int seq = resp.getSequence();
    WaitSetRequest waitSet = new WaitSetRequest(waitSetId, Integer.toString(seq));
    WaitSetResponse wsResp = (WaitSetResponse) sendReq(waitSet, authToken, TestUtil.getSoapUrl());
    assertEquals("0", wsResp.getSeqNo());
    String subject = NAME_PREFIX + " test wait set request 1";
    TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
    TestUtil.waitForMessages(mbox, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
    wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
    assertTrue(wsResp.getSeqNo().equals("0"));
    assertEquals("Number of signalled accounts", 0, wsResp.getSignalledAccounts().size());
    QueryWaitSetResponse qwsResp;
    QueryWaitSetRequest qwsReq = new QueryWaitSetRequest(waitSetId);
    qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
    validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
    /* interested in funFolder AND inbox */
    folderInterest.add(Integer.valueOf(Mailbox.ID_FOLDER_INBOX));
    waitSet.addUpdateAccount(createWaitSetAddSpec(acctId, folderInterest));
    wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
    assertTrue(wsResp.getSeqNo().equals("0"));
    assertEquals("Number of signalled accounts", 0, wsResp.getSignalledAccounts().size());
    qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
    validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
    subject = NAME_PREFIX + " test wait set request 2";
    TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
    TestUtil.waitForMessages(mbox, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
    qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
    validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
    waitSet = new WaitSetRequest(waitSetId, Integer.toString(seq));
    waitSet.setExpand(true);
    wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
    assertFalse(wsResp.getSeqNo().equals("0"));
    assertEquals("Number of signalled accounts", 1, wsResp.getSignalledAccounts().size());
    AccountWithModifications acctInfo = wsResp.getSignalledAccounts().get(0);
    assertEquals("Signaled account id", mbox.getAccountId(), acctInfo.getId());
    Collection<PendingFolderModifications> mods = acctInfo.getPendingFolderModifications();
    assertNotNull("'mod' field should not be null", mods);
    assertEquals("Should have 1 folder object with modifications", 1, mods.size());
    Integer foldInt = mods.iterator().next().getFolderId();
    assertEquals(String.format("Folder ID should be %d (Inbox). Getting %d instead", Mailbox.ID_FOLDER_INBOX, foldInt), foldInt.intValue(), Mailbox.ID_FOLDER_INBOX);
}
Also used : CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) WaitSetRequest(com.zimbra.soap.mail.message.WaitSetRequest) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) AdminWaitSetRequest(com.zimbra.soap.admin.message.AdminWaitSetRequest) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) WaitSetResponse(com.zimbra.soap.mail.message.WaitSetResponse) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) AdminWaitSetResponse(com.zimbra.soap.admin.message.AdminWaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) AccountWithModifications(com.zimbra.soap.type.AccountWithModifications) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) PendingFolderModifications(com.zimbra.soap.mail.type.PendingFolderModifications) Test(org.junit.Test)

Example 4 with CreateWaitSetResponse

use of com.zimbra.soap.mail.message.CreateWaitSetResponse in project zm-mailbox by Zimbra.

the class CreateWaitSet method handle.

/*
     <!--*************************************
          CreateWaitSet: must be called once to initialize the WaitSet
          and to set its "default interest types"
         ************************************* -->
        <CreateWaitSetRequest defTypes="DEFAULT_INTEREST_TYPES" [all="1"]>
          [ <add>
            [<a id="ACCTID" [token="lastKnownSyncToken"] [types="if_not_default"]/>]+
            </add> ]
        </CreateWaitSetRequest>

        <CreateWaitSetResponse waitSet="setId" defTypes="types" seq="0">
          [ <error ...something.../>]*
        </CreateWaitSetResponse>
     */
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    CreateWaitSetRequest req = zsc.elementToJaxb(request);
    CreateWaitSetResponse resp = new CreateWaitSetResponse();
    staticHandle(this, req, context, resp);
    return zsc.jaxbToElement(resp);
/* MUST use zsc variant NOT JaxbUtil */
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest)

Example 5 with CreateWaitSetResponse

use of com.zimbra.soap.mail.message.CreateWaitSetResponse in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method createWaitSet.

private CreateWaitSetResponse createWaitSet(String accountId, String authToken, Set<Integer> folderInterest) throws Exception {
    CreateWaitSetRequest req = new CreateWaitSetRequest("all", (Boolean) null);
    req.addAccount(createWaitSetAddSpec(accountId, folderInterest));
    return (CreateWaitSetResponse) sendReq(envelope(authToken, jaxbToString(req), "urn:zimbra"), TestUtil.getSoapUrl() + "CreateWaitSetRequest");
}
Also used : AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest)

Aggregations

CreateWaitSetRequest (com.zimbra.soap.mail.message.CreateWaitSetRequest)6 CreateWaitSetResponse (com.zimbra.soap.mail.message.CreateWaitSetResponse)6 ZMailbox (com.zimbra.client.ZMailbox)4 AdminCreateWaitSetRequest (com.zimbra.soap.admin.message.AdminCreateWaitSetRequest)4 AdminCreateWaitSetResponse (com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)4 WaitSetRequest (com.zimbra.soap.mail.message.WaitSetRequest)4 WaitSetResponse (com.zimbra.soap.mail.message.WaitSetResponse)4 Test (org.junit.Test)4 AdminDestroyWaitSetRequest (com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest)3 AdminDestroyWaitSetResponse (com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse)3 AdminWaitSetRequest (com.zimbra.soap.admin.message.AdminWaitSetRequest)3 AdminWaitSetResponse (com.zimbra.soap.admin.message.AdminWaitSetResponse)3 QueryWaitSetRequest (com.zimbra.soap.admin.message.QueryWaitSetRequest)3 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)3 ServiceException (com.zimbra.common.service.ServiceException)2 AccountWithModifications (com.zimbra.soap.type.AccountWithModifications)2 IOException (java.io.IOException)2 ZFolder (com.zimbra.client.ZFolder)1 Element (com.zimbra.common.soap.Element)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1