Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Feb 15, 2023
1 parent c81be92 commit e0fb34b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 108 deletions.
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
<dependencies>
<!-- shared test dependencies -->
<!-- Testing: JUnit -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/repository/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-junit-jupiter</artifactId>
<artifactId>mockserver-junit-jupiter-no-dependencies</artifactId>
<version>5.15.0</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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 org.junit.jupiter.api.extension.ExtendWith;
import org.mockserver.client.MockServerClient;
Expand All @@ -56,58 +57,34 @@
*/
@ExtendWith(MockServerExtension.class)
public class RDFLoaderTest {
@Test
public void testTurtleJavaResource() throws Exception {
RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory());

RDFHandler rdfHandler = mock(RDFHandler.class);

rdfLoader.load(this.getClass().getResource("Socrates.ttl"), null, RDFFormat.TURTLE, rdfHandler);

verify(rdfHandler).startRDF();
verify(rdfHandler)
.handleStatement(statement(iri("http://example.org/Socrates"),
RDF.TYPE,
FOAF.PERSON, null));
verify(rdfHandler).endRDF();
}

@Test
public void testTurtleDocument(MockServerClient client) throws Exception {
@BeforeAll
static void defineMockServerBehavior(MockServerClient client) {
client.when(
request()
.withMethod("GET")
.withPath("/Socrates.ttl")
)
.respond(
response()
.withStatusCode(200)
.withContentType(MediaType.parse(RDFFormat.TURTLE.getDefaultMIMEType()))
.withBody("<http://example.org/Socrates> a <http://xmlns.com/foaf/0.1/Person> .")

);
client.when(
request()
.withMethod("GET")
.withPath("/Socrates")
)
.respond(
response()
.withStatusCode(301)
.withHeader("Location", "/Socrates.ttl")

RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory());

RDFHandler rdfHandler = mock(RDFHandler.class);

rdfLoader.load(new URL("http://localhost:" + client.getPort() + "/Socrates.ttl"), null, null,
rdfHandler);

verify(rdfHandler).startRDF();
verify(rdfHandler)
.handleStatement(statement(iri("http://example.org/Socrates"),
RDF.TYPE,
FOAF.PERSON, null));
verify(rdfHandler).endRDF();
}

@Test
public void testMultipleRedirects(MockServerClient client) throws Exception {
);
client.when(
request()
.withMethod("GET")
.withPath("/Socrates")
.withPath("/Socrates1")
)
.respond(
response()
Expand Down Expand Up @@ -137,24 +114,31 @@ public void testMultipleRedirects(MockServerClient client) throws Exception {
.withHeader("Location", "/Socrates.ttl")

);
client.when(
request()
.withMethod("GET")
.withPath("/Socrates.ttl")
)
.respond(
response()
.withStatusCode(200)
.withContentType(MediaType.parse(RDFFormat.TURTLE.getDefaultMIMEType()))
.withBody("<http://example.org/Socrates> a <http://xmlns.com/foaf/0.1/Person> .")
}

);
@Test
public void testTurtleJavaResource() throws Exception {
RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory());

RDFHandler rdfHandler = mock(RDFHandler.class);

rdfLoader.load(this.getClass().getResource("Socrates.ttl"), null, RDFFormat.TURTLE, rdfHandler);

verify(rdfHandler).startRDF();
verify(rdfHandler)
.handleStatement(statement(iri("http://example.org/Socrates"),
RDF.TYPE,
FOAF.PERSON, null));
verify(rdfHandler).endRDF();
}

@Test
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:" + client.getPort() + "/Socrates"), null, null,
rdfLoader.load(new URL("http://localhost:" + client.getPort() + "/Socrates.ttl"), null, null,
rdfHandler);

verify(rdfHandler).startRDF();
Expand All @@ -166,42 +150,24 @@ public void testMultipleRedirects(MockServerClient client) throws Exception {
}

@Test
public void testAbortOverMaxRedirects(MockServerClient client) throws Exception {
client.when(
request()
.withMethod("GET")
.withPath("/Socrates1")
)
.respond(
response()
.withStatusCode(301)
.withHeader("Location", "/Socrates2")
public void testMultipleRedirects(MockServerClient client) throws Exception {
RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory());

);
client.when(
request()
.withMethod("GET")
.withPath("/Socrates2")
)
.respond(
response()
.withStatusCode(301)
.withHeader("Location", "/Socrates3")
RDFHandler rdfHandler = mock(RDFHandler.class);

);
client.when(
request()
.withMethod("GET")
.withPath("/Socrates3")
)
.respond(
response()
.withStatusCode(200)
.withContentType(MediaType.parse(RDFFormat.TURTLE.getDefaultMIMEType()))
.withBody("<http://example.org/Socrates> a <http://xmlns.com/foaf/0.1/Person> .")
rdfLoader.load(new URL("http://localhost:" + client.getPort() + "/Socrates1"), null, null,
rdfHandler);

);
verify(rdfHandler).startRDF();
verify(rdfHandler)
.handleStatement(statement(iri("http://example.org/Socrates"),
RDF.TYPE,
FOAF.PERSON, null));
verify(rdfHandler).endRDF();
}

@Test
public void testAbortOverMaxRedirects(MockServerClient client) throws Exception {
/* nullable */
String oldMaxRedirects = System.getProperty("http.maxRedirects");
try {
Expand Down Expand Up @@ -236,32 +202,6 @@ public void testNonInformationResource(MockServerClient client) throws Exception
try {
final HostnameVerifier toRestoreHostnameVerifier = disableHostnameVerifier();
try {
client.when(
request()
.withMethod("GET")
.withPath("/Socrates")
)
.respond(
response()
.withStatusCode(301)
.withHeader("Location",
"http://localhost:" + client.getPort() + "/Socrates.ttl")

);
client.when(
request()
.withMethod("GET")
.withPath("/Socrates.ttl")
)
.respond(
response()
.withStatusCode(200)
.withContentType(MediaType.parse(RDFFormat.TURTLE.getDefaultMIMEType()))
.withBody(
"<http://example.org/Socrates> a <http://xmlns.com/foaf/0.1/Person> .")

);

RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), getValueFactory());

RDFHandler rdfHandler = mock(RDFHandler.class);
Expand Down

0 comments on commit e0fb34b

Please sign in to comment.