Search in sources :

Example 36 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.

the class FeedEntryMessageSourceTests method testReceiveFeedWithRealEntriesAndRepeatWithPersistentMetadataStore.

// will test that last feed entry is remembered between the sessions
// and no duplicate entries are retrieved
@Test
public void testReceiveFeedWithRealEntriesAndRepeatWithPersistentMetadataStore() throws Exception {
    ClassPathResource resource = new ClassPathResource("org/springframework/integration/feed/sample.rss");
    FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(resource, "foo");
    feedEntrySource.setBeanName("feedReader");
    PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore();
    metadataStore.afterPropertiesSet();
    feedEntrySource.setMetadataStore(metadataStore);
    feedEntrySource.setBeanFactory(mock(BeanFactory.class));
    feedEntrySource.afterPropertiesSet();
    SyndEntry entry1 = feedEntrySource.receive().getPayload();
    SyndEntry entry2 = feedEntrySource.receive().getPayload();
    SyndEntry entry3 = feedEntrySource.receive().getPayload();
    // only 3 entries in the test feed
    assertNull(feedEntrySource.receive());
    assertEquals("Spring Integration download", entry1.getTitle().trim());
    assertEquals(1266088337000L, entry1.getPublishedDate().getTime());
    assertEquals("Check out Spring Integration forums", entry2.getTitle().trim());
    assertEquals(1268469501000L, entry2.getPublishedDate().getTime());
    assertEquals("Spring Integration adapters", entry3.getTitle().trim());
    assertEquals(1272044098000L, entry3.getPublishedDate().getTime());
    metadataStore.destroy();
    metadataStore.afterPropertiesSet();
    // now test that what's been read is no longer retrieved
    feedEntrySource = new FeedEntryMessageSource(resource, "foo");
    feedEntrySource.setBeanName("feedReader");
    metadataStore = new PropertiesPersistingMetadataStore();
    metadataStore.afterPropertiesSet();
    feedEntrySource.setMetadataStore(metadataStore);
    feedEntrySource.setBeanFactory(mock(BeanFactory.class));
    feedEntrySource.afterPropertiesSet();
    assertNull(feedEntrySource.receive());
    assertNull(feedEntrySource.receive());
    assertNull(feedEntrySource.receive());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) BeanFactory(org.springframework.beans.factory.BeanFactory) PropertiesPersistingMetadataStore(org.springframework.integration.metadata.PropertiesPersistingMetadataStore) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 37 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.

the class FeedEntryMessageSourceTests method testReceiveFeedWithRealEntriesAndRepeatNoPersistentMetadataStore.

// will test that last feed entry is NOT remembered between the sessions, since
// no persistent MetadataStore is provided and the same entries are retrieved again
@Test
public void testReceiveFeedWithRealEntriesAndRepeatNoPersistentMetadataStore() throws Exception {
    ClassPathResource resource = new ClassPathResource("org/springframework/integration/feed/sample.rss");
    FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(resource, "foo");
    feedEntrySource.setBeanName("feedReader");
    feedEntrySource.setBeanFactory(mock(BeanFactory.class));
    feedEntrySource.afterPropertiesSet();
    SyndEntry entry1 = feedEntrySource.receive().getPayload();
    SyndEntry entry2 = feedEntrySource.receive().getPayload();
    SyndEntry entry3 = feedEntrySource.receive().getPayload();
    // only 3 entries in the test feed
    assertNull(feedEntrySource.receive());
    assertEquals("Spring Integration download", entry1.getTitle().trim());
    assertEquals(1266088337000L, entry1.getPublishedDate().getTime());
    assertEquals("Check out Spring Integration forums", entry2.getTitle().trim());
    assertEquals(1268469501000L, entry2.getPublishedDate().getTime());
    assertEquals("Spring Integration adapters", entry3.getTitle().trim());
    assertEquals(1272044098000L, entry3.getPublishedDate().getTime());
    // UNLIKE the previous test
    // now test that what's been read is read AGAIN
    feedEntrySource = new FeedEntryMessageSource(resource, "foo");
    feedEntrySource.setBeanName("feedReader");
    feedEntrySource.setBeanFactory(mock(BeanFactory.class));
    feedEntrySource.afterPropertiesSet();
    entry1 = feedEntrySource.receive().getPayload();
    entry2 = feedEntrySource.receive().getPayload();
    entry3 = feedEntrySource.receive().getPayload();
    // only 3 entries in the test feed
    assertNull(feedEntrySource.receive());
    assertEquals("Spring Integration download", entry1.getTitle().trim());
    assertEquals(1266088337000L, entry1.getPublishedDate().getTime());
    assertEquals("Check out Spring Integration forums", entry2.getTitle().trim());
    assertEquals(1268469501000L, entry2.getPublishedDate().getTime());
    assertEquals("Spring Integration adapters", entry3.getTitle().trim());
    assertEquals(1272044098000L, entry3.getPublishedDate().getTime());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) BeanFactory(org.springframework.beans.factory.BeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 38 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.

the class FeedDslTests method testFeedEntryMessageSourceFlow.

@Test
@SuppressWarnings("unchecked")
public void testFeedEntryMessageSourceFlow() throws Exception {
    Message<SyndEntry> message1 = (Message<SyndEntry>) this.entries.receive(10000);
    Message<SyndEntry> message2 = (Message<SyndEntry>) this.entries.receive(10000);
    Message<SyndEntry> message3 = (Message<SyndEntry>) this.entries.receive(10000);
    long time1 = message1.getPayload().getPublishedDate().getTime();
    long time2 = message2.getPayload().getPublishedDate().getTime();
    long time3 = message3.getPayload().getPublishedDate().getTime();
    assertTrue(time1 < time2);
    assertTrue(time2 < time3);
    assertNull(this.entries.receive(10));
    this.metadataStore.flush();
    FileReader metadataStoreFile = new FileReader(tempFolder.getRoot().getAbsolutePath() + "/metadata-store.properties");
    Properties metadataStoreProperties = new Properties();
    metadataStoreProperties.load(metadataStoreFile);
    assertFalse(metadataStoreProperties.isEmpty());
    assertEquals(1, metadataStoreProperties.size());
    assertTrue(metadataStoreProperties.containsKey("feedTest"));
}
Also used : Message(org.springframework.messaging.Message) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FileReader(java.io.FileReader) Properties(java.util.Properties) Test(org.junit.Test)

Example 39 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project BIMserver by opensourceBIM.

the class SyndicationServlet method writeRevisionsFeed.

private void writeRevisionsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws IOException, FeedException, ServiceException, PublicInterfaceNotFoundException {
    long poid = Long.parseLong(request.getParameter("poid"));
    SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(FEED_TYPE);
    feed.setTitle("BIMserver.org revisions feed for project '" + sProject.getName() + "'");
    feed.setLink(request.getContextPath());
    feed.setDescription("This feed represents all the revisions of project '" + sProject.getName() + "'");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        List<SRevision> allRevisionsOfProject = serviceMap.getServiceInterface().getAllRevisionsOfProject(poid);
        Collections.sort(allRevisionsOfProject, new SRevisionIdComparator(false));
        for (SRevision sVirtualRevision : allRevisionsOfProject) {
            SUser user = serviceMap.getServiceInterface().getUserByUoid(sVirtualRevision.getUserId());
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("Revision " + sVirtualRevision.getOid());
            entry.setLink(request.getContextPath() + "/revision.jsp?poid=" + sVirtualRevision.getOid() + "&roid=" + sVirtualRevision.getOid());
            entry.setPublishedDate(sVirtualRevision.getDate());
            SyndContent description = new SyndContentImpl();
            description.setType("text/html");
            description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Comment</td><td>" + sVirtualRevision.getComment() + "</td></tr></table>");
            entry.setDescription(description);
            entries.add(entry);
        }
    } catch (ServiceException e) {
        LOGGER.error("", e);
    }
    feed.setEntries(entries);
    SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, response.getWriter());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SUser(org.bimserver.interfaces.objects.SUser) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SProject(org.bimserver.interfaces.objects.SProject) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SRevision(org.bimserver.interfaces.objects.SRevision) SyndContent(com.rometools.rome.feed.synd.SyndContent) ServiceException(org.bimserver.shared.exceptions.ServiceException) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) SRevisionIdComparator(org.bimserver.shared.comparators.SRevisionIdComparator)

Example 40 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project books by aidanwhiteley.

the class FeedsControllerTest method checkRssFeedsHasEntries.

@Test
void checkRssFeedsHasEntries() throws Exception {
    // Find the port the test is running on
    String rootUri = this.testRestTemplate.getRootUri();
    String url = rootUri + "/feeds/rss";
    XmlReader reader = new XmlReader(new URL(url));
    SyndFeed feed = new SyndFeedInput().build(reader);
    assertEquals(booksFeedsTitles, feed.getTitle());
    assertTrue(feed.getEntries().size() > 0);
    for (SyndEntry entry : feed.getEntries()) {
        assertFalse(entry.getContents().get(0).getValue().isEmpty());
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) XmlReader(com.rometools.rome.io.XmlReader) URL(java.net.URL) Test(org.junit.jupiter.api.Test) IntegrationTest(com.aidanwhiteley.books.util.IntegrationTest)

Aggregations

SyndEntry (com.rometools.rome.feed.synd.SyndEntry)45 ArrayList (java.util.ArrayList)23 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)22 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)18 SyndContent (com.rometools.rome.feed.synd.SyndContent)15 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)14 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)13 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)9 FeedException (com.rometools.rome.io.FeedException)7 Test (org.junit.Test)7 XmlReader (com.rometools.rome.io.XmlReader)6 URL (java.net.URL)6 Date (java.util.Date)5 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)5 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)5 IOException (java.io.IOException)4 BeanFactory (org.springframework.beans.factory.BeanFactory)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 Post (it.vige.rubia.model.Post)3