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());
}
Aggregations