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

nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new 2b832a43 Ref #359: Add camel-http integration test (#360)
2b832a43 is described below

commit 2b832a434022172254575f3d6b3562af51f73454
Author: François de Parscau <[email protected]>
AuthorDate: Tue Jun 18 09:59:57 2024 +0200

    Ref #359: Add camel-http integration test (#360)
---
 tests/features/camel-http/pom.xml                  | 42 ++++++++++++++++
 .../karaf/camel/test/CamelHttpRouteSupplier.java   | 47 ++++++++++++++++++
 .../apache/karaf/camel/itest/CamelHttpITest.java   | 58 ++++++++++++++++++++++
 tests/features/pom.xml                             |  1 +
 4 files changed, 148 insertions(+)

diff --git a/tests/features/camel-http/pom.xml 
b/tests/features/camel-http/pom.xml
new file mode 100644
index 00000000..e189e57e
--- /dev/null
+++ b/tests/features/camel-http/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.karaf</groupId>
+        <artifactId>camel-karaf-features-test</artifactId>
+        <version>4.6.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-http-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: Http</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <version>${testcontainers-version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git 
a/tests/features/camel-http/src/main/java/org/apache/karaf/camel/test/CamelHttpRouteSupplier.java
 
b/tests/features/camel-http/src/main/java/org/apache/karaf/camel/test/CamelHttpRouteSupplier.java
new file mode 100644
index 00000000..28422e97
--- /dev/null
+++ 
b/tests/features/camel-http/src/main/java/org/apache/karaf/camel/test/CamelHttpRouteSupplier.java
@@ -0,0 +1,47 @@
+/*
+ * 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 static org.apache.camel.builder.Builder.constant;
+
+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-http-test",
+        immediate = true,
+        service = CamelRouteSupplier.class
+)
+public class CamelHttpRouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    @Override
+    protected boolean consumerEnabled() {
+        return false;
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+        configureConsumer(
+            producerRoute.log("calling local http server")
+                    .setHeader("CamelHttpMethod", constant("GET"))
+                    .toF("http://localhost:%s";, 
System.getProperty("http.port"))
+                    .log("got ${body}"));
+    }
+}
+
diff --git 
a/tests/features/camel-http/src/test/java/org/apache/karaf/camel/itest/CamelHttpITest.java
 
b/tests/features/camel-http/src/test/java/org/apache/karaf/camel/itest/CamelHttpITest.java
new file mode 100644
index 00000000..cff038ef
--- /dev/null
+++ 
b/tests/features/camel-http/src/test/java/org/apache/karaf/camel/itest/CamelHttpITest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.function.Consumer;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.CamelKarafTestHint;
+import org.apache.karaf.camel.itests.GenericContainerResource;
+import org.apache.karaf.camel.itests.PaxExamWithExternalResource;
+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;
+import org.testcontainers.containers.GenericContainer;
+
+@CamelKarafTestHint(externalResourceProvider = 
CamelHttpITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelHttpITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedBodiesReceived("<html><body><h1>It 
works!</h1></body></html>\n");
+    }
+
+    @Test
+    public void testResultMock() throws Exception {
+        assertMockEndpointsSatisfied();
+    }
+
+    public static final class ExternalResourceProviders {
+
+        private static final int HTTP_PORT = 80;
+
+        public static GenericContainerResource createHttpContainer() {
+            final GenericContainer<?> httpContainer =
+                    new GenericContainer<>("library/httpd:2.4.59")
+                            .withExposedPorts(HTTP_PORT);
+
+            return new GenericContainerResource(httpContainer, 
(Consumer<GenericContainerResource>) resource -> {
+                resource.setProperty("http.port", 
Integer.toString(httpContainer.getMappedPort(HTTP_PORT)));
+            });
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 03c6a5f0..4858d0e5 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -46,6 +46,7 @@
         <module>camel-ehcache</module>
         <module>camel-elasticsearch</module>
         <module>camel-hazelcast</module>
+        <module>camel-http</module>
         <module>camel-jcache</module>
         <module>camel-jetty</module>
         <module>camel-kafka</module>

Reply via email to