Search in sources :

Example 1 with RemoteDataInfo

use of com.zimbra.cs.service.FeedManager.RemoteDataInfo in project zm-mailbox by Zimbra.

the class FeedManagerTest method atomEnabledOrg.

@Test
public void atomEnabledOrg() throws Exception {
    long lastModified = 0;
    String expectedCharset = MimeConstants.P_CHARSET_UTF8;
    BufferedInputStream content = new BufferedInputStream(getClass().getResourceAsStream("atomEnabledOrg.xml"));
    RemoteDataInfo rdi = new RemoteDataInfo(HttpStatus.OK_200, 0, content, expectedCharset, lastModified);
    SubscriptionData<?> subsData = FeedManager.retrieveRemoteDatasource(null, rdi, null);
    List<?> subs = subsData.getItems();
    Assert.assertNotNull("List of subscriptions", subs);
    Assert.assertEquals("Number of items", 2, subs.size());
    Object obj;
    obj = subs.get(0);
    if (obj instanceof ParsedMessage) {
        ParsedMessage pm = (ParsedMessage) obj;
        List<MPartInfo> parts = pm.getMessageParts();
        Assert.assertEquals("Number of message parts", 1, parts.size());
        String msgContent = streamToString(parts.get(0).getMimePart().getInputStream(), Charsets.UTF_8);
        Assert.assertTrue("Some content text", msgContent.indexOf("Rev 0.9 of the AtomAPI has just been posted") > 0);
    } else {
        Assert.fail("Expecting a ParsedMessage where is " + obj.getClass().getName());
    }
    obj = subs.get(1);
    if (obj instanceof ParsedMessage) {
        ParsedMessage pm = (ParsedMessage) obj;
        List<MPartInfo> parts = pm.getMessageParts();
        Assert.assertEquals("Number of message parts", 1, parts.size());
        String msgContent = streamToString(parts.get(0).getMimePart().getInputStream(), Charsets.UTF_8);
        Assert.assertTrue("Some content text", msgContent.indexOf("AtomAPI at ApacheCon in Las Vegas") > 0);
    } else {
        Assert.fail("Expecting a ParsedMessage where is " + obj.getClass().getName());
    }
}
Also used : MPartInfo(com.zimbra.cs.mime.MPartInfo) BufferedInputStream(java.io.BufferedInputStream) RemoteDataInfo(com.zimbra.cs.service.FeedManager.RemoteDataInfo) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Test(org.junit.Test)

Example 2 with RemoteDataInfo

use of com.zimbra.cs.service.FeedManager.RemoteDataInfo in project zm-mailbox by Zimbra.

the class FeedManagerTest method socialcastAtomFeed.

@Test
public void socialcastAtomFeed() throws Exception {
    long lastModified = 0;
    String expectedCharset = MimeConstants.P_CHARSET_UTF8;
    BufferedInputStream content = new BufferedInputStream(getClass().getResourceAsStream("socialcastAtomFeed.xml"));
    RemoteDataInfo rdi = new RemoteDataInfo(HttpStatus.OK_200, 0, content, expectedCharset, lastModified);
    SubscriptionData<?> subsData = FeedManager.retrieveRemoteDatasource(null, rdi, null);
    List<?> subs = subsData.getItems();
    Assert.assertNotNull("List of subscriptions", subs);
    Assert.assertEquals("Number of items", 1, subs.size());
    for (Object obj : subs) {
        if (obj instanceof ParsedMessage) {
            ParsedMessage pm = (ParsedMessage) obj;
            List<MPartInfo> parts = pm.getMessageParts();
            Assert.assertEquals("Number of message parts", 1, parts.size());
            String msgContent = streamToString(parts.get(0).getMimePart().getInputStream(), Charsets.UTF_8);
            Assert.assertTrue("Text from inside <div>", msgContent.indexOf("Congratulations for passing!") > 0);
            Assert.assertTrue("Article reference", msgContent.indexOf("https://pink.socialcast.com/messages/15629747-active-learner-thanks-to-cccc") > 0);
        } else {
            Assert.fail("Expecting a ParsedMessage where is " + obj.getClass().getName());
        }
    }
}
Also used : MPartInfo(com.zimbra.cs.mime.MPartInfo) BufferedInputStream(java.io.BufferedInputStream) RemoteDataInfo(com.zimbra.cs.service.FeedManager.RemoteDataInfo) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Test(org.junit.Test)

Aggregations

MPartInfo (com.zimbra.cs.mime.MPartInfo)2 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)2 RemoteDataInfo (com.zimbra.cs.service.FeedManager.RemoteDataInfo)2 BufferedInputStream (java.io.BufferedInputStream)2 Test (org.junit.Test)2