Search in sources :

Example 1 with ZDataSource

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));
}
Also used : ZImapDataSource(com.zimbra.client.ZImapDataSource) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource)

Example 2 with ZDataSource

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;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) ZDataSource(com.zimbra.client.ZDataSource)

Example 3 with ZDataSource

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;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) ZDataSource(com.zimbra.client.ZDataSource)

Example 4 with ZDataSource

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();
    }
}
Also used : ZImportStatus(com.zimbra.client.ZMailbox.ZImportStatus) ArrayList(java.util.ArrayList) ZDataSource(com.zimbra.client.ZDataSource)

Example 5 with ZDataSource

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);
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) Provisioning(com.zimbra.cs.account.Provisioning) ZDataSource(com.zimbra.client.ZDataSource) 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)

Aggregations

ZDataSource (com.zimbra.client.ZDataSource)10 ZMailbox (com.zimbra.client.ZMailbox)6 ZFolder (com.zimbra.client.ZFolder)5 ZImapDataSource (com.zimbra.client.ZImapDataSource)3 ArrayList (java.util.ArrayList)3 ZCalDataSource (com.zimbra.client.ZCalDataSource)2 ZPop3DataSource (com.zimbra.client.ZPop3DataSource)2 ZRssDataSource (com.zimbra.client.ZRssDataSource)2 Test (org.junit.Test)2 ZContact (com.zimbra.client.ZContact)1 ZImportStatus (com.zimbra.client.ZMailbox.ZImportStatus)1 ZMessage (com.zimbra.client.ZMessage)1 ZTag (com.zimbra.client.ZTag)1 ServiceException (com.zimbra.common.service.ServiceException)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 Account (com.zimbra.cs.account.Account)1 DataSource (com.zimbra.cs.account.DataSource)1 Provisioning (com.zimbra.cs.account.Provisioning)1 ConvActionRequest (com.zimbra.soap.mail.message.ConvActionRequest)1 ConvActionSelector (com.zimbra.soap.mail.type.ConvActionSelector)1