Updated Branches:
  refs/heads/camel-2.11.x 0b72a3229 -> 93116d156
  refs/heads/camel-2.12.x e4a81eac7 -> 78de11e39


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/93116d15
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/93116d15
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/93116d15

Branch: refs/heads/camel-2.11.x
Commit: 93116d1569163b1a8521b38f205bb355f4b22c7e
Parents: 0b72a32
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Sep 13 10:46:16 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Sep 13 10:47:57 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/93116d15/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/93116d15/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;
+        }
+    }
+}

Reply via email to