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 2018/12/13 10:54:27 UTC
[camel] branch master updated:
CAMEL-12947:MockEndpoint.expectedHeaderReceived should fail when no
exchange received (#2669)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new f91a920 CAMEL-12947:MockEndpoint.expectedHeaderReceived should fail when no exchange received (#2669)
f91a920 is described below
commit f91a92093aaf80db757ff0401f41dd2fc049023a
Author: ramu11 <kr...@gmail.com>
AuthorDate: Thu Dec 13 16:24:21 2018 +0530
CAMEL-12947:MockEndpoint.expectedHeaderReceived should fail when no exchange received (#2669)
---
.../apache/camel/component/mock/MockEndpoint.java | 3 ++
.../patterns/MockEndpointFailNoHeaderTest.java | 62 ++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
index 6bb30e4..1681bfa 100644
--- a/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
@@ -517,6 +517,9 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint {
* <b>Important:</b> This overrides any previous set value using {@link #expectedMessageCount(int)}
*/
public void expectedHeaderReceived(final String name, final Object value) {
+ if (expectedCount == -1) {
+ expectedMessageCount(1);
+ }
if (expectedHeaderValues == null) {
expectedHeaderValues = getCamelContext().getHeadersMapFactory().newMap();
// we just wants to expects to be called once
diff --git a/components/camel-test/src/test/java/org/apache/camel/test/patterns/MockEndpointFailNoHeaderTest.java b/components/camel-test/src/test/java/org/apache/camel/test/patterns/MockEndpointFailNoHeaderTest.java
new file mode 100644
index 0000000..931a472
--- /dev/null
+++ b/components/camel-test/src/test/java/org/apache/camel/test/patterns/MockEndpointFailNoHeaderTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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.test.patterns;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+public class MockEndpointFailNoHeaderTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @Override
+ public boolean isDumpRouteCoverage() {
+ return true;
+ }
+
+ @Test
+ public void withHeaderTestCase() throws InterruptedException {
+ String expectedBody = "<matched/>";
+ resultEndpoint.expectedHeaderReceived("foo", "bar");
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
+ resultEndpoint.assertIsSatisfied();
+ }
+
+
+ @Test
+ public void noHeaderTestCase() throws InterruptedException {
+ resultEndpoint.expectedHeaderReceived("foo", "bar");
+ resultEndpoint.assertIsNotSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ }
+ };
+ }
+}