diff --git a/README.md b/README.md index cc660ac6..f040605e 100644 --- a/README.md +++ b/README.md @@ -499,6 +499,10 @@ The Secret is exposed by mounting it into the container file system. Checks that the application can read configuration from a Secret. The Secret is obtained directly from the Kubernetes API server. +### `lifecycle-application` + +Verifies lifecycle application features like `@QuarkusMain` and `@CommandLineArguments`. + ### `sql-db` Verifies that the application can connect to a SQL database and persist data using Hibernate ORM with Panache. diff --git a/lifecycle-application/pom.xml b/lifecycle-application/pom.xml new file mode 100644 index 00000000..f24260bc --- /dev/null +++ b/lifecycle-application/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + + io.quarkus.ts.openshift + parent + 1.0.0-SNAPSHOT + ../.. + + + lifecycle-application + jar + + Quarkus OpenShift TS: Lifecycle Application + + + + io.quarkus + quarkus-openshift + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-smallrye-health + + + io.quarkus.ts.openshift + app-metadata + + + + io.quarkus + quarkus-junit5 + test + + + io.quarkus.ts.openshift + common + test + + + io.rest-assured + rest-assured + test + + + + + + + io.quarkus + quarkus-maven-plugin + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + diff --git a/lifecycle-application/src/main/java/io/quarkus/ts/openshift/lifecycle/ArgsResource.java b/lifecycle-application/src/main/java/io/quarkus/ts/openshift/lifecycle/ArgsResource.java new file mode 100644 index 00000000..06c83ac7 --- /dev/null +++ b/lifecycle-application/src/main/java/io/quarkus/ts/openshift/lifecycle/ArgsResource.java @@ -0,0 +1,25 @@ +package io.quarkus.ts.openshift.lifecycle; + +import io.quarkus.runtime.annotations.CommandLineArguments; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Path("/args") +public class ArgsResource { + @Inject + @CommandLineArguments + String[] args; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String get() { + return Stream.of(args).collect(Collectors.joining(",")); + } +} diff --git a/lifecycle-application/src/main/java/io/quarkus/ts/openshift/lifecycle/Main.java b/lifecycle-application/src/main/java/io/quarkus/ts/openshift/lifecycle/Main.java new file mode 100644 index 00000000..d34bfa29 --- /dev/null +++ b/lifecycle-application/src/main/java/io/quarkus/ts/openshift/lifecycle/Main.java @@ -0,0 +1,19 @@ +package io.quarkus.ts.openshift.lifecycle; + +import io.quarkus.runtime.Quarkus; +import io.quarkus.runtime.annotations.QuarkusMain; +import org.jboss.logging.Logger; + +@QuarkusMain +public class Main { + + public static final String MESSAGE = "Hello from Main"; + + private static final Logger LOG = Logger.getLogger(Main.class); + + public static void main(String... args) { + LOG.info(MESSAGE); + LOG.info("Received arguments: " + String.join(",", args)); + Quarkus.run(args); + } +} diff --git a/lifecycle-application/src/main/resources/application.properties b/lifecycle-application/src/main/resources/application.properties new file mode 100644 index 00000000..72215ba7 --- /dev/null +++ b/lifecycle-application/src/main/resources/application.properties @@ -0,0 +1,2 @@ +quarkus.openshift.expose=true +quarkus.s2i.base-jvm-image=registry.access.redhat.com/ubi8/openjdk-11:latest \ No newline at end of file diff --git a/lifecycle-application/src/test/java/io/quarkus/ts/openshift/lifecycle/LifecycleApplicationOpenShiftIT.java b/lifecycle-application/src/test/java/io/quarkus/ts/openshift/lifecycle/LifecycleApplicationOpenShiftIT.java new file mode 100644 index 00000000..b4ff9af6 --- /dev/null +++ b/lifecycle-application/src/test/java/io/quarkus/ts/openshift/lifecycle/LifecycleApplicationOpenShiftIT.java @@ -0,0 +1,42 @@ +package io.quarkus.ts.openshift.lifecycle; + +import io.fabric8.kubernetes.api.model.PodList; +import io.fabric8.openshift.client.OpenShiftClient; +import io.quarkus.ts.openshift.common.OpenShiftTest; +import io.quarkus.ts.openshift.common.injection.TestResource; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@OpenShiftTest +public class LifecycleApplicationOpenShiftIT { + + private static final String DEFAULT_ARGUMENT = "-Djava.util.logging.manager=org.jboss.logmanager.LogManager"; + private static final String RUNTIME_LABEL = "app.openshift.io/runtime"; + private static final String RUNTIME_QUARKUS = "quarkus"; + + @TestResource + private OpenShiftClient openshiftClient; + + @Test + public void shouldArgumentsContainDefaultArgument() { + when().get("/args") + .then().statusCode(200) + .body(containsString(DEFAULT_ARGUMENT)); + } + + @Test + public void shouldPrintMessagesFromQuarkusMain() { + PodList pods = openshiftClient.pods().withLabel(RUNTIME_LABEL, RUNTIME_QUARKUS).list(); + assertEquals(1, pods.getItems().size(), "Found more than one pod with Quarkus runtime"); + + String actualLog = openshiftClient.pods().withName(pods.getItems().get(0).getMetadata().getName()).getLog(); + + assertTrue(actualLog.contains(Main.MESSAGE), "Pod log does not contain the expected message from Main.java"); + assertTrue(actualLog.contains(DEFAULT_ARGUMENT), "Pod log does not contain the default argument"); + } + +} diff --git a/pom.xml b/pom.xml index e28668da..ec086db2 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ configmap/file-system config-secret/api-server config-secret/file-system + lifecycle-application messaging/artemis messaging/artemis-jta messaging/amqp-reactive