You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/10/08 16:55:46 UTC
[camel] branch master updated: CAMEL-15658: camel-pgevent :
automate integration tests (#4399)
This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 893fa5f CAMEL-15658: camel-pgevent : automate integration tests (#4399)
893fa5f is described below
commit 893fa5facdd3ff12f607ea21283bdc99b3cf6bd7
Author: Zineb BENDHIBA <be...@gmail.com>
AuthorDate: Thu Oct 8 18:55:33 2020 +0200
CAMEL-15658: camel-pgevent : automate integration tests (#4399)
---
components/camel-pgevent/pom.xml | 91 +++++++++++++++++++++-
...IntegrationTest.java => PgEventPubSubTest.java} | 19 ++---
.../apache/camel/pgevent/PgEventTestSupport.java | 85 ++++++++++++++++++++
....java => PgEventWithDefinedDatasourceTest.java} | 23 +++---
.../AbstractPgEventIntegrationTest.java | 32 --------
.../src/test/resources/test-options.properties | 37 ---------
6 files changed, 192 insertions(+), 95 deletions(-)
diff --git a/components/camel-pgevent/pom.xml b/components/camel-pgevent/pom.xml
index 4c60b5f..03e0223 100644
--- a/components/camel-pgevent/pom.xml
+++ b/components/camel-pgevent/pom.xml
@@ -17,7 +17,8 @@
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/maven-v4_0_0.xsd">
+<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -64,6 +65,94 @@
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-testcontainers-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+ <profiles>
+ <profile>
+ <id>pgevent-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>pgevent-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>pgevent-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-pgevent/src/test/java/org/apache/camel/pgevent/integration/PgEventPubSubIntegrationTest.java b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventPubSubTest.java
similarity index 75%
rename from components/camel-pgevent/src/test/java/org/apache/camel/pgevent/integration/PgEventPubSubIntegrationTest.java
rename to components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventPubSubTest.java
index 867cd4c..1dd1d2b 100644
--- a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/integration/PgEventPubSubIntegrationTest.java
+++ b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventPubSubTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.pgevent.integration;
+package org.apache.camel.pgevent;
import org.apache.camel.Endpoint;
import org.apache.camel.EndpointInject;
@@ -23,13 +23,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.Test;
-public class PgEventPubSubIntegrationTest extends AbstractPgEventIntegrationTest {
-
- @EndpointInject("pgevent://{{host}}:{{port}}/{{database}}/testchannel?user={{databaseUser}}&pass={{password}}")
- private Endpoint subscribeEndpoint;
-
- @EndpointInject("pgevent://{{host}}:{{port}}/{{database}}/testchannel?user={{databaseUser}}&pass={{password}}")
- private Endpoint notifyEndpoint;
+public class PgEventPubSubTest extends PgEventTestSupport {
@EndpointInject("timer://test?repeatCount=1&period=1")
private Endpoint timerEndpoint;
@@ -50,10 +44,13 @@ public class PgEventPubSubIntegrationTest extends AbstractPgEventIntegrationTest
public void configure() throws Exception {
from(timerEndpoint)
.setBody(constant(TEST_MESSAGE_BODY))
- .to(notifyEndpoint);
+ .to(String.format(
+ "pgevent://%s:%s/%s/testchannel?user=%s&pass=%s", getHost(), getMappedPort(), POSTGRES_DB,
+ POSTGRES_USER, POSTGRES_PASSWORD));
- from(subscribeEndpoint)
- .to(mockEndpoint);
+ from(String.format("pgevent://%s:%s/%s/testchannel?user=%s&pass=%s",
+ getHost(), getMappedPort(), POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD))
+ .to(mockEndpoint);
}
};
}
diff --git a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventTestSupport.java b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventTestSupport.java
new file mode 100644
index 0000000..41dfec6
--- /dev/null
+++ b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventTestSupport.java
@@ -0,0 +1,85 @@
+/*
+ * 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.pgevent;
+
+import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.utility.TestcontainersConfiguration;
+
+public class PgEventTestSupport extends ContainerAwareTestSupport {
+
+ public static final String CONTAINER_NAME = "pg-event";
+ protected static final String TEST_MESSAGE_BODY = "Test Camel PGEvent";
+ protected static final String POSTGRES_USER = "postgres";
+ protected static final String POSTGRES_PASSWORD = "mysecretpassword";
+ protected static final String POSTGRES_DB = "postgres";
+
+ private static final Logger LOG = LoggerFactory.getLogger(PgEventTestSupport.class);
+ private static final int POSTGRES_PORT = 5432;
+ private static final String POSTGRES_IMAGE = "postgres:13.0";
+
+ protected GenericContainer container;
+
+ @BeforeEach
+ public void beforeEach() {
+ container = createContainer();
+ container.start();
+ }
+
+ @AfterEach
+ public void afterEach() {
+ if (container != null) {
+ container.stop();
+ }
+ }
+
+ @Override
+ protected GenericContainer<?> createContainer() {
+ LOG.info(TestcontainersConfiguration.getInstance().toString());
+
+ GenericContainer<?> container = new GenericContainer(POSTGRES_IMAGE)
+ .withCommand("postgres -c wal_level=logical")
+ .withExposedPorts(POSTGRES_PORT)
+ .withNetworkAliases(CONTAINER_NAME)
+ .withEnv("POSTGRES_USER", POSTGRES_USER)
+ .withEnv("POSTGRES_PASSWORD", POSTGRES_PASSWORD)
+ .withEnv("POSTGRES_DB", POSTGRES_DB)
+ .withLogConsumer(new Slf4jLogConsumer(LOG))
+ .waitingFor(Wait.forListeningPort());
+ return container;
+ }
+
+ public String getAuthority() {
+ return String.format("%s:%s", getContainer(CONTAINER_NAME).getContainerIpAddress(),
+ getContainer(CONTAINER_NAME).getMappedPort(POSTGRES_PORT));
+ }
+
+ public Integer getMappedPort() {
+ return getContainer(CONTAINER_NAME).getMappedPort(POSTGRES_PORT);
+ }
+
+ public String getHost() {
+ return getContainer(CONTAINER_NAME).getHost();
+ }
+
+}
diff --git a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/integration/PgEventWithDefinedDatasourceIntegrationTest.java b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventWithDefinedDatasourceTest.java
similarity index 73%
rename from components/camel-pgevent/src/test/java/org/apache/camel/pgevent/integration/PgEventWithDefinedDatasourceIntegrationTest.java
rename to components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventWithDefinedDatasourceTest.java
index 2583efa..3b1b903 100644
--- a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/integration/PgEventWithDefinedDatasourceIntegrationTest.java
+++ b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventWithDefinedDatasourceTest.java
@@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.pgevent.integration;
-
-import java.util.Properties;
+package org.apache.camel.pgevent;
import com.impossibl.postgres.jdbc.PGDataSource;
import org.apache.camel.BindToRegistry;
@@ -27,12 +25,12 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.Test;
-public class PgEventWithDefinedDatasourceIntegrationTest extends AbstractPgEventIntegrationTest {
+public class PgEventWithDefinedDatasourceTest extends PgEventTestSupport {
- @EndpointInject("pgevent:///{{database}}/testchannel?datasource=#pgDataSource")
+ @EndpointInject("pgevent:///postgres/testchannel?datasource=#pgDataSource")
private Endpoint subscribeEndpoint;
- @EndpointInject("pgevent:///{{database}}/testchannel?datasource=#pgDataSource")
+ @EndpointInject("pgevent:///postgres/testchannel?datasource=#pgDataSource")
private Endpoint notifyEndpoint;
@EndpointInject("timer://test?repeatCount=1&period=1")
@@ -43,15 +41,12 @@ public class PgEventWithDefinedDatasourceIntegrationTest extends AbstractPgEvent
@BindToRegistry("pgDataSource")
public PGDataSource loadDataSource() throws Exception {
- Properties properties = new Properties();
- properties.load(getClass().getResourceAsStream("/test-options.properties"));
-
PGDataSource dataSource = new PGDataSource();
- dataSource.setHost(properties.getProperty("host"));
- dataSource.setPort(Integer.parseInt(properties.getProperty("port")));
- dataSource.setDatabaseName(properties.getProperty("database"));
- dataSource.setUser(properties.getProperty("databaseUser"));
- dataSource.setPassword(properties.getProperty("password"));
+ dataSource.setHost(getHost());
+ dataSource.setPort(getMappedPort());
+ dataSource.setDatabaseName(POSTGRES_DB);
+ dataSource.setUser(POSTGRES_USER);
+ dataSource.setPassword(POSTGRES_PASSWORD);
return dataSource;
}
diff --git a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/integration/AbstractPgEventIntegrationTest.java b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/integration/AbstractPgEventIntegrationTest.java
deleted file mode 100644
index 89e0214..0000000
--- a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/integration/AbstractPgEventIntegrationTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.pgevent.integration;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.test.junit5.CamelTestSupport;
-
-public class AbstractPgEventIntegrationTest extends CamelTestSupport {
-
- protected static final String TEST_MESSAGE_BODY = "Test Camel PGEvent";
-
- @Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext camelContext = super.createCamelContext();
- camelContext.getPropertiesComponent().setLocation("classpath:/test-options.properties");
- return camelContext;
- }
-}
diff --git a/components/camel-pgevent/src/test/resources/test-options.properties b/components/camel-pgevent/src/test/resources/test-options.properties
deleted file mode 100644
index 0b6b18e..0000000
--- a/components/camel-pgevent/src/test/resources/test-options.properties
+++ /dev/null
@@ -1,37 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-# Change the following properties to work with your PostgreSQL instance.
-
-# The default values work with the PostgreSQL docker image https://hub.docker.com/_/postgres/.
-
-# docker run -ti --rm -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 postgres
-
-# The host where PostgreSQL is running
-host=localhost
-
-# The port that PostgreSQL is bound to
-port=5432
-
-# The user name used for connecting to PostgreSQL
-databaseUser=postgres
-
-# The password used for connecting to PostgreSQL
-password=mysecretpassword
-
-# The name of the database to use during integration testing
-database=postgres