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

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

commit 81e45143777392271b930ea2595ef281ed334e63
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Jan 15 14:42:49 2025 +0100

    CAMEL-21620: camel-core - Fix onWhen to not include outputs in model
---
 .../main/docs/modules/eips/pages/intercept.adoc    | 18 ++++++++--------
 .../InterceptSendToEndpointProcessor.java          |  6 +++---
 .../InterceptSendToEndpointAfterTest.java          |  2 +-
 ...nterceptSendToEndpointConditionalSkip2Test.java |  4 ++--
 ...nterceptSendToEndpointConditionalSkip3Test.java |  4 ++--
 ...InterceptSendToEndpointConditionalSkipTest.java | 24 +---------------------
 6 files changed, 18 insertions(+), 40 deletions(-)

diff --git 
a/core/camel-core-engine/src/main/docs/modules/eips/pages/intercept.adoc 
b/core/camel-core-engine/src/main/docs/modules/eips/pages/intercept.adoc
index 25a73f2a1a1..a645efda661 100644
--- a/core/camel-core-engine/src/main/docs/modules/eips/pages/intercept.adoc
+++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/intercept.adoc
@@ -30,7 +30,7 @@ xref:manual::route-configuration.adoc[Route Configuration].
 
 All these interceptors support the following features:
 
-* xref:manual::predicate.adoc[Predicate] using `when` to only trigger the 
interceptor in certain conditions
+* xref:manual::predicate.adoc[Predicate] using `onWhen` to only trigger the 
interceptor in certain conditions
 * `stop` forces stopping continue routing the Exchange and mark it as 
completed successful (it's actually the xref:stop-eip.adoc[Stop] EIP).
 * `skip` when used with `interceptSendToEndpoint` will *skip* sending the 
message to the original intended endpoint.
 * `afterUri` when used with `interceptSendToEndpoint` allows to send
@@ -109,7 +109,7 @@ Java::
 
 [source,java]
 ----
-intercept().when(body().contains("Hello")).to("mock:intercepted");
+intercept().onWhen(body().contains("Hello")).to("mock:intercepted");
 
 from("jms:queue:order")
   .to("bean:validateOrder")
@@ -124,9 +124,9 @@ XML::
 <camelContext>
 
   <intercept>
-      <when>
+      <onWhen>
           <simple>${in.body} contains 'Hello'</simple>
-      </when>
+      </onWhen>
       <to uri="mock:intercepted"/>
   </intercept>
 
@@ -154,7 +154,7 @@ Java::
 
 [source,java]
 ----
-intercept().when(body().contains("Hello"))
+intercept().onWhen(body().contains("Hello"))
   .to("log:test")
   .stop(); // stop continue routing
 
@@ -171,11 +171,11 @@ XML::
 <camelContext>
 
   <intercept>
-      <when>
+      <onWhen>
         <simple>${body} contains 'Hello'</simple>
         <to uri="log:test"/>
         <stop/> <!-- stop continue routing -->
-      </when>
+      </onWhen>
   </intercept>
 
   <route>
@@ -461,7 +461,7 @@ Java::
 [source,java]
 ----
 interceptSendToEndpoint("kafka*").skipSendToOriginalEndpoint()
-  .when(simple("${header.biztype} == 'TEST'")
+  .onWhen(simple("${header.biztype} == 'TEST'")
   .log("TEST message detected - is NOT send to kafka");
 
 from("jms:queue:order")
@@ -478,7 +478,7 @@ XML::
 <camelContext>
 
   <interceptSendToEndpoint uri="kafka*" skipSendToOriginalEndpoint="true">
-    <when><simple>${header.biztype} == 'TEST'</simple></when>
+    <onWhen><simple>${header.biztype} == 'TEST'</simple></onWhen>
     <log message="TEST message detected - is NOT send to kafka"/>
   </interceptSendToEndpoint>
 
diff --git 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/InterceptSendToEndpointProcessor.java
 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/InterceptSendToEndpointProcessor.java
index ee03d5ef80f..fc0495186a1 100644
--- 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/InterceptSendToEndpointProcessor.java
+++ 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/InterceptSendToEndpointProcessor.java
@@ -96,13 +96,13 @@ public class InterceptSendToEndpointProcessor extends 
DefaultAsyncProducer {
         // determine if we should skip or not
         boolean shouldSkip = skip;
 
-        // if then interceptor had a when predicate, then we should only skip 
if it matched
+        // if then interceptor has predicate, then we should only skip if 
matched
         Boolean whenMatches;
         if (endpoint.getAfter() != null) {
             // only get the property as after also needs to check this property
             whenMatches = (Boolean) 
exchange.getProperty(ExchangePropertyKey.INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED);
         } else {
-            // remove property as its not longer needed
+            // remove property as it's no longer needed
             whenMatches = (Boolean) 
exchange.removeProperty(ExchangePropertyKey.INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED);
         }
         if (whenMatches != null) {
@@ -119,7 +119,7 @@ public class InterceptSendToEndpointProcessor extends 
DefaultAsyncProducer {
             return doneSync && s;
         } else {
             if (LOG.isDebugEnabled()) {
-                LOG.debug("Stop() means skip sending exchange to original 
intended destination: {} for exchange: {}",
+                LOG.debug("Skip sending exchange to original intended 
destination: {} for exchange: {}",
                         getEndpoint(), exchange);
             }
             callback.done(doneSync);
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointAfterTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointAfterTest.java
index 21960bdd976..f2faf7e52aa 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointAfterTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointAfterTest.java
@@ -105,7 +105,7 @@ public class InterceptSendToEndpointAfterTest extends 
ContextTestSupport {
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() {
-                interceptSendToEndpoint("direct:start").when(simple("${body} 
contains 'World'")).to("mock:detour")
+                interceptSendToEndpoint("direct:start").onWhen(simple("${body} 
contains 'World'")).to("mock:detour")
                         .afterUri("mock:after");
 
                 from("direct:start").to("mock:foo").transform().constant("Bye 
World");
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java
index 249f2039e11..0b0bdad873d 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java
@@ -80,10 +80,10 @@ public class InterceptSendToEndpointConditionalSkip2Test 
extends ContextTestSupp
             public void configure() {
                 // we have 2 interceptors, which may both trigger, or either 
or,
                 // or none
-                
interceptSendToEndpoint("mock:skip1").skipSendToOriginalEndpoint().when(body().contains("skip1"))
+                
interceptSendToEndpoint("mock:skip1").skipSendToOriginalEndpoint().onWhen(body().contains("skip1"))
                         .to("mock:detour1");
 
-                
interceptSendToEndpoint("mock:skip2").skipSendToOriginalEndpoint().when(body().contains("skip2"))
+                
interceptSendToEndpoint("mock:skip2").skipSendToOriginalEndpoint().onWhen(body().contains("skip2"))
                         .to("mock:detour2");
 
                 
from("direct:start").to("mock:a").to("mock:skip1").to("mock:skip2").to("mock:c");
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java
index b4c453eb0e3..06accd19191 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java
@@ -68,11 +68,11 @@ public class InterceptSendToEndpointConditionalSkip3Test 
extends ContextTestSupp
             public void configure() {
                 // we have 2 interceptors, which may both trigger, or either 
or,
                 // or none
-                
interceptSendToEndpoint("mock:skip").skipSendToOriginalEndpoint().when(body().contains("skip"))
+                
interceptSendToEndpoint("mock:skip").skipSendToOriginalEndpoint().onWhen(body().contains("skip"))
                         .to("mock:detour1");
 
                 // we intercept the interceptor
-                
interceptSendToEndpoint("mock:detour1").skipSendToOriginalEndpoint().when(body().contains("skip2"))
+                
interceptSendToEndpoint("mock:detour1").skipSendToOriginalEndpoint().onWhen(body().contains("skip2"))
                         .to("mock:detour2");
 
                 from("direct:start").to("mock:a").to("mock:skip").to("mock:c");
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkipTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkipTest.java
index c4b3b5057bd..79d2061f5be 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkipTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkipTest.java
@@ -75,29 +75,13 @@ public class InterceptSendToEndpointConditionalSkipTest 
extends ContextTestSuppo
         assertMockEndpointsSatisfied();
     }
 
-    /**
-     * Test that when multiple conditions are chained together in Java DSL, 
only the first one will determine whether
-     * the endpoint is skipped or not
-     */
-    @Test
-    public void testInterceptSendToEndpointSkipMultipleConditions() throws 
Exception {
-        getMockEndpoint("mock:a").expectedMessageCount(1);
-        
getMockEndpoint("mock:skippableMultipleConditions").expectedMessageCount(0);
-        getMockEndpoint("mock:detour").expectedMessageCount(1);
-        getMockEndpoint("mock:c").expectedMessageCount(1);
-
-        template.sendBody("direct:startMultipleConditions", "skip");
-
-        assertMockEndpointsSatisfied();
-    }
-
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             @Override
             public void configure() {
                 // only skip if the body equals 'skip'
-                
interceptSendToEndpoint("mock:skippable").skipSendToOriginalEndpoint().when(body().isEqualTo("skip"))
+                
interceptSendToEndpoint("mock:skippable").skipSendToOriginalEndpoint().onWhen(body().isEqualTo("skip"))
                         .to("mock:detour");
 
                 // always skip with a normal with a normal choice inside
@@ -106,12 +90,6 @@ public class InterceptSendToEndpointConditionalSkipTest 
extends ContextTestSuppo
                         
.when(body().isEqualTo("skipNoEffectWhen")).to("mock:noSkipWhen").otherwise()
                         .to("mock:noSkipOW");
 
-                // in this case, the original endpoint will be skipped but no
-                // message will be sent to mock:detour
-                
interceptSendToEndpoint("mock:skippableMultipleConditions").skipSendToOriginalEndpoint()
-                        
.when(body().isEqualTo("skip")).when(body().isNotEqualTo("skip"))
-                        .to("mock:detour");
-
                 
from("direct:start").to("mock:a").to("mock:skippable").to("mock:c");
 
                 
from("direct:startNoEffect").to("mock:a").to("mock:skippableNoEffect").to("mock:c");

Reply via email to