Search in sources :

Example 66 with DataSource

use of com.zimbra.cs.account.DataSource 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 67 with DataSource

use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.

the class TestDataSource method testPollingInterval.

@Test
public void testPollingInterval() throws Exception {
    // Create data source
    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, "testhost");
    attrs.put(Provisioning.A_zimbraDataSourcePort, "0");
    attrs.put(Provisioning.A_zimbraDataSourceUsername, "testuser");
    attrs.put(Provisioning.A_zimbraDataSourcePassword, "testpass");
    attrs.put(Provisioning.A_zimbraDataSourceFolderId, "1");
    attrs.put(Provisioning.A_zimbraDataSourceConnectionType, ConnectionType.cleartext.toString());
    DataSource ds = prov.createDataSource(account, DataSourceType.pop3, NAME_PREFIX + " testPollingInterval", attrs);
    // Valid polling interval
    assertNotNull("Min not defined", account.getAttr(Provisioning.A_zimbraDataSourceMinPollingInterval));
    long min = account.getTimeInterval(Provisioning.A_zimbraDataSourceMinPollingInterval, 0) / 1000;
    attrs.clear();
    attrs.put(Provisioning.A_zimbraDataSourcePollingInterval, Long.toString(min));
    prov.modifyDataSource(account, ds.getId(), attrs);
    // Invalid polling interval
    attrs.clear();
    attrs.put(Provisioning.A_zimbraDataSourcePollingInterval, Long.toString(min - 1));
    try {
        prov.modifyDataSource(account, ds.getId(), attrs);
        fail("modifyDataSource() was not supposed to succeed");
    } catch (ServiceException e) {
        assertTrue("Unexpected message: " + e.getMessage(), e.getMessage().contains("shorter than the allowed minimum"));
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) 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 68 with DataSource

use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.

the class ProvTestUtil method createDataSource.

public DataSource createDataSource(Account acct, String dataSourceName) throws Exception {
    DataSource dataSource = prov.get(acct, Key.DataSourceBy.name, dataSourceName);
    assertNull(dataSource);
    dataSource = createDataSourceRaw(acct, dataSourceName);
    assertNotNull(dataSource);
    dataSource = prov.get(acct, Key.DataSourceBy.name, dataSourceName);
    assertNotNull(dataSource);
    assertEquals(dataSourceName, dataSource.getName());
    return dataSource;
}
Also used : DataSource(com.zimbra.cs.account.DataSource)

Aggregations

DataSource (com.zimbra.cs.account.DataSource)68 Account (com.zimbra.cs.account.Account)29 HashMap (java.util.HashMap)19 Provisioning (com.zimbra.cs.account.Provisioning)18 DbDataSource (com.zimbra.cs.db.DbDataSource)17 ServiceException (com.zimbra.common.service.ServiceException)15 Element (com.zimbra.common.soap.Element)14 Mailbox (com.zimbra.cs.mailbox.Mailbox)11 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)11 ArrayList (java.util.ArrayList)11 ZDataSource (com.zimbra.client.ZDataSource)8 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 Folder (com.zimbra.cs.mailbox.Folder)7 DataSourceType (com.zimbra.soap.admin.type.DataSourceType)7 HashSet (java.util.HashSet)7 DataSourceItem (com.zimbra.cs.db.DbDataSource.DataSourceItem)6 ZMailbox (com.zimbra.client.ZMailbox)5 LdapDataSource (com.zimbra.cs.account.ldap.entry.LdapDataSource)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5 Test (org.junit.Test)5