Author: davsclaus
Date: Wed Apr 13 14:50:54 2011
New Revision: 1091807

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

Added:
    
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/Animal.java
    
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyInvokeMethodTest.java
      - copied, changed from r1091802, 
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovySetHeaderTest.java
    
camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/Animal.java
    
camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlInvokeMethodTest.java

Added: 
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/Animal.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/Animal.java?rev=1091807&view=auto
==============================================================================
--- 
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/Animal.java
 (added)
+++ 
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/Animal.java
 Wed Apr 13 14:50:54 2011
@@ -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.language.groovy;
+
+/**
+ *
+ */
+public class Animal {
+    private String name;
+    private int age;
+    private Animal friend;
+
+    public Animal(String name, int age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public Animal getFriend() {
+        return friend;
+    }
+
+    public void setFriend(Animal friend) {
+        this.friend = friend;
+    }
+
+    public boolean isDangerous() {
+        return name.contains("Tiger");
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+}
+

Copied: 
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyInvokeMethodTest.java
 (from r1091802, 
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovySetHeaderTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyInvokeMethodTest.java?p2=camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyInvokeMethodTest.java&p1=camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovySetHeaderTest.java&r1=1091802&r2=1091807&rev=1091807&view=diff
==============================================================================
--- 
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovySetHeaderTest.java
 (original)
+++ 
camel/trunk/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyInvokeMethodTest.java
 Wed Apr 13 14:50:54 2011
@@ -16,9 +16,6 @@
  */
 package org.apache.camel.language.groovy;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -26,24 +23,16 @@ import org.apache.camel.component.mock.M
 /**
  * @version 
  */
-public class GroovySetHeaderTest extends ContextTestSupport {
+public class GroovyInvokeMethodTest extends ContextTestSupport {
 
-    public void testSetHeader() throws Exception {
+    public void testInvokeMethod() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        mock.expectedBodiesReceived("Hello World");
-        mock.expectedHeaderReceived("one", "einz");
-        mock.expectedHeaderReceived("two", "twei");
-        mock.expectedHeaderReceived("beer", "Carlsberg");
-        mock.expectedHeaderReceived("drink", "Carlsberg");
-        mock.expectedHeaderReceived("camelId", "camel-1");
-
-        Map<String, Object> headers = new HashMap<String, Object>();
-        headers.put("one", "einz");
-        headers.put("two", "twei");
-        headers.put("beer", "Carlsberg");
+        mock.expectedHeaderReceived("name", "Tony the Tiger");
+        mock.expectedHeaderReceived("dangerous", true);
 
-        template.sendBodyAndHeaders("direct:start", "Hello World", headers);
+        Animal animal = new Animal("Tony the Tiger", 12);
+        template.sendBody("direct:start", animal);
 
         assertMockEndpointsSatisfied();
     }
@@ -53,14 +42,10 @@ public class GroovySetHeaderTest extends
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                
                 from("direct:start")
-                    .setHeader("drink").groovy("request.headers.beer")
-                    // shows how to access the camelContext value
-                    .setHeader("camelId").groovy("camelContext.name")
+                    .setHeader("name").groovy("request.body.name")
+                    
.setHeader("dangerous").groovy("request.body.isDangerous()")
                     .to("mock:result");
-                
-                
             }
         };
     }

Added: 
camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/Animal.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/Animal.java?rev=1091807&view=auto
==============================================================================
--- 
camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/Animal.java
 (added)
+++ 
camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/Animal.java
 Wed Apr 13 14:50:54 2011
@@ -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.language.ognl;
+
+/**
+ *
+ */
+public class Animal {
+    private String name;
+    private int age;
+    private Animal friend;
+
+    public Animal(String name, int age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public Animal getFriend() {
+        return friend;
+    }
+
+    public void setFriend(Animal friend) {
+        this.friend = friend;
+    }
+
+    public boolean isDangerous() {
+        return name.contains("Tiger");
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+}
+

Added: 
camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlInvokeMethodTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlInvokeMethodTest.java?rev=1091807&view=auto
==============================================================================
--- 
camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlInvokeMethodTest.java
 (added)
+++ 
camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/OgnlInvokeMethodTest.java
 Wed Apr 13 14:50:54 2011
@@ -0,0 +1,52 @@
+/**
+ * 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.language.ognl;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ *
+ */
+public class OgnlInvokeMethodTest extends ContextTestSupport {
+
+    public void testInvokeMethod() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived("name", "Tony the Tiger");
+        mock.expectedHeaderReceived("dangerous", true);
+
+        Animal animal = new Animal("Tony the Tiger", 12);
+        template.sendBody("direct:start", animal);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .setHeader("name").ognl("request.body.name")
+                    .setHeader("dangerous").ognl("request.body.isDangerous()")
+                    .to("mock:result");
+            }
+        };
+    }
+}


Reply via email to