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 2010/06/30 07:59:35 UTC

svn commit: r959201 - in /camel/trunk/tests/camel-itest/src/test: java/org/apache/camel/itest/jms/ resources/ resources/org/apache/camel/itest/jms/

Author: davsclaus
Date: Wed Jun 30 05:59:35 2010
New Revision: 959201

URL: http://svn.apache.org/viewvc?rev=959201&view=rev
Log:
Added test based on user issue

Added:
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java   (with props)
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java   (with props)
    camel/trunk/tests/camel-itest/src/test/resources/myschema.xsd   (with props)
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/SpringJmsValidatorTest.xml
      - copied, changed from r959195, camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/FileToJmsTest-context.xml

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java?rev=959201&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java (added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java Wed Jun 30 05:59:35 2010
@@ -0,0 +1,83 @@
+/**
+ * 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.itest.jms;
+
+import javax.naming.Context;
+
+import org.apache.activemq.camel.component.ActiveMQComponent;
+import org.apache.camel.ValidationException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.BrowsableEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.jndi.JndiContext;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class JmsValidatorTest extends CamelTestSupport {
+
+    @Test
+    public void testJmsValidator() throws Exception {
+        String body = "<?xml version=\"1.0\"?>\n<p>Hello world!</p>";
+
+        template.sendBody("jms:queue:inbox", body);
+
+        // wait a sec
+        Thread.sleep(1000);
+
+        // it should end up in the valid and finally queue
+        BrowsableEndpoint bev = context.getEndpoint("jms:queue:valid", BrowsableEndpoint.class);
+        assertEquals(1, bev.getExchanges().size());
+
+        BrowsableEndpoint beiv = context.getEndpoint("jms:queue:invalid", BrowsableEndpoint.class);
+        assertEquals(0, beiv.getExchanges().size());
+
+        BrowsableEndpoint bef = context.getEndpoint("jms:queue:finally", BrowsableEndpoint.class);
+        assertEquals(1, bef.getExchanges().size());
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        JndiContext answer = new JndiContext();
+
+        // add ActiveMQ with embedded broker
+        ActiveMQComponent amq = ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false");
+        amq.setCamelContext(context);
+        answer.bind("jms", amq);
+        return answer;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jms:queue:inbox")
+                    .convertBodyTo(String.class)
+                    .doTry()
+                        .to("validator:file:src/test/resources/myschema.xsd")
+                        .to("jms:queue:valid")
+                    .doCatch(ValidationException.class)
+                        .to("jms:queue:invalid")
+                    .doFinally()
+                        .to("jms:queue:finally")
+                    .end();
+            }
+        };
+    }
+}

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java?rev=959201&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java (added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java Wed Jun 30 05:59:35 2010
@@ -0,0 +1,55 @@
+/**
+ * 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.itest.jms;
+
+import org.apache.camel.spi.BrowsableEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class SpringJmsValidatorTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/itest/jms/SpringJmsValidatorTest.xml");
+    }
+
+    @Test
+    public void testJmsValidator() throws Exception {
+        String body = "<?xml version=\"1.0\"?>\n<p>Hello world!</p>";
+
+        template.sendBody("jms:queue:inbox", body);
+
+        // wait a sec
+        Thread.sleep(1000);
+
+        // it should end up in the valid and finally queue
+        BrowsableEndpoint bev = context.getEndpoint("jms:queue:valid", BrowsableEndpoint.class);
+        assertEquals(1, bev.getExchanges().size());
+
+        BrowsableEndpoint beiv = context.getEndpoint("jms:queue:invalid", BrowsableEndpoint.class);
+        assertEquals(0, beiv.getExchanges().size());
+
+        BrowsableEndpoint bef = context.getEndpoint("jms:queue:finally", BrowsableEndpoint.class);
+        assertEquals(1, bef.getExchanges().size());
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest/src/test/resources/myschema.xsd
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/myschema.xsd?rev=959201&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/myschema.xsd (added)
+++ camel/trunk/tests/camel-itest/src/test/resources/myschema.xsd Wed Jun 30 05:59:35 2010
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+    <xsd:element name="p" type="xsd:string"/>
+</xsd:schema> 
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest/src/test/resources/myschema.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest/src/test/resources/myschema.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/tests/camel-itest/src/test/resources/myschema.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Copied: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/SpringJmsValidatorTest.xml (from r959195, camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/FileToJmsTest-context.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/SpringJmsValidatorTest.xml?p2=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/SpringJmsValidatorTest.xml&p1=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/FileToJmsTest-context.xml&r1=959195&r2=959201&rev=959201&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/FileToJmsTest-context.xml (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/SpringJmsValidatorTest.xml Wed Jun 30 05:59:35 2010
@@ -17,44 +17,30 @@
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:broker="http://activemq.apache.org/schema/core"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
-       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
-       http://activemq.apache.org/schema/core http://activemq.org/config/1.0/1.0.xsd">
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
 
-    <!-- camel stuff below to send and listen to broker with a spring JMS transaction manager -->
-    <bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
+    <bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
         <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
     </bean>
 
-    <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
-        <property name="connectionFactory" ref="jmsFactory"/>
-    </bean>
-
-    <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
-        <property name="connectionFactory" ref="jmsFactory"/>
-        <property name="transactionManager" ref="jmsTransactionManager"/>
-        <property name="transacted" value="true"/>
-        <property name="concurrentConsumers" value="1"/>
-    </bean>
-
-    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
-        <property name="connectionFactory" ref="jmsFactory"/>
-    </bean>
-
-
-    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-        <template id="camelTemplate"/>
-
-        <route>
-            <from uri="file://target/jmsfile?initialDelay=1000&amp;delay=5000"/>
-            <to uri="activemq:queue:foo"/>
-        </route>
-
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
         <route>
-            <from uri="activemq:queue:foo"/>
-            <to uri="mock:result"/>
+            <from uri="jms:queue:inbox"/>
+            <!-- enforce the body as a String to let it be easier to work with -->
+            <convertBodyTo type="String"/>
+            <doTry>
+                <to uri="validator:file:src/test/resources/myschema.xsd"/>
+                <to uri="jms:queue:valid"/>
+                <doCatch>
+                    <exception>org.apache.camel.ValidationException</exception>
+                    <to uri="jms:queue:invalid"/>
+                </doCatch>
+                <doFinally>
+                    <to uri="jms:queue:finally"/>
+                </doFinally>
+            </doTry>
         </route>
     </camelContext>