Author: janstey
Date: Wed Dec 3 11:57:47 2008
New Revision: 723046
URL: http://svn.apache.org/viewvc?rev=723046&view=rev
Log:
CAMEL-1101 - Add dataformat for converting between RSS data types and XML.
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/RssDataFormat.java
(with props)
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssConverter.java
(with props)
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java
(with props)
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssDataFormatTest.java
(with props)
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssFilterWithXPathTest.java
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
activemq/camel/trunk/components/camel-rss/pom.xml
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithFilterTest.java
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerTest.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
Wed Dec 3 11:57:47 2008
@@ -27,6 +27,7 @@
import org.apache.camel.model.dataformat.HL7DataFormat;
import org.apache.camel.model.dataformat.JaxbDataFormat;
import org.apache.camel.model.dataformat.JsonDataFormat;
+import org.apache.camel.model.dataformat.RssDataFormat;
import org.apache.camel.model.dataformat.SerializationDataFormat;
import org.apache.camel.model.dataformat.StringDataFormat;
import org.apache.camel.model.dataformat.XMLBeansDataFormat;
@@ -125,6 +126,13 @@
}
/**
+ * Uses the RSS data format
+ */
+ public T rss() {
+ return dataFormat(new RssDataFormat());
+ }
+
+ /**
* Uses the Java Serialization data format
*/
public T serialization() {
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java
Wed Dec 3 11:57:47 2008
@@ -30,6 +30,7 @@
import org.apache.camel.model.dataformat.FlatpackDataFormat;
import org.apache.camel.model.dataformat.HL7DataFormat;
import org.apache.camel.model.dataformat.JaxbDataFormat;
+import org.apache.camel.model.dataformat.RssDataFormat;
import org.apache.camel.model.dataformat.SerializationDataFormat;
import org.apache.camel.model.dataformat.StringDataFormat;
import org.apache.camel.model.dataformat.XMLBeansDataFormat;
@@ -57,6 +58,7 @@
@XmlElement(required = false, name = "flatpack", type =
FlatpackDataFormat.class),
@XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
@XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
+ @XmlElement(required = false, name = "rss", type = RssDataFormat.class),
@XmlElement(required = false, name = "serialization", type =
SerializationDataFormat.class),
@XmlElement(required = false, name = "string", type =
StringDataFormat.class),
@XmlElement(required = false, name = "xmlBeans", type =
XMLBeansDataFormat.class),
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java
Wed Dec 3 11:57:47 2008
@@ -30,6 +30,7 @@
import org.apache.camel.model.dataformat.FlatpackDataFormat;
import org.apache.camel.model.dataformat.HL7DataFormat;
import org.apache.camel.model.dataformat.JaxbDataFormat;
+import org.apache.camel.model.dataformat.RssDataFormat;
import org.apache.camel.model.dataformat.SerializationDataFormat;
import org.apache.camel.model.dataformat.StringDataFormat;
import org.apache.camel.model.dataformat.XMLBeansDataFormat;
@@ -57,6 +58,7 @@
@XmlElement(required = false, name = "flatpack", type =
FlatpackDataFormat.class),
@XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
@XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
+ @XmlElement(required = false, name = "rss", type = RssDataFormat.class),
@XmlElement(required = false, name = "serialization", type =
SerializationDataFormat.class),
@XmlElement(required = false, name = "string", type =
StringDataFormat.class),
@XmlElement(required = false, name = "xmlBeans", type =
XMLBeansDataFormat.class),
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsType.java
Wed Dec 3 11:57:47 2008
@@ -45,6 +45,7 @@
@XmlElement(required = false, name = "hl7", type =
HL7DataFormat.class),
@XmlElement(required = false, name = "jaxb", type =
JaxbDataFormat.class),
@XmlElement(required = false, name = "json", type =
JsonDataFormat.class),
+ @XmlElement(required = false, name = "rss", type =
RssDataFormat.class),
@XmlElement(required = false, name = "serialization", type =
SerializationDataFormat.class),
@XmlElement(required = false, name = "string", type =
StringDataFormat.class),
@XmlElement(required = false, name = "xmlBeans", type =
XMLBeansDataFormat.class),
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/RssDataFormat.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/RssDataFormat.java?rev=723046&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/RssDataFormat.java
(added)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/RssDataFormat.java
Wed Dec 3 11:57:47 2008
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.model.dataformat;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.spi.DataFormat;
+
+/**
+ * Represents a <a href="http://activemq.apache.org/camel/rss.html">RSS</a>
[EMAIL PROTECTED] org.apache.camel.spi.DataFormat}.
+ *
+ */
[EMAIL PROTECTED](name = "rss")
[EMAIL PROTECTED](XmlAccessType.FIELD)
+public class RssDataFormat extends DataFormatType {
+
+ public RssDataFormat() {
+ super("org.apache.camel.dataformat.rss.RssDataFormat");
+ }
+
+}
\ No newline at end of file
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/RssDataFormat.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
(original)
+++
activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
Wed Dec 3 11:57:47 2008
@@ -22,6 +22,7 @@
DataFormatsType
JaxbDataFormat
JsonDataFormat
+RssDataFormat
SerializationDataFormat
StringDataFormat
XMLBeansDataFormat
Modified: activemq/camel/trunk/components/camel-rss/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/pom.xml?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-rss/pom.xml (original)
+++ activemq/camel/trunk/components/camel-rss/pom.xml Wed Dec 3 11:57:47 2008
@@ -12,7 +12,7 @@
<description>Camel RSS support</description>
<properties>
-
<camel.osgi.export.pkg>org.apache.camel.component.rss.*</camel.osgi.export.pkg>
+
<camel.osgi.export.pkg>org.apache.camel.component.rss.*;org.apache.camel.dataformat.rss.*</camel.osgi.export.pkg>
</properties>
<dependencies>
Modified:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java
(original)
+++
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/component/rss/RssEndpoint.java
Wed Dec 3 11:57:47 2008
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.rss;
+import java.util.Arrays;
import java.util.Date;
import com.sun.syndication.feed.synd.SyndEntry;
@@ -28,7 +29,10 @@
import org.apache.camel.component.feed.FeedComponent;
import org.apache.camel.component.feed.FeedEndpoint;
import org.apache.camel.component.feed.FeedPollingConsumer;
+import org.apache.camel.dataformat.rss.RssDataFormat;
import org.apache.camel.impl.DefaultPollingEndpoint;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* An <a href="http://activemq.apache.org/camel/rss.html">RSS Endpoint</a>.
@@ -38,7 +42,8 @@
/**
* Header key for the [EMAIL PROTECTED]
com.sun.syndication.feed.synd.SyndFeed} object is stored on the in message on
the exchange.
*/
- public static final String HEADER_RSS_FEED =
"org.apache.camel.component.rss.feed";
+ public static final String HEADER_RSS_FEED =
"org.apache.camel.component.rss.feed";
+ protected static final transient Log LOG =
LogFactory.getLog(RssEndpoint.class);
public RssEndpoint(String endpointUri, FeedComponent component, String
feedUri) {
super(endpointUri, component, feedUri);
@@ -55,14 +60,22 @@
@Override
public Exchange createExchange(Object feed) {
Exchange exchange = createExchangeWithFeedHeader(feed,
HEADER_RSS_FEED);
- exchange.getIn().setBody(((SyndFeed)feed).getEntries());
+ exchange.getIn().setBody(feed);
return exchange;
}
@Override
public Exchange createExchange(Object feed, Object entry) {
Exchange exchange = createExchangeWithFeedHeader(feed,
HEADER_RSS_FEED);
- exchange.getIn().setBody(entry);
+ SyndFeed newFeed;
+ try {
+ newFeed = (SyndFeed)((SyndFeed) feed).clone();
+ newFeed.setEntries(Arrays.asList(new Object[] {entry}));
+ } catch (CloneNotSupportedException e) {
+ LOG.debug("Could not create a new feed.", e);
+ newFeed = null;
+ }
+ exchange.getIn().setBody(newFeed);
return exchange;
}
Added:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssConverter.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssConverter.java?rev=723046&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssConverter.java
(added)
+++
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssConverter.java
Wed Dec 3 11:57:47 2008
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.dataformat.rss;
+
+import java.io.StringReader;
+
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.SyndFeedOutput;
+import org.apache.camel.Converter;
+
[EMAIL PROTECTED]
+public final class RssConverter {
+ private RssConverter() {
+ }
+
+ @Converter
+ public static String feedToXml(SyndFeed feed) throws FeedException {
+ SyndFeedOutput out = new SyndFeedOutput();
+ return out.outputString(feed);
+ }
+
+ @Converter
+ public static SyndFeed xmlToFeed(String xml) throws FeedException {
+ SyndFeedInput input = new SyndFeedInput();
+ return input.build(new StringReader(xml));
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java?rev=723046&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java
(added)
+++
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java
Wed Dec 3 11:57:47 2008
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.dataformat.rss;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+/**
+ * RSS DataFormat
+ * <p/>
+ * This data format supports two operations:
+ * <ul>
+ * <li>marshal = from ROME SyndFeed to XML String </li>
+ * <li>unmarshal = from XML String to ROME SyndFeed </li>
+ * </ul>
+ * <p/>
+ * Uses <a href="https://rome.dev.java.net/">ROME</a> for RSS parsing.
+ * <p/>
+ */
+public class RssDataFormat implements DataFormat {
+ protected static final transient Log LOG =
LogFactory.getLog(RssDataFormat.class);
+
+ public void marshal(Exchange exchange, Object body, OutputStream out)
throws Exception {
+ SyndFeed feed = ExchangeHelper.convertToMandatoryType(exchange,
SyndFeed.class, body);
+ String xml = RssConverter.feedToXml(feed);
+ if (xml != null) {
+ out.write(xml.getBytes());
+ } else {
+ LOG.debug("Couldn't marshal RSS feed to XML.");
+ }
+ }
+
+ public Object unmarshal(Exchange exchange, InputStream in) throws
Exception {
+ String xml = ExchangeHelper.convertToMandatoryType(exchange,
String.class, in);
+ return RssConverter.xmlToFeed(xml);
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-rss/src/main/java/org/apache/camel/dataformat/rss/RssDataFormat.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithFilterTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithFilterTest.java?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithFilterTest.java
(original)
+++
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntryPollingConsumerWithFilterTest.java
Wed Dec 3 11:57:47 2008
@@ -23,7 +23,10 @@
import javax.naming.Context;
+import junit.framework.Assert;
+
import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
@@ -56,7 +59,7 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
-
from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=500").
+
from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=100").
filter().method("myBean", "isAfterDate").to("mock:result");
}
};
@@ -70,7 +73,9 @@
}
public boolean isAfterDate(Exchange ex) {
- SyndEntry entry = ex.getIn().getBody(SyndEntry.class);
+ SyndFeed feed = ex.getIn().getBody(SyndFeed.class);
+ Assert.assertTrue(feed.getEntries().size() == 1);
+ SyndEntry entry = (SyndEntry) feed.getEntries().get(0);
return entry.getPublishedDate().after(time);
}
}
Modified:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerTest.java?rev=723046&r1=723045&r2=723046&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerTest.java
(original)
+++
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssPollingConsumerTest.java
Wed Dec 3 11:57:47 2008
@@ -36,20 +36,20 @@
Exchange exchange = mock.getExchanges().get(0);
Message in = exchange.getIn();
assertNotNull(in);
- assertTrue(in.getBody() instanceof List);
+ assertTrue(in.getBody() instanceof SyndFeed);
assertTrue(in.getHeader(RssEndpoint.HEADER_RSS_FEED) instanceof
SyndFeed);
SyndFeed feed = in.getHeader(RssEndpoint.HEADER_RSS_FEED,
SyndFeed.class);
assertTrue(feed.getAuthor().contains("Jonathan Anstey"));
- List entries = in.getBody(List.class);
- assertEquals(10, entries.size());
+ SyndFeed body = in.getBody(SyndFeed.class);
+ assertEquals(10, body.getEntries().size());
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
-
from("rss:file:src/test/data/rss20.xml?splitEntries=false").to("mock:result");
+
from("rss:file:src/test/data/rss20.xml?splitEntries=false&consumer.delay=100").to("mock:result");
}
};
}
Added:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssDataFormatTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssDataFormatTest.java?rev=723046&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssDataFormatTest.java
(added)
+++
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssDataFormatTest.java
Wed Dec 3 11:57:47 2008
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.dataformat.rss;
+
+import java.util.List;
+
+import com.sun.syndication.feed.synd.SyndFeed;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.rss.RssEndpoint;
+import org.apache.camel.component.rss.RssUtils;
+
+public class RssDataFormatTest extends ContextTestSupport {
+ private String feedXml;
+ private SyndFeed feed;
+
+ public void testMarshalling() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:marshal");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(byte[].class);
+ mock.message(0).bodyAs(String.class).contains(feedXml);
+ mock.assertIsSatisfied();
+ }
+
+ public void testUnmarshalling() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:unmarshal");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(SyndFeed.class);
+ mock.message(0).bodyAs(SyndFeed.class).equals(feed);
+ mock.assertIsSatisfied();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ feed = RssUtils.createFeed("file:src/test/data/rss20.xml");
+ feedXml = RssConverter.feedToXml(feed);
+ super.setUp();
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+
from("rss:file:src/test/data/rss20.xml?splitEntries=false&consumer.delay=100").marshal().rss().to("mock:marshal");
+
from("rss:file:src/test/data/rss20.xml?splitEntries=false&consumer.delay=100").marshal().rss().unmarshal().rss().to("mock:unmarshal");
+ }
+ };
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssDataFormatTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssFilterWithXPathTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssFilterWithXPathTest.java?rev=723046&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssFilterWithXPathTest.java
(added)
+++
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssFilterWithXPathTest.java
Wed Dec 3 11:57:47 2008
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.dataformat.rss;
+
+import java.util.List;
+
+import com.sun.syndication.feed.synd.SyndFeed;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.rss.RssEndpoint;
+import org.apache.camel.component.rss.RssUtils;
+
+public class RssFilterWithXPathTest extends ContextTestSupport {
+
+ public void testMarshalToXmlThenFilter() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(6);
+ mock.assertIsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ // only entries with Camel in the title will get through the
filter
+
from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=100").marshal().rss().
+
filter().xpath("//item/title[contains(.,'Camel')]").to("mock:result");
+ }
+ };
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssFilterWithXPathTest.java
------------------------------------------------------------------------------
svn:eol-style = native