camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1357114 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/language/simple/ast/ test/java/org/apache/camel/language/simple/
Date Wed, 04 Jul 2012 07:21:50 GMT
Author: davsclaus
Date: Wed Jul  4 07:21:49 2012
New Revision: 1357114

URL: http://svn.apache.org/viewvc?rev=1357114&view=rev
Log:
CAMEL-5415: Fixed simple empty quoted literals to be empty expression when used in predicates,
so you can compare against empty strings.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/DoubleQuoteStart.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SingleQuoteStart.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/DoubleQuoteStart.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/DoubleQuoteStart.java?rev=1357114&r1=1357113&r2=1357114&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/DoubleQuoteStart.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/DoubleQuoteStart.java
Wed Jul  4 07:21:49 2012
@@ -17,6 +17,7 @@
 package org.apache.camel.language.simple.ast;
 
 import org.apache.camel.Expression;
+import org.apache.camel.builder.ExpressionBuilder;
 import org.apache.camel.language.simple.types.SimpleToken;
 
 /**
@@ -39,11 +40,15 @@ public class DoubleQuoteStart extends Ba
 
     @Override
     public Expression createExpression(String expression) {
+        Expression answer = null;
         if (block != null) {
-            return block.createExpression(expression);
-        } else {
-            return null;
+            answer = block.createExpression(expression);
         }
+        if (answer == null) {
+            // there quoted literal is empty
+            answer = ExpressionBuilder.constantExpression("");
+        }
+        return answer;
     }
 
     @Override

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SingleQuoteStart.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SingleQuoteStart.java?rev=1357114&r1=1357113&r2=1357114&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SingleQuoteStart.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SingleQuoteStart.java
Wed Jul  4 07:21:49 2012
@@ -17,6 +17,7 @@
 package org.apache.camel.language.simple.ast;
 
 import org.apache.camel.Expression;
+import org.apache.camel.builder.ExpressionBuilder;
 import org.apache.camel.language.simple.types.SimpleToken;
 
 /**
@@ -39,11 +40,15 @@ public class SingleQuoteStart extends Ba
 
     @Override
     public Expression createExpression(String expression) {
+        Expression answer = null;
         if (block != null) {
-            return block.createExpression(expression);
-        } else {
-            return null;
+            answer = block.createExpression(expression);
         }
+        if (answer == null) {
+            // there quoted literal is empty
+            answer = ExpressionBuilder.constantExpression("");
+        }
+        return answer;
     }
 
     @Override

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java?rev=1357114&r1=1357113&r2=1357114&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
Wed Jul  4 07:21:49 2012
@@ -48,6 +48,24 @@ public class SimpleOperatorTest extends 
         assertPredicate("${body} != null", false);
     }
 
+    public void testEmptyValue() throws Exception {
+        exchange.getIn().setBody("");
+        assertPredicate("${in.body} == null", false);
+        assertPredicate("${body} == null", false);
+
+        exchange.getIn().setBody("");
+        assertPredicate("${in.body} == ''", true);
+        assertPredicate("${body} == \"\"", true);
+
+        exchange.getIn().setBody(" ");
+        assertPredicate("${in.body} == ''", false);
+        assertPredicate("${body} == \"\"", false);
+
+        exchange.getIn().setBody("Value");
+        assertPredicate("${in.body} == ''", false);
+        assertPredicate("${body} == \"\"", false);
+    }
+
     public void testAnd() throws Exception {
         assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == 123", true);
         assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == 444", false);



Mime
View raw message