From 4e859cc53fd427ff69d9d147a1d8bebeedf1a7a5 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Fri, 26 Apr 2019 16:56:50 +0200 Subject: [PATCH 1/2] Add an integration test for camel-jdbc component --- integration-tests/camel-jdbc/pom.xml | 165 ++++++++++++++++++ .../quarkus/it/camel/jdbc/CamelLifecycle.java | 51 ++++++ .../io/quarkus/it/camel/jdbc/CamelRoute.java | 19 ++ .../src/main/resources/application.properties | 5 + .../io/quarkus/it/camel/jdbc/CamelJdbcIT.java | 8 + .../quarkus/it/camel/jdbc/CamelJdbcTest.java | 45 +++++ .../quarkus/it/camel/jdbc/TestResources.java | 24 +++ integration-tests/pom.xml | 1 + 8 files changed, 318 insertions(+) create mode 100644 integration-tests/camel-jdbc/pom.xml create mode 100644 integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelLifecycle.java create mode 100644 integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelRoute.java create mode 100644 integration-tests/camel-jdbc/src/main/resources/application.properties create mode 100644 integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/CamelJdbcIT.java create mode 100644 integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/CamelJdbcTest.java create mode 100644 integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/TestResources.java diff --git a/integration-tests/camel-jdbc/pom.xml b/integration-tests/camel-jdbc/pom.xml new file mode 100644 index 0000000000000..f365496a0f413 --- /dev/null +++ b/integration-tests/camel-jdbc/pom.xml @@ -0,0 +1,165 @@ + + + + + + quarkus-integration-tests-parent + io.quarkus + 999-SNAPSHOT + ../ + + 4.0.0 + + quarkus-integration-test-camel-jdbc + Quarkus - Integration Tests - Camel - JDBC + Integration tests for Camel JDBC component + + + + io.quarkus + quarkus-hibernate-orm + + + + io.quarkus + quarkus-jdbc-h2 + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-camel-core + + + org.jboss.spec.javax.security.jacc + jboss-jacc-api_1.5_spec + + + + org.apache.camel + camel-jdbc + 3.0.0-M2 + + + org.apache.camel + camel-csv + 3.0.0-M2 + + + org.jboss.slf4j + slf4j-jboss-logging + provided + + + + + io.quarkus + quarkus-junit5 + test + + + io.quarkus + quarkus-test-h2 + test + + + io.rest-assured + rest-assured + test + + + + + + + src/main/resources + true + + + + + ${project.groupId} + quarkus-maven-plugin + + + + build + + + + + + + + + + native-image + + + native + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + + + + ${project.groupId} + quarkus-maven-plugin + + + native-image + + native-image + + + true + true + true + ${graalvmHome} + false + false + + + + + + + + + + diff --git a/integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelLifecycle.java b/integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelLifecycle.java new file mode 100644 index 0000000000000..cfd148ac99d29 --- /dev/null +++ b/integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelLifecycle.java @@ -0,0 +1,51 @@ +package io.quarkus.it.camel.jdbc; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import javax.sql.DataSource; + +import org.jboss.logging.Logger; + +import io.quarkus.camel.core.runtime.CamelRuntime; +import io.quarkus.camel.core.runtime.InitializingEvent; +import io.quarkus.camel.core.runtime.StartingEvent; + +@ApplicationScoped +public class CamelLifecycle { + + private static final Logger log = Logger.getLogger(CamelLifecycle.class); + + @Inject + CamelRuntime runtime; + + @Inject + DataSource dataSource; + + public void initializing(@Observes InitializingEvent event) { + log.debug("Binding camelsDs"); + runtime.getRegistry().bind("camelsDs", dataSource); + } + + public void starting(@Observes StartingEvent event) throws SQLException { + log.debug("Initializing camels table"); + try (Connection con = dataSource.getConnection()) { + try (Statement statement = con.createStatement()) { + try { + statement.execute("drop table camels"); + } catch (Exception ignored) { + } + statement.execute("create table camels (id int primary key, species varchar(255))"); + statement.execute("insert into camels (id, species) values (1, 'Camelus dromedarius')"); + statement.execute("insert into camels (id, species) values (2, 'Camelus bactrianus')"); + statement.execute("insert into camels (id, species) values (3, 'Camelus ferus')"); + } + log.warn("Initialized camels table"); + } + } + +} diff --git a/integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelRoute.java b/integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelRoute.java new file mode 100644 index 0000000000000..c72e8b2c74091 --- /dev/null +++ b/integration-tests/camel-jdbc/src/main/java/io/quarkus/it/camel/jdbc/CamelRoute.java @@ -0,0 +1,19 @@ +package io.quarkus.it.camel.jdbc; + +import javax.enterprise.context.ApplicationScoped; + +import org.apache.camel.builder.RouteBuilder; + +@ApplicationScoped +public class CamelRoute extends RouteBuilder { + + @Override + public void configure() { + from("timer:jdbc?repeatCount=1") + .setBody(constant("select * from camels")) + .to("jdbc:camelsDs") + .marshal().csv() + .to("file:target?fileName=out.csv"); + } + +} diff --git a/integration-tests/camel-jdbc/src/main/resources/application.properties b/integration-tests/camel-jdbc/src/main/resources/application.properties new file mode 100644 index 0000000000000..782b21824f66f --- /dev/null +++ b/integration-tests/camel-jdbc/src/main/resources/application.properties @@ -0,0 +1,5 @@ +quarkus.camel.disable-xml=true +quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:test +quarkus.datasource.driver=org.h2.Driver +quarkus.datasource.max-size=8 +quarkus.datasource.min-size=2 \ No newline at end of file diff --git a/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/CamelJdbcIT.java b/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/CamelJdbcIT.java new file mode 100644 index 0000000000000..a43f38b2bc5bd --- /dev/null +++ b/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/CamelJdbcIT.java @@ -0,0 +1,8 @@ +package io.quarkus.it.camel.jdbc; + +import io.quarkus.test.junit.SubstrateTest; + +@SubstrateTest +public class CamelJdbcIT extends CamelJdbcTest { + +} diff --git a/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/CamelJdbcTest.java b/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/CamelJdbcTest.java new file mode 100644 index 0000000000000..efcf53b259ec0 --- /dev/null +++ b/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/CamelJdbcTest.java @@ -0,0 +1,45 @@ +package io.quarkus.it.camel.jdbc; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class CamelJdbcTest { + + @Test + public void selectCamelsToCsv() throws Throwable { + final long timeoutMs = 10000; + final long deadline = System.currentTimeMillis() + timeoutMs; + final Path outCsv = Paths.get("target/out.csv"); + Throwable lastException = null; + final String expectedCsv = "1,Camelus dromedarius\r\n2,Camelus bactrianus\r\n3,Camelus ferus\r\n"; + while (System.currentTimeMillis() <= deadline) { + try { + Thread.sleep(100); + if (!Files.exists(outCsv)) { + lastException = new AssertionError(String.format("%s does not exist", outCsv)); + } else { + final String actual = new String(Files.readAllBytes(outCsv), StandardCharsets.UTF_8); + if (expectedCsv.equals(actual)) { + /* Test passed */ + return; + } else { + lastException = new AssertionError(String.format("expected: <%s> but was: <%s>", expectedCsv, actual)); + } + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw e; + } catch (Exception e) { + lastException = e; + } + } + throw lastException; + } +} diff --git a/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/TestResources.java b/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/TestResources.java new file mode 100644 index 0000000000000..d6dcbfcce0879 --- /dev/null +++ b/integration-tests/camel-jdbc/src/test/java/io/quarkus/it/camel/jdbc/TestResources.java @@ -0,0 +1,24 @@ +/* + * Copyright 2019 Red Hat, Inc. + * + * 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 io.quarkus.it.camel.jdbc; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.h2.H2DatabaseTestResource; + +@QuarkusTestResource(H2DatabaseTestResource.class) +public class TestResources { +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 730cf7d286369..88b7972e3efd5 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -54,6 +54,7 @@ infinispan-cache-jpa elytron-security camel-core + camel-jdbc camel-salesforce camel-aws-s3 flyway From 168aac51959864b1b04ac4c981163800848e2dc7 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Fri, 10 May 2019 12:32:13 +0200 Subject: [PATCH 2/2] disable jaxb --- .../camel-jdbc/src/main/resources/application.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/integration-tests/camel-jdbc/src/main/resources/application.properties b/integration-tests/camel-jdbc/src/main/resources/application.properties index 782b21824f66f..80fcdd645a607 100644 --- a/integration-tests/camel-jdbc/src/main/resources/application.properties +++ b/integration-tests/camel-jdbc/src/main/resources/application.properties @@ -1,4 +1,5 @@ quarkus.camel.disable-xml=true +quarkus.camel.disable-jaxb=true quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:test quarkus.datasource.driver=org.h2.Driver quarkus.datasource.max-size=8