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 06c0a2d47577 CAMEL-22950: Tests for UseOriginalAggregationStrategy for 
MulticastProcessor (#21273)
06c0a2d47577 is described below

commit 06c0a2d4757753b85d50f8e501319afbb4a252e6
Author: David Riseley <[email protected]>
AuthorDate: Fri Feb 6 08:49:31 2026 +0000

    CAMEL-22950: Tests for UseOriginalAggregationStrategy for 
MulticastProcessor (#21273)
---
 ...ticastUseOriginalNotPropagateExceptionTest.java |  87 +++++++++++++++++
 ...astUseOriginalPropagateExceptionCaughtTest.java | 107 +++++++++++++++++++++
 ...MulticastUseOriginalPropagateExceptionTest.java | 106 ++++++++++++++++++++
 3 files changed, 300 insertions(+)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalNotPropagateExceptionTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalNotPropagateExceptionTest.java
new file mode 100644
index 000000000000..dc1d2714751b
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalNotPropagateExceptionTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.UseOriginalAggregationStrategy;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+public class MulticastUseOriginalNotPropagateExceptionTest extends 
ContextTestSupport {
+
+    @ParameterizedTest
+    @ValueSource(strings = {
+            "body",
+            "throw1",
+            "throw2",
+            "throw1;throw2"
+    })
+    public void testWithoutPropagation(String body) throws Exception {
+
+        
getMockEndpoint("mock:recipient1").expectedMessageCount(body.contains("throw1") 
? 0 : 1);
+        
getMockEndpoint("mock:recipient2").expectedMessageCount(body.contains("throw2") 
? 0 : 1);
+
+        getMockEndpoint("mock:result").expectedBodiesReceived(body);
+
+        template.sendBody("direct:start", body);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+
+                from("direct:start")
+                        .errorHandler(noErrorHandler())
+                        .multicast(new UseOriginalAggregationStrategy(false))
+                            .to("direct:recipient1")
+                            .to("direct:recipient2")
+                        .end()
+                        .to("mock:result");
+
+                from("direct:recipient1")
+                        .log("recipient1")
+                        .choice()
+                        .when(bodyAs(String.class).contains("throw1"))
+                        .process(
+                                exchange -> {
+                                    throw new RuntimeException("recipient1");
+                                })
+                        .end()
+                        .setBody(constant("recipient1"))
+                        .to("mock:recipient1");
+
+                from("direct:recipient2")
+                        .log("recipient2")
+                        .choice()
+                        .when(bodyAs(String.class).contains("throw2"))
+                        .process(
+                                exchange -> {
+                                    throw new RuntimeException("recipient2");
+                                })
+                        .end()
+                        .setBody(constant("recipient2"))
+                        .to("mock:recipient2");
+            }
+        };
+    }
+
+}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalPropagateExceptionCaughtTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalPropagateExceptionCaughtTest.java
new file mode 100644
index 000000000000..0cf9ed2b3892
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalPropagateExceptionCaughtTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.UseOriginalAggregationStrategy;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class MulticastUseOriginalPropagateExceptionCaughtTest extends 
ContextTestSupport {
+
+    @ParameterizedTest
+    @ValueSource(strings = {
+            "caught1",
+            "caught2",
+    })
+    public void testWithPropagation(String body) throws Exception {
+
+        getMockEndpoint("mock:recipient1").expectedMessageCount(1);
+        getMockEndpoint("mock:recipient2").expectedMessageCount(1);
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", body);
+
+        assertEquals(1, 
getMockEndpoint("mock:result").getReceivedExchanges().size());
+        Exchange exchange = 
getMockEndpoint("mock:result").getReceivedExchanges().get(0);
+        Exception exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, 
Exception.class);
+        assertNotNull(exception);
+        Throwable rootCause = exception;
+        while (rootCause.getCause() != null) {
+            rootCause = rootCause.getCause();
+        }
+        assertInstanceOf(RuntimeException.class, rootCause);
+
+        if (body.contains("caught1")) {
+            assertEquals("recipient1", rootCause.getMessage());
+        }
+        if (body.contains("caught2")) {
+            assertEquals("recipient2", rootCause.getMessage());
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+
+                from("direct:start")
+                        .errorHandler(noErrorHandler())
+                        .multicast(new UseOriginalAggregationStrategy(true))
+                            .to("direct:recipient1")
+                            .to("direct:recipient2")
+                        .end()
+                        .to("mock:result");
+
+                from("direct:recipient1")
+                        .log("recipient1")
+                        .choice()
+                        .when(bodyAs(String.class).contains("caught1"))
+                        .process(
+                                exchange -> {
+                                    
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new 
RuntimeException("recipient1"));
+                                })
+                        .end()
+                        .setBody(constant("recipient1"))
+                        .to("mock:recipient1");
+
+                from("direct:recipient2")
+                        .log("recipient2")
+                        .choice()
+                        .when(bodyAs(String.class).contains("caught2"))
+                        .process(
+                                exchange -> {
+                                    
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new 
RuntimeException("recipient2"));
+                                })
+                        .end()
+                        .setBody(constant("recipient2"))
+                        .to("mock:recipient2");
+            }
+        };
+    }
+
+}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalPropagateExceptionTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalPropagateExceptionTest.java
new file mode 100644
index 000000000000..b2ffdebe97ac
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/MulticastUseOriginalPropagateExceptionTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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.processor;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.UseOriginalAggregationStrategy;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class MulticastUseOriginalPropagateExceptionTest extends 
ContextTestSupport {
+
+    @ParameterizedTest
+    @ValueSource(strings = {
+            "throw1",
+            "throw2",
+    })
+    public void testWithPropagation(String body) throws Exception {
+
+        
getMockEndpoint("mock:recipient1").expectedMessageCount(body.contains("throw1") 
? 0 : 1);
+        
getMockEndpoint("mock:recipient2").expectedMessageCount(body.contains("throw2") 
? 0 : 1);
+
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        CamelExecutionException exception
+                = assertThrows(CamelExecutionException.class, () -> 
template.sendBody("direct:start", body));
+
+        Throwable rootCause = exception;
+        while (rootCause.getCause() != null) {
+            rootCause = rootCause.getCause();
+        }
+        assertInstanceOf(RuntimeException.class, rootCause);
+
+        if (body.contains("throw1")) {
+            assertEquals("recipient1", rootCause.getMessage());
+        }
+        if (body.contains("throw2")) {
+            assertEquals("recipient2", rootCause.getMessage());
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+
+                from("direct:start")
+                        .errorHandler(noErrorHandler())
+                        .multicast(new UseOriginalAggregationStrategy(true))
+                            .to("direct:recipient1")
+                            .to("direct:recipient2")
+                        .end()
+                        .to("mock:result");
+
+                from("direct:recipient1")
+                        .log("recipient1")
+                        .choice()
+                        .when(bodyAs(String.class).contains("throw1"))
+                        .process(
+                                exchange -> {
+                                    
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new 
RuntimeException("recipient1Caught"));
+                                    throw new RuntimeException("recipient1");
+                                })
+                        .end()
+                        .setBody(constant("recipient1"))
+                        .to("mock:recipient1");
+
+                from("direct:recipient2")
+                        .log("recipient2")
+                        .choice()
+                        .when(bodyAs(String.class).contains("throw2"))
+                        .process(
+                                exchange -> {
+                                    throw new RuntimeException("recipient2");
+                                })
+                        .end()
+                        .setBody(constant("recipient2"))
+                        .to("mock:recipient2");
+            }
+        };
+    }
+
+}

Reply via email to