From ba104c26223eaaba7fea9d789e4a703564337801 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Tue, 15 Jun 2021 17:49:32 +0200 Subject: [PATCH] Fixed a few issues in example test: (#3112) * Javadoc * Ordering of elements * Health was checked twice, metrics never Signed-off-by: Tomas Langer --- .../microprofile/multiport/MainTest.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/microprofile/multiport/src/test/java/io/helidon/examples/microprofile/multiport/MainTest.java b/examples/microprofile/multiport/src/test/java/io/helidon/examples/microprofile/multiport/MainTest.java index a20e3f47e41..ddd9790e204 100644 --- a/examples/microprofile/multiport/src/test/java/io/helidon/examples/microprofile/multiport/MainTest.java +++ b/examples/microprofile/multiport/src/test/java/io/helidon/examples/microprofile/multiport/MainTest.java @@ -26,6 +26,8 @@ import io.helidon.microprofile.server.ServerCdiExtension; import io.helidon.microprofile.tests.junit5.AddConfig; import io.helidon.microprofile.tests.junit5.HelidonTest; + +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -38,20 +40,12 @@ import static org.hamcrest.MatcherAssert.assertThat; /** - * Unit test for {@link Main}. + * Unit test for MP multiport example. */ @HelidonTest @AddConfig(key = "server.sockets.0.port", value = "0") // Force ports to be dynamically allocated @AddConfig(key = "server.sockets.1.port", value = "0") class MainTest { - - // Used for the default (public) port which HelidonTest will configure for us - @Inject - private WebTarget publicWebTarget; - - // Used for other (private, admin) ports - private static Client client; - // Port names private static final String ADMIN_PORT = "admin"; private static final String PRIVATE_PORT = "private"; @@ -59,6 +53,13 @@ class MainTest { private static final String BASE_URL = "http://localhost:"; + // Used for other (private, admin) ports + private static Client client; + + // Used for the default (public) port which HelidonTest will configure for us + @Inject + private WebTarget publicWebTarget; + // Needed to get values of dynamically allocated admin and private ports @Inject private ServerCdiExtension serverCdiExtension; @@ -67,7 +68,7 @@ static Stream initParams() { final String PUBLIC_PATH = "/hello"; final String PRIVATE_PATH = "/private/hello"; final String HEALTH_PATH = "/health"; - final String METRICS_PATH = "/health"; + final String METRICS_PATH = "/metrics"; return List.of( new Params(PUBLIC_PORT, PUBLIC_PATH, Status.OK), @@ -92,18 +93,26 @@ static void initClass() { client = ClientBuilder.newClient(); } + @AfterAll + static void destroyClass() { + client.close();; + } + @MethodSource("initParams") @ParameterizedTest public void testPortAccess(Params params) { + WebTarget webTarget; - WebTarget webTarget = publicWebTarget; - if (!PUBLIC_PORT.equals(params.portName)) { + if (params.portName.equals(PUBLIC_PORT)) { + webTarget = publicWebTarget; + } else { webTarget = client.target(BASE_URL + serverCdiExtension.port(params.portName)); } Response response = webTarget.path(params.path) .request() .get(); + assertThat(webTarget.getUri() + " returned incorrect HTTP status", response.getStatusInfo().toEnum(), is(params.httpStatus)); }