Search in sources :

Example 1 with GetDataSourcesResponse

use of com.zimbra.soap.mail.message.GetDataSourcesResponse in project zm-mailbox by Zimbra.

the class DataSourceJaxbTest method testGetDataSourcesResponse.

@Test
public void testGetDataSourcesResponse() throws Exception {
    // response with one Unknown datasource
    JAXBContext jaxb = JAXBContext.newInstance(GetDataSourcesResponse.class);
    Unmarshaller unmarshaller = jaxb.createUnmarshaller();
    GetDataSourcesResponse resp = (GetDataSourcesResponse) unmarshaller.unmarshal(getClass().getResourceAsStream("GetUnknownDataSourcesResponse.xml"));
    List<DataSource> dsList = resp.getDataSources();
    assertNotNull("datasources should not be NULL", dsList);
    assertFalse("list of datasources should not be empty", dsList.isEmpty());
    assertEquals("expecting one datasource in the list", 1, dsList.size());
    DataSource ds = dsList.get(0);
    assertNotNull("Generic DataSource should not be NULL", ds);
    assertNotNull("Generic DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for generic DataSource", "8d17e182-fdc6-4f6c-b83f-d478c9b04bfd", ds.getId());
    assertTrue("DataSource should be an instance of MailDataSource", ds instanceof MailDataSource);
    assertEquals("wrong refresh token", "AAbbcdd22wkBVsVdNHR.l0_jzuWvPNiAt0DBOcRm7w9zLorEM", ds.getRefreshToken());
    assertEquals("wrong host", "yahoo.com", ds.getHost());
    assertEquals("wrong import class", "com.synacor.zimbra.OAuthDataImport", ds.getImportClass());
    assertEquals("wrong datasource name", "blablah@yahoo.com", ds.getName());
    // response with one IMAP datasource
    resp = (GetDataSourcesResponse) unmarshaller.unmarshal(getClass().getResourceAsStream("GetImapDataSourcesResponse.xml"));
    dsList = resp.getDataSources();
    assertNotNull("datasources should not be NULL", dsList);
    assertFalse("list of datasources should not be empty", dsList.isEmpty());
    assertEquals("expecting 1 datasource in the list", 1, dsList.size());
    ds = dsList.get(0);
    assertNotNull("IMAP DataSource should not be NULL", ds);
    assertNotNull("IMAP DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for IMAP DataSource", "d96e9a7d-6af9-4625-ba68-37bcd73fce6d", ds.getId());
    assertTrue("DataSource should be an instance of MailImapDataSource", ds instanceof MailImapDataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "imap.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "myIMAPSource", ds.getName());
    // response with an Unknown and an IMAP datasources
    resp = (GetDataSourcesResponse) unmarshaller.unmarshal(getClass().getResourceAsStream("GetTwoDataSourcesResponse.xml"));
    dsList = resp.getDataSources();
    assertNotNull("datasources should not be NULL", dsList);
    assertFalse("list of datasources should not be empty", dsList.isEmpty());
    assertEquals("expecting 2 datasources in the list", 2, dsList.size());
    ds = dsList.get(0);
    assertNotNull("Generic DataSource should not be NULL", ds);
    assertNotNull("Generic DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for generic DataSource", "8d17e182-fdc6-4f6c-b83f-d478c9b04bfd", ds.getId());
    assertTrue("DataSource should be an instance of MailDataSource", ds instanceof MailDataSource);
    assertEquals("wrong refresh token", "AAbbcdd22wkBVsVdNHR.l0_jzuWvPNiAt0DBOcRm7w9zLorEM", ds.getRefreshToken());
    assertEquals("wrong host", "yahoo.com", ds.getHost());
    assertEquals("wrong import class", "com.synacor.zimbra.OAuthDataImport", ds.getImportClass());
    assertEquals("wrong datasource name", "blablah@yahoo.com", ds.getName());
    ds = dsList.get(1);
    assertNotNull("IMAP DataSource should not be NULL", ds);
    assertNotNull("IMAP DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for IMAP DataSource", "d96e9a7d-6af9-4625-ba68-37bcd73fce6d", ds.getId());
    assertTrue("DataSource should be an instance of MailImapDataSource", ds instanceof MailImapDataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "imap.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "myIMAPSource", ds.getName());
    // Response with one element of each type of datasource
    resp = (GetDataSourcesResponse) unmarshaller.unmarshal(getClass().getResourceAsStream("GetOneEachDataSourcesResponse.xml"));
    dsList = resp.getDataSources();
    assertNotNull("datasources should not be NULL", dsList);
    assertFalse("list of datasources should not be empty", dsList.isEmpty());
    assertEquals("expecting 7 datasources in the list", 7, dsList.size());
    ds = dsList.get(0);
    assertNotNull("Generic DataSource should not be NULL", ds);
    assertNotNull("Generic DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for generic DataSource", "8d17e182-fdc6-4f6c-b83f-d478c9b04bfd", ds.getId());
    assertTrue("DataSource should be an instance of MailDataSource", ds instanceof MailDataSource);
    assertEquals("wrong refresh token", "AAbbcdd22wkBVsVdNHR.l0_jzuWvPNiAt0DBOcRm7w9zLorEM", ds.getRefreshToken());
    assertEquals("wrong host", "yahoo.com", ds.getHost());
    assertEquals("wrong import class", "com.synacor.zimbra.OAuthDataImport", ds.getImportClass());
    assertEquals("wrong datasource name", "blablah@yahoo.com", ds.getName());
    ds = dsList.get(1);
    assertNotNull("IMAP DataSource should not be NULL", ds);
    assertNotNull("IMAP DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for IMAP DataSource", "d96e9a7d-6af9-4625-ba68-37bcd73fce6d", ds.getId());
    assertTrue("DataSource should be an instance of MailImapDataSource", ds instanceof MailImapDataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "imap.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "myIMAPSource", ds.getName());
    ds = dsList.get(2);
    assertNotNull("POP3 DataSource should not be NULL", ds);
    assertNotNull("POP3 DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for POP3 DataSource", "b5e98a1f-5f93-4e19-a1a4-956c4c95af1b", ds.getId());
    assertTrue("DataSource should be an instance of MailPop3DataSource", ds instanceof MailPop3DataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "pop.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "myPop3Mail", ds.getName());
    assertTrue("wrong leaveOnServer", ((MailPop3DataSource) ds).isLeaveOnServer());
    ds = dsList.get(3);
    assertNotNull("RSS DataSource should not be NULL", ds);
    assertNotNull("RSS DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for RSS DataSource", "89bca37f-9096-419d-9471-62149a58cbdc", ds.getId());
    assertTrue("DataSource should be an instance of MailRssDataSource", ds instanceof MailRssDataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "rss.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "myRssFeed", ds.getName());
    assertEquals("wrong polling interval", "43200000", ds.getPollingInterval());
    assertEquals("wrong FolderId", "260", ds.getFolderId());
    ds = dsList.get(4);
    assertNotNull("Cal DataSource should not be NULL", ds);
    assertNotNull("Cal DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for Cal DataSource", "112da07b-43e3-41ab-a0b3-5c109169ee49", ds.getId());
    assertTrue("DataSource should be an instance of MailCalDataSource", ds instanceof MailCalDataSource);
    assertEquals("wrong host", "calendar.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "GCal", ds.getName());
    assertEquals("wrong polling interval", "63100000", ds.getPollingInterval());
    ds = dsList.get(5);
    assertNotNull("GAL DataSource should not be NULL", ds);
    assertNotNull("GAL DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for GAL DataSource", "ed408f4d-f8d5-4597-bf49-563ed62b64de", ds.getId());
    assertTrue("DataSource should be an instance of MailCalDataSource", ds instanceof MailGalDataSource);
    assertEquals("wrong host", "ldap.somehost.local", ds.getHost());
    assertEquals("wrong datasource name", "corpAddressBook", ds.getName());
    ds = dsList.get(6);
    assertNotNull("Caldav DataSource should not be NULL", ds);
    assertNotNull("Caldav DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for Caldav DataSource", "95c066a8-5ad6-40fa-a094-06f8b3531878", ds.getId());
    assertTrue("DataSource should be an instance of MailCaldavDataSource", ds instanceof MailCaldavDataSource);
    assertEquals("wrong host", "dav.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "externalDAV", ds.getName());
    // Response with multiple instances of some types of data sources
    resp = (GetDataSourcesResponse) unmarshaller.unmarshal(getClass().getResourceAsStream("GetManyDataSourcesResponse.xml"));
    dsList = resp.getDataSources();
    assertNotNull("datasources should not be NULL", dsList);
    assertFalse("list of datasources should not be empty", dsList.isEmpty());
    assertEquals("expecting 10 datasources in the list", 10, dsList.size());
    ds = dsList.get(0);
    assertNotNull("Generic DataSource should not be NULL", ds);
    assertNotNull("Generic DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for generic DataSource", "8d17e182-fdc6-4f6c-b83f-d478c9b04bfd", ds.getId());
    assertTrue("DataSource should be an instance of MailDataSource", ds instanceof MailDataSource);
    assertEquals("wrong refresh token", "AAbbcdd22wkBVsVdNHR.l0_jzuWvPNiAt0DBOcRm7w9zLorEM", ds.getRefreshToken());
    assertEquals("wrong host", "yahoo.com", ds.getHost());
    assertEquals("wrong import class", "com.synacor.zimbra.OAuthDataImport", ds.getImportClass());
    assertEquals("wrong datasource name", "blablah@yahoo.com", ds.getName());
    ds = dsList.get(1);
    assertNotNull("IMAP DataSource should not be NULL", ds);
    assertNotNull("IMAP DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for IMAP DataSource", "d96e9a7d-6af9-4625-ba68-37bcd73fce6d", ds.getId());
    assertTrue("DataSource should be an instance of MailImapDataSource", ds instanceof MailImapDataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "imap.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "myIMAPSource", ds.getName());
    assertEquals("wrong port", 143, ds.getPort().intValue());
    ds = dsList.get(2);
    assertNotNull("POP3 DataSource should not be NULL", ds);
    assertNotNull("POP3 DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for POP3 DataSource", "b5e98a1f-5f93-4e19-a1a4-956c4c95af1b", ds.getId());
    assertTrue("DataSource should be an instance of MailPop3DataSource", ds instanceof MailPop3DataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "pop.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "myPop3Mail", ds.getName());
    assertTrue("wrong leaveOnServer", ((MailPop3DataSource) ds).isLeaveOnServer());
    ds = dsList.get(3);
    assertNotNull("RSS DataSource should not be NULL", ds);
    assertNotNull("RSS DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for RSS DataSource", "89bca37f-9096-419d-9471-62149a58cbdc", ds.getId());
    assertTrue("DataSource should be an instance of MailRssDataSource", ds instanceof MailRssDataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "rss.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "myRssFeed", ds.getName());
    assertEquals("wrong polling interval", "43200000", ds.getPollingInterval());
    assertEquals("wrong FolderId", "260", ds.getFolderId());
    ds = dsList.get(4);
    assertNotNull("Cal DataSource should not be NULL", ds);
    assertNotNull("Cal DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for Cal DataSource", "112da07b-43e3-41ab-a0b3-5c109169ee49", ds.getId());
    assertTrue("DataSource should be an instance of MailCalDataSource", ds instanceof MailCalDataSource);
    assertEquals("wrong host", "calendar.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "GCal", ds.getName());
    assertEquals("wrong polling interval", "63100000", ds.getPollingInterval());
    ds = dsList.get(5);
    assertNotNull("GAL DataSource should not be NULL", ds);
    assertNotNull("GAL DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for GAL DataSource", "ed408f4d-f8d5-4597-bf49-563ed62b64de", ds.getId());
    assertTrue("DataSource should be an instance of MailCalDataSource", ds instanceof MailGalDataSource);
    assertEquals("wrong host", "ldap.somehost.local", ds.getHost());
    assertEquals("wrong datasource name", "corpAddressBook", ds.getName());
    ds = dsList.get(6);
    assertNotNull("Caldav DataSource should not be NULL", ds);
    assertNotNull("Caldav DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for Caldav DataSource", "95c066a8-5ad6-40fa-a094-06f8b3531878", ds.getId());
    assertTrue("DataSource should be an instance of MailCaldavDataSource", ds instanceof MailCaldavDataSource);
    assertEquals("wrong host", "dav.zimbra.com", ds.getHost());
    assertEquals("wrong datasource name", "externalDAV", ds.getName());
    ds = dsList.get(7);
    assertNotNull("2d RSS DataSource should not be NULL", ds);
    assertNotNull("2d RSS DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for the 2d RSS DataSource", "f32349af-9a78-4c26-80a1-338203378930", ds.getId());
    assertTrue("DataSource should be an instance of MailRssDataSource", ds instanceof MailRssDataSource);
    assertEquals("wrong connectionType", ConnectionType.cleartext, ds.getConnectionType());
    assertEquals("wrong host", "news.yahoo.com", ds.getHost());
    assertEquals("wrong datasource name", "myYahoo", ds.getName());
    assertEquals("wrong polling interval", "43200000", ds.getPollingInterval());
    assertEquals("wrong FolderId", "261", ds.getFolderId());
    ds = dsList.get(8);
    assertNotNull("2d IMAP DataSource should not be NULL", ds);
    assertNotNull("2d IMAP DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for the 2d IMAP DataSource", "b2e929f5-e124-47a0-b1b4-a7fbcd14fb31", ds.getId());
    assertTrue("DataSource should be an instance of MailImapDataSource", ds instanceof MailImapDataSource);
    assertEquals("wrong connectionType", ConnectionType.tls_if_available, ds.getConnectionType());
    assertEquals("wrong host", "imap3.zimbra.com", ds.getHost());
    assertEquals("wrong port", 193, ds.getPort().intValue());
    assertEquals("wrong datasource name", "forgottenMail", ds.getName());
    ds = dsList.get(9);
    assertNotNull("2d Generic DataSource should not be NULL", ds);
    assertNotNull("2d Generic DataSource ID should not be NULL", ds.getId());
    assertEquals("Wrong ID for the 2d generic DataSource", "82e3b467-5a0f-4cff-ad8d-533ed6fc4992", ds.getId());
    assertTrue("DataSource should be an instance of MailDataSource", ds instanceof MailDataSource);
    assertNull("Refresh token should be NULL", ds.getRefreshToken());
    assertEquals("wrong host", "abook.gmail.com", ds.getHost());
    assertEquals("wrong import class", "com.synacor.zimbra.OAuthDataImport", ds.getImportClass());
    assertEquals("wrong datasource name", "someone@gmail.com", ds.getName());
}
Also used : MailCalDataSource(com.zimbra.soap.mail.type.MailCalDataSource) MailDataSource(com.zimbra.soap.mail.type.MailDataSource) MailCaldavDataSource(com.zimbra.soap.mail.type.MailCaldavDataSource) MailRssDataSource(com.zimbra.soap.mail.type.MailRssDataSource) MailGalDataSource(com.zimbra.soap.mail.type.MailGalDataSource) GetDataSourcesResponse(com.zimbra.soap.mail.message.GetDataSourcesResponse) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) MailImapDataSource(com.zimbra.soap.mail.type.MailImapDataSource) MailPop3DataSource(com.zimbra.soap.mail.type.MailPop3DataSource) MailCalDataSource(com.zimbra.soap.mail.type.MailCalDataSource) MailDataSource(com.zimbra.soap.mail.type.MailDataSource) MailGalDataSource(com.zimbra.soap.mail.type.MailGalDataSource) MailImapDataSource(com.zimbra.soap.mail.type.MailImapDataSource) MailCaldavDataSource(com.zimbra.soap.mail.type.MailCaldavDataSource) MailPop3DataSource(com.zimbra.soap.mail.type.MailPop3DataSource) MailRssDataSource(com.zimbra.soap.mail.type.MailRssDataSource) DataSource(com.zimbra.soap.type.DataSource) Test(org.junit.Test)

Example 2 with GetDataSourcesResponse

use of com.zimbra.soap.mail.message.GetDataSourcesResponse in project zm-mailbox by Zimbra.

the class ZMailbox method getAllDataSources.

public List<ZDataSource> getAllDataSources() throws ServiceException {
    GetDataSourcesResponse res = invokeJaxb(new GetDataSourcesRequest());
    List<ZDataSource> result = new ArrayList<ZDataSource>();
    for (DataSource ds : res.getDataSources()) {
        if (ds instanceof Pop3DataSource) {
            result.add(new ZPop3DataSource((Pop3DataSource) ds));
        } else if (ds instanceof ImapDataSource) {
            result.add(new ZImapDataSource((ImapDataSource) ds));
        } else if (ds instanceof CalDataSource) {
            result.add(new ZCalDataSource((CalDataSource) ds));
        } else if (ds instanceof RssDataSource) {
            result.add(new ZRssDataSource((RssDataSource) ds));
        } else {
            result.add(new ZDataSource(ds));
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ImapDataSource(com.zimbra.soap.type.ImapDataSource) GetDataSourcesResponse(com.zimbra.soap.mail.message.GetDataSourcesResponse) CalDataSource(com.zimbra.soap.type.CalDataSource) RssDataSource(com.zimbra.soap.type.RssDataSource) TestDataSource(com.zimbra.soap.mail.type.TestDataSource) DataSource(com.zimbra.soap.type.DataSource) Pop3DataSource(com.zimbra.soap.type.Pop3DataSource) ImapDataSource(com.zimbra.soap.type.ImapDataSource) CalDataSource(com.zimbra.soap.type.CalDataSource) Pop3DataSource(com.zimbra.soap.type.Pop3DataSource) RssDataSource(com.zimbra.soap.type.RssDataSource) GetDataSourcesRequest(com.zimbra.soap.mail.message.GetDataSourcesRequest)

Aggregations

GetDataSourcesResponse (com.zimbra.soap.mail.message.GetDataSourcesResponse)2 DataSource (com.zimbra.soap.type.DataSource)2 GetDataSourcesRequest (com.zimbra.soap.mail.message.GetDataSourcesRequest)1 MailCalDataSource (com.zimbra.soap.mail.type.MailCalDataSource)1 MailCaldavDataSource (com.zimbra.soap.mail.type.MailCaldavDataSource)1 MailDataSource (com.zimbra.soap.mail.type.MailDataSource)1 MailGalDataSource (com.zimbra.soap.mail.type.MailGalDataSource)1 MailImapDataSource (com.zimbra.soap.mail.type.MailImapDataSource)1 MailPop3DataSource (com.zimbra.soap.mail.type.MailPop3DataSource)1 MailRssDataSource (com.zimbra.soap.mail.type.MailRssDataSource)1 TestDataSource (com.zimbra.soap.mail.type.TestDataSource)1 CalDataSource (com.zimbra.soap.type.CalDataSource)1 ImapDataSource (com.zimbra.soap.type.ImapDataSource)1 Pop3DataSource (com.zimbra.soap.type.Pop3DataSource)1 RssDataSource (com.zimbra.soap.type.RssDataSource)1 ArrayList (java.util.ArrayList)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Test (org.junit.Test)1