Search in sources :

Example 6 with CreateWaitSetResponse

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

the class TestWaitSetRequest method testBlockingWaitSetRequest.

@Test
public void testBlockingWaitSetRequest() throws Exception {
    ZimbraLog.test.info("Starting testBlockingWaitSetRequest");
    String user1Name = "testBlockingWaitSetRequest_user1";
    acc1 = TestUtil.createAccount(user1Name);
    ZMailbox mbox = TestUtil.getZMailbox(user1Name);
    String authToken = mbox.getAuthToken().getValue();
    String accId = mbox.getAccountId();
    CreateWaitSetResponse resp = createWaitSet(accId, authToken);
    assertNotNull(resp);
    waitSetId = resp.getWaitSetId();
    int seq = resp.getSequence();
    assertNotNull(waitSetId);
    WaitSetRequest waitSetReq = new WaitSetRequest(waitSetId, Integer.toString(seq));
    waitSetReq.setBlock(true);
    final CountDownLatch doneSignal = new CountDownLatch(1);
    mbox.getTransport().invokeAsync(JaxbUtil.jaxbToElement(waitSetReq), new FutureCallback<HttpResponse>() {

        @Override
        public void completed(final HttpResponse response) {
            cbCalled.set(true);
            int respCode = response.getStatusLine().getStatusCode();
            success.set((respCode == 200));
            if (!success.get()) {
                failureMessage = "Response code " + respCode;
            }
            if (success.get()) {
                Element envelope;
                try {
                    envelope = W3cDomUtil.parseXML(response.getEntity().getContent());
                    SoapProtocol proto = SoapProtocol.determineProtocol(envelope);
                    Element doc = proto.getBodyElement(envelope);
                    ZimbraLog.test.info(new String(doc.toUTF8(), "UTF-8"));
                    WaitSetResponse wsResp = (WaitSetResponse) JaxbUtil.elementToJaxb(doc);
                    success.set((Integer.parseInt(wsResp.getSeqNo()) > 0));
                    if (!success.get()) {
                        failureMessage = "wrong squence number. Sequence #" + wsResp.getSeqNo();
                    }
                    if (success.get()) {
                        success.set((wsResp.getSignalledAccounts().size() == 1));
                        if (!success.get()) {
                            failureMessage = "wrong number of signaled accounts " + wsResp.getSignalledAccounts().size();
                        }
                    }
                    if (success.get()) {
                        success.set(wsResp.getSignalledAccounts().get(0).getId().equalsIgnoreCase(accId));
                        if (!success.get()) {
                            failureMessage = "signaled wrong account " + wsResp.getSignalledAccounts().get(0).getId();
                        }
                    }
                } catch (UnsupportedOperationException | IOException | ServiceException e) {
                    fail(e.getMessage());
                }
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                }
            }
            doneSignal.countDown();
        }

        @Override
        public void failed(final Exception ex) {
            ZimbraLog.test.error("request :: failed ", ex);
            success.set(false);
            failureMessage = ex.getMessage();
            doneSignal.countDown();
        }

        @Override
        public void cancelled() {
            ZimbraLog.test.info("request :: cancelled");
            success.set(false);
            failureMessage = "request :: cancelled";
            doneSignal.countDown();
        }
    });
    String subject = NAME_PREFIX + " test wait set request 1";
    TestUtil.addMessage(mbox, subject);
    try {
        doneSignal.await(5, TimeUnit.SECONDS);
    } catch (Exception e) {
        fail("Wait interrupted. ");
    }
    assertTrue("callback was not triggered.", cbCalled.get());
    assertTrue(failureMessage, success.get());
}
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) Element(com.zimbra.common.soap.Element) SoapProtocol(com.zimbra.common.soap.SoapProtocol) HttpResponse(org.apache.http.HttpResponse) CountDownLatch(java.util.concurrent.CountDownLatch) JAXBException(javax.xml.bind.JAXBException) AdminServiceException(com.zimbra.cs.service.admin.AdminServiceException) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) SoapParseException(com.zimbra.common.soap.SoapParseException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZMailbox(com.zimbra.client.ZMailbox) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) Test(org.junit.Test)

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