camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-6743: Bean parameter binding with boolean types should eval as predicates.
Date Fri, 13 Sep 2013 08:48:30 GMT
Updated Branches:
  refs/heads/master 51ec17fc9 -> 745a85abb


CAMEL-6743: Bean parameter binding with boolean types should eval as predicates.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/745a85ab
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/745a85ab
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/745a85ab

Branch: refs/heads/master
Commit: 745a85abbfce62da6c2b35561bd1df6e88143d66
Parents: 51ec17f
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Sep 13 10:46:16 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Sep 13 10:48:24 2013 +0200

----------------------------------------------------------------------
 .../DefaultAnnotationExpressionFactory.java     | 10 ++-
 ...eanWithExpressionInjectionPredicateTest.java | 70 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/745a85ab/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
b/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
index 1038cdf..cf961c3 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
@@ -21,9 +21,11 @@ import java.lang.reflect.Method;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
 import org.apache.camel.language.LanguageAnnotation;
 import org.apache.camel.spi.Language;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.PredicateToExpressionAdapter;
 
 /**
  * Default implementation of the {@link AnnotationExpressionFactory}.
@@ -42,7 +44,13 @@ public class DefaultAnnotationExpressionFactory implements AnnotationExpressionF
             throw new IllegalArgumentException("Cannot find the language: " + languageName
+ " on the classpath");
         }
         String expression = getExpressionFromAnnotation(annotation);
-        return language.createExpression(expression);
+
+        if (expressionReturnType == Boolean.class || expressionReturnType == boolean.class)
{
+            Predicate predicate = language.createPredicate(expression);
+            return PredicateToExpressionAdapter.toExpression(predicate);
+        } else {
+            return language.createExpression(expression);
+        }
     }
 
     protected String getExpressionFromAnnotation(Annotation annotation) {

http://git-wip-us.apache.org/repos/asf/camel/blob/745a85ab/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithExpressionInjectionPredicateTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithExpressionInjectionPredicateTest.java
b/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithExpressionInjectionPredicateTest.java
new file mode 100644
index 0000000..62529c6
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithExpressionInjectionPredicateTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.component.bean;
+
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.language.Simple;
+import org.apache.camel.util.jndi.JndiContext;
+
+/**
+ * @version 
+ */
+public class BeanWithExpressionInjectionPredicateTest extends ContextTestSupport {
+    protected MyBean myBean = new MyBean();
+
+    public void testSendMessage() throws Exception {
+        template.sendBody("direct:in", "Hello");
+
+        assertEquals("Hello", myBean.body);
+        assertEquals(false, myBean.foo);
+    }
+
+    public void testSendMessageWithFoo() throws Exception {
+        template.sendBodyAndHeader("direct:in", "Hello", "foo", 123);
+
+        assertEquals("Hello", myBean.body);
+        assertEquals(true, myBean.foo);
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        JndiContext answer = new JndiContext();
+        answer.bind("myBean", myBean);
+        return answer;
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:in").beanRef("myBean");
+            }
+        };
+    }
+
+    public static class MyBean {
+        public String body;
+        public boolean foo;
+
+        public void read(String body, @Simple("${header.foo} != null") boolean foo) {
+            this.body = body;
+            this.foo = foo;
+        }
+    }
+}


Mime
View raw message