Search in sources :

Example 36 with ZMailbox

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

the class TestFolders method testCreateManyFolders.

@Ignore
@Test
public void testCreateManyFolders() throws Exception {
    // normally skip this test since it takes a long time to complete. just keep it around for quick perf checks
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String parentPath = "/parent";
    ZFolder parent = TestUtil.createFolder(mbox, parentPath);
    int max = 10000;
    int pad = ((int) Math.log10(max)) + 1;
    long totalTime = 0;
    double avgTime;
    long maxTime = 0;
    for (int i = 0; i < max; i++) {
        long start = System.currentTimeMillis();
        TestUtil.createFolder(mbox, parent.getId(), "child" + Strings.padStart(i + "", pad, '0'));
        long end = System.currentTimeMillis();
        long elapsed = (end - start);
        totalTime += elapsed;
        if (elapsed > maxTime) {
            maxTime = elapsed;
            ZimbraLog.mailbox.info("FOLDER TIME new max time %dms at index %d", maxTime, i);
        }
        if (i > 0 && (i % 100 == 0 || i == max - 1)) {
            avgTime = (totalTime * 1.0) / (i * 1.0);
            ZimbraLog.mailbox.info("FOLDER TIME average after %d = %dms", i, Math.round(avgTime));
        }
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with ZMailbox

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

the class TestCalDav method testCalendarQueryOnInbox.

@Test
public void testCalendarQueryOnInbox() throws Exception {
    String url = getSchedulingInboxUrl(dav1, dav1);
    Document doc = calendarQuery(url, dav1);
    org.w3c.dom.Element rootElem = doc.getDocumentElement();
    assertFalse("response when there are no items should have no child elements", rootElem.hasChildNodes());
    // Send an invite from user1 and check tags.
    ZMailbox organizer = TestUtil.getZMailbox(USER_NAME);
    String subject = TEST_NAME + " testInvite request 1";
    Date startDate = new Date(System.currentTimeMillis() + Constants.MILLIS_PER_DAY);
    Date endDate = new Date(startDate.getTime() + Constants.MILLIS_PER_HOUR);
    TestUtil.createAppointment(organizer, subject, dav1.getName(), startDate, endDate);
    waitForNewSchedulingRequestByUID(dav1, "");
    doc = calendarQuery(url, dav1);
    rootElem = doc.getDocumentElement();
    assertTrue("response should have child elements", rootElem.hasChildNodes());
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Document(org.w3c.dom.Document) Date(java.util.Date) Test(org.junit.Test)

Example 38 with ZMailbox

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

the class TestCalDav method testAppleCaldavProxyFunctions.

/**
 * http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-proxy.txt
 * This is an Apple standard implemented by Apple Mac OSX at least up to Yosemite and offers a fairly simple
 * sharing model for calendars.  The model is simpler than Zimbra's native model and there are mismatches,
 * for instance Zimbra requires the proposed delegate to accept shares.
 */
@Test
public void testAppleCaldavProxyFunctions() throws ServiceException, IOException {
    Account sharer = dav3;
    Account sharee1 = dav1;
    Account sharee2 = dav2;
    ZMailbox mboxSharer = TestUtil.getZMailbox(sharer.getName());
    ZMailbox mboxSharee1 = TestUtil.getZMailbox(sharee1.getName());
    ZMailbox mboxSharee2 = TestUtil.getZMailbox(sharee2.getName());
    setZimbraPrefAppleIcalDelegationEnabled(mboxSharer, true);
    setZimbraPrefAppleIcalDelegationEnabled(mboxSharee1, true);
    setZimbraPrefAppleIcalDelegationEnabled(mboxSharee2, true);
    // Test PROPPATCH to "calendar-proxy-read" URL
    setGroupMemberSet(TestCalDav.getCalendarProxyReadUrl(sharer), sharer, sharee2);
    // Test PROPPATCH to "calendar-proxy-write" URL
    setGroupMemberSet(TestCalDav.getCalendarProxyWriteUrl(sharer), sharer, sharee1);
    // verify that adding new members to groups triggered notification messages
    List<ZMessage> msgs = TestUtil.waitForMessages(mboxSharee1, "in:inbox subject:\"Share Created: Calendar shared by \"", 1, 10000);
    assertNotNull(String.format("Notification msgs for %s", sharee1.getName()), msgs);
    assertEquals(String.format("num msgs for %s", sharee1.getName()), 1, msgs.size());
    msgs = TestUtil.waitForMessages(mboxSharee2, "in:inbox subject:\"Share Created: Calendar shared by \"", 1, 10000);
    assertNotNull(String.format("Notification msgs for %s", sharee2.getName()), msgs);
    assertEquals(String.format("num msgs for %s", sharee2.getName()), 1, msgs.size());
    // Simulate acceptance of the shares (would normally need to be done in ZWC
    createCalendarMountPoint(mboxSharee1, sharer);
    createCalendarMountPoint(mboxSharee2, sharer);
    Document doc = delegateForExpandProperty(sharee1);
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(TestCalDav.NamespaceContextForXPath.forCalDAV());
    XPathExpression xPathExpr;
    try {
        String xpathS = "/D:multistatus/D:response/D:href/text()";
        xPathExpr = xpath.compile(xpathS);
        NodeList result = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
        assertEquals(String.format("num XPath nodes for %s for %s", xpathS, sharee1.getName()), 1, result.getLength());
        String text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
        assertEquals("HREF for account owner", UrlNamespace.getPrincipalUrl(sharee1).replaceAll("@", "%40"), text);
        xpathS = "/D:multistatus/D:response/D:propstat/D:prop/CS:calendar-proxy-write-for/D:response/D:href/text()";
        xPathExpr = xpath.compile(xpathS);
        result = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
        assertEquals(String.format("num XPath nodes for %s for %s", xpathS, sharee1.getName()), 1, result.getLength());
        text = (String) xPathExpr.evaluate(doc, XPathConstants.STRING);
        assertEquals("HREF for sharer", UrlNamespace.getPrincipalUrl(sharer).replaceAll("@", "%40"), text);
    } catch (XPathExpressionException e1) {
        ZimbraLog.test.debug("xpath problem", e1);
    }
    // Check that proxy write has sharee1 in it
    doc = groupMemberSetExpandProperty(sharer, sharee1, true);
    // Check that proxy read has sharee2 in it
    doc = groupMemberSetExpandProperty(sharer, sharee2, false);
    String davBaseName = "notAllowed@There";
    String url = String.format("%s%s", getFolderUrl(sharee1, "Shared Calendar"), davBaseName);
    HttpMethodExecutor exe;
    if (DebugConfig.enableDAVclientCanChooseResourceBaseName) {
        exe = doIcalPut(url, sharee1, simpleEvent(sharer), HttpStatus.SC_CREATED);
        // rest of test deals with how redirecting to new name works - not needed here
        return;
    } else {
        exe = doIcalPut(url, sharee1, simpleEvent(sharer), HttpStatus.SC_MOVED_TEMPORARILY);
    }
    String location = exe.getNonNullHeaderValue("Location", "When creating in shared calendar");
    url = String.format("%s%s", getFolderUrl(sharee1, "Shared Calendar"), location.substring(location.lastIndexOf('/') + 1));
    doIcalPut(url, sharee1, simpleEvent(sharer), HttpStatus.SC_CREATED);
}
Also used : ZMessage(com.zimbra.client.ZMessage) XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 39 with ZMailbox

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

the class TestDocument method testContentType.

/**
 * Tests the content-type based on file extension.
 */
@Test
public void testContentType() throws Exception {
    TestUtil.createAccount(USER_NAME);
    // Create two documents.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String folderId = Integer.toString(Mailbox.ID_FOLDER_BRIEFCASE);
    ZDocument doc1 = TestUtil.createDocument(mbox, folderId, NAME_PREFIX + "-docOne.doc", "application/octet-stream", "doc1".getBytes());
    ZDocument doc2 = TestUtil.createDocument(mbox, folderId, NAME_PREFIX + "-docTwo.xls", "application/ms-tnef", "doc2".getBytes());
    // Confirm that the content-type changed based on file extension
    Assert.assertEquals("application/msword", doc1.getContentType());
    Assert.assertEquals("application/vnd.ms-excel", doc2.getContentType());
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZDocument(com.zimbra.client.ZDocument) Test(org.junit.Test)

Example 40 with ZMailbox

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

the class TestConversion method downloadAttachmentsFromTNEFmsg.

/**
 * Tests downloading attachments from a TNEF message (bug 44263).
 */
@Test
public void downloadAttachmentsFromTNEFmsg() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String msgName = "/unittest/tnef.msg";
    File tnefMsg = new File(LC.zimbra_home.value() + msgName);
    Assert.assertTrue(String.format("To run this test copy data%1$s to /opt/zimbra%1$s", msgName), tnefMsg.exists() && tnefMsg.canRead());
    // Add the TNEF message
    String msgContent = new String(ByteUtil.getContent(tnefMsg));
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, msgContent);
    // Test downloading attachments.
    ZMessage msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + NAME_PREFIX + " Rich text (TNEF) test\"");
    byte[] data = TestUtil.getContent(mbox, msg.getId(), "upload.gif");
    Assert.assertEquals(73, data.length);
    data = TestUtil.getContent(mbox, msg.getId(), "upload2.gif");
    Assert.assertEquals(851, data.length);
    ZMimePart part = TestUtil.getPart(msg, "upload.gif");
    checkPartSize(73, part.getSize());
    part = TestUtil.getPart(msg, "upload2.gif");
    checkPartSize(851, part.getSize());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZMimePart(com.zimbra.client.ZMessage.ZMimePart) File(java.io.File) Test(org.junit.Test)

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