diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c854b84..67c28cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,11 +21,11 @@ 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 - run: mvn -B clean package + run: mvn -B clean verify 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 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..93f717e --- /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) + .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, 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..dc308b4 --- /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, stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); + } +}