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 2012/02/12 11:49:00 UTC

svn commit: r1243234 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/model/language/MethodCallExpression.java test/java/org/apache/camel/issues/MethodClassByTypeIssueTest.java test/java/org/apache/camel/issues/MyTransformBean.java

Author: davsclaus
Date: Sun Feb 12 10:49:00 2012
New Revision: 1243234

URL: http://svn.apache.org/viewvc?rev=1243234&view=rev
Log:
CAMEL-4997: Improved method call expression to detect class type passed in as an instance due Object type.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MethodClassByTypeIssueTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MyTransformBean.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java?rev=1243234&r1=1243233&r2=1243234&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java Sun Feb 12 10:49:00 2012
@@ -75,8 +75,9 @@ public class MethodCallExpression extend
     
     public MethodCallExpression(Object instance, String method) {
         super(ObjectHelper.className(instance));
-        this.instance = instance;
-        this.method = method;
+        // must use setter as they have special logic
+        setInstance(instance);
+        setMethod(method);
     }
 
     public MethodCallExpression(Class<?> type) {
@@ -123,6 +124,7 @@ public class MethodCallExpression extend
 
     public void setBeanType(Class<?> beanType) {
         this.beanType = beanType;
+        this.instance = null;
     }
 
     public String getBeanTypeName() {
@@ -138,7 +140,14 @@ public class MethodCallExpression extend
     }
 
     public void setInstance(Object instance) {
-        this.instance = instance;
+        // people may by mistake pass in a class type as the instance
+        if (instance instanceof Class) {
+            this.beanType = (Class<?>) instance;
+            this.instance = null;
+        } else {
+            this.beanType = null;
+            this.instance = instance;
+        }
     }
 
     @Override

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MethodClassByTypeIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MethodClassByTypeIssueTest.java?rev=1243234&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MethodClassByTypeIssueTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MethodClassByTypeIssueTest.java Sun Feb 12 10:49:00 2012
@@ -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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class MethodClassByTypeIssueTest extends ContextTestSupport {
+    
+    private Object methodClass = MyTransformBean.class;
+    
+    public void testMethodClassByTypeAIssue() throws Exception {
+        getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:a", "World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testMethodClassByTypeBIssue() throws Exception {
+        getMockEndpoint("mock:b").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:b", "World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a")
+                    .transform().method(MyTransformBean.class, "transformMe")
+                    .to("mock:a");
+
+                from("direct:b")
+                    .transform().method(methodClass, "transformMe")
+                    .to("mock:b");
+            }
+        };
+    }
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MyTransformBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MyTransformBean.java?rev=1243234&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MyTransformBean.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/MyTransformBean.java Sun Feb 12 10:49:00 2012
@@ -0,0 +1,27 @@
+/**
+ * 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.issues;
+
+/**
+ *
+ */
+public class MyTransformBean {
+    
+    public String transformMe(String data) {
+        return "Hello " + data;
+    }
+}