camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/6] git commit: CAMEL-7767: Mock - Defining assertion on message doest work if using convertTo
Date Sat, 30 Aug 2014 13:06:55 GMT
CAMEL-7767: Mock - Defining assertion on message doest work if using convertTo


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

Branch: refs/heads/camel-2.13.x
Commit: e3993f92993e688847f4ab669dfec6b089e4cd03
Parents: c521f5c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Aug 30 11:07:57 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Aug 30 15:05:22 2014 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/util/MessageHelper.java   | 16 +++++++++++++---
 .../camel/issues/TryCatchWithSplitIssueTest.java    |  4 ++--
 .../onexception/OnExceptionHandledTest.java         |  2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e3993f92/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
index e2f59ec..0182594 100644
--- a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
@@ -17,6 +17,7 @@
 package org.apache.camel.util;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
@@ -235,12 +236,15 @@ public final class MessageHelper {
             }
         }
 
-        // is the body a stream cache
-        StreamCache cache;
+        // is the body a stream cache or input stream
+        StreamCache cache = null;
+        InputStream is = null;
         if (obj instanceof StreamCache) {
             cache = (StreamCache)obj;
-        } else {
+            is = null;
+        } else if (obj instanceof InputStream) {
             cache = null;
+            is = (InputStream) obj;
         }
 
         // grab the message body as a string
@@ -259,6 +263,12 @@ public final class MessageHelper {
         // reset stream cache after use
         if (cache != null) {
             cache.reset();
+        } else if (is != null && is.markSupported()) {
+            try {
+                is.reset();
+            } catch (IOException e) {
+                // ignore
+            }
         }
 
         if (body == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e3993f92/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 3818190..2dd5e3f 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).isEqualTo("This
is a dummy error James!");
+        error.message(0).property(Exchange.EXCEPTION_CAUGHT).convertTo(String.class).contains("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).isEqualTo("This
is a dummy error James!");
+        error.message(0).property(Exchange.EXCEPTION_CAUGHT).convertTo(String.class).contains("This
is a dummy error James!");
 
         template.sendBody("direct:start", "James");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/e3993f92/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 565b942..3254244 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).isEqualTo("Forced");
+        mock.message(0).property(Exchange.EXCEPTION_CAUGHT).convertTo(String.class).contains("Forced");
 
         template.sendBody("direct:start", "Hello World");
 


Mime
View raw message