Search in sources :

Example 1 with SoapTransport

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));
}
Also used : ImapFolder(com.zimbra.cs.imap.ImapFolder) 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) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 2 with SoapTransport

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;
}
Also used : WaitSetSessionInfo(com.zimbra.soap.admin.type.WaitSetSessionInfo) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) SessionForWaitSet(com.zimbra.soap.admin.type.SessionForWaitSet) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) ZMountpoint(com.zimbra.client.ZMountpoint)

Example 3 with SoapTransport

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);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) DistributionListRightSpec(com.zimbra.soap.account.type.DistributionListRightSpec) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test)

Example 4 with SoapTransport

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());
}
Also used : GetDistributionListResponse(com.zimbra.soap.account.message.GetDistributionListResponse) Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListGranteeInfoInterface(com.zimbra.soap.base.DistributionListGranteeInfoInterface) DistributionListInfo(com.zimbra.soap.account.type.DistributionListInfo) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 5 with SoapTransport

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);
        }
    }
}
Also used : CalendarAttendeeWithGroupInfo(com.zimbra.soap.mail.type.CalendarAttendeeWithGroupInfo) MsgWithGroupInfo(com.zimbra.soap.mail.type.MsgWithGroupInfo) GetMsgRequest(com.zimbra.soap.mail.message.GetMsgRequest) GetMsgResponse(com.zimbra.soap.mail.message.GetMsgResponse) InviteWithGroupInfo(com.zimbra.soap.mail.type.InviteWithGroupInfo) MsgSpec(com.zimbra.soap.mail.type.MsgSpec) SoapTransport(com.zimbra.common.soap.SoapTransport) InviteComponentWithGroupInfo(com.zimbra.soap.mail.type.InviteComponentWithGroupInfo) Test(org.junit.Test)

Aggregations

SoapTransport (com.zimbra.common.soap.SoapTransport)89 Test (org.junit.Test)69 Account (com.zimbra.cs.account.Account)38 Element (com.zimbra.common.soap.Element)24 Group (com.zimbra.cs.account.Group)23 ServiceException (com.zimbra.common.service.ServiceException)18 SoapFaultException (com.zimbra.common.soap.SoapFaultException)16 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 AccountServiceException (com.zimbra.cs.account.AccountServiceException)11 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 SoapTest (com.zimbra.qa.unittest.prov.soap.SoapTest)10 ArrayList (java.util.ArrayList)10 SoapProtocol (com.zimbra.common.soap.SoapProtocol)9 Bug (com.zimbra.qa.QA.Bug)9 CreateSignatureRequest (com.zimbra.soap.account.message.CreateSignatureRequest)9 Signature (com.zimbra.soap.account.type.Signature)9 Domain (com.zimbra.cs.account.Domain)8 GetDistributionListRequest (com.zimbra.soap.account.message.GetDistributionListRequest)8 GetDistributionListResponse (com.zimbra.soap.account.message.GetDistributionListResponse)6