This is an automated email from the ASF dual-hosted git repository. aldettinger pushed a commit to branch CAMEL-13965 in repository https://gitbox.apache.org/repos/asf/camel.git
commit b3aa2af3316c3f3f0b622f1b6abf4eb77b5045d8 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Thu Oct 24 13:01:49 2019 +0200 CAMEL-14084: Initial import of camel-testcontainers-spring-junit5 from camel-testcontainers-spring --- apache-camel/pom.xml | 5 + apache-camel/src/main/descriptors/common-bin.xml | 1 + bom/camel-bom/pom.xml | 5 + .../camel-testcontainers-spring-junit5/pom.xml | 158 +++++++++++++++++++++ .../main/docs/testcontainers-spring-junit5.adoc | 9 ++ .../junit5/ContainerAwareSpringTestSupport.java | 110 ++++++++++++++ .../junit5/ContainerAwareSpringTestSupportIT.java | 62 ++++++++ .../src/test/resources/log4j2.properties | 30 ++++ .../junit5/ContainerAwareSpringTestSupportTest.xml | 33 +++++ components/pom.xml | 1 + docs/components/modules/ROOT/nav.adoc | 1 + docs/components/modules/ROOT/pages/index.adoc | 4 +- .../ROOT/pages/testcontainers-spring-junit5.adoc | 10 ++ parent/pom.xml | 5 + .../camel-spring-boot-dependencies/pom.xml | 5 + 15 files changed, 438 insertions(+), 1 deletion(-) diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml index b43d980..36d78e1 100644 --- a/apache-camel/pom.xml +++ b/apache-camel/pom.xml @@ -1533,6 +1533,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-testcontainers-spring-junit5</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-thrift</artifactId> <version>${project.version}</version> </dependency> diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml index 45a6c0a..d9df21d 100644 --- a/apache-camel/src/main/descriptors/common-bin.xml +++ b/apache-camel/src/main/descriptors/common-bin.xml @@ -327,6 +327,7 @@ <include>org.apache.camel:camel-testcontainers</include> <include>org.apache.camel:camel-testcontainers-junit5</include> <include>org.apache.camel:camel-testcontainers-spring</include> + <include>org.apache.camel:camel-testcontainers-spring-junit5</include> <include>org.apache.camel:camel-thrift</include> <include>org.apache.camel:camel-tika</include> <include>org.apache.camel:camel-timer</include> diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml index 5024615..992a9e3 100644 --- a/bom/camel-bom/pom.xml +++ b/bom/camel-bom/pom.xml @@ -2950,6 +2950,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-testcontainers-spring-junit5</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-thrift</artifactId> <version>${project.version}</version> </dependency> diff --git a/components/camel-testcontainers-spring-junit5/pom.xml b/components/camel-testcontainers-spring-junit5/pom.xml new file mode 100644 index 0000000..67666eb --- /dev/null +++ b/components/camel-testcontainers-spring-junit5/pom.xml @@ -0,0 +1,158 @@ +<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" + 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</groupId> + <artifactId>components</artifactId> + <version>3.0.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-testcontainers-spring-junit5</artifactId> + <packaging>jar</packaging> + + <name>Camel :: Testcontainers :: Spring :: JUnit5</name> + <description>Camel unit testing with Spring, testcontainers and JUnit 5</description> + + <properties> + <firstVersion>3.0.0</firstVersion> + <label>testing,java,docker</label> + + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring-junit5</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-testcontainers-junit5</artifactId> + </dependency> + <!-- optional dependencies for running tests --> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>${assertj-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + <profiles> + <profile> + <id>testcontainers-spring-skip-tests</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <!-- activate integration test if the docker socket file is accessible --> + <profile> + <id>testcontainers-spring-integration-tests-docker-file</id> + <activation> + <file> + <exists>/var/run/docker.sock</exists> + </file> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <configuration> + <skipTests>${skipTests}</skipTests> + <systemPropertyVariables> + <visibleassertions.silence>true</visibleassertions.silence> + </systemPropertyVariables> + </configuration> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + <!-- activate integration test if the DOCKER_HOST env var is set --> + <profile> + <id>testcontainers-spring-integration-tests-docker-env</id> + <activation> + <property> + <name>env.DOCKER_HOST</name> + </property> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <configuration> + <skipTests>${skipTests}</skipTests> + <systemPropertyVariables> + <visibleassertions.silence>true</visibleassertions.silence> + </systemPropertyVariables> + </configuration> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + </profiles> +</project> diff --git a/components/camel-testcontainers-spring-junit5/src/main/docs/testcontainers-spring-junit5.adoc b/components/camel-testcontainers-spring-junit5/src/main/docs/testcontainers-spring-junit5.adoc new file mode 100644 index 0000000..96b3347 --- /dev/null +++ b/components/camel-testcontainers-spring-junit5/src/main/docs/testcontainers-spring-junit5.adoc @@ -0,0 +1,9 @@ += Testcontainers Spring + +*Available since 2.22.0* + +Testing camel components is sometime complex because the 3th party system a component interacts with does not provide testing facilities and/or is only available as a native application. To reduce this complexity, *Camel Testcontainers Spring* extends camel spring test support providing a way to create and interact with containerized applications. + +This module is an extension to the camel-testcontainers component to add support for Spring. +Therefore see the documentation for testcontainers for more details. + diff --git a/components/camel-testcontainers-spring-junit5/src/main/java/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupport.java b/components/camel-testcontainers-spring-junit5/src/main/java/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupport.java new file mode 100644 index 0000000..7d8630c --- /dev/null +++ b/components/camel-testcontainers-spring-junit5/src/main/java/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupport.java @@ -0,0 +1,110 @@ +/* + * 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.test.testcontainers.spring.junit5; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.properties.PropertiesComponent; +import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; +import org.apache.camel.test.testcontainers.junit5.ContainerPropertiesFunction; +import org.apache.camel.test.testcontainers.junit5.Containers; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; + +public abstract class ContainerAwareSpringTestSupport extends CamelSpringTestSupport { + private List<GenericContainer<?>> containers = new CopyOnWriteArrayList<>(); + + // ****************** + // Setup + // ****************** + + @Override + protected void setupResources() throws Exception { + super.setupResources(); + + containers.clear(); + containers.addAll(createContainers()); + + final Network network = containerNetwork(); + final long timeout = containersStartupTimeout(); + + Containers.start(containers, network, timeout); + } + + @Override + protected void cleanupResources() throws Exception { + super.cleanupResources(); + + Containers.stop(containers, containerShutdownTimeout()); + } + + @Override + protected CamelContext createCamelContext() throws Exception { + final CamelContext context = super.createCamelContext(); + final PropertiesComponent pc = (PropertiesComponent)context.getPropertiesComponent(); + + pc.addFunction(new ContainerPropertiesFunction(containers)); + + return context; + } + + // ****************** + // Containers set-up + // ****************** + + protected GenericContainer<?> createContainer() { + return null; + } + + protected List<GenericContainer<?>> createContainers() { + GenericContainer<?> container = createContainer(); + + return container == null ? Collections.emptyList() : Collections.singletonList(container); + } + + protected long containersStartupTimeout() { + return TimeUnit.MINUTES.toSeconds(1); + } + + protected long containerShutdownTimeout() { + return TimeUnit.MINUTES.toSeconds(1); + } + + protected Network containerNetwork() { + return null; + } + + // ****************** + // Helpers + // ****************** + + protected GenericContainer<?> getContainer(String containerName) { + return Containers.lookup(containers, containerName); + } + + protected String getContainerHost(String containerName) { + return getContainer(containerName).getContainerIpAddress(); + } + + protected int getContainerPort(String containerName, int originalPort) { + return getContainer(containerName).getMappedPort(originalPort); + } +} diff --git a/components/camel-testcontainers-spring-junit5/src/test/java/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupportIT.java b/components/camel-testcontainers-spring-junit5/src/test/java/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupportIT.java new file mode 100644 index 0000000..a328cbb --- /dev/null +++ b/components/camel-testcontainers-spring-junit5/src/test/java/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupportIT.java @@ -0,0 +1,62 @@ +/* + * 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.test.testcontainers.spring.junit5; + +import org.apache.camel.test.testcontainers.junit5.Wait; +import org.apache.camel.test.testcontainers.spring.junit5.ContainerAwareSpringTestSupport; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.testcontainers.containers.GenericContainer; + +public class ContainerAwareSpringTestSupportIT extends ContainerAwareSpringTestSupport { + @Override + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupportTest.xml"); + } + + @Test + public void testPropertyPlaceholders() throws Exception { + final GenericContainer<?> container = getContainer("myconsul"); + + final String host = context.resolvePropertyPlaceholders("{{container:host:myconsul}}"); + Assertions.assertThat(host).isEqualTo(container.getContainerIpAddress()); + + final String port = context.resolvePropertyPlaceholders("{{container:port:8500@myconsul}}"); + Assertions.assertThat(port).isEqualTo("" + container.getMappedPort(8500)); + } + + @Override + protected GenericContainer<?> createContainer() { + return new GenericContainer("consul:1.5.3") + .withNetworkAliases("myconsul") + .withExposedPorts(8500) + .waitingFor(Wait.forLogMessageContaining("Synced node info", 1)) + .withCommand( + "agent", + "-dev", + "-server", + "-bootstrap", + "-client", + "0.0.0.0", + "-log-level", + "trace" + ); + } + +} diff --git a/components/camel-testcontainers-spring-junit5/src/test/resources/log4j2.properties b/components/camel-testcontainers-spring-junit5/src/test/resources/log4j2.properties new file mode 100644 index 0000000..6d3bc2f --- /dev/null +++ b/components/camel-testcontainers-spring-junit5/src/test/resources/log4j2.properties @@ -0,0 +1,30 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-testcontainers-spring.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d %-5p %c{1} - %m %n +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n +logger.spring.name = org.apache.camel.test.testcontainers.spring +logger.spring.level = DEBUG +rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file diff --git a/components/camel-testcontainers-spring-junit5/src/test/resources/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupportTest.xml b/components/camel-testcontainers-spring-junit5/src/test/resources/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupportTest.xml new file mode 100644 index 0000000..746954c --- /dev/null +++ b/components/camel-testcontainers-spring-junit5/src/test/resources/org/apache/camel/test/testcontainers/spring/junit5/ContainerAwareSpringTestSupportTest.xml @@ -0,0 +1,33 @@ +<?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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:camel="http://camel.apache.org/schema/spring" + xsi:schemaLocation=" + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd "> + + <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <to uri="mock:result"/> + </route> + </camelContext> +</beans> \ No newline at end of file diff --git a/components/pom.xml b/components/pom.xml index d505f5d..8d3e752e 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -68,6 +68,7 @@ <module>camel-test-junit5</module> <module>camel-test-spring-junit5</module> <module>camel-testcontainers-junit5</module> + <module>camel-testcontainers-spring-junit5</module> <module>camel-blueprint</module> <module>camel-spring</module> <module>camel-groovy</module> diff --git a/docs/components/modules/ROOT/nav.adoc b/docs/components/modules/ROOT/nav.adoc index 3cdc6d9..f2c1c6b 100644 --- a/docs/components/modules/ROOT/nav.adoc +++ b/docs/components/modules/ROOT/nav.adoc @@ -354,6 +354,7 @@ * xref:test-spring.adoc[Test Spring] * xref:test.adoc[Test Module] * xref:testcontainers-junit5.adoc[Testcontainers] +* xref:testcontainers-spring-junit5.adoc[Testcontainers Spring] * xref:testcontainers-spring.adoc[Testcontainers Spring] * xref:testcontainers.adoc[Testcontainers] * xref:thrift-component.adoc[Thrift Component] diff --git a/docs/components/modules/ROOT/pages/index.adoc b/docs/components/modules/ROOT/pages/index.adoc index 9a20a65..faf0834 100644 --- a/docs/components/modules/ROOT/pages/index.adoc +++ b/docs/components/modules/ROOT/pages/index.adoc @@ -762,7 +762,7 @@ Number of Languages: 17 in 11 JAR artifacts (0 deprecated) == Miscellaneous Components // others: START -Number of Miscellaneous Components: 37 in 37 JAR artifacts (0 deprecated) +Number of Miscellaneous Components: 38 in 38 JAR artifacts (0 deprecated) [width="100%",cols="4,1,5",options="header"] |=== @@ -840,6 +840,8 @@ Number of Miscellaneous Components: 37 in 37 JAR artifacts (0 deprecated) | xref:testcontainers-spring.adoc[Testcontainers Spring] (camel-testcontainers-spring) | 2.22 | Camel unit testing with Spring and testcontainers +| xref:testcontainers-spring-junit5.adoc[Testcontainers Spring Junit5] (camel-testcontainers-spring-junit5) | 3.0 | Camel unit testing with Spring, testcontainers and JUnit 5 + | xref:zipkin.adoc[Zipkin] (camel-zipkin) | 2.18 | Distributed message tracing using Zipkin |=== // others: END diff --git a/docs/components/modules/ROOT/pages/testcontainers-spring-junit5.adoc b/docs/components/modules/ROOT/pages/testcontainers-spring-junit5.adoc new file mode 100644 index 0000000..86b1f77 --- /dev/null +++ b/docs/components/modules/ROOT/pages/testcontainers-spring-junit5.adoc @@ -0,0 +1,10 @@ += Testcontainers Spring +:page-source: components/camel-testcontainers-spring-junit5/src/main/docs/testcontainers-spring-junit5.adoc + +*Available since 2.22.0* + +Testing camel components is sometime complex because the 3th party system a component interacts with does not provide testing facilities and/or is only available as a native application. To reduce this complexity, *Camel Testcontainers Spring* extends camel spring test support providing a way to create and interact with containerized applications. + +This module is an extension to the camel-testcontainers component to add support for Spring. +Therefore see the documentation for testcontainers for more details. + diff --git a/parent/pom.xml b/parent/pom.xml index b1827c3..3af91aa 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -2293,6 +2293,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-testcontainers-spring-junit5</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-thrift</artifactId> <version>${project.version}</version> </dependency> diff --git a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml index 59f94fe..aa30b49 100644 --- a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml +++ b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml @@ -3180,6 +3180,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-testcontainers-spring-junit5</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-thrift</artifactId> <version>${project.version}</version> </dependency>