Author: davsclaus
Date: Tue Jul 22 23:05:42 2008
New Revision: 678999

URL: http://svn.apache.org/viewvc?rev=678999&view=rev
Log:
Added spring based xpath header test

Added:
    
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderTest.java
    
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringXPathHeaderTest-context.xml
      - copied, changed from r678984, 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringSetHeaderTest-context.xml

Added: 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderTest.java?rev=678999&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderTest.java
 Tue Jul 22 23:05:42 2008
@@ -0,0 +1,51 @@
+package org.apache.camel.spring.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.CamelContext;
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Spring basesd XPathHeaderTest.
+ */
+public class SpringXPathHeaderTest extends ContextTestSupport {
+
+    public void testChoiceWithHeaderSelectCamel() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:camel");
+        mock.expectedBodiesReceived("<name>King</name>");
+        mock.expectedHeaderReceived("type", "Camel");
+
+        template.sendBodyAndHeader("direct:in", "<name>King</name>", "type", 
"Camel");
+
+        mock.assertIsSatisfied();
+    }
+
+    public void testChoiceWithNoHeaderSelectDonkey() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:donkey");
+        mock.expectedBodiesReceived("<name>Kong</name>");
+
+        // TODO: must send header type so $type evaluates
+        // however maybe we should support missing headers is evaluated to 
false
+        // if so the we should test by sending no headers
+        template.sendBodyAndHeader("direct:in", "<name>Kong</name>", "type", 
"Donkey");
+
+        mock.assertIsSatisfied();
+    }
+
+    public void testChoiceWithNoHeaderSelectOther() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:other");
+        mock.expectedBodiesReceived("<name>Other</name>");
+
+        // TODO: must send header type so $type evaluates
+        // however maybe we should support missing headers is evaluated to 
false
+        // if so the we should test by sending no headers
+        template.sendBodyAndHeader("direct:in", "<name>Other</name>", "type", 
"Foo");
+
+        mock.assertIsSatisfied();
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/SpringXPathHeaderTest-context.xml");
+    }
+
+}

Copied: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringXPathHeaderTest-context.xml
 (from r678984, 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringSetHeaderTest-context.xml)
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringXPathHeaderTest-context.xml?p2=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringXPathHeaderTest-context.xml&p1=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringSetHeaderTest-context.xml&r1=678984&r2=678999&rev=678999&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringSetHeaderTest-context.xml
 (original)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringXPathHeaderTest-context.xml
 Tue Jul 22 23:05:42 2008
@@ -22,15 +22,24 @@
        http://activemq.apache.org/camel/schema/spring 
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
     ">
 
-  <!-- START SNIPPET: example -->
-  <camelContext id="camel" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
-    <route>
-      <from uri="seda:a"/>
-      <setHeader headerName="oldBodyValue">
-        <simple>body</simple>
-      </setHeader>
-      <to uri="mock:b"/>     
-    </route>
-  </camelContext>
-  <!-- END SNIPPET: example -->
+    <!-- START SNIPPET: example -->
+    <camelContext id="camel" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
+        <route>
+            <from uri="direct:in"/>
+            <choice>
+                <when>
+                    <xpath>$type = 'Camel'</xpath>
+                    <to uri="mock:camel"/>
+                </when>
+                <when>
+                    <xpath>//name = 'Kong'</xpath>
+                    <to uri="mock:donkey"/>
+                </when>
+                <otherwise>
+                    <to uri="mock:other"/>
+                </otherwise>
+            </choice>
+        </route>
+    </camelContext>
+    <!-- END SNIPPET: example -->
 </beans>


Reply via email to