You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/11/15 10:17:12 UTC
[camel] branch camel-2.19.x updated: CAMEL-12010: Mock endpoint -
Should reset StreamCache when evaluating expecations
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.19.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.19.x by this push:
new d31f273 CAMEL-12010: Mock endpoint - Should reset StreamCache when evaluating expecations
d31f273 is described below
commit d31f2734cc7671b40b45ccf11f09c2c6a0caed2d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Nov 15 10:38:05 2017 +0100
CAMEL-12010: Mock endpoint - Should reset StreamCache when evaluating expecations
---
.../camel/component/mock/AssertionClause.java | 9 ++++
.../component/mock/MockStreamCachingTest.java | 61 ++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java b/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
index f3cb263..d79e92d 100644
--- a/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
+++ b/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
@@ -23,6 +23,7 @@ import java.util.Set;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
+import org.apache.camel.StreamCache;
import org.apache.camel.builder.ExpressionClause;
import org.apache.camel.builder.ExpressionClauseSupport;
import org.apache.camel.builder.ValueBuilder;
@@ -103,6 +104,14 @@ public abstract class AssertionClause extends ExpressionClauseSupport<ValueBuild
protected void applyAssertionOn(MockEndpoint endpoint, int index, Exchange exchange) {
for (Predicate predicate : predicates) {
currentIndex = index;
+
+ Object value = exchange.hasOut() ? exchange.getOut().getBody() : exchange.getIn().getBody();
+ // if the value is StreamCache then ensure its readable before evaluating any predicates
+ // by resetting it (this is also what StreamCachingAdvice does)
+ if (value instanceof StreamCache) {
+ ((StreamCache) value).reset();
+ }
+
PredicateAssertHelper.assertMatches(predicate, "Assertion error at index " + index + " on mock " + endpoint.getEndpointUri() + " with predicate: ", exchange);
}
}
diff --git a/camel-core/src/test/java/org/apache/camel/component/mock/MockStreamCachingTest.java b/camel-core/src/test/java/org/apache/camel/component/mock/MockStreamCachingTest.java
new file mode 100644
index 0000000..fc35555
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/mock/MockStreamCachingTest.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mock;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class MockStreamCachingTest extends ContextTestSupport {
+
+ public void testMockStreamCaching() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:result").message(0).body(String.class).contains("Camel");
+ getMockEndpoint("mock:result").message(0).body(String.class).contains("World");
+
+ Object body = new ByteArrayInputStream("Hello Camel and Bye World".getBytes());
+
+ template.sendBody("direct:start", body);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testMockStreamCachingConvertTo() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:result").message(0).body().convertToString().contains("Camel");
+ getMockEndpoint("mock:result").message(0).body().convertToString().contains("World");
+
+ Object body = new ByteArrayInputStream("Hello Camel and Bye World".getBytes());
+
+ template.sendBody("direct:start", body);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .streamCaching()
+ .to("mock:result");
+ }
+ };
+ }
+}
--
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].