Skip to content

Commit 97beb77

Browse files
committed
cleanup tests
1 parent 63668c0 commit 97beb77

File tree

3 files changed

+35
-40
lines changed

3 files changed

+35
-40
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Licensed under MIT 2025. */
2+
package stanfordnlp;
3+
4+
import java.nio.file.Path;
5+
6+
import org.testcontainers.containers.GenericContainer;
7+
import org.testcontainers.images.builder.ImageFromDockerfile;
8+
import org.testcontainers.junit.jupiter.Container;
9+
import org.testcontainers.junit.jupiter.Testcontainers;
10+
11+
@Testcontainers
12+
public class StanfordTestBase {
13+
@Container
14+
protected static ProjectContainer simpleWebServer = new ProjectContainer().withExposedPorts(8080);
15+
16+
protected final String username = "admin";
17+
protected final String password = "changeme";
18+
protected final String registrationEndpoint = "/stanfordnlp/registration";
19+
protected final String healthEndpoint = "/stanfordnlp/health";
20+
protected final String textEndpoint = "/stanfordnlp";
21+
22+
protected static final class ProjectContainer extends GenericContainer<ProjectContainer> {
23+
public ProjectContainer() {
24+
super(new ImageFromDockerfile("localhost/testcontainers/stanfordcorenlp-provider-service", true) //
25+
.withFileFromPath("./src", Path.of("./src")) //
26+
.withFileFromPath("./pom.xml", Path.of("./pom.xml")) //
27+
.withFileFromPath("./Dockerfile", Path.of("./Dockerfile")));
28+
}
29+
}
30+
}

src/test/java/stanfordnlp/authentication/RegistrationControllerTest.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* Licensed under MIT 2023-2025. */
22
package stanfordnlp.authentication;
33

4-
import java.nio.file.Path;
5-
64
import org.junit.jupiter.api.AfterAll;
75
import org.junit.jupiter.api.Assertions;
86
import org.junit.jupiter.api.BeforeAll;
@@ -13,29 +11,14 @@
1311
import org.springframework.http.HttpStatus;
1412
import org.springframework.http.MediaType;
1513
import org.springframework.http.ResponseEntity;
16-
import org.testcontainers.containers.GenericContainer;
17-
import org.testcontainers.images.builder.ImageFromDockerfile;
18-
import org.testcontainers.junit.jupiter.Container;
19-
import org.testcontainers.junit.jupiter.Testcontainers;
2014

21-
@Testcontainers
22-
class RegistrationControllerTest {
15+
import stanfordnlp.StanfordTestBase;
16+
17+
class RegistrationControllerTest extends StanfordTestBase {
2318

24-
String username = "admin";
25-
String password = "changeme";
26-
String registrationEndpoint = "/stanfordnlp/registration";
27-
String healthEndpoint = "/stanfordnlp/health";
2819
static String address;
2920
static TestRestTemplate restTemplate;
3021

31-
@Container
32-
public static GenericContainer<?> simpleWebServer = new GenericContainer<>(new ImageFromDockerfile(
33-
"localhost/testcontainers/stanfordcorenlp-provider-service", true) //
34-
.withFileFromPath("./src", Path.of("./src")) //
35-
.withFileFromPath("./pom.xml", Path.of("./pom.xml")) //
36-
.withFileFromPath("./Dockerfile", Path.of("./Dockerfile")) //
37-
).withExposedPorts(8080);
38-
3922
@BeforeAll
4023
static void beforeAll() {
4124
simpleWebServer.start();

src/test/java/stanfordnlp/corenlp/TextControllerTest.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package stanfordnlp.corenlp;
33

44
import java.io.IOException;
5-
import java.nio.file.Path;
65

76
import org.junit.jupiter.api.AfterAll;
87
import org.junit.jupiter.api.Assertions;
@@ -11,33 +10,18 @@
1110
import org.springframework.boot.resttestclient.TestRestTemplate;
1211
import org.springframework.http.HttpStatus;
1312
import org.springframework.http.ResponseEntity;
14-
import org.testcontainers.containers.GenericContainer;
15-
import org.testcontainers.images.builder.ImageFromDockerfile;
16-
import org.testcontainers.junit.jupiter.Container;
17-
import org.testcontainers.junit.jupiter.Testcontainers;
1813

1914
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.converter.JsonConverter;
2015
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.dto.TextDto;
2116
import edu.kit.kastel.mcse.ardoco.core.textproviderjson.error.InvalidJsonException;
17+
import stanfordnlp.StanfordTestBase;
2218
import stanfordnlp.TestUtil;
2319

24-
@Testcontainers
25-
public class TextControllerTest {
20+
class TextControllerTest extends StanfordTestBase {
2621

27-
String username = "admin";
28-
String password = "changeme";
29-
String textEndpoint = "/stanfordnlp";
3022
static String address;
3123
static TestRestTemplate restTemplate;
3224

33-
@Container
34-
public static GenericContainer<?> simpleWebServer = new GenericContainer<>(new ImageFromDockerfile(
35-
"localhost/testcontainers/stanfordcorenlp-provider-service", true) //
36-
.withFileFromPath("./src", Path.of("./src")) //
37-
.withFileFromPath("./pom.xml", Path.of("./pom.xml")) //
38-
.withFileFromPath("./Dockerfile", Path.of("./Dockerfile")) //
39-
).withExposedPorts(8080);
40-
4125
@BeforeAll
4226
static void setUp() {
4327
simpleWebServer.start();
@@ -64,7 +48,5 @@ void testTextProcessing() throws InvalidJsonException, IOException {
6448
TextDto expected = JsonConverter.fromJsonString(TestUtil.getJsonExample());
6549
TextDto actual = JsonConverter.fromJsonString(response1.getBody());
6650
Assertions.assertEquals(expected, actual);
67-
6851
}
69-
7052
}

0 commit comments

Comments
 (0)