camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1144628 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ValueBuilder.java main/java/org/apache/camel/component/mock/AssertionClause.java test/java/org/apache/camel/builder/PredicateBuilderTest.java
Date Sat, 09 Jul 2011 10:08:03 GMT
Author: davsclaus
Date: Sat Jul  9 10:08:02 2011
New Revision: 1144628

URL: http://svn.apache.org/viewvc?rev=1144628&view=rev
Log:
CAMEL-4199: Added not() to ValueBuilder.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java?rev=1144628&r1=1144627&r2=1144628&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java Sat Jul
 9 10:08:02 2011
@@ -31,6 +31,7 @@ import org.apache.camel.Predicate;
  */
 public class ValueBuilder implements Expression {
     private Expression expression;
+    private boolean not;
 
     public ValueBuilder(Expression expression) {
         this.expression = expression;
@@ -249,6 +250,16 @@ public class ValueBuilder implements Exp
         return new ValueBuilder(newExp);
     }
 
+    /**
+     * Negates the built expression.
+     *
+     * @return the current builder
+     */
+    public ValueBuilder not() {
+        not = true;
+        return this;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
 
@@ -257,7 +268,11 @@ public class ValueBuilder implements Exp
      * predicate in different ways
      */
     protected Predicate onNewPredicate(Predicate predicate) {
-        return predicate;
+        if (not) {
+            return PredicateBuilder.not(predicate);
+        } else {
+            return predicate;
+        }
     }
 
     protected Expression asExpression(Object value) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java?rev=1144628&r1=1144627&r2=1144628&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
Sat Jul  9 10:08:02 2011
@@ -143,6 +143,7 @@ public abstract class AssertionClause ex
         }
 
         protected Predicate onNewPredicate(Predicate predicate) {
+            predicate = super.onNewPredicate(predicate);
             addPredicate(predicate);
             return predicate;
         }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java?rev=1144628&r1=1144627&r2=1144628&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java
Sat Jul  9 10:08:02 2011
@@ -122,6 +122,19 @@ public class PredicateBuilderTest extend
         assertDoesNotMatch(header("size").endsWith(9));
     }
 
+    public void testNot() throws Exception {
+        assertMatches(body().not().isInstanceOf(Integer.class));
+        assertMatches(header("name").not().isEqualTo("Claus"));
+        assertMatches(header("size").not().isLessThan(7));
+
+        try {
+            assertMatches(header("name").not().isEqualTo("James"));
+            fail("Should fail");
+        } catch (AssertionError e) {
+            // expected
+        }
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();



Mime
View raw message