camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r673135 - in /activemq/camel/trunk: ./ camel-core/ camel-core/src/test/java/org/apache/camel/ components/camel-script/ components/camel-script/src/test/java/org/apache/camel/builder/script/
Date Tue, 01 Jul 2008 16:48:24 GMT
Author: ammulder
Date: Tue Jul  1 09:48:23 2008
New Revision: 673135

URL: http://svn.apache.org/viewvc?rev=673135&view=rev
Log:
Add a test that demonstrates how Python expressions evaluate to null
  and therefore always "false"
Add a base test class method that takes apecific headers
Add some IntelliJ ignores

Added:
    activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java
Modified:
    activemq/camel/trunk/   (props changed)
    activemq/camel/trunk/camel-core/   (props changed)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
    activemq/camel/trunk/components/camel-script/   (props changed)
    activemq/camel/trunk/components/camel-script/pom.xml

Propchange: activemq/camel/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jul  1 09:48:23 2008
@@ -1 +1,2 @@
 target
+*.i??

Propchange: activemq/camel/trunk/camel-core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jul  1 09:48:23 2008
@@ -5,3 +5,4 @@
 target
 .settings
 eclipse-classes
+*.i??

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java?rev=673135&r1=673134&r2=673135&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
Tue Jul  1 09:48:23 2008
@@ -17,6 +17,7 @@
 package org.apache.camel;
 
 import java.util.List;
+import java.util.Map;
 
 import javax.naming.Context;
 
@@ -195,6 +196,26 @@
     }
 
     /**
+     * Sends a message to the given endpoint URI with the body value and specified headers
+     *
+     * @param endpointUri the URI of the endpoint to send to
+     * @param body        the body for the message
+     * @param headers     any headers to set on the message
+     */
+    protected void sendBody(String endpointUri, final Object body, final Map<String, Object>
headers) {
+        template.send(endpointUri, new Processor() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setBody(body);
+                in.setHeader("testCase", getName());
+                for (Map.Entry<String, Object> entry : headers.entrySet()) {
+                    in.setHeader(entry.getKey(), entry.getValue());
+                }
+            }
+        });
+    }
+
+    /**
      * Sends messages to the given endpoint for each of the specified bodies
      *
      * @param endpointUri the endpoint URI to send to

Propchange: activemq/camel/trunk/components/camel-script/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jul  1 09:48:23 2008
@@ -5,3 +5,4 @@
 .classpath
 .project
 .settings
+*.i??

Modified: activemq/camel/trunk/components/camel-script/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-script/pom.xml?rev=673135&r1=673134&r2=673135&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-script/pom.xml (original)
+++ activemq/camel/trunk/components/camel-script/pom.xml Tue Jul  1 09:48:23 2008
@@ -166,7 +166,11 @@
             <!--<include>**/*Test.*</include>-->
           </includes>
           <excludes>
-            <exclude>**/*Test.*</exclude>
+            <!-- These tests fail/error; I haven't investigated yet.
+                 The PythonExpressionTest also fails but that is demonstrating a problem
that should be fixed. -->
+            <exclude>**/PythonLanguageTest.*</exclude>
+            <exclude>**/JavaScriptLanguageTest.*</exclude>
+            <exclude>**/GroovyFilterTest.*</exclude>
           </excludes>
         </configuration>
       </plugin>

Added: activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java?rev=673135&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java
(added)
+++ activemq/camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/PythonExpressionTest.java
Tue Jul  1 09:48:23 2008
@@ -0,0 +1,49 @@
+package org.apache.camel.builder.script;
+
+import java.util.Map;
+import java.util.HashMap;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Tests a routing expression using Python
+ */
+public class PythonExpressionTest extends ContextTestSupport {
+    public void testSendMatchingMessage() throws Exception {
+        // Currently, this test fails because the Python expression in createRouteBuilder
+        // below returns null and that is treated as 'false', therefore it's as if the
+        // message didn't match the expression
+        // To fix that, we need to figure out how to get the expression to return a boolean
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+        getMockEndpoint("mock:unmatched").expectedMessageCount(0);
+
+        Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("foo", "bar");
+        sendBody("direct:start", "hello", headers);
+
+        assertMockEndpointsSatisifed();
+    }
+
+    public void testSendNonMatchingMessage() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+        getMockEndpoint("mock:unmatched").expectedMessageCount(1);
+
+        Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("foo", "foo");
+        sendBody("direct:start", "hello", headers);
+
+        assertMockEndpointsSatisifed();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start").choice().
+                        // The following python expression should return a boolean
+                        // but it seems to return null instead -- what's up with that?
+                        when().python("request.headers['foo'] == 'bar'").to("mock:result")
+                        .otherwise().to("mock:unmatched");
+            }
+        };
+    }
+}



Mime
View raw message