use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestImapServerListener method testDestroyWaitset.
@Test
public void testDestroyWaitset() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
TestUtil.addMessage(mboxStore, "TestImapServerListener - testDestroyWaitset - init message", Integer.toString(Mailbox.ID_FOLDER_INBOX));
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);
remoteListener.addListener(session);
// wait for waitset session to be created
String waitSetId = remoteListener.getWSId();
TestUtil.waitForSessions(1, 1, 6000, waitSetId, remoteServer);
// delete waitset
ZimbraLog.test.debug("Destroying waitset %s", waitSetId);
AdminDestroyWaitSetRequest destroyReq = new AdminDestroyWaitSetRequest(waitSetId);
SoapTransport transport = TestUtil.getAdminSoapTransport(remoteServer);
AdminDestroyWaitSetResponse destroyResp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(destroyReq)));
Assert.assertNotNull("AdminDestroyWaitSetResponse should not be null", destroyResp);
Assert.assertNotNull("AdminDestroyWaitSetResponse::waitSetId should not be null", destroyResp.getWaitSetId());
Assert.assertEquals("AdminDestroyWaitSetResponse has wrong waitSetId", waitSetId, destroyResp.getWaitSetId());
// wait for ImapServerListener to create a new WaitSet
int maxWait = 5000;
while (maxWait > 0) {
if (remoteListener.getWSId() != null && !waitSetId.equalsIgnoreCase(remoteListener.getWSId())) {
break;
} else {
maxWait -= 500;
Thread.sleep(500);
}
}
Assert.assertFalse("ImapServerListener should have created a new waitset", waitSetId.equalsIgnoreCase(remoteListener.getWSId()));
// send a message
session.doneSignal = new CountDownLatch(1);
String subject = "TestImapServerListener - testDestroyWaitset - trigger message";
TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), TestUtil.getAddress("TestImapServerListener-testDestroyWaitset"));
TestUtil.waitForMessages(mboxStore, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertTrue("Expected session to NOT be triggered", session.wasTriggered());
assertFalse("ImapServerListener should have created a new waitset", remoteListener.getWSId().equalsIgnoreCase(waitSetId));
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestUtil method waitForSessions.
public static QueryWaitSetResponse waitForSessions(int numExpectedSessions, int numExpectedFolderInterests, int timeout_millis, String wsID, Server server) throws Exception {
QueryWaitSetResponse resp = null;
while (timeout_millis > 0) {
QueryWaitSetRequest req = new QueryWaitSetRequest(wsID);
SoapTransport transport = getAdminSoapTransport(server);
resp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(req)));
List<WaitSetInfo> wsInfoList = resp.getWaitsets();
assertFalse("Expecting to find a waitset", wsInfoList.isEmpty());
assertEquals("Expecting to find only one waitset", 1, wsInfoList.size());
WaitSetInfo wsInfo = wsInfoList.get(0);
assertEquals("Found wrong waitset", wsID, wsInfo.getWaitSetId());
List<SessionForWaitSet> sessions = wsInfo.getSessions();
if (sessions != null && numExpectedSessions > 0) {
if (sessions.size() == numExpectedSessions) {
int foundFolderInterests = 0;
for (SessionForWaitSet s : sessions) {
WaitSetSessionInfo sessionInfo = s.getWaitSetSession();
if (sessionInfo != null) {
foundFolderInterests += s.getWaitSetSession().getFolderInterestsAsSet().size();
}
}
if (foundFolderInterests == numExpectedFolderInterests) {
return resp;
}
}
} else if ((sessions == null || sessions.isEmpty()) && numExpectedSessions == 0) {
return resp;
}
try {
if (timeout_millis > 500) {
Thread.sleep(500);
timeout_millis = timeout_millis - 500;
} else {
Thread.sleep(timeout_millis);
timeout_millis = 0;
}
} catch (InterruptedException e) {
ZimbraLog.test.debug("sleep got interrupted", e);
}
}
return resp;
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionManipulateOwnerRight.
/*
* verify owner right can never be altered directly, all modification on
* owners must go through addOwners/remvoeOwners/setOwners operations
*/
@Test
public void distributionListActionManipulateOwnerRight() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
Group group = createGroupAndAddOwner(GROUP_NAME);
String right = Group.GroupOwner.GROUP_OWNER_RIGHT.getName();
Account grantee = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
SoapTransport transport = authUser(USER_OWNER);
//
// grantRights
//
DistributionListAction action = new DistributionListAction(Operation.grantRights);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
DistributionListRightSpec dlRight = new DistributionListRightSpec(right);
dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
action.addRight(dlRight);
DistributionListActionResponse resp;
boolean caughtException = false;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
//
// revokeRights
//
action = new DistributionListAction(Operation.revokeRights);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
dlRight = new DistributionListRightSpec(right);
dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
action.addRight(dlRight);
caughtException = false;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
//
// setRights
//
action = new DistributionListAction(Operation.setRights);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
dlRight = new DistributionListRightSpec(right);
dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
action.addRight(dlRight);
caughtException = false;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionSetOwners.
@Test
public void distributionListActionSetOwners() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
Group group = createGroupAndAddOwner(GROUP_NAME);
Account owner1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
Account owner2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
Account owner3 = provUtil.createAccount(genAcctNameLocalPart("3"), domain);
SoapTransport transport = authUser(USER_OWNER);
//
// setOwners
//
DistributionListAction action = new DistributionListAction(Operation.setOwners);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, USER_OWNER));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, owner3.getName()));
DistributionListActionResponse resp = invokeJaxb(transport, req);
//
// verify owners are replaced
//
GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
DistributionListInfo dlInfo = getDLResp.getDl();
List<? extends DistributionListGranteeInfoInterface> owners = dlInfo.getOwners();
Set<String> ownerNames = Sets.newHashSet();
for (DistributionListGranteeInfoInterface owner : owners) {
if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
ownerNames.add(owner.getName());
}
}
assertEquals(4, owners.size());
Verify.verifyEquals(Sets.newHashSet(USER_OWNER, owner1.getName(), owner2.getName(), owner3.getName()), ownerNames);
/*
* test invalid grantee type for owner
*/
action = new DistributionListAction(Operation.setOwners);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, "user@external.com"));
String errCode = null;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
errCode = e.getCode();
}
assertEquals(ServiceException.INVALID_REQUEST, errCode);
// remove all owners
action = new DistributionListAction(Operation.setOwners);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
resp = invokeJaxb(transport, req);
getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
getDLResp = invokeJaxb(transport, getDLReq);
dlInfo = getDLResp.getDl();
owners = dlInfo.getOwners();
assertEquals(0, owners.size());
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestExpandGroupInfo method getMsg.
@Test
public void getMsg() throws Exception {
String SUBJECT = getTestName();
String msgId = createAppt(acct, group.getName(), SUBJECT, "blah");
SoapTransport transport = authUser(acct.getName());
MsgSpec msgSpec = new MsgSpec(msgId);
msgSpec.setNeedCanExpand(Boolean.TRUE);
GetMsgRequest req = new GetMsgRequest(msgSpec);
GetMsgResponse resp = invokeJaxb(transport, req);
MsgWithGroupInfo msg = resp.getMsg();
InviteWithGroupInfo invite = msg.getInvite();
List<InviteComponentWithGroupInfo> invComps = invite.getInviteComponents();
for (InviteComponentWithGroupInfo invComp : invComps) {
List<CalendarAttendeeWithGroupInfo> attendees = invComp.getAttendees();
for (CalendarAttendeeWithGroupInfo attendee : attendees) {
Boolean isGroup = attendee.getGroup();
Boolean canExpandGroupMembers = attendee.getCanExpandGroupMembers();
assertTrue(isGroup);
assertTrue(canExpandGroupMembers);
}
}
}
Aggregations