You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2008/05/15 07:17:16 UTC
svn commit: r656509 - in /activemq/camel/trunk/components/camel-atom/src:
main/java/org/apache/camel/component/atom/
main/resources/META-INF/services/org/apache/camel/
test/java/org/apache/camel/component/atom/ test/resources/
Author: davsclaus
Date: Wed May 14 22:17:16 2008
New Revision: 656509
URL: http://svn.apache.org/viewvc?rev=656509&view=rev
Log:
CAMEL-504 - Refactored atom and added unit tests
Added:
activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomConverter.java
activemq/camel/trunk/components/camel-atom/src/main/resources/META-INF/services/org/apache/camel/TypeConverter (with props)
activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerTest.java
activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomProducerTest.java (with props)
activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/UpdatedDateFilterTest.java (with props)
Modified:
activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java
activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties
Added: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomConverter.java?rev=656509&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomConverter.java (added)
+++ activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomConverter.java Wed May 14 22:17:16 2008
@@ -0,0 +1,40 @@
+/**
+ * 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.component.atom;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.camel.Converter;
+
+/**
+ * Date converters.
+ */
+@Converter
+public final class AtomConverter {
+
+ public static final String DATE_PATTERN_NO_TIMEZONE = "yyyy-MM-dd'T'HH:mm:ss";
+
+ @Converter
+ public static Date toDate(String text) throws ParseException {
+ DateFormat sdf = new SimpleDateFormat(DATE_PATTERN_NO_TIMEZONE);
+ return sdf.parse(text);
+ }
+
+}
Added: activemq/camel/trunk/components/camel-atom/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=656509&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/main/resources/META-INF/services/org/apache/camel/TypeConverter (added)
+++ activemq/camel/trunk/components/camel-atom/src/main/resources/META-INF/services/org/apache/camel/TypeConverter Wed May 14 22:17:16 2008
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.component.atom
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-atom/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerTest.java?rev=656509&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerTest.java (added)
+++ activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntryPollingConsumerTest.java Wed May 14 22:17:16 2008
@@ -0,0 +1,57 @@
+/**
+ * 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.component.atom;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test for AtomEntryPollingConsumer
+ */
+public class AtomEntryPollingConsumerTest extends ContextTestSupport {
+
+ public void testResult() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result1");
+ mock.expectedMessageCount(7);
+ mock.assertIsSatisfied();
+ }
+
+ public void testResult2() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result2");
+ mock.expectedMessageCount(7);
+ mock.assertIsSatisfied();
+ }
+
+ public void testResult3() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result3");
+ mock.expectedMessageCount(4);
+ mock.assertIsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("atom:file:src/test/data/feed.atom?splitEntries=true").to("mock:result1");
+
+ from("atom:file:src/test/data/feed.atom?splitEntries=true&filter=false").to("mock:result2");
+
+ from("atom:file:src/test/data/feed.atom?splitEntries=true&filter=true&lastUpdate=2007-11-13T14:35:00").to("mock:result3");
+ }
+ };
+ }
+}
Modified: activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java?rev=656509&r1=656508&r2=656509&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java (original)
+++ activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomPollingConsumerTest.java Wed May 14 22:17:16 2008
@@ -1,3 +1,19 @@
+/**
+ * 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.component.atom;
import java.util.List;
@@ -30,13 +46,21 @@
List entries = in.getBody(List.class);
assertEquals(7, entries.size());
+ }
+ public void testUsingAtomUriParameter() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result2");
+ mock.expectedMessageCount(1);
+ mock.assertIsSatisfied();
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("atom:file:src/test/data/feed.atom?splitEntries=false").to("mock:result");
+
+ // this is a bit weird syntax that normally is not used using the atomUri parameter
+ from("atom:?atomUri=file:src/test/data/feed.atom&splitEntries=false").to("mock:result2");
}
};
}
Added: activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomProducerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomProducerTest.java?rev=656509&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomProducerTest.java (added)
+++ activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomProducerTest.java Wed May 14 22:17:16 2008
@@ -0,0 +1,35 @@
+/**
+ * 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.component.atom;
+
+import org.apache.camel.ContextTestSupport;
+
+/**
+ * Unit test for AtomProducer.
+ */
+public class AtomProducerTest extends ContextTestSupport {
+
+ public void testNotYetImplemented() throws Exception {
+ try {
+ context.getEndpoint("atom:file:target/out.atom").createProducer();
+ fail("Should have thrown an UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // ok
+ }
+ }
+
+}
Propchange: activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomProducerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomProducerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/UpdatedDateFilterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/UpdatedDateFilterTest.java?rev=656509&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/UpdatedDateFilterTest.java (added)
+++ activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/UpdatedDateFilterTest.java Wed May 14 22:17:16 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.component.atom;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+
+/**
+ * Unit test for UpdatedDateFilter
+ */
+public class UpdatedDateFilterTest extends TestCase {
+
+ public void testFilter() throws Exception {
+ Document<Feed> doc = AtomUtils.parseDocument("file:src/test/data/feed.atom");
+ assertNotNull(doc);
+
+ // 2007-11-13T13:35:25.014Z
+ Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT+1:00"));
+ cal.set(2007, Calendar.NOVEMBER, 13, 14, 35, 0);
+ System.out.println(cal.getTime());
+ EntryFilter filter = new UpdatedDateFilter(cal.getTime());
+
+ List<Entry> entries = doc.getRoot().getEntries();
+
+ // must reverse backwards
+ for (int i = entries.size() - 1; i > 0; i--) {
+ Entry entry = entries.get(i);
+ boolean valid = filter.isValidEntry(null, doc, entry);
+ // only the 3 last should be true
+ if (i > 3) {
+ assertEquals("not valid", false, valid);
+ } else {
+ assertEquals("valid", true, valid);
+ }
+ }
+ }
+
+}
Propchange: activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/UpdatedDateFilterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-atom/src/test/java/org/apache/camel/component/atom/UpdatedDateFilterTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties?rev=656509&r1=656508&r2=656509&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties Wed May 14 22:17:16 2008
@@ -18,15 +18,23 @@
#
# The logging properties used for eclipse testing, We want to see debug output on the console.
#
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
#log4j.logger.org.apache.activemq=DEBUG
#log4j.logger.org.apache.camel=DEBUG
log4j.logger.org.apache.camel.impl.converter=INFO
+log4j.logger.org.apache.camel.component.atom=DEBUG
# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-atom-test.log
+log4j.appender.file.append=true
\ No newline at end of file