From c1edd429f86ef3be597fdcfc2c55bdb422dba409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Fri, 4 Oct 2024 00:44:08 +0200 Subject: [PATCH 1/4] Added trivial test for every besic variant of execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- pom.xml | 78 ++++++++++++++++++- .../main/distributions/docker/AsadminIT.java | 62 +++++++++++++++ .../distributions/docker/RunembeddedIT.java | 58 ++++++++++++++ .../distributions/docker/StartServIT.java | 62 +++++++++++++++ 4 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java create mode 100644 src/test/java/org/glassfish/main/distributions/docker/RunembeddedIT.java create mode 100644 src/test/java/org/glassfish/main/distributions/docker/StartServIT.java diff --git a/pom.xml b/pom.xml index 74ce4e5..46fd657 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,38 @@ UTF-8 + + + org.slf4j + slf4j-jdk14 + 2.0.16 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.10.3 + test + + + org.hamcrest + hamcrest + 2.2 + test + + + org.testcontainers + testcontainers + 1.20.2 + test + + + org.testcontainers + junit-jupiter + 1.20.2 + + + @@ -169,14 +201,56 @@ + + maven-failsafe-plugin + + + execute + integration-test + + integration-test + + + + verify + verify + + verify + + + + maven-compiler-plugin - 3.11.0 + 3.13.0 + + 21 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.0 + + + **/*Test.java + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.5.0 - 17 + + ${docker.glassfish.image} + + + **/*IT.java + diff --git a/src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java b/src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java new file mode 100644 index 0000000..73fa9b3 --- /dev/null +++ b/src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.main.distributions.docker; + +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * + */ +@Testcontainers +public class AsadminIT { + + @SuppressWarnings({"rawtypes", "resource"}) + @Container + private final GenericContainer server = new GenericContainer<>(System.getProperty("docker.glassfish.image")) + .withCommand("asadmin start-domain").withExposedPorts(8080).withExposedPorts(8080) + .withLogConsumer(o -> System.err.print("GF: " + o.getUtf8String())); + + @Test + void getRoot() throws Exception { + URL url = URI.create("http://localhost:" + server.getMappedPort(8080) + "/").toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + String content; + try { + connection.setRequestMethod("GET"); + assertEquals(200, connection.getResponseCode(), "Response code"); + try (InputStream in = connection.getInputStream()) { + content = new String(in.readAllBytes(), StandardCharsets.UTF_8); + } + } finally { + connection.disconnect(); + } + assertThat(content.toString(), stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); + } +} diff --git a/src/test/java/org/glassfish/main/distributions/docker/RunembeddedIT.java b/src/test/java/org/glassfish/main/distributions/docker/RunembeddedIT.java new file mode 100644 index 0000000..2eb038d --- /dev/null +++ b/src/test/java/org/glassfish/main/distributions/docker/RunembeddedIT.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.main.distributions.docker; + +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URL; + +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.output.OutputFrame.OutputType; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * + */ +@Testcontainers +public class RunembeddedIT { + + @SuppressWarnings({"rawtypes", "resource"}) + @Container + private final GenericContainer server = new GenericContainer<>(System.getProperty("docker.glassfish.image")) + .withCommand("runembedded").withExposedPorts(8080).withLogConsumer(o -> { + // FIXME: If we don't use the interactive terminal, spams STDOUT. To be fixed in 7.0.19+. + if (o.getType() == OutputType.STDERR) { + System.err.print("GF: " + o.getUtf8String()); + } + }); + + @Test + void getRoot() throws Exception { + URL url = URI.create("http://localhost:" + server.getMappedPort(8080) + "/").toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + try { + connection.setRequestMethod("GET"); + assertEquals(404, connection.getResponseCode(), "Response code"); + } finally { + connection.disconnect(); + } + } +} diff --git a/src/test/java/org/glassfish/main/distributions/docker/StartServIT.java b/src/test/java/org/glassfish/main/distributions/docker/StartServIT.java new file mode 100644 index 0000000..b759666 --- /dev/null +++ b/src/test/java/org/glassfish/main/distributions/docker/StartServIT.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.main.distributions.docker; + +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * + */ +@Testcontainers +public class StartServIT { + + @SuppressWarnings({"rawtypes", "resource"}) + @Container + private final GenericContainer server = new GenericContainer<>(System.getProperty("docker.glassfish.image")) + .withCommand("startserv").withExposedPorts(8080) + .withLogConsumer(o -> System.err.print("GF: " + o.getUtf8String())); + + @Test + void getRoot() throws Exception { + URL url = URI.create("http://localhost:" + server.getMappedPort(8080) + "/").toURL(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + String content; + try { + connection.setRequestMethod("GET"); + assertEquals(200, connection.getResponseCode(), "Response code"); + try (InputStream in = connection.getInputStream()) { + content = new String(in.readAllBytes(), StandardCharsets.UTF_8); + } + } finally { + connection.disconnect(); + } + assertThat(content.toString(), stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); + } +} From 3d28580c73e14405b16f00b98988a81327883281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Fri, 4 Oct 2024 01:34:37 +0200 Subject: [PATCH 2/4] Use Java 21 for build. GF still uses 17 inside the docker container. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .github/workflows/build.yml | 4 ++-- .github/workflows/docker-publish.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c854b84..0c61fe8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,10 +21,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' cache: maven - name: Build with Maven diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 422ba03..f359160 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -29,7 +29,7 @@ jobs: - name: Maven Configure uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Set up Docker Buildx From 38ad5c229208fd3324364d34bc3074759654cf67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Fri, 4 Oct 2024 01:38:21 +0200 Subject: [PATCH 3/4] Run also integration tests on CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c61fe8..67c28cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,4 +28,4 @@ jobs: distribution: 'temurin' cache: maven - name: Build with Maven - run: mvn -B clean package + run: mvn -B clean verify From 6d4802f5266bee6a531e7e2d906fce2decd56e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Fri, 4 Oct 2024 11:27:58 +0200 Subject: [PATCH 4/4] Removed redundant withExposedPorts and toString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../org/glassfish/main/distributions/docker/AsadminIT.java | 4 ++-- .../org/glassfish/main/distributions/docker/StartServIT.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java b/src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java index 73fa9b3..93f717e 100644 --- a/src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java +++ b/src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java @@ -40,7 +40,7 @@ public class AsadminIT { @SuppressWarnings({"rawtypes", "resource"}) @Container private final GenericContainer server = new GenericContainer<>(System.getProperty("docker.glassfish.image")) - .withCommand("asadmin start-domain").withExposedPorts(8080).withExposedPorts(8080) + .withCommand("asadmin start-domain").withExposedPorts(8080) .withLogConsumer(o -> System.err.print("GF: " + o.getUtf8String())); @Test @@ -57,6 +57,6 @@ void getRoot() throws Exception { } finally { connection.disconnect(); } - assertThat(content.toString(), stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); + assertThat(content, stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); } } diff --git a/src/test/java/org/glassfish/main/distributions/docker/StartServIT.java b/src/test/java/org/glassfish/main/distributions/docker/StartServIT.java index b759666..dc308b4 100644 --- a/src/test/java/org/glassfish/main/distributions/docker/StartServIT.java +++ b/src/test/java/org/glassfish/main/distributions/docker/StartServIT.java @@ -57,6 +57,6 @@ void getRoot() throws Exception { } finally { connection.disconnect(); } - assertThat(content.toString(), stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); + assertThat(content, stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); } }