INT-3700: Fix FeedEntryMS for correct lastTime
JIRA: https://jira.spring.io/browse/INT-3700 Change to calculate proper syndicate entry date for comparison when adding feeds for processing. I have signed and agree to the terms of the SpringSource Individual Contributor License Agreement. unit test for recent changes to FeedEntryMessageSourceTests to verify proper last seen date calculation. updates for comments from code review * newline at EOF on atom.xml * removed question from code * fetch files via classpath instead of file system * 'else' on newline * authorship on class Polishing
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- example atom feed provided in rfc4287 -->
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title type="text">dive into mark</title>
|
||||
<subtitle type="html">
|
||||
A <em>lot</em> of effort
|
||||
went into making this effortless
|
||||
</subtitle>
|
||||
<updated>2005-07-31T12:29:29Z</updated>
|
||||
<id>tag:example.org,2003:3</id>
|
||||
<link rel="alternate" type="text/html" hreflang="en"
|
||||
href="http://example.org/" />
|
||||
<link rel="self" type="application/atom+xml" href="http://example.org/feed.atom" />
|
||||
<rights>Copyright (c) 2003, Mark Pilgrim</rights>
|
||||
<generator uri="http://www.example.com/" version="1.0">
|
||||
Example Toolkit
|
||||
</generator>
|
||||
<entry>
|
||||
<title>Atom draft-07 snapshot</title>
|
||||
<link rel="alternate" type="text/html" href="http://example.org/2005/04/02/atom" />
|
||||
<link rel="enclosure" type="audio/mpeg" length="1337"
|
||||
href="http://example.org/audio/ph34r_my_podcast.mp3" />
|
||||
<id>tag:example.org,2003:3.2397</id>
|
||||
<updated>2005-07-31T12:29:29Z</updated>
|
||||
<published>2003-12-13T08:29:29-04:00</published>
|
||||
<author>
|
||||
<name>Mark Pilgrim</name>
|
||||
<uri>http://example.org/</uri>
|
||||
<email>f8dy@example.com</email>
|
||||
</author>
|
||||
<contributor>
|
||||
<name>Sam Ruby</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Joe Gregorio</name>
|
||||
</contributor>
|
||||
<content type="xhtml" xml:lang="en" xml:base="http://diveintomark.org/">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml">
|
||||
<p>
|
||||
<i>[Update: The Atom draft is finished.]</i>
|
||||
</p>
|
||||
</div>
|
||||
</content>
|
||||
</entry>
|
||||
</feed>
|
||||
@@ -6,12 +6,12 @@
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/feed http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd">
|
||||
|
||||
<feed:inbound-channel-adapter id="feedAdapter"
|
||||
channel="feedChannel"
|
||||
auto-startup="false"
|
||||
<feed:inbound-channel-adapter id="feedAdapter"
|
||||
channel="feedChannel"
|
||||
auto-startup="false"
|
||||
feed-fetcher="fileUrlFeedFetcher"
|
||||
metadata-store="customMetadataStore"
|
||||
url="file:src/test/java/org/springframework/integration/feed/sample.rss">
|
||||
url="classpath:org/springframework/integration/feed/sample.rss">
|
||||
<int:poller fixed-rate="10000" max-messages-per-poll="100" />
|
||||
</feed:inbound-channel-adapter>
|
||||
|
||||
@@ -23,4 +23,4 @@
|
||||
|
||||
<bean id="customMetadataStore" class="org.springframework.integration.feed.config.FeedInboundChannelAdapterParserTests.SampleMetadataStore"/>
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<int-feed:inbound-channel-adapter id="feedAdapterUsage"
|
||||
channel="feedChannelUsage"
|
||||
url="file:src/test/java/org/springframework/integration/feed/sample.rss"
|
||||
url="classpath:org/springframework/integration/feed/sample.rss"
|
||||
feed-fetcher="fileUrlFeedFetcher">
|
||||
<int:poller fixed-rate="10000" max-messages-per-poll="100"/>
|
||||
</int-feed:inbound-channel-adapter>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -117,7 +117,7 @@ public class FeedInboundChannelAdapterParserTests {
|
||||
latch = spy(new CountDownLatch(3));
|
||||
context = new ClassPathXmlApplicationContext(
|
||||
"FeedInboundChannelAdapterParserTests-file-usage-context.xml", this.getClass());
|
||||
latch.await(5, TimeUnit.SECONDS);
|
||||
latch.await(500, TimeUnit.MILLISECONDS);
|
||||
verify(latch, times(0)).countDown();
|
||||
context.destroy();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,8 +26,8 @@ import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.integration.metadata.PropertiesPersistingMetadataStore;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
@@ -38,13 +38,13 @@ import com.rometools.rome.feed.synd.SyndEntry;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Aaron Loes
|
||||
* @since 2.0
|
||||
*/
|
||||
public class FeedEntryMessageSourceTests {
|
||||
|
||||
private final FeedFetcher feedFetcher = new FileUrlFeedFetcher();
|
||||
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
File metadataStoreFile = new File(System.getProperty("java.io.tmpdir") + "/spring-integration/",
|
||||
@@ -56,14 +56,14 @@ public class FeedEntryMessageSourceTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testFailureWhenNotInitialized() throws Exception {
|
||||
URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss");
|
||||
URL url = new ClassPathResource("org/springframework/integration/feed/sample.rss").getURL();
|
||||
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url, "foo");
|
||||
feedEntrySource.receive();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveFeedWithNoEntries() throws Exception {
|
||||
URL url = new URL("file:src/test/java/org/springframework/integration/feed/empty.rss");
|
||||
URL url = new ClassPathResource("org/springframework/integration/feed/empty.rss").getURL();
|
||||
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url, "foo", this.feedFetcher);
|
||||
feedEntrySource.setBeanName("feedReader");
|
||||
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
|
||||
@@ -73,7 +73,7 @@ public class FeedEntryMessageSourceTests {
|
||||
|
||||
@Test
|
||||
public void testReceiveFeedWithEntriesSorted() throws Exception {
|
||||
URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss");
|
||||
URL url = new ClassPathResource("org/springframework/integration/feed/sample.rss").getURL();
|
||||
FeedEntryMessageSource source = new FeedEntryMessageSource(url, "foo", this.feedFetcher);
|
||||
source.setComponentName("feedReader");
|
||||
source.setBeanFactory(mock(BeanFactory.class));
|
||||
@@ -89,11 +89,45 @@ public class FeedEntryMessageSourceTests {
|
||||
assertNull(source.receive());
|
||||
}
|
||||
|
||||
// verifies that when entry has been updated since publish, that is taken into
|
||||
// account when determining if the feed entry has been seen before
|
||||
@Test
|
||||
public void testEntryHavingBeenUpdatedAfterPublishAndRepeat() throws Exception {
|
||||
URL url = new ClassPathResource("org/springframework/integration/feed/atom.xml").getURL();
|
||||
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url, "foo", this.feedFetcher);
|
||||
feedEntrySource.setBeanName("feedReader");
|
||||
PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore();
|
||||
metadataStore.afterPropertiesSet();
|
||||
feedEntrySource.setMetadataStore(metadataStore);
|
||||
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
|
||||
feedEntrySource.afterPropertiesSet();
|
||||
|
||||
SyndEntry entry1 = feedEntrySource.receive().getPayload();
|
||||
assertNull(feedEntrySource.receive()); // only 1 entries in the test feed
|
||||
|
||||
assertEquals("Atom draft-07 snapshot", entry1.getTitle().trim());
|
||||
assertEquals(1071318569000L, entry1.getPublishedDate().getTime());
|
||||
assertEquals(1122812969000L, entry1.getUpdatedDate().getTime());
|
||||
|
||||
metadataStore.destroy();
|
||||
metadataStore.afterPropertiesSet();
|
||||
|
||||
// now test that what's been read is no longer retrieved
|
||||
feedEntrySource = new FeedEntryMessageSource(url, "foo", this.feedFetcher);
|
||||
feedEntrySource.setBeanName("feedReader");
|
||||
metadataStore = new PropertiesPersistingMetadataStore();
|
||||
metadataStore.afterPropertiesSet();
|
||||
feedEntrySource.setMetadataStore(metadataStore);
|
||||
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
|
||||
feedEntrySource.afterPropertiesSet();
|
||||
assertNull(feedEntrySource.receive());
|
||||
}
|
||||
|
||||
// will test that last feed entry is remembered between the sessions
|
||||
// and no duplicate entries are retrieved
|
||||
@Test
|
||||
public void testReceiveFeedWithRealEntriesAndRepeatWithPersistentMetadataStore() throws Exception {
|
||||
URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss");
|
||||
URL url = new ClassPathResource("org/springframework/integration/feed/sample.rss").getURL();
|
||||
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url, "foo", this.feedFetcher);
|
||||
feedEntrySource.setBeanName("feedReader");
|
||||
PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore();
|
||||
@@ -135,7 +169,7 @@ public class FeedEntryMessageSourceTests {
|
||||
// no persistent MetadataStore is provided and the same entries are retrieved again
|
||||
@Test
|
||||
public void testReceiveFeedWithRealEntriesAndRepeatNoPersistentMetadataStore() throws Exception {
|
||||
URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss");
|
||||
URL url = new ClassPathResource("org/springframework/integration/feed/sample.rss").getURL();
|
||||
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url, "foo", this.feedFetcher);
|
||||
feedEntrySource.setBeanName("feedReader");
|
||||
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
|
||||
|
||||
Reference in New Issue
Block a user