Search in sources :

Example 1 with ZRssDataSource

use of com.zimbra.client.ZRssDataSource in project zm-mailbox by Zimbra.

the class TestDataSource method testRss.

/**
 * Creates a folder that syncs to another folder via RSS, and verifies that an
 * RSS data source was implicitly created.
 */
@Test
public void testRss() throws Exception {
    // Create source folder, make it publicly readable, and add a message to it.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String parentId = Integer.toString(Mailbox.ID_FOLDER_USER_ROOT);
    ZFolder sourceFolder = TestUtil.createFolder(mbox, "/" + NAME_PREFIX + " testRss source");
    mbox.modifyFolderGrant(sourceFolder.getId(), GranteeType.pub, null, "r", null);
    String subject = NAME_PREFIX + " testRss";
    TestUtil.addMessage(mbox, subject, sourceFolder.getId());
    // Create destination folder that syncs to the source folder via RSS.
    String urlString = String.format("https://%s:%s/home/%s%s.rss", TestUtil.getServerAttr(Provisioning.A_zimbraServiceHostname), TestUtil.getServerAttr(Provisioning.A_zimbraMailSSLPort), USER_NAME, sourceFolder.getPath());
    urlString = HttpUtil.encodePath(urlString);
    ZFolder rssFolder = mbox.createFolder(parentId, NAME_PREFIX + " testRss destination", null, null, null, urlString);
    // Get the data source that was implicitly created.
    ZRssDataSource ds = (ZRssDataSource) getDataSource(mbox, rssFolder.getId());
    assertNotNull(ds);
    assertNull(mbox.testDataSource(ds));
    // Import data and validate the synced message.
    List<ZDataSource> list = new ArrayList<ZDataSource>();
    list.add(ds);
    mbox.importData(list);
    waitForData(mbox, rssFolder);
    ZMessage syncedMsg = TestUtil.getMessage(mbox, "in:\"" + rssFolder.getPath() + "\"");
    assertEquals(subject, syncedMsg.getSubject());
    /*
         *   Bug 102261 - simulate ZWC deleting an item from the folder
         */
    ConvActionSelector sel = ConvActionSelector.createForIdsAndOperation(syncedMsg.getConversationId(), "trash");
    sel.setConstraint("-dtjs");
    sel.setFolder(syncedMsg.getFolderId());
    try {
        mbox.invokeJaxb(new ConvActionRequest(sel));
    } catch (SoapFaultException sfe) {
        fail("SoapFaultException caught when deleting item from RSS datasource folder - " + sfe.getMessage());
    }
    // Delete folder, import data, and make sure that the data source was deleted.
    // Data source import runs asynchronously, so poll until the data source is gone.
    mbox.deleteFolder(rssFolder.getId());
// JBF - do not do the import; it will fail if DS is already deleted
// mbox.importData(list);
// XXX bburtin: disabled check to avoid false positives (bug 54816).  Some sort
// of race condition is causing this check to fail intermittently.  I was unable
// to consistently repro.
/*
        for (int i = 1; i <= 10; i++) {
            ds = (ZRssDataSource) getDataSource(mbox, rssFolder.getId());
            if (ds == null) {
                break;
            }
            Thread.sleep(500);
        }
        assertNull(ds);
        */
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ConvActionSelector(com.zimbra.soap.mail.type.ConvActionSelector) ConvActionRequest(com.zimbra.soap.mail.message.ConvActionRequest) ArrayList(java.util.ArrayList) ZRssDataSource(com.zimbra.client.ZRssDataSource) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Aggregations

ZDataSource (com.zimbra.client.ZDataSource)1 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 ZMessage (com.zimbra.client.ZMessage)1 ZRssDataSource (com.zimbra.client.ZRssDataSource)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 ConvActionRequest (com.zimbra.soap.mail.message.ConvActionRequest)1 ConvActionSelector (com.zimbra.soap.mail.type.ConvActionSelector)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1