From 35f2bc1444e960025206c9126e2f80eef65609ec Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 27 Oct 2010 11:37:08 -0400 Subject: [PATCH] INT-786 refactored Feed MessageSource and related classes --- .../integration/feed/FeedConstants.java | 28 ---- ...ource.java => FeedEntryMessageSource.java} | 85 +++++++++-- .../feed/FeedReaderMessageSource.java | 137 ------------------ .../integration/feed/FileUrlFeedFetcher.java | 6 +- ...a => FeedInboundChannelAdapterParser.java} | 18 +-- .../feed/config/FeedNamespaceHandler.java | 3 +- ....java => FeedEntryMessageSourceTests.java} | 71 ++++----- ...BeanDefinitionParserTests-file-context.xml | 6 +- ...essageSourceBeanDefinitionParserTests.java | 29 ++-- .../integration/feed/empty.rss | 20 +++ 10 files changed, 154 insertions(+), 249 deletions(-) delete mode 100644 spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedConstants.java rename spring-integration-feed/src/main/java/org/springframework/integration/feed/{FeedEntryReaderMessageSource.java => FeedEntryMessageSource.java} (63%) delete mode 100644 spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedReaderMessageSource.java rename spring-integration-feed/src/main/java/org/springframework/integration/feed/config/{FeedMessageSourceBeanDefinitionParser.java => FeedInboundChannelAdapterParser.java} (59%) rename spring-integration-feed/src/test/java/org/springframework/integration/feed/{FeedEntryReaderMessageSourceTests.java => FeedEntryMessageSourceTests.java} (68%) create mode 100644 spring-integration-feed/src/test/java/org/springframework/integration/feed/empty.rss diff --git a/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedConstants.java b/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedConstants.java deleted file mode 100644 index a14cab37fa..0000000000 --- a/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedConstants.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.feed; - -/** - * Header keys for {@link FeedReaderMessageSource}. - * - * @author Josh Long - */ -public abstract class FeedConstants { - - static public final String FEED_URL = "feedUrl"; - -} diff --git a/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedEntryReaderMessageSource.java b/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedEntryMessageSource.java similarity index 63% rename from spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedEntryReaderMessageSource.java rename to spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedEntryMessageSource.java index 22e3ef1a2f..b6ceff1e7c 100644 --- a/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedEntryReaderMessageSource.java +++ b/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedEntryMessageSource.java @@ -16,6 +16,7 @@ package org.springframework.integration.feed; +import java.net.URL; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -24,6 +25,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import org.springframework.beans.factory.BeanFactory; import org.springframework.integration.Message; +import org.springframework.integration.MessagingException; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.context.metadata.MetadataStore; @@ -36,6 +38,12 @@ import org.springframework.util.StringUtils; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.fetcher.FetcherEvent; +import com.sun.syndication.fetcher.FetcherListener; +import com.sun.syndication.fetcher.impl.AbstractFeedFetcher; +import com.sun.syndication.fetcher.impl.FeedFetcherCache; +import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache; +import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher; /** * This implementation of {@link MessageSource} will produce individual @@ -46,12 +54,16 @@ import com.sun.syndication.feed.synd.SyndFeed; * @author Oleg Zhurakousky * @since 2.0 */ -public class FeedEntryReaderMessageSource extends IntegrationObjectSupport implements MessageSource { +public class FeedEntryMessageSource extends IntegrationObjectSupport implements MessageSource { + + private final URL feedUrl; + + private final AbstractFeedFetcher fetcher; + + private final Queue feeds = new ConcurrentLinkedQueue(); private final Queue entries = new ConcurrentLinkedQueue(); - private final FeedReaderMessageSource feedReaderMessageSource; - private volatile String metadataKey; private volatile MetadataStore metadataStore; @@ -64,10 +76,22 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple private final Comparator syndEntryComparator = new SyndEntryComparator(); + private final Object feedMonitor = new Object(); - public FeedEntryReaderMessageSource(FeedReaderMessageSource feedReaderMessageSource) { - Assert.notNull(feedReaderMessageSource, "'feedReaderMessageSource' must not be null"); - this.feedReaderMessageSource = feedReaderMessageSource; + + public FeedEntryMessageSource(URL feedUrl) { + Assert.notNull(feedUrl, "feedUrl must not be null"); + this.feedUrl = feedUrl; + if (feedUrl.getProtocol().equals("file")) { + this.fetcher = new FileUrlFeedFetcher(); + } + else if (feedUrl.getProtocol().equals("http")) { + FeedFetcherCache fetcherCache = HashMapFeedInfoCache.getInstance(); + this.fetcher = new HttpURLFeedFetcher(fetcherCache); + } + else { + throw new IllegalArgumentException("Unsupported URL protocol: " + feedUrl.getProtocol()); + } } @@ -91,6 +115,7 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple @Override protected void onInit() throws Exception { + this.fetcher.addFetcherEventListener(new FeedQueueUpdatingFetcherListener()); if (this.metadataStore == null) { // first try to look for a 'messageStore' in the context BeanFactory beanFactory = this.getBeanFactory(); @@ -103,8 +128,7 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple } } Assert.hasText(this.getComponentName(), "FeedEntryReaderMessageSource must have a name"); - this.metadataKey = this.getComponentType() + "." + this.getComponentName() - + "." + this.feedReaderMessageSource.getFeedUrl(); + this.metadataKey = this.getComponentType() + "." + this.getComponentName() + "." + this.feedUrl; String lastTimeValue = this.metadataStore.get(this.metadataKey); if (StringUtils.hasText(lastTimeValue)) { this.lastTime = Long.parseLong(lastTimeValue); @@ -137,7 +161,7 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple @SuppressWarnings("unchecked") private void populateEntryList() { - SyndFeed syndFeed = this.feedReaderMessageSource.receiveFeed(); + SyndFeed syndFeed = this.getFeed(); if (syndFeed != null) { List retrievedEntries = (List) syndFeed.getEntries(); if (!CollectionUtils.isEmpty(retrievedEntries)) { @@ -151,6 +175,28 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple } } + private SyndFeed getFeed() { + SyndFeed feed = null; + try { + synchronized (this.feedMonitor) { + feed = this.fetcher.retrieveFeed(this.feedUrl); + if (logger.isDebugEnabled()) { + logger.debug("retrieved feed at url '" + this.feedUrl + "'"); + } + if (feed == null) { + if (logger.isDebugEnabled()) { + logger.debug("no feeds updated, returning null"); + } + } + } + } + catch (Exception e) { + throw new MessagingException( + "Failed to retrieve feed at url '" + this.feedUrl + "'", e); + } + return feed; + } + private static class SyndEntryComparator implements Comparator { @@ -159,4 +205,25 @@ public class FeedEntryReaderMessageSource extends IntegrationObjectSupport imple } } + + private class FeedQueueUpdatingFetcherListener implements FetcherListener { + + /** + * @see com.sun.syndication.fetcher.FetcherListener#fetcherEvent(com.sun.syndication.fetcher.FetcherEvent) + */ + public void fetcherEvent(final FetcherEvent event) { + String eventType = event.getEventType(); + if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) { + logger.debug("\tEVENT: Feed Polled. URL = " + event.getUrlString()); + } + else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) { + logger.debug("\tEVENT: Feed Retrieved. URL = " + event.getUrlString()); + feeds.add(event.getFeed()); + } + else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) { + logger.debug("\tEVENT: Feed Unchanged. URL = " + event.getUrlString()); + } + } + } + } diff --git a/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedReaderMessageSource.java b/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedReaderMessageSource.java deleted file mode 100644 index d72aaa6beb..0000000000 --- a/spring-integration-feed/src/main/java/org/springframework/integration/feed/FeedReaderMessageSource.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.feed; - -import java.net.URL; -import java.util.concurrent.ConcurrentLinkedQueue; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.integration.Message; -import org.springframework.integration.MessagingException; -import org.springframework.integration.context.IntegrationObjectSupport; -import org.springframework.integration.core.MessageSource; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.util.Assert; - -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.fetcher.FetcherEvent; -import com.sun.syndication.fetcher.FetcherListener; -import com.sun.syndication.fetcher.impl.AbstractFeedFetcher; -import com.sun.syndication.fetcher.impl.FeedFetcherCache; -import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache; -import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher; - -/** - * This implementation of {@link MessageSource} will produce a Message whose payload is - * an instance of {@link SyndFeed} for a feed identified with the 'feedUrl' attribute. - * - * @author Josh Long - * @author Mario Gray - * @author Oleg Zhurakousky - * @author Mark Fisher - * @since 2.0 - */ -public class FeedReaderMessageSource extends IntegrationObjectSupport implements InitializingBean, MessageSource { - - private final URL feedUrl; - - private final AbstractFeedFetcher fetcher; - - private volatile FeedFetcherCache fetcherCache; - - private final ConcurrentLinkedQueue feeds = new ConcurrentLinkedQueue(); - - private final Object feedMonitor = new Object(); - - - public FeedReaderMessageSource(URL feedUrl) { - this.feedUrl = feedUrl; - if (feedUrl.getProtocol().equals("file")) { - this.fetcher = new FileUrlFeedFetcher(); - } - else if (feedUrl.getProtocol().equals("http")) { - this.fetcherCache = HashMapFeedInfoCache.getInstance(); - this.fetcher = new HttpURLFeedFetcher(fetcherCache); - } - else { - throw new IllegalArgumentException("Unsupported URL protocol: " + feedUrl.getProtocol()); - } - } - - - URL getFeedUrl() { - return this.feedUrl; - } - - @Override - protected void onInit() throws Exception { - fetcher.addFetcherEventListener(new FeedQueueUpdatingFetcherListener()); - Assert.notNull(this.feedUrl, "the feedUrl must not be null"); - } - - SyndFeed receiveFeed() { - SyndFeed feed = null; - try { - synchronized (this.feedMonitor) { - feed = this.fetcher.retrieveFeed(this.feedUrl); - if (logger.isDebugEnabled()) { - logger.debug("retrieved feed at url '" + this.feedUrl + "'"); - } - if (feed == null) { - if (logger.isDebugEnabled()) { - logger.debug("no feeds updated, returning null"); - } - } - } - } - catch (Exception e) { - throw new MessagingException( - "Failed to retrieve feed at url '" + this.feedUrl + "'", e); - } - return feed; - } - - public Message receive() { - SyndFeed feed = this.receiveFeed(); - if (feed == null) { - return null; - } - return MessageBuilder.withPayload(feed).setHeader(FeedConstants.FEED_URL, this.feedUrl).build(); - } - - - private class FeedQueueUpdatingFetcherListener implements FetcherListener { - - /** - * @see com.sun.syndication.fetcher.FetcherListener#fetcherEvent(com.sun.syndication.fetcher.FetcherEvent) - */ - public void fetcherEvent(final FetcherEvent event) { - String eventType = event.getEventType(); - if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) { - logger.debug("\tEVENT: Feed Polled. URL = " + event.getUrlString()); - } - else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) { - logger.debug("\tEVENT: Feed Retrieved. URL = " + event.getUrlString()); - feeds.add(event.getFeed()); - } - else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) { - logger.debug("\tEVENT: Feed Unchanged. URL = " + event.getUrlString()); - } - } - } - -} diff --git a/spring-integration-feed/src/main/java/org/springframework/integration/feed/FileUrlFeedFetcher.java b/spring-integration-feed/src/main/java/org/springframework/integration/feed/FileUrlFeedFetcher.java index b6423da376..d0244b45dd 100644 --- a/spring-integration-feed/src/main/java/org/springframework/integration/feed/FileUrlFeedFetcher.java +++ b/spring-integration-feed/src/main/java/org/springframework/integration/feed/FileUrlFeedFetcher.java @@ -39,10 +39,10 @@ import com.sun.syndication.io.XmlReader; * @author Mark Fisher * @since 2.0 */ -public class FileUrlFeedFetcher extends AbstractFeedFetcher { +class FileUrlFeedFetcher extends AbstractFeedFetcher { - /* - * (non-Javadoc) + /** + * Retrieve a SyndFeed for the given URL. * @see com.sun.syndication.fetcher.FeedFetcher#retrieveFeed(java.net.URL) */ public SyndFeed retrieveFeed(URL feedUrl) throws IOException, FeedException, FetcherException { diff --git a/spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParser.java b/spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParser.java similarity index 59% rename from spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParser.java rename to spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParser.java index 70896e92d7..5dafbdb398 100644 --- a/spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParser.java +++ b/spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParser.java @@ -25,24 +25,22 @@ import org.springframework.integration.config.xml.AbstractPollingInboundChannelA import org.springframework.integration.config.xml.IntegrationNamespaceUtils; /** - * Handles parsing the configuration for the feed inbound channel adapter. + * Handles parsing the configuration for the feed inbound-channel-adapter. * * @author Josh Long * @author Oleg Zhurakousky + * @author Mark Fisher * @since 2.0 */ -public class FeedMessageSourceBeanDefinitionParser extends AbstractPollingInboundChannelAdapterParser { +public class FeedInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser { @Override protected String parseSource(final Element element, final ParserContext parserContext) { - BeanDefinitionBuilder feedEntryBuilder = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.integration.feed.FeedEntryReaderMessageSource"); - BeanDefinitionBuilder feedBuilder = BeanDefinitionBuilder.genericBeanDefinition( - "org.springframework.integration.feed.FeedReaderMessageSource"); - feedBuilder.addConstructorArgValue(element.getAttribute("url")); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(feedEntryBuilder, element, "metadata-store"); - feedEntryBuilder.addConstructorArgValue(feedBuilder.getBeanDefinition()); - return BeanDefinitionReaderUtils.registerWithGeneratedName(feedEntryBuilder.getBeanDefinition(), parserContext.getRegistry()); + BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder.genericBeanDefinition( + "org.springframework.integration.feed.FeedEntryMessageSource"); + sourceBuilder.addConstructorArgValue(element.getAttribute("url")); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(sourceBuilder, element, "metadata-store"); + return BeanDefinitionReaderUtils.registerWithGeneratedName(sourceBuilder.getBeanDefinition(), parserContext.getRegistry()); } } diff --git a/spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedNamespaceHandler.java b/spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedNamespaceHandler.java index 0f28fe5f45..a047ad2024 100644 --- a/spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedNamespaceHandler.java +++ b/spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedNamespaceHandler.java @@ -22,12 +22,13 @@ import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHa * NamespaceHandler for the feed module. * * @author Josh Long + * @author Mark Fisher * @since 2.0 */ public class FeedNamespaceHandler extends AbstractIntegrationNamespaceHandler { public void init() { - registerBeanDefinitionParser("inbound-channel-adapter", new FeedMessageSourceBeanDefinitionParser()); + registerBeanDefinitionParser("inbound-channel-adapter", new FeedInboundChannelAdapterParser()); } } diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/FeedEntryReaderMessageSourceTests.java b/spring-integration-feed/src/test/java/org/springframework/integration/feed/FeedEntryMessageSourceTests.java similarity index 68% rename from spring-integration-feed/src/test/java/org/springframework/integration/feed/FeedEntryReaderMessageSourceTests.java rename to spring-integration-feed/src/test/java/org/springframework/integration/feed/FeedEntryMessageSourceTests.java index 187636ff8e..7881996f91 100644 --- a/spring-integration-feed/src/test/java/org/springframework/integration/feed/FeedEntryReaderMessageSourceTests.java +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/FeedEntryMessageSourceTests.java @@ -18,15 +18,10 @@ package org.springframework.integration.feed; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.when; +import static org.junit.Assert.assertTrue; import java.io.File; import java.net.URL; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; import org.junit.Before; import org.junit.Test; @@ -35,14 +30,13 @@ import org.springframework.integration.Message; import org.springframework.integration.context.metadata.PropertiesPersistingMetadataStore; import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndFeed; /** * @author Oleg Zhurakousky * @author Mark Fisher * @since 2.0 */ -public class FeedEntryReaderMessageSourceTests { +public class FeedEntryMessageSourceTests { @Before public void prepare() { @@ -53,47 +47,36 @@ public class FeedEntryReaderMessageSourceTests { } @Test(expected=IllegalArgumentException.class) - public void testFailureWhenNotInitialized() { - FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(mock(FeedReaderMessageSource.class)); + public void testFailureWhenNotInitialized() throws Exception { + URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss"); + FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url); feedEntrySource.receive(); } @Test - public void testReceiveFeedWithNoEntries() { - FeedReaderMessageSource feedReaderSource = mock(FeedReaderMessageSource.class); - SyndFeed feed = mock(SyndFeed.class); - when(feedReaderSource.receiveFeed()).thenReturn(feed); - FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource); + public void testReceiveFeedWithNoEntries() throws Exception { + URL url = new URL("file:src/test/java/org/springframework/integration/feed/empty.rss"); + FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url); feedEntrySource.setBeanName("feedReader"); feedEntrySource.afterPropertiesSet(); assertNull(feedEntrySource.receive()); } @Test - public void testReceiveFeedWithEntriesSorted() { - FeedReaderMessageSource feedReaderSource = mock(FeedReaderMessageSource.class); - SyndFeed feed = mock(SyndFeed.class); - SyndEntry entry1 = mock(SyndEntry.class); - SyndEntry entry2 = mock(SyndEntry.class); - when(entry1.getPublishedDate()).thenReturn(new Date(System.currentTimeMillis())); - when(entry2.getPublishedDate()).thenReturn(new Date(System.currentTimeMillis()-10000)); - - List entries = new ArrayList(); - entries.add(entry2); - entries.add(entry1); - when(feed.getEntries()).thenReturn(entries); - when(feedReaderSource.receiveFeed()).thenReturn(feed); - - FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource); - feedEntrySource.setComponentName("feedReader"); - feedEntrySource.afterPropertiesSet(); - Message entryMessage = feedEntrySource.receive(); - assertEquals(entry2, entryMessage.getPayload()); - entryMessage = feedEntrySource.receive(); - assertEquals(entry1, entryMessage.getPayload()); - reset(feed); - entryMessage = feedEntrySource.receive(); - assertNull(entryMessage); + public void testReceiveFeedWithEntriesSorted() throws Exception { + URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss"); + FeedEntryMessageSource source = new FeedEntryMessageSource(url); + source.setComponentName("feedReader"); + source.afterPropertiesSet(); + Message message1 = source.receive(); + Message message2 = source.receive(); + Message message3 = source.receive(); + 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(source.receive()); } // will test that last feed entry is remembered between the sessions @@ -101,8 +84,7 @@ public class FeedEntryReaderMessageSourceTests { @Test public void testReceiveFeedWithRealEntriesAndRepeatWithPersistentMetadataStore() throws Exception { URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss"); - FeedReaderMessageSource feedReaderSource = new FeedReaderMessageSource(url); - FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource); + FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url); feedEntrySource.setBeanName("feedReader"); PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore(); metadataStore.afterPropertiesSet(); @@ -126,7 +108,7 @@ public class FeedEntryReaderMessageSourceTests { metadataStore.afterPropertiesSet(); // now test that what's been read is no longer retrieved - feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource); + feedEntrySource = new FeedEntryMessageSource(url); feedEntrySource.setBeanName("feedReader"); metadataStore = new PropertiesPersistingMetadataStore(); metadataStore.afterPropertiesSet(); @@ -142,8 +124,7 @@ public class FeedEntryReaderMessageSourceTests { @Test public void testReceiveFeedWithRealEntriesAndRepeatNoPersistentMetadataStore() throws Exception { URL url = new URL("file:src/test/java/org/springframework/integration/feed/sample.rss"); - FeedReaderMessageSource feedReaderSource = new FeedReaderMessageSource(url); - FeedEntryReaderMessageSource feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource); + FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url); feedEntrySource.setBeanName("feedReader"); feedEntrySource.afterPropertiesSet(); SyndEntry entry1 = feedEntrySource.receive().getPayload(); @@ -162,7 +143,7 @@ public class FeedEntryReaderMessageSourceTests { // UNLIKE the previous test // now test that what's been read is read AGAIN - feedEntrySource = new FeedEntryReaderMessageSource(feedReaderSource); + feedEntrySource = new FeedEntryMessageSource(url); feedEntrySource.setBeanName("feedReader"); feedEntrySource.afterPropertiesSet(); entry1 = feedEntrySource.receive().getPayload(); diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParserTests-file-context.xml b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParserTests-file-context.xml index 2403d1d3e0..3e3cf9472f 100644 --- a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParserTests-file-context.xml +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParserTests-file-context.xml @@ -1,18 +1,18 @@ - - + diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParserTests.java b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParserTests.java index 05b8e9b274..bcfe3ce86f 100644 --- a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParserTests.java +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedMessageSourceBeanDefinitionParserTests.java @@ -41,9 +41,7 @@ import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.context.metadata.MetadataStore; import org.springframework.integration.core.MessageHandler; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; -import org.springframework.integration.feed.FeedEntryReaderMessageSource; -import org.springframework.integration.feed.FeedReaderMessageSource; -import org.springframework.integration.feed.FileUrlFeedFetcher; +import org.springframework.integration.feed.FeedEntryMessageSource; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.test.util.TestUtils; @@ -69,23 +67,28 @@ public class FeedMessageSourceBeanDefinitionParserTests { } @Test - public void validateSuccessfulConfigurationWithCustomMetadataStore() { + public void validateSuccessfulFileConfigurationWithCustomMetadataStore() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "FeedMessageSourceBeanDefinitionParserTests-file-context.xml", this.getClass()); SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class); - FeedEntryReaderMessageSource source = (FeedEntryReaderMessageSource) TestUtils.getPropertyValue(adapter, "source"); + FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source"); MetadataStore metadataStore = (MetadataStore) TestUtils.getPropertyValue(source, "metadataStore"); assertTrue(metadataStore instanceof SampleMetadataStore); assertEquals(metadataStore, context.getBean("customMetadataStore")); - FeedReaderMessageSource feedReaderMessageSource = (FeedReaderMessageSource) TestUtils.getPropertyValue(source, "feedReaderMessageSource"); - AbstractFeedFetcher fetcher = (AbstractFeedFetcher) TestUtils.getPropertyValue(feedReaderMessageSource, "fetcher"); - assertTrue(fetcher instanceof FileUrlFeedFetcher); - context = new ClassPathXmlApplicationContext( + AbstractFeedFetcher fetcher = (AbstractFeedFetcher) TestUtils.getPropertyValue(source, "fetcher"); + assertEquals("FileUrlFeedFetcher", fetcher.getClass().getSimpleName()); + context.destroy(); + } + + public void validateSuccessfulHttpConfigurationWithCustomMetadataStore() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "FeedMessageSourceBeanDefinitionParserTests-http-context.xml", this.getClass()); - adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class); - source = (FeedEntryReaderMessageSource) TestUtils.getPropertyValue(adapter, "source"); - feedReaderMessageSource = (FeedReaderMessageSource) TestUtils.getPropertyValue(source, "feedReaderMessageSource"); - fetcher = (AbstractFeedFetcher) TestUtils.getPropertyValue(feedReaderMessageSource, "fetcher"); + SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class); + FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source"); + MetadataStore metadataStore = (MetadataStore) TestUtils.getPropertyValue(source, "metadataStore"); + assertTrue(metadataStore instanceof SampleMetadataStore); + assertEquals(metadataStore, context.getBean("customMetadataStore")); + AbstractFeedFetcher fetcher = (AbstractFeedFetcher) TestUtils.getPropertyValue(source, "fetcher"); assertTrue(fetcher instanceof HttpURLFeedFetcher); context.destroy(); } diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/empty.rss b/spring-integration-feed/src/test/java/org/springframework/integration/feed/empty.rss new file mode 100644 index 0000000000..dc33a94ea5 --- /dev/null +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/empty.rss @@ -0,0 +1,20 @@ + + +Spring Integration +http://www.springsource.org/spring-integration + +Spring Integration is a really cool framework + +en-us +Copyright 2004-2010 SpringSource/VMWare +All Rights Reserved. +Tue, 12 Apr 2010 18:21:32 EST +240 + +http://www.springsource.org/sites/all/themes/dotorg09/images/dotorg09_logo.png +Spring Integration +http://www.springsource.org/spring-integration + + + +