This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new a7629e5e4bc CAMEL-18396: camel-mock - NotifyBuilder.matches returns always true when using mock with ...InAnyOrder exceptations. a7629e5e4bc is described below commit a7629e5e4bc114cb5d5f66edf6d71c438b668796 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Aug 17 13:04:11 2022 +0200 CAMEL-18396: camel-mock - NotifyBuilder.matches returns always true when using mock with ...InAnyOrder exceptations. --- .../apache/camel/component/mock/MockEndpoint.java | 18 ++++++++++++++ .../apache/camel/builder/NotifyBuilderTest.java | 29 +++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java index 0e7cccbf4ff..a26d72d099c 100644 --- a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java +++ b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java @@ -1341,6 +1341,24 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint, @Override public boolean notifyBuilderMatches() { + if (failFastAssertionError != null) { + // the test failed so we do not match + return false; + } + + for (Runnable test : tests) { + // skip tasks which we have already been running in fail fast mode + boolean skip = failFast && test instanceof AssertionTask; + if (!skip) { + try { + test.run(); + } catch (Throwable e) { + // the test failed so we do not match + return false; + } + } + } + if (latch != null) { try { return latch.await(0, TimeUnit.SECONDS); diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java index 1c4eedd1062..e2eb225ec50 100644 --- a/core/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java @@ -702,7 +702,6 @@ public class NotifyBuilderTest extends ContextTestSupport { MockEndpoint mock = getMockEndpoint("mock:assert"); mock.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World", "Hi World"); - // TODO: CAMEL-18396 NotifyBuilder notify = new NotifyBuilder(context).from("direct:foo").whenDoneSatisfied(mock).create(); assertEquals(false, notify.matches()); @@ -722,6 +721,34 @@ public class NotifyBuilderTest extends ContextTestSupport { assertEquals(true, notify.matches()); } + @Test + public void testWhenReceivedSatisfiedFalse() throws Exception { + // lets use a mock to set the expressions as it got many great + // assertions for that + // notice we use mock:assert which does NOT exist in the route, its just + // a pseudo name + MockEndpoint mock = getMockEndpoint("mock:assert"); + mock.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World", "Does not happen", "Hi World"); + + NotifyBuilder notify = new NotifyBuilder(context).from("direct:foo").whenDoneSatisfied(mock).create(); + + assertEquals(false, notify.matches()); + + template.sendBody("direct:foo", "Bye World"); + assertEquals(false, notify.matches()); + + template.sendBody("direct:foo", "Hello World"); + assertEquals(false, notify.matches()); + + // the notify is based on direct:foo so sending to bar should not + // trigger match + template.sendBody("direct:bar", "Hi World"); + assertEquals(false, notify.matches()); + + template.sendBody("direct:foo", "Hi World"); + assertEquals(false, notify.matches()); + } + @Test public void testWhenReceivedNotSatisfied() throws Exception { // lets use a mock to set the expressions as it got many great