From fbe47e81335e1044fe46323abe2cfdcfe572ac70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Parscau?= <116000379+f2par0@users.noreply.github.com> Date: Wed, 5 Jun 2024 09:29:29 +0200 Subject: [PATCH] Ref #318: Add camel netty http test (#319) --- tests/features/camel-netty-http/pom.xml | 33 ++++++++++++ .../test/CamelNettyHttpRouteSupplier.java | 52 +++++++++++++++++++ .../camel/itest/CamelNettyHttpITest.java | 47 +++++++++++++++++ tests/features/pom.xml | 1 + 4 files changed, 133 insertions(+) create mode 100644 tests/features/camel-netty-http/pom.xml create mode 100644 tests/features/camel-netty-http/src/main/java/org/apache/karaf/camel/test/CamelNettyHttpRouteSupplier.java create mode 100644 tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java diff --git a/tests/features/camel-netty-http/pom.xml b/tests/features/camel-netty-http/pom.xml new file mode 100644 index 000000000..d3a39afb0 --- /dev/null +++ b/tests/features/camel-netty-http/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + org.apache.camel.karaf + camel-karaf-features-test + 4.6.0-SNAPSHOT + + + camel-netty-http-test + Apache Camel :: Karaf :: Tests :: Features :: Netty Http + + \ No newline at end of file diff --git a/tests/features/camel-netty-http/src/main/java/org/apache/karaf/camel/test/CamelNettyHttpRouteSupplier.java b/tests/features/camel-netty-http/src/main/java/org/apache/karaf/camel/test/CamelNettyHttpRouteSupplier.java new file mode 100644 index 000000000..7dcf5664d --- /dev/null +++ b/tests/features/camel-netty-http/src/main/java/org/apache/karaf/camel/test/CamelNettyHttpRouteSupplier.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.karaf.camel.test; + +import java.util.function.Function; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.RouteDefinition; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier; +import org.apache.karaf.camel.itests.CamelRouteSupplier; +import org.osgi.service.component.annotations.Component; + + +@Component( + name = "karaf-camel-netty-http-test", + immediate = true, + service = CamelRouteSupplier.class +) +public class CamelNettyHttpRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + private static final String HTTP_PROP = "http.port"; + + @Override + protected Function consumerRoute() { + return builder -> + builder.fromF("netty-http:http://127.0.0.1:%s/testNetty", System.getProperty(HTTP_PROP)) + .log("receiving http request") + .setBody(builder.constant("OK")); + } + + @Override + protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) { + producerRoute.log("calling http endpoint") + .setBody(builder.constant("OK")) + .log("sending http request") + .toF("netty-http:http://127.0.0.1:%s/testNetty", System.getProperty(HTTP_PROP)); + } +} + diff --git a/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java b/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java new file mode 100644 index 000000000..216d56faf --- /dev/null +++ b/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java @@ -0,0 +1,47 @@ +/* + * Licensed 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.karaf.camel.itest; + +import java.util.List; + +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.karaf.camel.itests.*; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; + +@CamelKarafTestHint(externalResourceProvider = CamelNettyHttpITest.ExternalResourceProviders.class) +@RunWith(PaxExamWithExternalResource.class) +@ExamReactorStrategy(PerClass.class) +public class CamelNettyHttpITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest { + + + @Override + public void configureMock(MockEndpoint mock) { + mock.expectedBodiesReceived("OK"); + } + + @Test + public void testResultMock() throws Exception { + assertMockEndpointsSatisfied(); + } + + public static final class ExternalResourceProviders { + public static AvailablePortProvider createAvailablePortProvider() { + return new AvailablePortProvider(List.of("http.port")); + } + + } +} \ No newline at end of file diff --git a/tests/features/pom.xml b/tests/features/pom.xml index c26243f0f..6649592c8 100644 --- a/tests/features/pom.xml +++ b/tests/features/pom.xml @@ -43,6 +43,7 @@ camel-core camel-elasticsearch camel-jetty + camel-netty-http camel-mail