From 408c9919b1ecae66a5872c4e920fe3c949bc71cd Mon Sep 17 00:00:00 2001 From: Manuel Aude Morales Date: Fri, 7 May 2021 06:51:34 -0500 Subject: [PATCH] Fix file mess. Update micro-java endpoints, test, deployment file and pom. --- micro-java/pom.xml | 13 + .../openshift/hello/HelloResource.java | 24 +- micro-java/src/main/jkube/deployment.yml | 41 +++ .../resources/META-INF/resources/index.html | 242 ------------------ .../openshift/hello/HelloResourceTest.java | 8 +- 5 files changed, 81 insertions(+), 247 deletions(-) create mode 100644 micro-java/src/main/jkube/deployment.yml delete mode 100644 micro-java/src/main/resources/META-INF/resources/index.html diff --git a/micro-java/pom.xml b/micro-java/pom.xml index 28554ef..8c59632 100644 --- a/micro-java/pom.xml +++ b/micro-java/pom.xml @@ -108,6 +108,19 @@ org.eclipse.jkube openshift-maven-plugin 1.2.0 + + + + configmap-hello + + + APP_MSG + My custom application message. + + + + + diff --git a/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java b/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java index 99cccae..a3623cd 100644 --- a/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java +++ b/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java @@ -1,16 +1,36 @@ package com.redhat.training.openshift.hello; +import java.util.Optional; + +import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.eclipse.microprofile.config.inject.ConfigProperty; + @Path("/api") +@Produces(MediaType.TEXT_PLAIN) +@Consumes(MediaType.TEXT_PLAIN) public class HelloResource { + @ConfigProperty(name = "HOSTNAME", defaultValue = "unknown") + String hostname; + @ConfigProperty(name = "APP_MSG") + Optional message; + @GET - @Produces(MediaType.TEXT_PLAIN) + @Path("/hello") public String hello() { - return "Hello RESTEasy"; + String response = ""; + + if (!message.isPresent()) { + response = "Hello world from host " + hostname + "\n"; + } else { + response = "Hello world from host [" + hostname + "].\n"; + response += "Message received = " + message.get() + "\n"; + } + return response; } } \ No newline at end of file diff --git a/micro-java/src/main/jkube/deployment.yml b/micro-java/src/main/jkube/deployment.yml new file mode 100644 index 0000000..ad926ba --- /dev/null +++ b/micro-java/src/main/jkube/deployment.yml @@ -0,0 +1,41 @@ +spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + app: micro-java + provider: jkube + group: com.redhat.training.openshift.hello + strategy: + rollingParams: + timeoutSeconds: 3600 + type: Rolling + template: + metadata: + annotations: + app.openshift.io/vcs-ref: master + jkube.io/git-url: git@github.com:maudemor/DO288-apps.git + app.openshift.io/vcs-uri: git@github.com:maudemor/DO288-apps.git + jkube.io/git-commit: 3bffad109a77ebd72831d8f791c38df68db28e60 + jkube.io/git-branch: master + labels: + app: micro-java + provider: jkube + version: 1.0.0-SNAPSHOT + group: com.redhat.training.openshift.hello + spec: + containers: + - envFrom: + - configMapRef: + name: configmap-hello + env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + image: micro-java:latest + imagePullPolicy: IfNotPresent + name: quarkus + ports: + - containerPort: 8080 + name: http + protocol: TCP diff --git a/micro-java/src/main/resources/META-INF/resources/index.html b/micro-java/src/main/resources/META-INF/resources/index.html deleted file mode 100644 index 0202a31..0000000 --- a/micro-java/src/main/resources/META-INF/resources/index.html +++ /dev/null @@ -1,242 +0,0 @@ - - - - - micro-java2 - 1.0.0-SNAPSHOT - - - - - - -
-
-

Congratulations, you have created a new Quarkus cloud application.

- -

Why do you see this?

- -

This page is served by Quarkus. The source is in - src/main/resources/META-INF/resources/index.html.

- -

What can I do from here?

- -

If not already done, run the application in dev mode using: ./mvnw compile quarkus:dev. -

-
    -
  • Play with your example code in src/main/java: -
    -
    -
    -

    RESTEasy JAX-RS

    - Guide -
    -
    -

    A Hello World RESTEasy resource

    - -
    -
    - GET /api -
    -
    - -
    -
  • -
  • Your static assets are located in src/main/resources/META-INF/resources.
  • -
  • Configure your application in src/main/resources/application.properties.
  • -
-

Do you like Quarkus?

-

Go give it a star on GitHub.

-
-
-
-

Application

-
    -
  • GroupId: com.redhat.training.openshift.hello
  • -
  • ArtifactId: micro-java2
  • -
  • Version: 1.0.0-SNAPSHOT
  • -
  • Quarkus Version: 1.11.6.Final-redhat-00001
  • -
-
- -
-
- - \ No newline at end of file diff --git a/micro-java/src/test/java/com/redhat/training/openshift/hello/HelloResourceTest.java b/micro-java/src/test/java/com/redhat/training/openshift/hello/HelloResourceTest.java index d32cb12..4ba6649 100644 --- a/micro-java/src/test/java/com/redhat/training/openshift/hello/HelloResourceTest.java +++ b/micro-java/src/test/java/com/redhat/training/openshift/hello/HelloResourceTest.java @@ -1,21 +1,23 @@ package com.redhat.training.openshift.hello; +import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.containsString; @QuarkusTest +@TestHTTPEndpoint(HelloResource.class) public class HelloResourceTest { @Test public void testHelloEndpoint() { given() - .when().get("/api") + .when().get("/hello") .then() .statusCode(200) - .body(is("Hello RESTEasy")); + .body(containsString("Hello world from")); } } \ No newline at end of file