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));
}
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"));
}
}
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;
}
Aggregations