This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new b589ac9 Adds test infra for ArangoDB (#4623) b589ac9 is described below commit b589ac9ea2daa20670083e8145f138b97c38ac5c Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com> AuthorDate: Wed Nov 18 16:28:35 2020 +0100 Adds test infra for ArangoDB (#4623) Also migrates the camel-arangodb tests to the shared test infra --- components/camel-arangodb/pom.xml | 14 +++- .../camel/component/arangodb/BaseArangoDbTest.java | 11 ++-- test-infra/camel-test-infra-arangodb/pom.xml | 60 +++++++++++++++++ .../src/main/resources/META-INF/MANIFEST.MF | 0 .../infra/arangodb/common/ArangoDBProperties.java | 28 ++++++++ .../services/ArangoDBLocalContainerService.java | 75 ++++++++++++++++++++++ .../arangodb/services/ArangoDBRemoteService.java | 47 ++++++++++++++ .../infra/arangodb/services/ArangoDBService.java | 46 +++++++++++++ .../arangodb/services/ArangoDBServiceFactory.java | 43 +++++++++++++ .../arangodb/services}/ArangoDbContainer.java | 15 ++++- test-infra/pom.xml | 11 ++-- 11 files changed, 333 insertions(+), 17 deletions(-) diff --git a/components/camel-arangodb/pom.xml b/components/camel-arangodb/pom.xml index 9999380..75b0b72 100644 --- a/components/camel-arangodb/pom.xml +++ b/components/camel-arangodb/pom.xml @@ -65,9 +65,21 @@ <artifactId>camel-test-junit5</artifactId> <scope>test</scope> </dependency> + + <!-- test infra --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-testcontainers-spring-junit5</artifactId> + <artifactId>camel-test-infra-arangodb</artifactId> + <version>${project.version}</version> + <type>test-jar</type> <scope>test</scope> </dependency> </dependencies> diff --git a/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/BaseArangoDbTest.java b/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/BaseArangoDbTest.java index ee02c7d..f325b18 100644 --- a/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/BaseArangoDbTest.java +++ b/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/BaseArangoDbTest.java @@ -20,25 +20,27 @@ import com.arangodb.ArangoDB; import com.arangodb.ArangoDatabase; import org.apache.camel.CamelContext; import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.test.infra.arangodb.services.ArangoDBService; +import org.apache.camel.test.infra.arangodb.services.ArangoDBServiceFactory; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.extension.RegisterExtension; public class BaseArangoDbTest extends CamelTestSupport { + @RegisterExtension + public static ArangoDBService service = ArangoDBServiceFactory.createService(); protected static final String DATABASE_NAME = "dbTest"; protected static final String COLLECTION_NAME = "camelTest"; protected static final String GRAPH_NAME = "graphTest"; protected static final String VERTEX_COLLECTION_NAME = "vertexTest"; protected static final String EDGE_COLLECTION_NAME = "edgeTest"; - protected static ArangoDbContainer container; protected static ArangoDB arangoDb; protected static ArangoDatabase arangoDatabase; @BeforeAll public static void doBeforeAll() { - container = new ArangoDbContainer(); - container.start(); arangoDb = new ArangoDB.Builder().build(); arangoDb.createDatabase(DATABASE_NAME); arangoDatabase = arangoDb.db(DATABASE_NAME); @@ -47,9 +49,6 @@ public class BaseArangoDbTest extends CamelTestSupport { @AfterAll public static void doAfterAll() { arangoDb.shutdown(); - if (container != null) { - container.stop(); - } } @Override diff --git a/test-infra/camel-test-infra-arangodb/pom.xml b/test-infra/camel-test-infra-arangodb/pom.xml new file mode 100644 index 0000000..17d0941 --- /dev/null +++ b/test-infra/camel-test-infra-arangodb/pom.xml @@ -0,0 +1,60 @@ +<?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"> + <parent> + <artifactId>camel-test-infra-parent</artifactId> + <groupId>org.apache.camel</groupId> + <relativePath>../camel-test-infra-parent/pom.xml</relativePath> + <version>3.7.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-test-infra-arangodb</artifactId> + <name>Camel :: Test Infra :: ArangoDB</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + </plugin> + </plugins> + </build> + + +</project> \ No newline at end of file diff --git a/test-infra/camel-test-infra-arangodb/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-arangodb/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29 diff --git a/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/common/ArangoDBProperties.java b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/common/ArangoDBProperties.java new file mode 100644 index 0000000..26172dc --- /dev/null +++ b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/common/ArangoDBProperties.java @@ -0,0 +1,28 @@ +/* + * 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.infra.arangodb.common; + +public final class ArangoDBProperties { + public static final String ARANGODB_CONTAINER = "arangodb.container"; + public static final String ARANGODB_HOST = "arangodb.host"; + public static final String ARANGODB_PORT = "arangodb.port"; + + private ArangoDBProperties() { + + } +} diff --git a/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBLocalContainerService.java b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBLocalContainerService.java new file mode 100644 index 0000000..7b74a04 --- /dev/null +++ b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBLocalContainerService.java @@ -0,0 +1,75 @@ +/* + * 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.infra.arangodb.services; + +import org.apache.camel.test.infra.arangodb.common.ArangoDBProperties; +import org.apache.camel.test.infra.common.services.ContainerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; + +public class ArangoDBLocalContainerService implements ArangoDBService, ContainerService<GenericContainer> { + private static final Logger LOG = LoggerFactory.getLogger(ArangoDBLocalContainerService.class); + + private ArangoDbContainer container; + + public ArangoDBLocalContainerService() { + String containerName = System.getProperty(ArangoDBProperties.ARANGODB_CONTAINER); + + if (containerName == null) { + container = new ArangoDbContainer(); + } else { + container = new ArangoDbContainer(containerName); + } + } + + @Override + public int getPort() { + return container.getServicePort(); + } + + @Override + public String getHost() { + return container.getHost(); + } + + @Override + public void registerProperties() { + System.setProperty(ArangoDBProperties.ARANGODB_HOST, container.getHost()); + System.setProperty(ArangoDBProperties.ARANGODB_PORT, String.valueOf(container.getServicePort())); + } + + @Override + public void initialize() { + LOG.info("Trying to start the ArangoDB container"); + container.start(); + + registerProperties(); + LOG.info("ArangoDB instance running at {}", getServiceAddress()); + } + + @Override + public void shutdown() { + LOG.info("Stopping the ArangoDB container"); + container.stop(); + } + + @Override + public GenericContainer getContainer() { + return container; + } +} diff --git a/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBRemoteService.java b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBRemoteService.java new file mode 100644 index 0000000..0560fc8 --- /dev/null +++ b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBRemoteService.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.camel.test.infra.arangodb.services; + +import org.apache.camel.test.infra.arangodb.common.ArangoDBProperties; + +public class ArangoDBRemoteService implements ArangoDBService { + + @Override + public int getPort() { + return Integer.valueOf(System.getProperty(ArangoDBProperties.ARANGODB_PORT)); + } + + @Override + public String getHost() { + return System.getProperty(ArangoDBProperties.ARANGODB_HOST); + } + + @Override + public void registerProperties() { + // NO-OP + } + + @Override + public void initialize() { + registerProperties(); + } + + @Override + public void shutdown() { + // NO-OP + } +} diff --git a/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBService.java b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBService.java new file mode 100644 index 0000000..81a479e --- /dev/null +++ b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBService.java @@ -0,0 +1,46 @@ +/* + * 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.infra.arangodb.services; + +import org.apache.camel.test.infra.common.services.TestService; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * Test infra service for ArangoDB + */ +public interface ArangoDBService extends BeforeAllCallback, AfterAllCallback, TestService { + + int getPort(); + + String getHost(); + + default String getServiceAddress() { + return String.format("%s:%d", getHost(), getPort()); + } + + @Override + default void beforeAll(ExtensionContext extensionContext) throws Exception { + initialize(); + } + + @Override + default void afterAll(ExtensionContext extensionContext) throws Exception { + shutdown(); + } +} diff --git a/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBServiceFactory.java b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBServiceFactory.java new file mode 100644 index 0000000..daf09e9 --- /dev/null +++ b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDBServiceFactory.java @@ -0,0 +1,43 @@ +/* + * 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.infra.arangodb.services; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class ArangoDBServiceFactory { + private static final Logger LOG = LoggerFactory.getLogger(ArangoDBServiceFactory.class); + + private ArangoDBServiceFactory() { + + } + + public static ArangoDBService createService() { + String instanceType = System.getProperty("arangodb.instance.type"); + + if (instanceType == null || instanceType.equals("local-arangodb-container")) { + return new ArangoDBLocalContainerService(); + } + + if (instanceType.equals("remote")) { + return new ArangoDBRemoteService(); + } + + LOG.error("ArangoDB instance must be one of 'local-arangodb-container' or 'remote"); + throw new UnsupportedOperationException("Invalid ArangoDB instance type"); + } +} diff --git a/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/ArangoDbContainer.java b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDbContainer.java similarity index 84% rename from components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/ArangoDbContainer.java rename to test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDbContainer.java index 8aea2f2..a156e72 100644 --- a/components/camel-arangodb/src/test/java/org/apache/camel/component/arangodb/ArangoDbContainer.java +++ b/test-infra/camel-test-infra-arangodb/src/test/java/org/apache/camel/test/infra/arangodb/services/ArangoDbContainer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.arangodb; +package org.apache.camel.test.infra.arangodb.services; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,15 +23,20 @@ import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; public class ArangoDbContainer extends GenericContainer { + public static final Integer PORT_DEFAULT = 8529; + private static final Logger LOGGER = LoggerFactory.getLogger(ArangoDbContainer.class); private static final String CONTAINER_NAME = "arango"; private static final String ARANGO_IMAGE = "arangodb:latest"; private static final String ARANGO_NO_AUTH = "ARANGO_NO_AUTH"; - private static final Integer PORT_DEFAULT = 8529; public ArangoDbContainer() { - super(ARANGO_IMAGE); + this(ARANGO_IMAGE); + } + + public ArangoDbContainer(String containerName) { + super(containerName); setWaitStrategy(Wait.forListeningPort()); addFixedExposedPort(PORT_DEFAULT, PORT_DEFAULT); withNetworkAliases(CONTAINER_NAME); @@ -40,4 +45,8 @@ public class ArangoDbContainer extends GenericContainer { waitingFor(Wait.forLogMessage(".*is ready for business. Have fun!.*", 1)); } + public int getServicePort() { + return getMappedPort(PORT_DEFAULT); + } + } diff --git a/test-infra/pom.xml b/test-infra/pom.xml index 0b2302e..952877d 100644 --- a/test-infra/pom.xml +++ b/test-infra/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- ~ Licensed to the Apache Software Foundation (ASF) under one or more ~ contributor license agreements. See the NOTICE file distributed with @@ -15,9 +15,7 @@ ~ 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" +<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"> <parent> <artifactId>camel-parent</artifactId> @@ -28,7 +26,6 @@ <modelVersion>4.0.0</modelVersion> <artifactId>test-infra</artifactId> - <packaging>pom</packaging> <name>Camel :: Test Infra</name> <description>Test infrastructure for Camel</description> @@ -53,6 +50,6 @@ <module>camel-test-infra-dispatch-router</module> <module>camel-test-infra-hdfs</module> <module>camel-test-infra-jdbc</module> - + <module>camel-test-infra-arangodb</module> </modules> -</project> \ No newline at end of file +</project>