Search in sources :

Example 81 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestJaxb method testBrowseRequestAttachments.

@Test
public void testBrowseRequestAttachments() throws Exception {
    TestUtil.createAccount(USER_NAME);
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    MessageBuilder mb = new MessageBuilder();
    String raw = mb.withSubject(NAME_PREFIX).withBody(bodyWithObject).withContentType(MimeConstants.CT_APPLICATION_PDF).create();
    TestUtil.addRawMessage(zmbox, raw);
    forceIndexing(USER_NAME);
    BrowseRequest browseRequest = new BrowseRequest("attachments", /* browseBy */
    "", /* regex */
    10);
    BrowseResponse browseResponse = doBrowseRequest(browseRequest);
    Assert.assertNotNull("JAXB BrowseResponse object", browseResponse);
    List<BrowseData> datas = browseResponse.getBrowseDatas();
    Assert.assertNotNull("JAXB BrowseResponse datas", datas);
    Assert.assertTrue("JAXB BrowseResponse datas", datas.size() >= 1);
}
Also used : BrowseResponse(com.zimbra.soap.mail.message.BrowseResponse) ZMailbox(com.zimbra.client.ZMailbox) BrowseRequest(com.zimbra.soap.mail.message.BrowseRequest) BrowseData(com.zimbra.soap.mail.type.BrowseData) Test(org.junit.Test)

Example 82 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestJaxb method testGetFolderWithCacheContainingNullParent.

@Test
public void testGetFolderWithCacheContainingNullParent() throws Exception {
    TestUtil.createAccount(USER_NAME);
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder f1 = TestUtil.createFolder(zmbox, FOLDER_F1);
    ZFolder f2 = TestUtil.createFolder(zmbox, SUB_FOLDER_F2);
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    OperationContext octxt = new OperationContext(mbox);
    ItemId f1ItemId = new ItemId(mbox, Integer.parseInt(f1.getId()));
    ItemId f2ItemId = new ItemId(mbox, Integer.parseInt(f2.getId()));
    // ItemId rootItemId = new ItemId(mbox, Mailbox.ID_FOLDER_USER_ROOT);
    // mbox.getFolderTree(octxt, rootItemId, false);
    Folder f1folder = mbox.getFolderById(octxt, f1ItemId.getId());
    Folder f2folder = mbox.getFolderById(octxt, f2ItemId.getId());
    // Bug 100588 f1folder/f2folder will have been retrieved from the folder cache.  Deliberately poison it
    // by setting the parent folder to null, and ensure that can still successfully do a GetFolderRequest
    f1folder.setParent(null);
    f2folder.setParent(null);
    GetFolderResponse gfResp = zmbox.invokeJaxb(new GetFolderRequest());
    Assert.assertNotNull("GetFolderResponse null", gfResp);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) ZMailbox(com.zimbra.client.ZMailbox) GetFolderResponse(com.zimbra.soap.mail.message.GetFolderResponse) GetFolderRequest(com.zimbra.soap.mail.message.GetFolderRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) ZFolder(com.zimbra.client.ZFolder) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 83 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestJaxb method acceptAndTentativeSeriesDeclineInstanceAcceptInstance.

/**
 * Bug 94018.  Accepting series, then declining single instance leads to inconsistent display of attendee
 * status for organizer copy for the declined instance.
 *
 * Pseudo exceptions should be created for each reply to an individual instance of the series.
 *
 * At the end of this, check that exceptions have been created.  Check that the exceptions register
 * the correct statuses for the users.
 */
@Test
public void acceptAndTentativeSeriesDeclineInstanceAcceptInstance() throws Exception {
    TestUtil.createAccount(ORGANIZER);
    TestUtil.createAccount(ATTENDEE1);
    TestUtil.createAccount(ATTENDEE2);
    String subject = NAME_PREFIX + " every 2 days";
    ZMailbox organizerZMbox = TestUtil.getZMailbox(ORGANIZER);
    ZMailbox attendee1ZMbox = TestUtil.getZMailbox(ATTENDEE1);
    ZMailbox attendee2ZMbox = TestUtil.getZMailbox(ATTENDEE2);
    String londonTZ = "Europe/London";
    int year = Calendar.getInstance().get(Calendar.YEAR) + 1;
    // Create and send meeting that occurs every 2 days
    InviteComponent inviteComp = createInviteComponentSkeleton(subject, "room 101", organizerZMbox, attendee1ZMbox, attendee2ZMbox);
    GregorianCalendar start = startTime(londonTZ, year, 1, /* February */
    2, /* day */
    14, /* hour */
    0);
    GregorianCalendar end = plus(start, Calendar.MINUTE, 30);
    setStartAndEnd(inviteComp, londonTZ, start, end);
    inviteComp.setRecurrence(recurrence("DAI", 2, /* every 2 days */
    String.format("%d0529", year)));
    sendMeetingRequest(organizerZMbox, createMsgForAppointmentRequest(subject, inviteComp, attendee1ZMbox, attendee2ZMbox));
    // attendee 1 wait for original invite
    ZMessage seriesMsg = waitForInvite(attendee1ZMbox, subject);
    // attendee 1 accepts the original invite to the whole series
    sendInviteReplyAndWaitForIt(attendee1ZMbox, organizerZMbox, seriesMsg.getId(), subject, "ACCEPT", null);
    // attendee 1 declines one instance of the daily meeting - 2 + 4 --> 6th Feb
    GregorianCalendar exceptionTime = plus(start, Calendar.DAY_OF_MONTH, 4);
    sendInviteReplyAndWaitForIt(attendee1ZMbox, organizerZMbox, seriesMsg.getId(), subject, "DECLINE", DtTimeInfo.createForDatetimeAndZone(dateTime(exceptionTime), londonTZ));
    // attendee 2 wait for original invite
    seriesMsg = waitForInvite(attendee2ZMbox, subject);
    // attendee 2 tentatively accepts the original invite to the whole series
    sendInviteReplyAndWaitForIt(attendee2ZMbox, organizerZMbox, seriesMsg.getId(), subject, "TENTATIVE", null);
    // attendee 2 declines one instance of the daily meeting 2 + 8 --> 10th Feb
    GregorianCalendar exceptionTime2 = plus(start, Calendar.DAY_OF_MONTH, 8);
    sendInviteReplyAndWaitForIt(attendee2ZMbox, organizerZMbox, seriesMsg.getId(), subject + " " + ATTENDEE2, "DECLINE", DtTimeInfo.createForDatetimeAndZone(dateTime(exceptionTime2), londonTZ));
    // Search for a range of instances of the organizer's calendar entry
    SearchRequest sReq = new SearchRequest();
    sReq.setSearchTypes(ZSearchParams.TYPE_APPOINTMENT);
    /* 2nd Feb + 1 --> 3rd, 2nd Feb + 13 --> 15th.  So should match instances on:
         *     4th, 6th, 8th, 10th, 12th, 14th. */
    List<AppointmentHitInfo> apptHits = findMatchingExpandedAppointments(organizerZMbox, plus(start, Calendar.DAY_OF_MONTH, 1).getTime(), plus(start, Calendar.DAY_OF_MONTH, 13).getTime(), String.format("in:Calendar and subject:%s", subject), 1);
    AppointmentHitInfo orgApptHit = apptHits.get(0);
    Assert.assertNotNull("Organizer Calendar at end - series invite id", orgApptHit.getInvId());
    List<InstanceDataInfo> instances = orgApptHit.getInstances();
    Assert.assertNotNull("Organizer Calendar at end - instances in expansion", instances);
    Assert.assertEquals("Organizer Calendar at end - number of instances in expansion", 6, instances.size());
    // The 2nd entry in the list should be for an exception
    Map<ZMailbox, String> partstatMap = new HashMap<>(2);
    partstatMap.put(attendee1ZMbox, ZAppointmentHit.PSTATUS_DECLINED);
    /* for this instance */
    partstatMap.put(attendee2ZMbox, ZAppointmentHit.PSTATUS_TENTATIVE);
    /* for the series */
    validateException(organizerZMbox, instances.get(1), partstatMap, exceptionTime);
    // The 4th entry in the list should also be for an exception
    partstatMap.put(attendee1ZMbox, ZAppointmentHit.PSTATUS_ACCEPT);
    /* for the series */
    partstatMap.put(attendee2ZMbox, ZAppointmentHit.PSTATUS_DECLINED);
    /* for the instance */
    validateException(organizerZMbox, instances.get(3), partstatMap, exceptionTime2);
    // Do a GetMsg for the series in the Organizer's calendar
    MsgSpec gmsMsgSpec = new MsgSpec(orgApptHit.getInvId());
    GetMsgRequest gmsReq = new GetMsgRequest(gmsMsgSpec);
    GetMsgResponse gmsResp = organizerZMbox.invokeJaxb(gmsReq);
    List<InviteComponentWithGroupInfo> sInviteComps = gmsResp.getMsg().getInvite().getInviteComponents();
    Assert.assertEquals("number of components in series", 1, sInviteComps.size());
    List<CalendarAttendeeWithGroupInfo> sAttendees = sInviteComps.get(0).getAttendees();
    Assert.assertEquals("number of attendees in exception", 2, sAttendees.size());
    for (CalendarAttendeeWithGroupInfo sAttendee : sAttendees) {
        String addr = sAttendee.getAddress();
        String ptst = sAttendee.getPartStat();
        if (addr.equals(attendee1ZMbox.getName())) {
            Assert.assertEquals("exception attendee1 partstat", ZAppointmentHit.PSTATUS_ACCEPT, ptst);
        } else if (addr.equals(attendee2ZMbox.getName())) {
            Assert.assertEquals("exception attendee2 partstat", ZAppointmentHit.PSTATUS_TENTATIVE, ptst);
        } else {
            Assert.fail(String.format("Unexpected attendee in exception [%s]", addr));
        }
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) HashMap(java.util.HashMap) GetMsgRequest(com.zimbra.soap.mail.message.GetMsgRequest) GregorianCalendar(java.util.GregorianCalendar) MsgSpec(com.zimbra.soap.mail.type.MsgSpec) AppointmentHitInfo(com.zimbra.soap.mail.type.AppointmentHitInfo) InviteComponent(com.zimbra.soap.mail.type.InviteComponent) CalendarAttendeeWithGroupInfo(com.zimbra.soap.mail.type.CalendarAttendeeWithGroupInfo) ZMailbox(com.zimbra.client.ZMailbox) GetMsgResponse(com.zimbra.soap.mail.message.GetMsgResponse) InstanceDataInfo(com.zimbra.soap.mail.type.InstanceDataInfo) InviteComponentWithGroupInfo(com.zimbra.soap.mail.type.InviteComponentWithGroupInfo) Test(org.junit.Test)

Example 84 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestJaxb method doBadBrowseRequest.

public Element doBadBrowseRequest(BrowseRequest browseRequest) throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String authToken = mbox.getAuthToken().getValue();
    DocumentResult dr = new DocumentResult();
    marshaller.marshal(browseRequest, dr);
    Document doc = dr.getDocument();
    ZimbraLog.test.debug(doc.getRootElement().asXML());
    return sendReqExpectingFail(envelope(authToken, doc.getRootElement().asXML()), "BrowseRequest", 500);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) DocumentResult(org.dom4j.io.DocumentResult) Document(org.dom4j.Document)

Example 85 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestJaxb method validateException.

private void validateException(ZMailbox zmbox, InstanceDataInfo instance, Map<ZMailbox, String> partstats, GregorianCalendar recurIdTime) throws ServiceException {
    String exceptionInviteId = instance.getInvId();
    Assert.assertNotNull("exception invite id", exceptionInviteId);
    String exceptionRidZ = instance.getRecurIdZ();
    Assert.assertNotNull("exception invite RecurIdZ", exceptionRidZ);
    Assert.assertEquals("RecurIdZ", ParsedDateTime.fromUTCTime(recurIdTime.getTimeInMillis()).getDateTimePartString(false), exceptionRidZ);
    // Do a GetMsg for the exception in the Organizer's calendar
    MsgSpec gmeMsgSpec = new MsgSpec(exceptionInviteId);
    gmeMsgSpec.setRecurIdZ(exceptionRidZ);
    GetMsgRequest gmeReq = new GetMsgRequest(gmeMsgSpec);
    GetMsgResponse gmeResp = zmbox.invokeJaxb(gmeReq);
    List<InviteComponentWithGroupInfo> eInviteComps = gmeResp.getMsg().getInvite().getInviteComponents();
    Assert.assertEquals("number of components in exception", 1, eInviteComps.size());
    List<CalendarAttendeeWithGroupInfo> eAttendees = eInviteComps.get(0).getAttendees();
    Assert.assertEquals("number of attendees in exception", 2, eAttendees.size());
    for (CalendarAttendeeWithGroupInfo eAttendee : eAttendees) {
        String addr = eAttendee.getAddress();
        String ptst = eAttendee.getPartStat();
        boolean found = false;
        for (Entry<ZMailbox, String> entry : partstats.entrySet()) {
            if (addr.equals(entry.getKey().getName())) {
                Assert.assertEquals(String.format("Exception partstat for %s", entry.getKey()), entry.getValue(), ptst);
                found = true;
            }
        }
        Assert.assertTrue(String.format("Unexpected attendee in exception [%s]", addr), found);
    }
}
Also used : CalendarAttendeeWithGroupInfo(com.zimbra.soap.mail.type.CalendarAttendeeWithGroupInfo) ZMailbox(com.zimbra.client.ZMailbox) GetMsgRequest(com.zimbra.soap.mail.message.GetMsgRequest) GetMsgResponse(com.zimbra.soap.mail.message.GetMsgResponse) MsgSpec(com.zimbra.soap.mail.type.MsgSpec) InviteComponentWithGroupInfo(com.zimbra.soap.mail.type.InviteComponentWithGroupInfo)

Aggregations

ZMailbox (com.zimbra.client.ZMailbox)383 Test (org.junit.Test)288 ZFolder (com.zimbra.client.ZFolder)90 ZMessage (com.zimbra.client.ZMessage)82 Mailbox (com.zimbra.cs.mailbox.Mailbox)61 Account (com.zimbra.cs.account.Account)60 ServiceException (com.zimbra.common.service.ServiceException)55 ArrayList (java.util.ArrayList)38 IOException (java.io.IOException)35 MessageData (com.zimbra.cs.mailclient.imap.MessageData)28 ZMountpoint (com.zimbra.client.ZMountpoint)26 Message (com.zimbra.cs.mailbox.Message)24 HashMap (java.util.HashMap)23 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)21 ZTag (com.zimbra.client.ZTag)21 SoapFaultException (com.zimbra.common.soap.SoapFaultException)21 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)21 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)20 HttpClient (org.apache.http.client.HttpClient)19 ZSearchParams (com.zimbra.client.ZSearchParams)18