-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from OmniFish-EE/tests
Added trivial test for every basic variant of execution
- Loading branch information
Showing
6 changed files
with
262 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/org/glassfish/main/distributions/docker/AsadminIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/org/glassfish/main/distributions/docker/RunembeddedIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/org/glassfish/main/distributions/docker/StartServIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} |