Search in sources :

Example 81 with ZFolder

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

the class TestDataSource method testMigratePollingInterval.

@Test
public void testMigratePollingInterval() throws Exception {
    Cos cos = account.getCOS();
    // Create data source
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder folder = TestUtil.createFolder(mbox, NAME_PREFIX + " testMigratePollingInterval");
    Provisioning prov = Provisioning.getInstance();
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_FALSE);
    attrs.put(Provisioning.A_zimbraDataSourceHost, "localhost");
    int port = Integer.parseInt(TestUtil.getServerAttr(Provisioning.A_zimbraPop3BindPort));
    attrs.put(Provisioning.A_zimbraDataSourcePort, Integer.toString(port));
    attrs.put(Provisioning.A_zimbraDataSourceUsername, "user2");
    attrs.put(Provisioning.A_zimbraDataSourcePassword, "test123");
    attrs.put(Provisioning.A_zimbraDataSourceFolderId, folder.getId());
    attrs.put(Provisioning.A_zimbraDataSourceConnectionType, ConnectionType.cleartext.toString());
    String dsName = NAME_PREFIX + " testMigratePollingInterval";
    DataSource ds = prov.createDataSource(account, DataSourceType.pop3, dsName, attrs);
    // Set old polling intervals and unset new ones.
    account.unsetDataSourcePop3PollingInterval();
    account.unsetDataSourceImapPollingInterval();
    cos.unsetDataSourcePop3PollingInterval();
    cos.unsetDataSourceImapPollingInterval();
    account.setDataSourcePollingInterval("1h");
    cos.setDataSourcePollingInterval("2h");
    // Trigger the migration.
    ds.getPollingInterval();
    // Refresh and verify migrated values.
    account = TestUtil.getAccount(USER_NAME);
    cos = account.getCOS();
    ds = account.getDataSourceByName(dsName);
    assertEquals("1h", account.getAttr(Provisioning.A_zimbraDataSourcePop3PollingInterval));
    assertEquals("1h", account.getAttr(Provisioning.A_zimbraDataSourceImapPollingInterval));
    assertEquals("2h", cos.getAttr(Provisioning.A_zimbraDataSourcePop3PollingInterval));
    assertEquals("2h", cos.getAttr(Provisioning.A_zimbraDataSourceImapPollingInterval));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) Cos(com.zimbra.cs.account.Cos) ZFolder(com.zimbra.client.ZFolder) Provisioning(com.zimbra.cs.account.Provisioning) ZDataSource(com.zimbra.client.ZDataSource) ZCalDataSource(com.zimbra.client.ZCalDataSource) ZRssDataSource(com.zimbra.client.ZRssDataSource) DataSource(com.zimbra.cs.account.DataSource) MailPop3DataSource(com.zimbra.soap.mail.type.MailPop3DataSource) Test(org.junit.Test)

Example 82 with ZFolder

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

the class TestDataSource method disabledTestCal.

// XXX bburtin: disabled test due to bug 37222 (unable to parse Google calendar).
public void disabledTestCal() throws Exception {
    // Create folder.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String parentId = Integer.toString(Mailbox.ID_FOLDER_USER_ROOT);
    String urlString = "http://www.google.com/calendar/ical/k2kh7ncij3s05dog63g0o0n254%40group.calendar.google.com/public/basic.ics";
    ZFolder folder;
    try {
        folder = mbox.createFolder(parentId, NAME_PREFIX + " testCal", ZFolder.View.appointment, null, null, urlString);
    } catch (ServiceException e) {
        assertEquals(ServiceException.RESOURCE_UNREACHABLE, e.getCode());
        ZimbraLog.test.warn("Unable to test calendar data source for %s: %s", urlString, e.toString());
        return;
    }
    // Get the data source that was implicitly created.
    ZCalDataSource ds = (ZCalDataSource) getDataSource(mbox, folder.getId());
    assertNotNull(ds);
    // Test data source.  If the test fails, skip validation so we don't
    // get false positives when the feed is down or the test
    // is running on a box that's not connected to the internet.
    String error = mbox.testDataSource(ds);
    if (error != null) {
        ZimbraLog.test.warn("Unable to test iCal data source for %s: %s.", urlString, error);
        return;
    }
    // Import data and confirm that the folder is not empty.
    List<ZDataSource> list = new ArrayList<ZDataSource>();
    list.add(ds);
    mbox.importData(list);
    waitForData(mbox, folder);
    // Delete folder, import data, and make sure that the data source was deleted.
    mbox.deleteFolder(folder.getId());
    mbox.importData(list);
    ds = (ZCalDataSource) getDataSource(mbox, folder.getId());
    assertNull(ds);
}
Also used : ZCalDataSource(com.zimbra.client.ZCalDataSource) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) ArrayList(java.util.ArrayList) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource)

Example 83 with ZFolder

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

the class TestDataSource method testRss.

/**
     * Creates a folder that syncs to another folder via RSS, and verifies that an
     * RSS data source was implicitly created.
     */
@Test
public void testRss() throws Exception {
    // Create source folder, make it publicly readable, and add a message to it.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String parentId = Integer.toString(Mailbox.ID_FOLDER_USER_ROOT);
    ZFolder sourceFolder = TestUtil.createFolder(mbox, "/" + NAME_PREFIX + " testRss source");
    mbox.modifyFolderGrant(sourceFolder.getId(), GranteeType.pub, null, "r", null);
    String subject = NAME_PREFIX + " testRss";
    TestUtil.addMessage(mbox, subject, sourceFolder.getId());
    // Create destination folder that syncs to the source folder via RSS.
    String urlString = String.format("https://%s:%s/home/%s%s.rss", TestUtil.getServerAttr(Provisioning.A_zimbraServiceHostname), TestUtil.getServerAttr(Provisioning.A_zimbraMailSSLPort), USER_NAME, sourceFolder.getPath());
    urlString = HttpUtil.encodePath(urlString);
    ZFolder rssFolder = mbox.createFolder(parentId, NAME_PREFIX + " testRss destination", null, null, null, urlString);
    // Get the data source that was implicitly created.
    ZRssDataSource ds = (ZRssDataSource) getDataSource(mbox, rssFolder.getId());
    assertNotNull(ds);
    assertNull(mbox.testDataSource(ds));
    // Import data and validate the synced message.
    List<ZDataSource> list = new ArrayList<ZDataSource>();
    list.add(ds);
    mbox.importData(list);
    waitForData(mbox, rssFolder);
    ZMessage syncedMsg = TestUtil.getMessage(mbox, "in:\"" + rssFolder.getPath() + "\"");
    assertEquals(subject, syncedMsg.getSubject());
    /*
         *   Bug 102261 - simulate ZWC deleting an item from the folder
         */
    ConvActionSelector sel = ConvActionSelector.createForIdsAndOperation(syncedMsg.getConversationId(), "trash");
    sel.setConstraint("-dtjs");
    sel.setFolder(syncedMsg.getFolderId());
    try {
        mbox.invokeJaxb(new ConvActionRequest(sel));
    } catch (SoapFaultException sfe) {
        fail("SoapFaultException caught when deleting item from RSS datasource folder - " + sfe.getMessage());
    }
    // Delete folder, import data, and make sure that the data source was deleted.
    // Data source import runs asynchronously, so poll until the data source is gone.
    mbox.deleteFolder(rssFolder.getId());
//JBF - do not do the import; it will fail if DS is already deleted
//mbox.importData(list);
// XXX bburtin: disabled check to avoid false positives (bug 54816).  Some sort
// of race condition is causing this check to fail intermittently.  I was unable
// to consistently repro.
/*
        for (int i = 1; i <= 10; i++) {
            ds = (ZRssDataSource) getDataSource(mbox, rssFolder.getId());
            if (ds == null) {
                break;
            }
            Thread.sleep(500);
        }
        assertNull(ds);
        */
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ConvActionSelector(com.zimbra.soap.mail.type.ConvActionSelector) ConvActionRequest(com.zimbra.soap.mail.message.ConvActionRequest) ArrayList(java.util.ArrayList) ZRssDataSource(com.zimbra.client.ZRssDataSource) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 84 with ZFolder

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

the class TestUtil method deleteTestData.

/**
     * Delete all messages, tags and folders in the user's mailbox whose subjects contain the given substring. For
     * messages, the subject must contain subjectString as a separate word. Tags and folders can have the string
     * anywhere in the name.
     */
public static void deleteTestData(String userName, String subjectSubstring) throws ServiceException {
    ZMailbox mbox = getZMailbox(userName);
    deleteMessages(mbox, "is:anywhere " + subjectSubstring);
    // Workaround for bug 15160 (is:anywhere is busted)
    deleteMessages(mbox, "in:trash " + subjectSubstring);
    deleteMessages(mbox, "in:junk " + subjectSubstring);
    deleteMessages(mbox, "in:sent " + subjectSubstring);
    // Workaround for bug 31370
    deleteMessages(mbox, "subject: " + subjectSubstring);
    // Delete tags
    for (ZTag tag : mbox.getAllTags()) {
        if (tag.getName().contains(subjectSubstring)) {
            mbox.deleteTag(tag.getId());
        }
    }
    // Delete folders
    for (ZFolder folder : mbox.getAllFolders()) {
        if (folder.getName().contains(subjectSubstring)) {
            mbox.deleteFolder(folder.getId());
        }
    }
    // Delete contacts
    for (ZContact contact : mbox.getAllContacts(null, ContactSortBy.nameAsc, false, null)) {
        String fullName = contact.getAttrs().get("fullName");
        if (fullName != null && fullName.contains(subjectSubstring)) {
            mbox.deleteContact(contact.getId());
        }
    }
    // Delete data sources
    List<ZDataSource> dataSources = mbox.getAllDataSources();
    for (ZDataSource ds : dataSources) {
        if (ds.getName().contains(subjectSubstring)) {
            mbox.deleteDataSource(ds);
        }
    }
    // Delete appointments
    List<String> ids = search(mbox, subjectSubstring, ZSearchParams.TYPE_APPOINTMENT);
    if (!ids.isEmpty()) {
        mbox.deleteItem(StringUtil.join(",", ids), null);
    }
    // Delete documents
    ids = search(mbox, subjectSubstring, ZSearchParams.TYPE_DOCUMENT);
    if (!ids.isEmpty()) {
        mbox.deleteItem(StringUtil.join(",", ids), null);
    }
    ZMailbox adminMbox = getZMailboxAsAdmin(userName);
    adminMbox.emptyDumpster();
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZTag(com.zimbra.client.ZTag) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource) ZContact(com.zimbra.client.ZContact)

Aggregations

ZFolder (com.zimbra.client.ZFolder)84 ZMailbox (com.zimbra.client.ZMailbox)54 Folder (com.zimbra.cs.mailbox.Folder)21 Test (org.junit.Test)21 ServiceException (com.zimbra.common.service.ServiceException)19 Account (com.zimbra.cs.account.Account)19 Mailbox (com.zimbra.cs.mailbox.Mailbox)17 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)17 SearchFolder (com.zimbra.cs.mailbox.SearchFolder)13 ItemId (com.zimbra.cs.service.util.ItemId)13 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)12 ZMessage (com.zimbra.client.ZMessage)10 ZMountpoint (com.zimbra.client.ZMountpoint)9 AccountServiceException (com.zimbra.cs.account.AccountServiceException)9 ZAuthToken (com.zimbra.common.auth.ZAuthToken)7 ArrayList (java.util.ArrayList)7 ZDataSource (com.zimbra.client.ZDataSource)6 ZSearchFolder (com.zimbra.client.ZSearchFolder)6 Provisioning (com.zimbra.cs.account.Provisioning)6 AuthToken (com.zimbra.cs.account.AuthToken)5