This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch kamelet2 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1010f52621d6deaf4b7fca243b78dea208880950 Author: Claus Ibsen <[email protected]> AuthorDate: Mon Jan 27 10:45:35 2025 +0100 CAMEL-21599: camel-kamelet - Rework error handler for kamelets to be more standard Camel. WIP --- .../kamelet/KameletSinkDeadLetterChannelTest.java | 55 ++++++++++++++++++++++ .../KameletSourceDeadLetterChannelTest.java | 52 ++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletSinkDeadLetterChannelTest.java b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletSinkDeadLetterChannelTest.java new file mode 100644 index 00000000000..fd6f95b5072 --- /dev/null +++ b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletSinkDeadLetterChannelTest.java @@ -0,0 +1,55 @@ +/* + * 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.component.kamelet; + +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +public class KameletSinkDeadLetterChannelTest extends CamelTestSupport { + + @Test + public void testDeadLetterChannel() throws Exception { + getMockEndpoint("mock:dead").expectedMessageCount(1); + getMockEndpoint("mock:result").expectedMessageCount(0); + + template.sendBody("direct:start", "Hello World"); + + MockEndpoint.assertIsSatisfied(context); + } + + @Override + protected RoutesBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + routeTemplate("fail") + .from("kamelet:source") + .throwException(new IllegalArgumentException("Forced")); + + errorHandler(deadLetterChannel("mock:dead")); + + from("direct:start").routeId("start") + .to("kamelet:fail") + .to("mock:result"); + } + }; + } + +} diff --git a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletSourceDeadLetterChannelTest.java b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletSourceDeadLetterChannelTest.java new file mode 100644 index 00000000000..d6f03b01b4e --- /dev/null +++ b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletSourceDeadLetterChannelTest.java @@ -0,0 +1,52 @@ +/* + * 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.component.kamelet; + +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +public class KameletSourceDeadLetterChannelTest extends CamelTestSupport { + + @Test + public void testDeadLetterChannel() throws Exception { + getMockEndpoint("mock:dead").expectedMessageCount(1); + getMockEndpoint("mock:result").expectedMessageCount(0); + + MockEndpoint.assertIsSatisfied(context); + } + + @Override + protected RoutesBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + routeTemplate("fail") + .from("timer:fail?delay=0&repeatCount=1") + .throwException(new IllegalArgumentException("Forced")); + + errorHandler(deadLetterChannel("mock:dead")); + + from("kamelet:fail").routeId("start") + .to("mock:result"); + } + }; + } + +}
