camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/4] git commit: CAMEL-7769: Mock - Allow to invoke a method while specifying an assertion
Date Sat, 30 Aug 2014 13:03:12 GMT
CAMEL-7769: Mock - Allow to invoke a method while specifying an assertion


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

Branch: refs/heads/master
Commit: e28e8ac4de10c6d5f89672808847644ad4844982
Parents: eab0618
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Aug 30 11:20:06 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Aug 30 11:20:06 2014 +0200

----------------------------------------------------------------------
 .../apache/camel/builder/ExpressionBuilder.java | 23 ++++++++++++++++++++
 .../org/apache/camel/builder/ValueBuilder.java  | 11 ++++++++++
 .../issues/TryCatchWithSplitIssueTest.java      |  4 ++--
 .../onexception/OnExceptionHandledTest.java     |  2 +-
 4 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e28e8ac4/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
index 44624d8..dfb4b99 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
@@ -830,6 +830,29 @@ public final class ExpressionBuilder {
     }
 
     /**
+     * Returns the expression for invoking a method (support OGNL syntax) on the given expression
+     *
+     * @param exp   the expression to evaluate and invoke the method on its result
+     * @param ognl  methods to invoke on the evaluated expression in a simple OGNL syntax
+     */
+    public static Expression ognlExpression(final Expression exp, final String ognl) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                Object value = exp.evaluate(exchange, Object.class);
+                if (value == null) {
+                    return null;
+                }
+                return new MethodCallExpression(value, ognl).evaluate(exchange);
+            }
+
+            @Override
+            public String toString() {
+                return "ognl(" + exp + ", " + ognl + ")";
+            }
+        };
+    }
+
+    /**
      * Returns the expression for the exchanges camelContext invoking methods defined
      * in a simple OGNL notation
      *

http://git-wip-us.apache.org/repos/asf/camel/blob/e28e8ac4/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
index 4724ddd..60782c3 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
@@ -282,6 +282,17 @@ public class ValueBuilder implements Expression, Predicate {
     }
 
     /**
+     * Invokes the method with the given name (supports OGNL syntax).
+     *
+     * @param methodName  name of method to invoke.
+     * @return the current builder
+     */
+    public ValueBuilder method(String methodName) {
+        Expression newExp = ExpressionBuilder.ognlExpression(expression, methodName);
+        return onNewValueBuilder(newExp);
+    }
+
+    /**
      * Negates the built expression.
      *
      * @return the current builder

http://git-wip-us.apache.org/repos/asf/camel/blob/e28e8ac4/camel-core/src/test/java/org/apache/camel/issues/TryCatchWithSplitIssueTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/TryCatchWithSplitIssueTest.java
b/camel-core/src/test/java/org/apache/camel/issues/TryCatchWithSplitIssueTest.java
index 2dd5e3f..043b902 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/TryCatchWithSplitIssueTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/TryCatchWithSplitIssueTest.java
@@ -31,7 +31,7 @@ public class TryCatchWithSplitIssueTest extends ContextTestSupport {
         MockEndpoint error = getMockEndpoint("mock:error");
         error.expectedBodiesReceived("James");
         error.message(0).property(Exchange.EXCEPTION_CAUGHT).isNotNull();
-        error.message(0).property(Exchange.EXCEPTION_CAUGHT).convertTo(String.class).contains("This
is a dummy error James!");
+        error.message(0).property(Exchange.EXCEPTION_CAUGHT).method("getMessage").isEqualTo("This
is a dummy error James!");
 
         MockEndpoint result = getMockEndpoint("mock:result");
         result.expectedBodiesReceived("Hi Claus", "Hi Willem");
@@ -45,7 +45,7 @@ public class TryCatchWithSplitIssueTest extends ContextTestSupport {
         MockEndpoint error = getMockEndpoint("mock:error");
         error.expectedBodiesReceived("James");
         error.message(0).property(Exchange.EXCEPTION_CAUGHT).isNotNull();
-        error.message(0).property(Exchange.EXCEPTION_CAUGHT).convertTo(String.class).contains("This
is a dummy error James!");
+        error.message(0).property(Exchange.EXCEPTION_CAUGHT).method("getMessage").isEqualTo("This
is a dummy error James!");
 
         template.sendBody("direct:start", "James");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/e28e8ac4/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledTest.java
b/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledTest.java
index 3254244..7f9f69f 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandledTest.java
@@ -31,7 +31,7 @@ public class OnExceptionHandledTest extends ContextTestSupport {
         mock.expectedBodiesReceived("Hello World");
         mock.message(0).property(Exchange.EXCEPTION_CAUGHT).isNotNull();
         mock.message(0).property(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
-        mock.message(0).property(Exchange.EXCEPTION_CAUGHT).convertTo(String.class).contains("Forced");
+        mock.message(0).property(Exchange.EXCEPTION_CAUGHT).method("getMessage").isEqualTo("Forced");
 
         template.sendBody("direct:start", "Hello World");
 


Mime
View raw message