diff --git a/core/pom.xml b/core/pom.xml index d26f8af625d..dc4575c0edb 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -120,6 +120,11 @@ + + org.junit.platform + junit-platform-launcher + test + org.junit.jupiter junit-jupiter-engine diff --git a/core/repository/api/pom.xml b/core/repository/api/pom.xml index 2f47f64fb2e..85842e2e1db 100644 --- a/core/repository/api/pom.xml +++ b/core/repository/api/pom.xml @@ -41,8 +41,8 @@ test - com.github.tomakehurst - wiremock-jre8 + org.mock-server + mockserver-junit-jupiter-no-dependencies test diff --git a/core/repository/api/src/test/java/org/eclipse/rdf4j/repository/util/RDFLoaderTest.java b/core/repository/api/src/test/java/org/eclipse/rdf4j/repository/util/RDFLoaderTest.java index d529ee0ebf3..1bcc624e8dd 100644 --- a/core/repository/api/src/test/java/org/eclipse/rdf4j/repository/util/RDFLoaderTest.java +++ b/core/repository/api/src/test/java/org/eclipse/rdf4j/repository/util/RDFLoaderTest.java @@ -10,10 +10,6 @@ *******************************************************************************/ package org.eclipse.rdf4j.repository.util; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.permanentRedirect; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static org.eclipse.rdf4j.model.util.Statements.statement; import static org.eclipse.rdf4j.model.util.Values.getValueFactory; import static org.eclipse.rdf4j.model.util.Values.iri; @@ -24,6 +20,8 @@ import static org.hamcrest.Matchers.hasProperty; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; import java.net.ProtocolException; import java.net.URL; @@ -45,18 +43,68 @@ import org.eclipse.rdf4j.rio.ParserConfig; import org.eclipse.rdf4j.rio.RDFFormat; import org.eclipse.rdf4j.rio.RDFHandler; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; - -import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; -import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockserver.client.MockServerClient; +import org.mockserver.junit.jupiter.MockServerExtension; +import org.mockserver.model.MediaType; /** * Unit tests for {@link RDFLoader}. * * @author Manuel Fiorelli */ -@WireMockTest +@ExtendWith(MockServerExtension.class) public class RDFLoaderTest { + @BeforeAll + static void defineMockServerBehavior(MockServerClient client) { + client.when( + request() + .withMethod("GET") + .withPath("/Socrates.ttl") + ) + .respond( + response() + .withContentType(MediaType.parse(RDFFormat.TURTLE.getDefaultMIMEType())) + .withBody(" a .") + + ); + client.when( + request() + .withMethod("GET") + .withPath("/Socrates") + ) + .respond( + response() + .withStatusCode(301) + .withHeader("Location", "/Socrates.ttl") + + ); + client.when( + request() + .withMethod("GET") + .withPath("/Socrates1") + ) + .respond( + response() + .withStatusCode(301) + .withHeader("Location", "/Socrates2") + + ); + client.when( + request() + .withMethod("GET") + .withPath("/Socrates2") + ) + .respond( + response() + .withStatusCode(301) + .withHeader("Location", "/Socrates.ttl") + + ); + } + @Test public void testTurtleJavaResource() throws Exception { RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory()); @@ -74,18 +122,12 @@ public void testTurtleJavaResource() throws Exception { } @Test - public void testTurtleDocument(WireMockRuntimeInfo wmRuntimeInfo) throws Exception { - stubFor(get("/Socrates.ttl") - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", RDFFormat.TURTLE.getDefaultMIMEType()) - .withBody(" a ."))); - + public void testTurtleDocument(MockServerClient client) throws Exception { RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory()); RDFHandler rdfHandler = mock(RDFHandler.class); - rdfLoader.load(new URL("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/Socrates.ttl"), null, null, + rdfLoader.load(new URL("http://localhost:" + client.getPort() + "/Socrates.ttl"), null, null, rdfHandler); verify(rdfHandler).startRDF(); @@ -97,24 +139,12 @@ public void testTurtleDocument(WireMockRuntimeInfo wmRuntimeInfo) throws Excepti } @Test - public void testMultipleRedirects(WireMockRuntimeInfo wmRuntimeInfo) throws Exception { - stubFor(get("/Socrates") - .willReturn(permanentRedirect("/Socrates2"))); - stubFor(get("/Socrates2") - .willReturn(permanentRedirect("/Socrates3"))); - stubFor(get("/Socrates3") - .willReturn(permanentRedirect("/Socrates.ttl"))); - stubFor(get("/Socrates.ttl") - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", RDFFormat.TURTLE.getDefaultMIMEType()) - .withBody(" a ."))); - + public void testMultipleRedirects(MockServerClient client) throws Exception { RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory()); RDFHandler rdfHandler = mock(RDFHandler.class); - rdfLoader.load(new URL("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/Socrates"), null, null, + rdfLoader.load(new URL("http://localhost:" + client.getPort() + "/Socrates1"), null, null, rdfHandler); verify(rdfHandler).startRDF(); @@ -126,17 +156,7 @@ public void testMultipleRedirects(WireMockRuntimeInfo wmRuntimeInfo) throws Exce } @Test - public void testAbortOverMaxRedirects(WireMockRuntimeInfo wmRuntimeInfo) throws Exception { - stubFor(get("/Socrates1") - .willReturn(permanentRedirect("/Socrates2"))); - stubFor(get("/Socrates2") - .willReturn(permanentRedirect("/Socrates3"))); - stubFor(get("/Socrates3") - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", RDFFormat.TURTLE.getDefaultMIMEType()) - .withBody(" a ."))); - + public void testAbortOverMaxRedirects(MockServerClient client) throws Exception { /* nullable */ String oldMaxRedirects = System.getProperty("http.maxRedirects"); try { @@ -148,7 +168,7 @@ public void testAbortOverMaxRedirects(WireMockRuntimeInfo wmRuntimeInfo) throws RDFHandler rdfHandler = mock(RDFHandler.class); try { - rdfLoader.load(new URL("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/Socrates1"), null, null, + rdfLoader.load(new URL("http://localhost:" + client.getPort() + "/Socrates1"), null, null, rdfHandler); } catch (ProtocolException e) { actualException = e; @@ -166,27 +186,16 @@ public void testAbortOverMaxRedirects(WireMockRuntimeInfo wmRuntimeInfo) throws } @Test - public void testNonInformationResource(WireMockRuntimeInfo wmRuntimeInfo) throws Exception { + public void testNonInformationResource(MockServerClient client) throws Exception { final SSLSocketFactory toRestoreSocketFactory = disableSSLCertificatCheck(); try { final HostnameVerifier toRestoreHostnameVerifier = disableHostnameVerifier(); try { - stubFor(get("/Socrates") - .willReturn( - permanentRedirect( - "http://localhost:" + wmRuntimeInfo.getHttpPort() + "/Socrates.ttl"))); - - stubFor(get("/Socrates.ttl") - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", RDFFormat.TURTLE.getDefaultMIMEType()) - .withBody(" a ."))); - RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory()); RDFHandler rdfHandler = mock(RDFHandler.class); - rdfLoader.load(new URL("http://localhost:" + wmRuntimeInfo.getHttpPort() + "/Socrates"), null, null, + rdfLoader.load(new URL("http://localhost:" + client.getPort() + "/Socrates"), null, null, rdfHandler); verify(rdfHandler).startRDF(); diff --git a/pom.xml b/pom.xml index a1b48590ac5..4c16ce851c1 100644 --- a/pom.xml +++ b/pom.xml @@ -588,6 +588,11 @@ wiremock-jre8 2.35.0 + + org.mock-server + mockserver-junit-jupiter-no-dependencies + 5.15.0 + org.assertj assertj-core