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 f1cf4d2f Ref #432: Add docker integration test (#433)
f1cf4d2f is described below
commit f1cf4d2f0546c41d65068f258e30d93ce9415d8c
Author: Stefan Tataru <[email protected]>
AuthorDate: Wed Jul 17 10:24:34 2024 +0200
Ref #432: Add docker integration test (#433)
---
features/src/main/feature/camel-features.xml | 11 +++-
tests/features/camel-docker/pom.xml | 42 +++++++++++++
.../karaf/camel/test/CamelDockerRouteSupplier.java | 60 +++++++++++++++++++
.../apache/karaf/camel/itest/CamelDockerITest.java | 69 ++++++++++++++++++++++
tests/features/pom.xml | 1 +
5 files changed, 182 insertions(+), 1 deletion(-)
diff --git a/features/src/main/feature/camel-features.xml
b/features/src/main/feature/camel-features.xml
index 579c452b..fa05ec69 100644
--- a/features/src/main/feature/camel-features.xml
+++ b/features/src/main/feature/camel-features.xml
@@ -146,6 +146,7 @@
<bundle
dependency='true'>mvn:io.netty/netty-buffer/${netty-version}</bundle>
<bundle
dependency='true'>mvn:io.netty/netty-common/${netty-version}</bundle>
<bundle
dependency='true'>mvn:io.netty/netty-codec/${netty-version}</bundle>
+ <bundle
dependency='true'>mvn:io.netty/netty-codec-http/${netty-version}</bundle>
<bundle
dependency='true'>mvn:io.netty/netty-handler/${netty-version}</bundle>
<bundle
dependency='true'>mvn:io.netty/netty-resolver/${netty-version}</bundle>
<bundle
dependency='true'>mvn:io.netty/netty-transport/${netty-version}</bundle>
@@ -952,8 +953,16 @@
</feature>
<feature name='camel-docker' version='${project.version}' start-level='50'>
<feature version='${camel-osgi-version-range}'>camel-core</feature>
+ <feature version='[32,33)'>guava</feature>
+ <feature version='${camel-osgi-jackson2-version}'>jackson</feature>
+ <feature version='[4.1,5)'>netty</feature>
+ <!-- both 'docker-java' and 'docker-java-core' export
'com.github.dockerjava.core',
+ the fragmented host option will enforce both bundles to share the same
class loader,
+ 'docker-java-core' was chosen as the host because 'docker-java'
contains only one package with a single class -->
+ <bundle
dependency='true'>wrap:mvn:com.github.docker-java/docker-java/${docker-java-version}$Fragment-Host=com.github.docker-java.docker-java-core;bundle-version=${docker-java-version}</bundle>
<bundle
dependency='true'>wrap:mvn:com.github.docker-java/docker-java-api/${docker-java-version}</bundle>
- <bundle
dependency='true'>wrap:mvn:com.github.docker-java/docker-java-core/${docker-java-version}</bundle>
+ <bundle
dependency='true'>wrap:mvn:com.github.docker-java/docker-java-core/${docker-java-version}$Bundle-SymbolicName=com.github.docker-java.docker-java-core</bundle>
+ <bundle
dependency='true'>wrap:mvn:com.github.docker-java/docker-java-transport/${docker-java-version}</bundle>
<bundle
dependency='true'>wrap:mvn:com.github.docker-java/docker-java-transport-jersey/${docker-java-version}</bundle>
<bundle
dependency='true'>wrap:mvn:com.github.docker-java/docker-java-transport-netty/${docker-java-version}</bundle>
<bundle
dependency='true'>mvn:org.apache.commons/commons-lang3/${commons-lang3-version}</bundle>
diff --git a/tests/features/camel-docker/pom.xml
b/tests/features/camel-docker/pom.xml
new file mode 100644
index 00000000..4d7ee572
--- /dev/null
+++ b/tests/features/camel-docker/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.7.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-docker-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: Docker</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-docker/src/main/java/org/apache/karaf/camel/test/CamelDockerRouteSupplier.java
b/tests/features/camel-docker/src/main/java/org/apache/karaf/camel/test/CamelDockerRouteSupplier.java
new file mode 100644
index 00000000..df34cd17
--- /dev/null
+++
b/tests/features/camel-docker/src/main/java/org/apache/karaf/camel/test/CamelDockerRouteSupplier.java
@@ -0,0 +1,60 @@
+/*
+ * 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 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-docker-test",
+ immediate = true,
+ service = CamelRouteSupplier.class
+)
+public class CamelDockerRouteSupplier extends
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ public static final String DOCKER_USERNAME = "test";
+ public static final String DOCKER_TEST_IMAGE = "hello-world:linux";
+
+ @Override
+ protected boolean consumerEnabled() {
+ return false;
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition
producerRoute) {
+ producerRoute.log("Will ping")
+
.toD("docker://ping?host=${properties:docker.host}&port=${properties:docker.port}")
+ .log("Ping: ${body}")
+ .setBody(builder.constant("OK_PING"))
+ .toF("mock:%s", getResultMockName())
+ .log("Will pull image")
+ .setHeader("CamelDockerUsername",
builder.constant(DOCKER_USERNAME))
+ .setHeader("CamelDockerRepository",
builder.constant(DOCKER_TEST_IMAGE))
+
.toD("docker://imagepull?host=${properties:docker.host}&port=${properties:docker.port}")
+ .log("Pull image: ${body}")
+ .setBody(builder.constant("OK_PULL_IMAGE"))
+ .toF("mock:%s", getResultMockName())
+ .log("Will remove image")
+ .setHeader("CamelDockerImageId",
builder.constant(DOCKER_TEST_IMAGE))
+
.toD("docker://imageremove?host=${properties:docker.host}&port=${properties:docker.port}")
+ .log("Remove image: ${body}")
+ .setBody(builder.constant("OK_REMOVE_IMAGE"))
+ .toF("mock:%s", getResultMockName());
+ }
+}
\ No newline at end of file
diff --git
a/tests/features/camel-docker/src/test/java/org/apache/karaf/camel/itest/CamelDockerITest.java
b/tests/features/camel-docker/src/test/java/org/apache/karaf/camel/itest/CamelDockerITest.java
new file mode 100644
index 00000000..893c4494
--- /dev/null
+++
b/tests/features/camel-docker/src/test/java/org/apache/karaf/camel/itest/CamelDockerITest.java
@@ -0,0 +1,69 @@
+/*
+ * 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 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;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+@CamelKarafTestHint(externalResourceProvider =
CamelDockerITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelDockerITest extends
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ private static final int ORIGINAL_DOCKER_NO_TLS_PORT = 2375;
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedBodiesReceived("OK_PING", "OK_PULL_IMAGE",
"OK_REMOVE_IMAGE");
+ }
+
+ @Test
+ public void testResultMock() throws Exception {
+ assertMockEndpointsSatisfied();
+ }
+
+ public static final class ExternalResourceProviders {
+ public static GenericContainerResource<DockerContainer>
createDockerContainer() {
+
+ DockerContainer dockerContainer = new
DockerContainer("docker:27.0");
+ return new GenericContainerResource<>(dockerContainer, resource ->
{
+ resource.setProperty("docker.host", dockerContainer.getHost());
+ resource.setProperty("docker.port",
Integer.toString(dockerContainer.getMappedPort(ORIGINAL_DOCKER_NO_TLS_PORT)));
+ });
+ }
+ }
+
+ public static class DockerContainer extends
GenericContainer<DockerContainer> {
+
+ public DockerContainer(final String containerName) {
+ super(containerName);
+
+ // is mandatory to run this image with --privileged
+ withPrivilegedMode(true)
+ // expose docker in docker container daemon on TCP without SSL
+ .withCommand("dockerd", "--host",
"tcp://0.0.0.0:%s".formatted(ORIGINAL_DOCKER_NO_TLS_PORT), "--tls=false")
+ .withExposedPorts(ORIGINAL_DOCKER_NO_TLS_PORT)
+ .waitingFor(Wait.forListeningPort());
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 009c9b00..6c103eb9 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -58,6 +58,7 @@
<module>camel-caffeine</module>
<module>camel-cbor</module>
<module>camel-core</module>
+ <module>camel-docker</module>
<module>camel-drill</module>
<module>camel-ehcache</module>
<module>camel-elasticsearch</module>