[
https://issues.apache.org/jira/browse/CAMEL-12947?focusedWorklogId=174834&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-174834
]
ASF GitHub Bot logged work on CAMEL-12947:
------------------------------------------
Author: ASF GitHub Bot
Created on: 13/Dec/18 10:54
Start Date: 13/Dec/18 10:54
Worklog Time Spent: 10m
Work Description: davsclaus closed pull request #2669:
CAMEL-12947:MockEndpoint.expectedHeaderReceived should fail when no e…
URL: https://github.com/apache/camel/pull/2669
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 6bb30e4ca5c..1681bfa07e2 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 void expectedMinimumMessageCount(int expectedCount) {
* <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 00000000000..931a472b01c
--- /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");
+ }
+ };
+ }
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 174834)
Time Spent: 20m (was: 10m)
> MockEndpoint.expectedHeaderReceived should fail when no exchange received
> -------------------------------------------------------------------------
>
> Key: CAMEL-12947
> URL: https://issues.apache.org/jira/browse/CAMEL-12947
> Project: Camel
> Issue Type: Bug
> Components: camel-test
> Affects Versions: 2.22.1
> Reporter: Antoine Wils
> Assignee: Ramu
> Priority: Minor
> Fix For: 3.0.0, 2.24.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> When expecting headers to be passed to a MockEndpoint that is never called
> the test should fail if the MockEndpoint was never called.
> However it is succeeding.
> Here an example of Junit 4 test succeeding when it should fail
> {code:java}
> import org.apache.camel.EndpointInject;
> 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 Test extends CamelTestSupport {
> @EndpointInject(uri = "mock:direct:foo")
> private MockEndpoint fooProducerMock;
> @Override
> public RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {}
> };
> }
> @Test
> public void failWhenHeaderAbsent() throws InterruptedException {
> fooProducerMock.expectedHeaderReceived("ghost", "you should be visible");
> MockEndpoint.assertIsSatisfied(context);
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)