use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestImapOneWayImport method setUp.
@Override
public void setUp() throws Exception {
cleanUp();
mDisplayMailFoldersOnly = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
Provisioning.getInstance().getLocalServer().setImapDisplayMailFoldersOnly(false);
// Get mailbox references
if (!TestUtil.accountExists(LOCAL_USER_NAME)) {
TestUtil.createAccount(LOCAL_USER_NAME);
}
if (!TestUtil.accountExists(REMOTE_USER_NAME)) {
TestUtil.createAccount(REMOTE_USER_NAME);
}
mRemoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
mLocalMbox = TestUtil.getZMailbox(LOCAL_USER_NAME);
// Get or create folder
ZFolder folder = mLocalMbox.getFolderByPath(DS_FOLDER_ROOT);
if (folder == null) {
folder = TestUtil.createFolder(mLocalMbox, NAME_PREFIX);
}
// Create data source
int port = Integer.parseInt(TestUtil.getServerAttr(Provisioning.A_zimbraImapBindPort));
mDataSource = new ZImapDataSource(NAME_PREFIX, true, "localhost", port, REMOTE_USER_NAME, TestUtil.DEFAULT_PASSWORD, folder.getId(), ConnectionType.cleartext, true);
String id = mLocalMbox.createDataSource(mDataSource);
mDataSource = null;
for (ZDataSource ds : mLocalMbox.getAllDataSources()) {
if (ds.getId().equals(id)) {
mDataSource = ds;
}
}
assertNotNull(mDataSource);
// Turn on cleartext login
mOriginalCleartextValue = TestUtil.getServerAttr(Provisioning.A_zimbraImapCleartextLoginEnabled);
TestUtil.setServerAttr(Provisioning.A_zimbraImapCleartextLoginEnabled, ProvisioningConstants.TRUE);
// Turn off STARTTLS support so that unit tests don't bomb on Linux
// (see bug 33683).
mOriginalEnableStarttls = LC.javamail_imap_enable_starttls.booleanValue();
LC.javamail_imap_enable_starttls.setDefault(Boolean.toString(false));
}
use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestPop3ImportServer method getZDataSource.
private ZPop3DataSource getZDataSource() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
List<ZDataSource> dataSources = mbox.getAllDataSources();
for (ZDataSource ds : dataSources) {
if (ds.getName().equals(DATA_SOURCE_NAME)) {
return (ZPop3DataSource) ds;
}
}
fail("Could not find data source " + DATA_SOURCE_NAME);
return null;
}
use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestPop3Import method getZDataSource.
private ZPop3DataSource getZDataSource() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
List<ZDataSource> dataSources = mbox.getAllDataSources();
for (ZDataSource ds : dataSources) {
if (ds.getName().equals(DATA_SOURCE_NAME)) {
return (ZPop3DataSource) ds;
}
}
Assert.fail("Could not find data source " + DATA_SOURCE_NAME);
return null;
}
use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestUtil method importDataSource.
/**
* Imports data from the given data source and updates state on both the local and remote mailboxes.
*/
public static void importDataSource(ZDataSource dataSource, ZMailbox localMbox, ZMailbox remoteMbox, boolean expectedSuccess) throws Exception {
List<ZDataSource> dataSources = new ArrayList<ZDataSource>();
dataSources.add(dataSource);
localMbox.importData(dataSources);
String type = dataSource.getType().toString();
// Wait for import to complete
ZImportStatus status;
while (true) {
Thread.sleep(500);
status = null;
for (ZImportStatus iter : localMbox.getImportStatus()) {
if (iter.getId().equals(dataSource.getId())) {
status = iter;
}
}
assertNotNull("No import status returned for data source " + dataSource.getName(), status);
assertEquals("Unexpected data source type", type, status.getType());
if (!status.isRunning()) {
break;
}
}
assertEquals("importDataSource status success value", expectedSuccess, status.getSuccess());
if (!expectedSuccess) {
assertNotNull("importDataSource status error value", status.getError());
}
// Get any state changes from the server
localMbox.noOp();
if (remoteMbox != null) {
remoteMbox.noOp();
}
}
use of com.zimbra.client.ZDataSource in project zm-mailbox by Zimbra.
the class TestDataSource method testErrorStatus.
/**
* Tests the <tt>lastError</tt> element and <tt>failingSince</tt> attribute
* for <tt>GetInfoRequest</tt> and <tt>GetDataSourcesRequest</tt>.
*/
@Test
public void testErrorStatus() throws Exception {
// Create data source.
Account testAccount = TestUtil.getAccount(TEST_USER_NAME);
Provisioning prov = Provisioning.getInstance();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
attrs.put(Provisioning.A_zimbraDataSourceHost, "localhost");
attrs.put(Provisioning.A_zimbraDataSourcePort, TestUtil.getServerAttr(Provisioning.A_zimbraPop3BindPort));
attrs.put(Provisioning.A_zimbraDataSourceUsername, USER_NAME_2);
attrs.put(Provisioning.A_zimbraDataSourcePassword, TestUtil.DEFAULT_PASSWORD);
attrs.put(Provisioning.A_zimbraDataSourceFolderId, Integer.toString(Mailbox.ID_FOLDER_INBOX));
attrs.put(Provisioning.A_zimbraDataSourceConnectionType, ConnectionType.cleartext.toString());
attrs.put(Provisioning.A_zimbraDataSourceLeaveOnServer, LdapConstants.LDAP_TRUE);
DataSource ds = prov.createDataSource(testAccount, DataSourceType.pop3, DS_NAME, attrs);
// Make sure error status is not set.
ZMailbox mbox = TestUtil.getZMailbox(TEST_USER_NAME);
confirmErrorStatus(mbox, null);
// Invoke data source sync and make sure error status is not set.
ZDataSource zds = TestUtil.getDataSource(mbox, DS_NAME);
TestUtil.importDataSource(zds, mbox, null, true);
confirmErrorStatus(mbox, null);
// Change to an invalid password, make sure error status is set.
attrs.clear();
attrs.put(Provisioning.A_zimbraDataSourcePassword, "bogus");
prov.modifyDataSource(testAccount, ds.getId(), attrs);
Thread.sleep(500);
zds = TestUtil.getDataSource(mbox, DS_NAME);
// timestamp is returned in seconds, not millis
long startTimestamp = System.currentTimeMillis() / 1000;
TestUtil.importDataSource(zds, mbox, null, false);
confirmErrorStatus(mbox, startTimestamp);
// Fix password, make sure that error status is reset (bug 39050).
attrs.put(Provisioning.A_zimbraDataSourcePassword, TestUtil.DEFAULT_PASSWORD);
prov.modifyDataSource(testAccount, ds.getId(), attrs);
Thread.sleep(500);
confirmErrorStatus(mbox, null);
// Do another sync, make sure error password is not set.
zds = TestUtil.getDataSource(mbox, DS_NAME);
startTimestamp = System.currentTimeMillis();
TestUtil.importDataSource(zds, mbox, null, true);
confirmErrorStatus(mbox, null);
}
Aggregations