This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git
The following commit(s) were added to refs/heads/master by this push: new d15c8c5 Add tests to example projects apache/camel-quarkus#1501 d15c8c5 is described below commit d15c8c53dbcdd7cca0e018d0f6e9e2d5d6adc020 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Thu Mar 18 15:39:29 2021 +0000 Add tests to example projects apache/camel-quarkus#1501 --- file-split-log-xml/pom.xml | 39 ++++- .../src/main/resources/application.properties | 4 +- .../org/acme/filereader/FileSplitLogXmlIT.java | 24 +-- .../org/acme/filereader/FileSplitLogXmlTest.java | 50 ++++++ health/pom.xml | 20 ++- .../src/test/java/org/acme/health/HealthIT.java | 25 +-- .../src/test/java/org/acme/health/HealthTest.java | 40 +++++ http-log/pom.xml | 46 +++++- .../main/resources/META-INF/resources/index.html | 170 --------------------- http-log/src/main/resources/application.properties | 1 + .../java/org/acme/http/HttpLogIT.java} | 23 +-- .../src/test/java/org/acme/http/HttpLogTest.java | 54 +++++++ timer-log-cdi/pom.xml | 41 ++++- .../src/main/resources/application.properties | 1 + .../test/java/org/acme/timer/TimerLogCdiIT.java | 24 +-- .../test/java/org/acme/timer/TimerLogCdiTest.java | 49 ++++++ timer-log-kotlin/pom.xml | 49 +++++- .../src/main/resources/application.properties | 1 + .../test/kotlin/org/acme/timer/TimerLogKotlin.kt | 44 +++--- .../test/kotlin/org/acme/timer/TimerLogKotlinIT.kt | 26 +--- timer-log-main/pom.xml | 83 +++++++++- .../src/main/java/org/acme/timer/Main.java | 28 ++-- .../src/main/resources/application.properties | 1 + .../test/java/org/acme/timer/TimerLogMainIT.java | 24 +-- .../test/java/org/acme/timer/TimerLogMainTest.java | 106 +++++++++++++ timer-log-spring/pom.xml | 41 ++++- .../src/main/resources/application.properties | 1 + .../test/java/org/acme/timer/TimerLogSpringIT.java | 24 +-- .../java/org/acme/timer/TimerLogSpringTest.java | 49 ++++++ timer-log-xml/pom.xml | 41 ++++- .../src/main/resources/application.properties | 1 + .../test/java/org/acme/timer/TimerLogXmlTest.java | 49 ++++++ .../test/java/org/acme/timer/TimerLogXmlXmlIT.java | 24 +-- timer-log/pom.xml | 37 +++++ .../src/main/resources/application.properties | 2 +- .../src/test/java/org/acme/timer/TimerLogIT.java | 24 +-- .../src/test/java/org/acme/timer/TimerLogTest.java | 49 ++++++ 37 files changed, 895 insertions(+), 420 deletions(-) diff --git a/file-split-log-xml/pom.xml b/file-split-log-xml/pom.xml index c1f210e..309985a 100644 --- a/file-split-log-xml/pom.xml +++ b/file-split-log-xml/pom.xml @@ -67,7 +67,7 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-timer</artifactId> + <artifactId>camel-quarkus-microprofile-health</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -75,12 +75,28 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-timer</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-xml-io</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-file</artifactId> </dependency> + + <!-- Test --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -240,6 +256,27 @@ <properties> <quarkus.package.type>native</quarkus.package.type> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/file-split-log-xml/src/main/resources/application.properties b/file-split-log-xml/src/main/resources/application.properties index ab79f43..76bf7d8 100644 --- a/file-split-log-xml/src/main/resources/application.properties +++ b/file-split-log-xml/src/main/resources/application.properties @@ -18,8 +18,7 @@ # Quarkus # quarkus.banner.enabled = false - -quarkus.log.category."org.apache.camel.main".level = DEBUG +quarkus.log.file.enable = true # # Camel @@ -29,4 +28,3 @@ camel.main.routes-include-pattern = file:src/main/resources/routes/camel-routes. camel.file.route.folder = src/main/resources/file camel.file.repeat.interval = 30000 camel.file.split.parallel = false - diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/file-split-log-xml/src/test/java/org/acme/filereader/FileSplitLogXmlIT.java similarity index 65% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to file-split-log-xml/src/test/java/org/acme/filereader/FileSplitLogXmlIT.java index 1db4c3e..864e86a 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/file-split-log-xml/src/test/java/org/acme/filereader/FileSplitLogXmlIT.java @@ -14,27 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.filereader; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { +@NativeImageTest +class FileSplitLogXmlIT extends FileSplitLogXmlTest { - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } } diff --git a/file-split-log-xml/src/test/java/org/acme/filereader/FileSplitLogXmlTest.java b/file-split-log-xml/src/test/java/org/acme/filereader/FileSplitLogXmlTest.java new file mode 100644 index 0000000..d3a502c --- /dev/null +++ b/file-split-log-xml/src/test/java/org/acme/filereader/FileSplitLogXmlTest.java @@ -0,0 +1,50 @@ +/* + * 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.acme.filereader; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.junit.QuarkusTest; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; + +@QuarkusTest +public class FileSplitLogXmlTest { + + @Test + public void testFileSplitLogXml() { + // Verify that all 1000 items were output to the log + File quarkusLogFile = getQuarkusLogFile(); + await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8); + return log.contains("line 1000 contains: Anna,COOKE"); + }); + } + + private File getQuarkusLogFile() { + String pathPrefix = "target"; + String packageType = System.getProperty("quarkus.package.type"); + if (packageType != null && packageType.equals("native")) { + pathPrefix += "/target"; + } + return new File(pathPrefix + "/quarkus.log"); + } +} diff --git a/health/pom.xml b/health/pom.xml index b798a6d..177fccd 100644 --- a/health/pom.xml +++ b/health/pom.xml @@ -62,11 +62,6 @@ <dependencies> <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-resteasy</artifactId> - </dependency> - - <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-bean</artifactId> </dependency> @@ -80,15 +75,26 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-microprofile-health</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-netty</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-timer</artifactId> </dependency> + + <!-- Test --> <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-microprofile-health</artifactId> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> </dependency> </dependencies> diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/health/src/test/java/org/acme/health/HealthIT.java similarity index 65% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to health/src/test/java/org/acme/health/HealthIT.java index 1db4c3e..adacdc9 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/health/src/test/java/org/acme/health/HealthIT.java @@ -14,27 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.health; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { - - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } +@NativeImageTest +class HealthIT extends HealthTest { } diff --git a/health/src/test/java/org/acme/health/HealthTest.java b/health/src/test/java/org/acme/health/HealthTest.java new file mode 100644 index 0000000..c12c1e0 --- /dev/null +++ b/health/src/test/java/org/acme/health/HealthTest.java @@ -0,0 +1,40 @@ +/* + * 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.acme.health; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.containsInAnyOrder; + +@QuarkusTest +public class HealthTest { + + @Test + public void testHealth() throws InterruptedException { + RestAssured.get("/q/health") + .then() + .statusCode(200) + .body("status", is("UP"), + "checks.status", containsInAnyOrder("UP", "UP", "UP"), + "checks.name", + containsInAnyOrder("camel-readiness-checks", "camel-liveness-checks", "camel-context-check"), + "checks.data.contextStatus", containsInAnyOrder(null, null, "Started")); + } +} diff --git a/http-log/pom.xml b/http-log/pom.xml index 7449d8d..a8208e7 100644 --- a/http-log/pom.xml +++ b/http-log/pom.xml @@ -62,10 +62,9 @@ <dependencies> <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-resteasy</artifactId> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-log</artifactId> </dependency> - <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-main</artifactId> @@ -76,16 +75,28 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-microprofile-health</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-microprofile-metrics</artifactId> </dependency> + + <!-- Test --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -241,6 +252,27 @@ <properties> <quarkus.package.type>native</quarkus.package.type> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/http-log/src/main/resources/META-INF/resources/index.html b/http-log/src/main/resources/META-INF/resources/index.html deleted file mode 100644 index cb44c76..0000000 --- a/http-log/src/main/resources/META-INF/resources/index.html +++ /dev/null @@ -1,170 +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. - ---> -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <title>code-with-quarkus - 1.0.0-SNAPSHOT</title> - <style> - h1, h2, h3, h4, h5, h6 { - margin-bottom: 0.5rem; - font-weight: 400; - line-height: 1.5; - } - - h1 { - font-size: 2.5rem; - } - - h2 { - font-size: 2rem - } - - h3 { - font-size: 1.75rem - } - - h4 { - font-size: 1.5rem - } - - h5 { - font-size: 1.25rem - } - - h6 { - font-size: 1rem - } - - .lead { - font-weight: 300; - font-size: 2rem; - } - - .banner { - font-size: 2.7rem; - margin: 0; - padding: 2rem 1rem; - background-color: #00A1E2; - color: white; - } - - body { - margin: 0; - font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; - } - - code { - font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; - font-size: 87.5%; - color: #e83e8c; - word-break: break-word; - } - - .left-column { - padding: .75rem; - max-width: 75%; - min-width: 55%; - } - - .right-column { - padding: .75rem; - max-width: 25%; - } - - .container { - display: flex; - width: 100%; - } - - li { - margin: 0.75rem; - } - - .right-section { - margin-left: 1rem; - padding-left: 0.5rem; - } - - .right-section h3 { - padding-top: 0; - font-weight: 200; - } - - .right-section ul { - border-left: 0.3rem solid #00A1E2; - list-style-type: none; - padding-left: 0; - } - - </style> -</head> -<body> - -<div class="banner lead"> - Your new Cloud-Native application is ready! -</div> - -<div class="container"> - <div class="left-column"> - <p class="lead"> Congratulations, you have created a new Quarkus application.</p> - - <h2>Why do you see this?</h2> - - <p>This page is served by Quarkus. The source is in - <code>src/main/resources/META-INF/resources/index.html</code>.</p> - - <h2>What can I do from here?</h2> - - <p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>. - </p> - <ul> - <li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li> - <li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li> - <li>Configure your application in <code>src/main/resources/application.properties</code>. - </li> - </ul> - - <h2>How do I get rid of this page?</h2> - <p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p> - </div> - <div class="right-column"> - <div class="right-section"> - <h3>Application</h3> - <ul> - <li>GroupId: org.apache.camel.quarkus</li> - <li>ArtifactId: http-log</li> - <li>Version: 1.0.0-SNAPSHOT</li> - <li>Quarkus Version: 1.3.2.Final</li> - </ul> - </div> - <div class="right-section"> - <h3>Next steps</h3> - <ul> - <li><a href="https://quarkus.io/guides/maven-tooling.html" target="_blank">Setup your IDE</a></li> - <li><a href="https://quarkus.io/guides/getting-started.html" target="_blank">Getting started</a></li> - <li><a href="https://quarkus.io" target="_blank">Quarkus Web Site</a></li> - </ul> - </div> - </div> -</div> - - -</body> -</html> \ No newline at end of file diff --git a/http-log/src/main/resources/application.properties b/http-log/src/main/resources/application.properties index 1d0efa7..1ed3a9f 100644 --- a/http-log/src/main/resources/application.properties +++ b/http-log/src/main/resources/application.properties @@ -18,6 +18,7 @@ # Quarkus # quarkus.banner.enabled = false +quarkus.log.file.enable = true # # Quarkus - Camel diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/http-log/src/test/java/org/acme/http/HttpLogIT.java similarity index 67% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to http-log/src/test/java/org/acme/http/HttpLogIT.java index 1db4c3e..3a792d4 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/http-log/src/test/java/org/acme/http/HttpLogIT.java @@ -16,25 +16,8 @@ */ package org.acme.http; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { - - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } +@NativeImageTest +class HttpLogIT extends HttpLogTest { } diff --git a/http-log/src/test/java/org/acme/http/HttpLogTest.java b/http-log/src/test/java/org/acme/http/HttpLogTest.java new file mode 100644 index 0000000..624db1e --- /dev/null +++ b/http-log/src/test/java/org/acme/http/HttpLogTest.java @@ -0,0 +1,54 @@ +/* + * 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.acme.http; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; + +@QuarkusTest +public class HttpLogTest { + + @Test + public void testHttpLog() { + RestAssured.get("/camel/hello") + .then() + .statusCode(200); + + File quarkusLogFile = getQuarkusLogFile(); + await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8); + return log.contains("Camel runs on"); + }); + } + + private File getQuarkusLogFile() { + String pathPrefix = "target"; + String packageType = System.getProperty("quarkus.package.type"); + if (packageType != null && packageType.equals("native")) { + pathPrefix += "/target"; + } + return new File(pathPrefix + "/quarkus.log"); + } +} diff --git a/timer-log-cdi/pom.xml b/timer-log-cdi/pom.xml index 93597f7..3ab588e 100644 --- a/timer-log-cdi/pom.xml +++ b/timer-log-cdi/pom.xml @@ -63,11 +63,27 @@ <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-timer</artifactId> + <artifactId>camel-quarkus-log</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> + <artifactId>camel-quarkus-microprofile-health</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-timer</artifactId> + </dependency> + + <!-- Test --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> </dependency> </dependencies> @@ -224,6 +240,27 @@ <properties> <quarkus.package.type>native</quarkus.package.type> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/timer-log-cdi/src/main/resources/application.properties b/timer-log-cdi/src/main/resources/application.properties index 63dd4fa..2346366 100644 --- a/timer-log-cdi/src/main/resources/application.properties +++ b/timer-log-cdi/src/main/resources/application.properties @@ -19,6 +19,7 @@ # Quarkus # quarkus.banner.enabled = false +quarkus.log.file.enable = true # # Integration diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/timer-log-cdi/src/test/java/org/acme/timer/TimerLogCdiIT.java similarity index 65% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to timer-log-cdi/src/test/java/org/acme/timer/TimerLogCdiIT.java index 1db4c3e..eb82d87 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/timer-log-cdi/src/test/java/org/acme/timer/TimerLogCdiIT.java @@ -14,27 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.timer; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { +@NativeImageTest +class TimerLogCdiIT extends TimerLogCdiTest { - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } } diff --git a/timer-log-cdi/src/test/java/org/acme/timer/TimerLogCdiTest.java b/timer-log-cdi/src/test/java/org/acme/timer/TimerLogCdiTest.java new file mode 100644 index 0000000..9259c7c --- /dev/null +++ b/timer-log-cdi/src/test/java/org/acme/timer/TimerLogCdiTest.java @@ -0,0 +1,49 @@ +/* + * 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.acme.timer; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.junit.QuarkusTest; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; + +@QuarkusTest +public class TimerLogCdiTest { + + @Test + public void testTimerLog() { + File quarkusLogFile = getQuarkusLogFile(); + await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8); + return log.contains("Incremented the counter"); + }); + } + + private File getQuarkusLogFile() { + String pathPrefix = "target"; + String packageType = System.getProperty("quarkus.package.type"); + if (packageType != null && packageType.equals("native")) { + pathPrefix += "/target"; + } + return new File(pathPrefix + "/quarkus.log"); + } +} diff --git a/timer-log-kotlin/pom.xml b/timer-log-kotlin/pom.xml index ba01e3f..cf11e91 100644 --- a/timer-log-kotlin/pom.xml +++ b/timer-log-kotlin/pom.xml @@ -64,23 +64,42 @@ <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-main</artifactId> + <artifactId>camel-quarkus-kotlin</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-timer</artifactId> + <artifactId>camel-quarkus-log</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> + <artifactId>camel-quarkus-main</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-kotlin</artifactId> + <artifactId>camel-quarkus-microprofile-health</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-timer</artifactId> + </dependency> + + <!-- Test --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> </dependency> </dependencies> <build> + <sourceDirectory>src/main/kotlin</sourceDirectory> + <testSourceDirectory>src/test/kotlin</testSourceDirectory> + <pluginManagement> <plugins> @@ -178,7 +197,6 @@ </plugins> </pluginManagement> - <sourceDirectory>src/main/kotlin</sourceDirectory> <plugins> <plugin> <groupId>io.quarkus</groupId> @@ -272,6 +290,27 @@ <properties> <quarkus.package.type>native</quarkus.package.type> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/timer-log-kotlin/src/main/resources/application.properties b/timer-log-kotlin/src/main/resources/application.properties index 16b8c20..6302ccf 100644 --- a/timer-log-kotlin/src/main/resources/application.properties +++ b/timer-log-kotlin/src/main/resources/application.properties @@ -18,6 +18,7 @@ # Quarkus # quarkus.banner.enabled = false +quarkus.log.file.enable = true # to turn on DEBUG logging in camel-main # quarkus.log.category."org.apache.camel.main".level = DEBUG diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/timer-log-kotlin/src/test/kotlin/org/acme/timer/TimerLogKotlin.kt similarity index 50% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to timer-log-kotlin/src/test/kotlin/org/acme/timer/TimerLogKotlin.kt index 1db4c3e..07e0f22 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/timer-log-kotlin/src/test/kotlin/org/acme/timer/TimerLogKotlin.kt @@ -14,27 +14,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.timer -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { +import io.quarkus.test.junit.QuarkusTest; +import org.awaitility.Awaitility.await +import org.junit.jupiter.api.Test; + +@QuarkusTest +open class TimerLogKotlinTest { + + @Test + fun testTimerLogKotlin() { + val packageType = System.getProperty("quarkus.package.type") + var pathPrefix = "target" + if (packageType != null && packageType == "native") { + pathPrefix += "/target" + } + + val quarkusLogFile = File("$pathPrefix/quarkus.log") - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; + await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until { + quarkusLogFile.readText(StandardCharsets.UTF_8).contains("Hello from Kotlin!") + } } -} +} \ No newline at end of file diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/timer-log-kotlin/src/test/kotlin/org/acme/timer/TimerLogKotlinIT.kt similarity index 65% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to timer-log-kotlin/src/test/kotlin/org/acme/timer/TimerLogKotlinIT.kt index 1db4c3e..dd3157a 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/timer-log-kotlin/src/test/kotlin/org/acme/timer/TimerLogKotlinIT.kt @@ -14,27 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.timer -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { - - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } -} +@NativeImageTest +class TimerLogKotlinIT : TimerLogKotlinTest() diff --git a/timer-log-main/pom.xml b/timer-log-main/pom.xml index f105513..96700f6 100644 --- a/timer-log-main/pom.xml +++ b/timer-log-main/pom.xml @@ -45,6 +45,8 @@ <maven-resources-plugin.version>3.1.0</maven-resources-plugin.version> <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> <mycila-license.version>3.0</mycila-license.version> + + <quarkus.runner>${project.build.directory}/quarkus-app/quarkus-run.jar</quarkus.runner> </properties> <dependencyManagement> @@ -57,21 +59,54 @@ <type>pom</type> <scope>import</scope> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom-test</artifactId> + <version>${camel-quarkus.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-log</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-main</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-microprofile-health</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-timer</artifactId> </dependency> + + <!-- Test --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> + <artifactId>camel-quarkus-integration-tests-process-executor-support</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> </dependency> </dependencies> @@ -113,16 +148,27 @@ </configuration> </plugin> + <!-- Move surefire:test to integration-test phase to be able to execute the runner JAR from a test --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${maven-surefire-plugin.version}</version> - <configuration> - <failIfNoTests>false</failIfNoTests> - <systemProperties> - <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> - </systemProperties> - </configuration> + <executions> + <execution> + <id>default-test</id> + <goals> + <goal>test</goal> + </goals> + <phase>integration-test</phase> + <configuration> + <failIfNoTests>false</failIfNoTests> + <systemProperties> + <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> + <quarkus.runner>${quarkus.runner}</quarkus.runner> + </systemProperties> + </configuration> + </execution> + </executions> </plugin> <plugin> @@ -227,7 +273,30 @@ </activation> <properties> <quarkus.package.type>native</quarkus.package.type> + <quarkus.runner>${project.build.directory}/${project.artifactId}-${project.version}-runner</quarkus.runner> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> + <quarkus.runner>${quarkus.runner}</quarkus.runner> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/timer-log-main/src/main/java/org/acme/timer/Main.java b/timer-log-main/src/main/java/org/acme/timer/Main.java index 575f326..342785a 100644 --- a/timer-log-main/src/main/java/org/acme/timer/Main.java +++ b/timer-log-main/src/main/java/org/acme/timer/Main.java @@ -26,10 +26,12 @@ import javax.inject.Named; import io.quarkus.runtime.Quarkus; import io.quarkus.runtime.annotations.QuarkusMain; import org.apache.camel.quarkus.main.CamelMainApplication; +import org.jboss.logging.Logger; @QuarkusMain public class Main { + private static final Logger LOG = Logger.getLogger(Main.class); private static String greeting; public static void main(String... args) { @@ -39,18 +41,24 @@ public class Main { * @Inject @Named("greeting") * And we pass the second argument as -durationMaxMessages which is the number of messages that the application * will process before terminating */ - if (args.length < 2) { - throw new IllegalStateException("Expected at least two CLI arguments"); - } - int i = 0; List<String> filteredArgs = new ArrayList<>(args.length); - greeting = args[i++]; - final String repeatTimes = args[i++]; - filteredArgs.add("-durationMaxMessages"); - filteredArgs.add(repeatTimes); + if (args.length < 2) { + LOG.warnf( + "Expected at least 2 CLI arguments but got %d. Will proceed with default greeting. Refer to the README instructions.", + args.length); + greeting = "Hello"; + filteredArgs.add("-durationMaxMessages"); + filteredArgs.add("2"); + } else { + int i = 0; + greeting = args[i++]; + final String repeatTimes = args[i++]; + filteredArgs.add("-durationMaxMessages"); + filteredArgs.add(repeatTimes); - for (; i < args.length; i++) { - filteredArgs.add(args[i++]); + for (; i < args.length; i++) { + filteredArgs.add(args[i++]); + } } Quarkus.run(CamelMainApplication.class, filteredArgs.toArray(new String[filteredArgs.size()])); diff --git a/timer-log-main/src/main/resources/application.properties b/timer-log-main/src/main/resources/application.properties index 3a0d58c..65d45b5 100644 --- a/timer-log-main/src/main/resources/application.properties +++ b/timer-log-main/src/main/resources/application.properties @@ -19,6 +19,7 @@ # Quarkus # quarkus.banner.enabled = false +quarkus.log.file.enable = true # # Camel - Main diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/timer-log-main/src/test/java/org/acme/timer/TimerLogMainIT.java similarity index 65% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to timer-log-main/src/test/java/org/acme/timer/TimerLogMainIT.java index 1db4c3e..6a45cb8 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/timer-log-main/src/test/java/org/acme/timer/TimerLogMainIT.java @@ -14,27 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.timer; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { +@NativeImageTest +class TimerLogMainIT extends TimerLogMainTest { - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } } diff --git a/timer-log-main/src/test/java/org/acme/timer/TimerLogMainTest.java b/timer-log-main/src/test/java/org/acme/timer/TimerLogMainTest.java new file mode 100644 index 0000000..fe0b62b --- /dev/null +++ b/timer-log-main/src/test/java/org/acme/timer/TimerLogMainTest.java @@ -0,0 +1,106 @@ +/* + * 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.acme.timer; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.apache.camel.quarkus.test.support.process.QuarkusProcessExecutor; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Test; +import org.zeroturnaround.exec.StartedProcess; + +import static org.awaitility.Awaitility.await; + +@QuarkusTest +public class TimerLogMainTest { + + private static final String PACKAGE_TYPE = System.getProperty("quarkus.package.type"); + + @Test + public void testTimerLogMain() throws IOException { + QuarkusRunnerExecutor quarkusProcessExecutor = new QuarkusRunnerExecutor(); + StartedProcess process = quarkusProcessExecutor.start(); + + awaitStartup(quarkusProcessExecutor); + + try { + File quarkusLogFile = getQuarkusLogFile(); + await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8); + return log.contains("Greetings"); + }); + } finally { + if (process != null && process.getProcess().isAlive()) { + process.getProcess().destroy(); + } + } + } + + private File getQuarkusLogFile() { + String pathPrefix = "target/quarkus"; + if (isNative()) { + pathPrefix += "-native"; + } + return new File(pathPrefix + ".log"); + } + + private void awaitStartup(QuarkusProcessExecutor quarkusProcessExecutor) { + await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + return isApplicationHealthy(quarkusProcessExecutor.getHttpPort()); + }); + } + + private boolean isApplicationHealthy(int port) { + try { + int status = RestAssured.given() + .port(port) + .get("/health") + .then() + .extract() + .statusCode(); + return status == 200; + } catch (Exception e) { + return false; + } + } + + private static boolean isNative() { + return PACKAGE_TYPE != null && PACKAGE_TYPE.equals("native"); + } + + static final class QuarkusRunnerExecutor extends QuarkusProcessExecutor { + @Override + protected List<String> command(String... args) { + List<String> command = super.command(args); + if (isNative()) { + command.add("-Dquarkus.log.file.path=target/quarkus-native.log"); + } else { + command.add(1, "-Dquarkus.log.file.path=target/quarkus.log"); + } + command.add("Greetings"); + command.add("2"); + return command; + } + + } +} diff --git a/timer-log-spring/pom.xml b/timer-log-spring/pom.xml index 73d0e7e..8a1bd15 100644 --- a/timer-log-spring/pom.xml +++ b/timer-log-spring/pom.xml @@ -63,20 +63,36 @@ <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-log</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-main</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-timer</artifactId> + <artifactId>camel-quarkus-microprofile-health</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> + <artifactId>camel-quarkus-timer</artifactId> </dependency> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-spring-di</artifactId> </dependency> + + <!-- Test --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -232,6 +248,27 @@ <properties> <quarkus.package.type>native</quarkus.package.type> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/timer-log-spring/src/main/resources/application.properties b/timer-log-spring/src/main/resources/application.properties index 096809f..82f885a 100644 --- a/timer-log-spring/src/main/resources/application.properties +++ b/timer-log-spring/src/main/resources/application.properties @@ -19,6 +19,7 @@ # Quarkus # quarkus.banner.enabled = false +quarkus.log.file.enable = true # # Camel diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/timer-log-spring/src/test/java/org/acme/timer/TimerLogSpringIT.java similarity index 65% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to timer-log-spring/src/test/java/org/acme/timer/TimerLogSpringIT.java index 1db4c3e..dee6660 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/timer-log-spring/src/test/java/org/acme/timer/TimerLogSpringIT.java @@ -14,27 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.timer; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { +@NativeImageTest +class TimerLogSpringIT extends TimerLogSpringTest { - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } } diff --git a/timer-log-spring/src/test/java/org/acme/timer/TimerLogSpringTest.java b/timer-log-spring/src/test/java/org/acme/timer/TimerLogSpringTest.java new file mode 100644 index 0000000..1691d95 --- /dev/null +++ b/timer-log-spring/src/test/java/org/acme/timer/TimerLogSpringTest.java @@ -0,0 +1,49 @@ +/* + * 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.acme.timer; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.junit.QuarkusTest; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; + +@QuarkusTest +public class TimerLogSpringTest { + + @Test + public void testTimerLogSpring() { + File quarkusLogFile = getQuarkusLogFile(); + await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8); + return log.contains("Incremented the counter"); + }); + } + + private File getQuarkusLogFile() { + String pathPrefix = "target"; + String packageType = System.getProperty("quarkus.package.type"); + if (packageType != null && packageType.equals("native")) { + pathPrefix += "/target"; + } + return new File(pathPrefix + "/quarkus.log"); + } +} diff --git a/timer-log-xml/pom.xml b/timer-log-xml/pom.xml index 5da0a9d..cc94e6c 100644 --- a/timer-log-xml/pom.xml +++ b/timer-log-xml/pom.xml @@ -63,20 +63,36 @@ <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-log</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-main</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-timer</artifactId> + <artifactId>camel-quarkus-microprofile-health</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> + <artifactId>camel-quarkus-timer</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-xml-io</artifactId> </dependency> + + <!-- Test --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -235,6 +251,27 @@ <properties> <quarkus.package.type>native</quarkus.package.type> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/timer-log-xml/src/main/resources/application.properties b/timer-log-xml/src/main/resources/application.properties index 20a531d..00bedd3 100644 --- a/timer-log-xml/src/main/resources/application.properties +++ b/timer-log-xml/src/main/resources/application.properties @@ -18,6 +18,7 @@ # Quarkus # quarkus.banner.enabled = false +quarkus.log.file.enable = true # to turn on DEBUG logging in camel-main # quarkus.log.category."org.apache.camel.main".level = DEBUG diff --git a/timer-log-xml/src/test/java/org/acme/timer/TimerLogXmlTest.java b/timer-log-xml/src/test/java/org/acme/timer/TimerLogXmlTest.java new file mode 100644 index 0000000..823dc14 --- /dev/null +++ b/timer-log-xml/src/test/java/org/acme/timer/TimerLogXmlTest.java @@ -0,0 +1,49 @@ +/* + * 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.acme.timer; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.junit.QuarkusTest; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; + +@QuarkusTest +public class TimerLogXmlTest { + + @Test + public void testTimerLogXml() { + File quarkusLogFile = getQuarkusLogFile(); + await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8); + return log.contains("Hello XML!"); + }); + } + + private File getQuarkusLogFile() { + String pathPrefix = "target"; + String packageType = System.getProperty("quarkus.package.type"); + if (packageType != null && packageType.equals("native")) { + pathPrefix += "/target"; + } + return new File(pathPrefix + "/quarkus.log"); + } +} diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/timer-log-xml/src/test/java/org/acme/timer/TimerLogXmlXmlIT.java similarity index 65% copy from http-log/src/main/java/org/acme/http/ExampleResource.java copy to timer-log-xml/src/test/java/org/acme/timer/TimerLogXmlXmlIT.java index 1db4c3e..fd26ac0 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/timer-log-xml/src/test/java/org/acme/timer/TimerLogXmlXmlIT.java @@ -14,27 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.timer; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { +@NativeImageTest +class TimerLogXmlXmlIT extends TimerLogXmlTest { - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } } diff --git a/timer-log/pom.xml b/timer-log/pom.xml index 489026a..db75ed9 100644 --- a/timer-log/pom.xml +++ b/timer-log/pom.xml @@ -67,12 +67,28 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-microprofile-health</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-timer</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-log</artifactId> </dependency> + + <!-- Test --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -228,6 +244,27 @@ <properties> <quarkus.package.type>native</quarkus.package.type> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> </profiles> diff --git a/timer-log/src/main/resources/application.properties b/timer-log/src/main/resources/application.properties index 261dde5..bac70c3 100644 --- a/timer-log/src/main/resources/application.properties +++ b/timer-log/src/main/resources/application.properties @@ -18,9 +18,9 @@ # Quarkus # quarkus.banner.enabled = false +quarkus.log.file.enable = true # # Camel # camel.context.name = quarkus-camel-example-timer-log - diff --git a/http-log/src/main/java/org/acme/http/ExampleResource.java b/timer-log/src/test/java/org/acme/timer/TimerLogIT.java similarity index 65% rename from http-log/src/main/java/org/acme/http/ExampleResource.java rename to timer-log/src/test/java/org/acme/timer/TimerLogIT.java index 1db4c3e..2f8e97f 100644 --- a/http-log/src/main/java/org/acme/http/ExampleResource.java +++ b/timer-log/src/test/java/org/acme/timer/TimerLogIT.java @@ -14,27 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.http; +package org.acme.timer; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import io.quarkus.test.junit.NativeImageTest; -/** - * A JAX-RS resource - */ -@Path("/hello") -public class ExampleResource { +@NativeImageTest +class TimerLogIT extends TimerLogTest { - /** - * A JAX-RS endpoint always returning {@code "hello"} - * - * @return {@code "hello"} - */ - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "hello"; - } } diff --git a/timer-log/src/test/java/org/acme/timer/TimerLogTest.java b/timer-log/src/test/java/org/acme/timer/TimerLogTest.java new file mode 100644 index 0000000..dd6898d --- /dev/null +++ b/timer-log/src/test/java/org/acme/timer/TimerLogTest.java @@ -0,0 +1,49 @@ +/* + * 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.acme.timer; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.junit.QuarkusTest; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; + +@QuarkusTest +public class TimerLogTest { + + @Test + public void testTimerLog() { + File quarkusLogFile = getQuarkusLogFile(); + await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + String log = FileUtils.readFileToString(quarkusLogFile, StandardCharsets.UTF_8); + return log.contains("Hello World"); + }); + } + + private File getQuarkusLogFile() { + String pathPrefix = "target"; + String packageType = System.getProperty("quarkus.package.type"); + if (packageType != null && packageType.equals("native")) { + pathPrefix += "/target"; + } + return new File(pathPrefix + "/quarkus.log"); + } +}