From a32f8538512e634983caf5b995b61bc34da6a424 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Mon, 28 Oct 2024 08:10:49 -0400 Subject: [PATCH] Update IT to use testcontainers And update pass-core container config --- .../pass-journal-loader-nih/pom.xml | 90 ++++--------------- .../pass/loader/journal/nih/DepositIT.java | 44 +++++++++ pass-journal-loader/pom.xml | 3 + 3 files changed, 63 insertions(+), 74 deletions(-) diff --git a/pass-journal-loader/pass-journal-loader-nih/pom.xml b/pass-journal-loader/pass-journal-loader-nih/pom.xml index be4abd329..b3e36c65f 100644 --- a/pass-journal-loader/pass-journal-loader-nih/pom.xml +++ b/pass-journal-loader/pass-journal-loader-nih/pom.xml @@ -13,11 +13,8 @@ 3.3.1 - - 8080 - http://localhost:8080 - backend - backend + 1.19.4 + 3.9.6 @@ -69,6 +66,20 @@ ${wiremock.version} test + + + org.testcontainers + junit-jupiter + ${testcontainers.version} + test + + + + org.apache.maven + maven-model + ${maven-model.version} + test + @@ -93,68 +104,6 @@ - - io.fabric8 - docker-maven-plugin - - - start - pre-integration-test - - start - - - - stop - post-integration-test - - stop - - - - build-after-its - post-integration-test - - - - ghcr.io/eclipse-pass/pass-journal-loader:%v - - - - - build - - - - - - - ghcr.io/eclipse-pass/pass-core-main:%v - - ${docker.platforms} - - ${pass.core.url} - ${pass.core.user} - ${pass.core.password} - - - - - ${pass.core.url}/data/grant - - 401 - - - - - ${pass.core.port}:${pass.core.port} - - - - - - - org.apache.maven.plugins maven-failsafe-plugin @@ -166,13 +115,6 @@ - - - ${pass.core.url} - ${pass.core.user} - ${pass.core.password} - - diff --git a/pass-journal-loader/pass-journal-loader-nih/src/test/java/org/eclipse/pass/loader/journal/nih/DepositIT.java b/pass-journal-loader/pass-journal-loader-nih/src/test/java/org/eclipse/pass/loader/journal/nih/DepositIT.java index fbc0bf418..4156ee569 100644 --- a/pass-journal-loader/pass-journal-loader-nih/src/test/java/org/eclipse/pass/loader/journal/nih/DepositIT.java +++ b/pass-journal-loader/pass-journal-loader-nih/src/test/java/org/eclipse/pass/loader/journal/nih/DepositIT.java @@ -21,27 +21,71 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.io.FileReader; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import com.github.dockerjava.api.model.ExposedPort; +import com.github.dockerjava.api.model.PortBinding; +import com.github.dockerjava.api.model.Ports; import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.eclipse.pass.support.client.PassClient; import org.eclipse.pass.support.client.PassClientSelector; import org.eclipse.pass.support.client.model.Journal; import org.eclipse.pass.support.client.model.PmcParticipation; import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; +import org.testcontainers.utility.MountableFile; /** * @author apb@jhu.edu */ +@Testcontainers @WireMockTest public class DepositIT { private final PassClient client = PassClient.newInstance(); + private static final DockerImageName PASS_CORE_IMG; + + static { + MavenXpp3Reader reader = new MavenXpp3Reader(); + try { + Model model = reader.read(new FileReader("pom.xml")); + String version = model.getParent().getVersion(); + PASS_CORE_IMG = DockerImageName.parse("ghcr.io/eclipse-pass/pass-core-main:" + version); + } catch (Exception e) { + throw new RuntimeException(e); + } + + System.setProperty("pass.core.url", "http://localhost:8080"); + System.setProperty("pass.core.user", "backend"); + System.setProperty("pass.core.password", "backend"); + } + + @Container + private static final GenericContainer PASS_CORE_CONTAINER = new GenericContainer<>(PASS_CORE_IMG) + .withCopyFileToContainer( + MountableFile.forHostPath("../../pass-core-test-config/"), + "/tmp/pass-core-test-config/" + ) + .withEnv("PASS_CORE_JAVA_OPTS", "-Dspring.config.import=file:/tmp/pass-core-test-config/application-test.yml") + .waitingFor(Wait.forHttp("/data/grant").forStatusCode(200).withBasicCredentials("backend", "backend")) + .withCreateContainerCmdModifier(cmd -> { + cmd.getHostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(8080), + new ExposedPort(8080))); + }) + .withExposedPorts(8080); + @Test public void loadFromFileTest(WireMockRuntimeInfo wmRuntimeInfo) throws Exception { String jmedlineJournals = Files.readString( diff --git a/pass-journal-loader/pom.xml b/pass-journal-loader/pom.xml index 030875a53..6113ef201 100644 --- a/pass-journal-loader/pom.xml +++ b/pass-journal-loader/pom.xml @@ -131,6 +131,9 @@ org.junit.jupiter:junit-jupiter-api: + + org.testcontainers:: + com.github.docker-java::