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 2022/08/17 11:04:46 UTC

[camel] branch camel-3.18.x updated: CAMEL-18396: camel-mock - NotifyBuilder.matches returns always true when using mock with ...InAnyOrder exceptations.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.18.x by this push:
     new d1fe0e6151e CAMEL-18396: camel-mock - NotifyBuilder.matches returns always true when using mock with ...InAnyOrder exceptations.
d1fe0e6151e is described below

commit d1fe0e6151e7fad54fde47c296f67f2c9b25395b
Author: Claus Ibsen <cl...@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    | 28 ++++++++++++++++++++++
 2 files changed, 46 insertions(+)

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 6f7b4a337e4..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
@@ -721,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