Skip to content

Commit 0dae91a

Browse files
committed
Move Nginx tests to JUnit Jupiter
1 parent 67a4701 commit 0dae91a

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

modules/nginx/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ description = "Testcontainers :: Nginx"
33
dependencies {
44
api project(':testcontainers')
55
compileOnly 'org.jetbrains:annotations:26.0.2'
6+
7+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
8+
9+
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
610
testImplementation 'org.assertj:assertj-core:3.27.4'
711
}
812

@@ -11,3 +15,7 @@ tasks.japicmp {
1115
"org.testcontainers.containers.NginxContainer"
1216
]
1317
}
18+
19+
test {
20+
useJUnitPlatform()
21+
}

modules/nginx/src/test/java/org/testcontainers/junit/SimpleNginxTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.testcontainers.junit;
22

33
import lombok.Cleanup;
4-
import org.junit.BeforeClass;
5-
import org.junit.Rule;
6-
import org.junit.Test;
4+
import org.junit.jupiter.api.BeforeAll;
5+
import org.junit.jupiter.api.Test;
76
import org.testcontainers.containers.NginxContainer;
87
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
98
import org.testcontainers.utility.DockerImageName;
@@ -20,23 +19,15 @@
2019

2120
import static org.assertj.core.api.Assertions.assertThat;
2221

23-
public class SimpleNginxTest {
22+
class SimpleNginxTest {
2423

2524
private static final DockerImageName NGINX_IMAGE = DockerImageName.parse("nginx:1.27.0-alpine3.19-slim");
2625

2726
private static String tmpDirectory = System.getProperty("user.home") + "/.tmp-test-container";
2827

29-
// creatingContainer {
30-
@Rule
31-
public NginxContainer nginx = new NginxContainer(NGINX_IMAGE)
32-
.withCopyFileToContainer(MountableFile.forHostPath(tmpDirectory), "/usr/share/nginx/html")
33-
.waitingFor(new HttpWaitStrategy());
34-
35-
// }
36-
3728
@SuppressWarnings({ "Duplicates", "ResultOfMethodCallIgnored" })
38-
@BeforeClass
39-
public static void setupContent() throws Exception {
29+
@BeforeAll
30+
static void setupContent() throws Exception {
4031
// addCustomContent {
4132
// Create a temporary dir
4233
File contentFolder = new File(tmpDirectory);
@@ -53,15 +44,24 @@ public static void setupContent() throws Exception {
5344
}
5445

5546
@Test
56-
public void testSimple() throws Exception {
57-
// getFromNginxServer {
58-
URL baseUrl = nginx.getBaseUrl("http", 80);
47+
void testSimple() throws Exception {
48+
try (
49+
// creatingContainer {
50+
NginxContainer nginx = new NginxContainer(NGINX_IMAGE)
51+
.withCopyFileToContainer(MountableFile.forHostPath(tmpDirectory), "/usr/share/nginx/html")
52+
.waitingFor(new HttpWaitStrategy());
53+
// }
54+
) {
55+
nginx.start();
56+
// getFromNginxServer {
57+
URL baseUrl = nginx.getBaseUrl("http", 80);
5958

60-
assertThat(responseFromNginx(baseUrl))
61-
.as("An HTTP GET from the Nginx server returns the index.html from the custom content directory")
62-
.contains("Hello World!");
63-
// }
64-
assertHasCorrectExposedAndLivenessCheckPorts(nginx);
59+
assertThat(responseFromNginx(baseUrl))
60+
.as("An HTTP GET from the Nginx server returns the index.html from the custom content directory")
61+
.contains("Hello World!");
62+
// }
63+
assertHasCorrectExposedAndLivenessCheckPorts(nginx);
64+
}
6565
}
6666

6767
private void assertHasCorrectExposedAndLivenessCheckPorts(NginxContainer nginxContainer) {

0 commit comments

Comments
 (0)