camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r797725 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ValueBuilder.java test/java/org/apache/camel/builder/ValueBuilderTest.java
Date Sat, 25 Jul 2009 09:18:48 GMT
Author: davsclaus
Date: Sat Jul 25 09:18:46 2009
New Revision: 797725

URL: http://svn.apache.org/viewvc?rev=797725&view=rev
Log:
Added matches(expression) to ValueBuilder so you can use custom expressions with for example
mock endpoints.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ValueBuilderTest.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=797725&r1=797724&r2=797725&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
25 09:18:46 2009
@@ -52,6 +52,10 @@
     // Predicate builders
     // -------------------------------------------------------------------------
 
+    public Predicate matches(Expression expression) {
+        return onNewPredicate(PredicateBuilder.toPredicate(expression));
+    }
+
     public Predicate isNotEqualTo(Object value) {
         Expression right = asExpression(value);
         return onNewPredicate(PredicateBuilder.isNotEqualTo(expression, right));

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ValueBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ValueBuilderTest.java?rev=797725&r1=797724&r2=797725&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ValueBuilderTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ValueBuilderTest.java Sat
Jul 25 09:18:46 2009
@@ -17,6 +17,8 @@
 package org.apache.camel.builder;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
 import org.apache.camel.component.mock.MockEndpoint;
 
 /**
@@ -62,4 +64,31 @@
 
         assertMockEndpointsSatisfied();
     }
+
+    public void testMatches() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("mock:result");
+            }
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.message(0).body().matches(new Expression() {
+            public <T> T evaluate(Exchange exchange, Class<T> type) {
+                String body = exchange.getIn().getBody(String.class);
+                Boolean answer = body.contains("Camel");
+                return type.cast(answer);
+            }
+        });
+
+        template.sendBody("direct:start", "Camel rocks");
+        mock.assertIsSatisfied();
+
+        // send in a false test
+        mock.reset();
+        template.sendBody("direct:start", "Hello World");
+        mock.assertIsNotSatisfied();
+    }
 }



Mime
View raw message