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 2025/07/21 08:09:00 UTC
(camel) 02/04: CAMEL-22251: Added unit test
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch vrest
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ad0dd37b568ad3a8467225623c84c7a41352f82e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jul 21 09:47:57 2025 +0200
CAMEL-22251: Added unit test
---
.../component/jetty/JettyEventNotifierTest.java | 104 +++++++++++++++++++
components/camel-platform-http-vertx/pom.xml | 5 +
.../http/vertx/VertxPlatformEventNotifierTest.java | 111 +++++++++++++++++++++
3 files changed, 220 insertions(+)
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
new file mode 100644
index 00000000000..b5f5e9e44f3
--- /dev/null
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.jetty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.support.EventNotifierSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class JettyEventNotifierTest extends BaseJettyTest {
+
+ private final List<String> events = new ArrayList<>();
+
+ @Test
+ void testEventNotifierOk() throws Exception {
+ context.getManagementStrategy().addEventNotifier(new MyEventListener());
+ events.clear();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("jetty:http://0.0.0.0:{{port}}/camel/ok").routeId("jetty")
+ .setBody().constant("Bye World");
+ }
+ });
+
+ context.start();
+
+ String out = template.requestBodyAndHeader("http://localhost:{{port}}/camel/ok", "Hello World",
+ Exchange.HTTP_METHOD, "GET", String.class);
+ assertEquals("Bye World", out);
+
+ Assertions.assertEquals(2, events.size());
+ Assertions.assertEquals("ExchangeCreated (failed:false)", events.get(0));
+ Assertions.assertEquals("ExchangeCompleted (failed:false)", events.get(1));
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ void testEventNotifierError() throws Exception {
+ context.getManagementStrategy().addEventNotifier(new MyEventListener());
+ events.clear();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("jetty:http://0.0.0.0:{{port}}/camel/fail").routeId("jetty")
+ .throwException(new IllegalArgumentException("Forced error"));
+ }
+ });
+
+ context.start();
+
+ String out = template.requestBodyAndHeader("http://localhost:{{port}}/camel/fail?throwExceptionOnFailure=false",
+ "Hello World",
+ Exchange.HTTP_METHOD, "GET", String.class);
+ assertEquals("", out);
+
+ Assertions.assertEquals(2, events.size());
+ Assertions.assertEquals("ExchangeCreated (failed:false)", events.get(0));
+ Assertions.assertEquals("ExchangeFailed (failed:true)", events.get(1));
+ } finally {
+ context.stop();
+ }
+ }
+
+ class MyEventListener extends EventNotifierSupport {
+
+ public void notify(CamelEvent event) throws Exception {
+ if (event.getSource() instanceof Exchange) {
+ Exchange ex = (Exchange) event.getSource();
+ if ("jetty".equals(ex.getFromRouteId())) {
+ events.add(event.getType().name() + " (failed:" + ex.isFailed() + ")");
+ }
+ }
+ }
+ }
+
+}
diff --git a/components/camel-platform-http-vertx/pom.xml b/components/camel-platform-http-vertx/pom.xml
index fa18920a5aa..b7b06385fa4 100644
--- a/components/camel-platform-http-vertx/pom.xml
+++ b/components/camel-platform-http-vertx/pom.xml
@@ -99,6 +99,11 @@
<artifactId>camel-vertx-http</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-timer</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformEventNotifierTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformEventNotifierTest.java
new file mode 100644
index 00000000000..92ab4e36ca3
--- /dev/null
+++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformEventNotifierTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.platform.http.vertx;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.support.EventNotifierSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.is;
+
+public class VertxPlatformEventNotifierTest {
+
+ private final List<String> events = new ArrayList<>();
+
+ @Test
+ void testEventNotifierOk() throws Exception {
+ final CamelContext context = VertxPlatformHttpEngineTest.createCamelContext();
+ context.getManagementStrategy().addEventNotifier(new MyEventListener());
+ events.clear();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/camel/ok")
+ .setBody().constant("Bye World");
+ }
+ });
+
+ context.start();
+
+ given()
+ .body("Hello World")
+ .post("/camel/ok")
+ .then()
+ .statusCode(200)
+ .body(is("Bye World"));
+
+ Assertions.assertEquals(2, events.size());
+ Assertions.assertEquals("ExchangeCreated (failed:false)", events.get(0));
+ Assertions.assertEquals("ExchangeCompleted (failed:false)", events.get(1));
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ void testEventNotifierError() throws Exception {
+ final CamelContext context = VertxPlatformHttpEngineTest.createCamelContext();
+ context.getManagementStrategy().addEventNotifier(new MyEventListener());
+ events.clear();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/camel/fail")
+ .throwException(new IllegalArgumentException("Forced error"));
+ }
+ });
+
+ context.start();
+
+ given()
+ .body("Hello World")
+ .post("/camel/fail")
+ .then()
+ .statusCode(500)
+ .body(is(""));
+
+ Assertions.assertEquals(2, events.size());
+ Assertions.assertEquals("ExchangeCreated (failed:false)", events.get(0));
+ Assertions.assertEquals("ExchangeFailed (failed:true)", events.get(1));
+ } finally {
+ context.stop();
+ }
+ }
+
+ class MyEventListener extends EventNotifierSupport {
+
+ public void notify(CamelEvent event) throws Exception {
+ if (event.getSource() instanceof Exchange) {
+ Exchange ex = (Exchange) event.getSource();
+ events.add(event.getType().name() + " (failed:" + ex.isFailed() + ")");
+ }
+ }
+ }
+
+}