This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch camel-2.23.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.23.x by this push: new 148dc97 CAMEL-12947:MockEndpoint.expectedHeaderReceived should fail when no exchange received (#2669) new b732a4c Merge pull request #2977 from jonathanvila/CAMEL-12947-patch-into-2.23.x 148dc97 is described below commit 148dc974e279b8ff811687a8ad34fa06cd6aa7a1 Author: ramu11 <kramu...@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 4f5ddd7..996b3cc 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 @@ -527,6 +527,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"); + } + }; + } +}