Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class JenaBodyHandlers {
private static void throwOnError(final Response.ResponseInfo responseInfo) {
if (!Response.isSuccess(responseInfo.statusCode())) {
throw new ClientHttpException(
"Could not map to a Jena entity.",
"An HTTP error was encountered mapping to a Jena entity.",
responseInfo.uri(),
responseInfo.statusCode(),
responseInfo.headers(),
Expand Down
212 changes: 207 additions & 5 deletions jena/src/test/java/com/inrupt/client/jena/JenaBodyHandlersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ void testOfJenaModelHandler() throws IOException,
);
}

/**
* @deprecated covers the deprecated JenaBodyHandlers::ofModel function. To be removed when removing the function
* from the API.
*/
@Test
void testOfModelHandler() throws IOException,
InterruptedException {
final Request request = Request.newBuilder()
.uri(URI.create(config.get("rdf_uri") + "/oneTriple"))
.GET()
.build();

final var response = client.send(request, JenaBodyHandlers.ofModel())
.toCompletableFuture().join();

assertEquals(200, response.statusCode());
final var responseBody = response.body();
assertEquals(1, responseBody.size());
assertTrue(responseBody.contains(
null,
null,
ResourceFactory.createResource("http://example.test/o"))
);
}

@Test
void testOfJenaModelHandlerAsync() throws IOException,
InterruptedException, ExecutionException {
Expand All @@ -102,6 +127,33 @@ void testOfJenaModelHandlerAsync() throws IOException,
);
}

/**
* @deprecated covers the deprecated JenaBodyHandlers::ofModel function. To be removed when removing the function
* from the API.
*/
@Test
void testOfModelHandlerAsync() throws IOException,
InterruptedException, ExecutionException {
final Request request = Request.newBuilder()
.uri(URI.create(config.get("rdf_uri") + "/oneTriple"))
.header("Accept", "text/turtle")
.GET()
.build();

final var asyncResponse = client.send(request, JenaBodyHandlers.ofModel());

final int statusCode = asyncResponse.thenApply(Response::statusCode).toCompletableFuture().join();
assertEquals(200, statusCode);

final var responseBody = asyncResponse.thenApply(Response::body).toCompletableFuture().join();
assertEquals(1, responseBody.size());
assertTrue(responseBody.contains(
null,
null,
ResourceFactory.createResource("http://example.test/o"))
);
}

@Test
void testOfJenaModelHandlerWithURL() throws IOException, InterruptedException {
final Request request = Request.newBuilder()
Expand All @@ -121,6 +173,29 @@ void testOfJenaModelHandlerWithURL() throws IOException, InterruptedException {
);
}

/**
* @deprecated covers the deprecated JenaBodyHandlers::ofModel function. To be removed when removing the function
* from the API.
*/
@Test
void testOfModelHandlerWithURL() throws IOException, InterruptedException {
final Request request = Request.newBuilder()
.uri(URI.create(config.get("rdf_uri") + "/example"))
.GET()
.build();

final var response = client.send(request, JenaBodyHandlers.ofModel())
.toCompletableFuture().join();

assertEquals(200, response.statusCode());
final var responseBody = response.body();
assertEquals(7, responseBody.size());
assertTrue(responseBody.contains(
null,
ResourceFactory.createProperty("http://www.w3.org/ns/pim/space#preferencesFile"))
);
}

@Test
void testOfJenaModelHandlerError() throws IOException,
InterruptedException {
Expand Down Expand Up @@ -152,16 +227,42 @@ void testOfJenaDatasetHandler() throws IOException,
.build();

final var response = client.send(request, JenaBodyHandlers.ofJenaDataset())
.toCompletableFuture().join();
.toCompletableFuture().join();

assertEquals(200, response.statusCode());
final var responseBody = response.body();
assertEquals(1, responseBody.asDatasetGraph().stream().count());
assertTrue(responseBody.asDatasetGraph().contains(
null,
NodeFactory.createURI("http://example.test/s"),
null,
null)
null,
NodeFactory.createURI("http://example.test/s"),
null,
null)
);
}

/**
* @deprecated covers the deprecated JenaBodyHandlers::ofDataset function. To be removed when removing the function
* from the API.
*/
@Test
void testOfDatasetHandler() throws IOException,
InterruptedException {
final Request request = Request.newBuilder()
.uri(URI.create(config.get("rdf_uri") + "/oneTriple"))
.GET()
.build();

final var response = client.send(request, JenaBodyHandlers.ofDataset())
.toCompletableFuture().join();

assertEquals(200, response.statusCode());
final var responseBody = response.body();
assertEquals(1, responseBody.asDatasetGraph().stream().count());
assertTrue(responseBody.asDatasetGraph().contains(
null,
NodeFactory.createURI("http://example.test/s"),
null,
null)
);
}

Expand All @@ -186,6 +287,31 @@ void testOfJenaDatasetHandlerWithURL() throws IOException, InterruptedException
);
}

/**
* @deprecated covers the deprecated JenaBodyHandlers::ofDataset function. To be removed when removing the function
* from the API.
*/
@Test
void testOfDatasetHandlerWithURL() throws IOException, InterruptedException {
final Request request = Request.newBuilder()
.uri(URI.create(config.get("rdf_uri") + "/example"))
.GET()
.build();

final var response = client.send(request, JenaBodyHandlers.ofDataset())
.toCompletableFuture().join();

assertEquals(200, response.statusCode());
final var responseBody = response.body();
assertEquals(7, responseBody.asDatasetGraph().stream().count());
assertTrue(responseBody.asDatasetGraph().contains(
null,
null,
NodeFactory.createURI("http://www.w3.org/ns/pim/space#preferencesFile"),
null)
);
}

@Test
void testOfJenaDatasetHandlerError() throws IOException,
InterruptedException {
Expand Down Expand Up @@ -231,6 +357,33 @@ void testOfJenaGraphHandlerAsync() throws IOException,
);
}

/**
* @deprecated covers the deprecated JenaBodyHandlers::ofGraph function. To be removed when removing the function
* from the API.
*/
@Test
void testOfGraphHandlerAsync() throws IOException,
InterruptedException, ExecutionException {
final Request request = Request.newBuilder()
.uri(URI.create(config.get("rdf_uri") + "/oneTriple"))
.header("Accept", "text/turtle")
.GET()
.build();

final var asyncResponse = client.send(request, JenaBodyHandlers.ofGraph());

final int statusCode = asyncResponse.thenApply(Response::statusCode).toCompletableFuture().join();
assertEquals(200, statusCode);

final var responseBody = asyncResponse.thenApply(Response::body).toCompletableFuture().join();
assertEquals(1, responseBody.size());
assertTrue(responseBody.contains(
NodeFactory.createURI("http://example.test/s"),
null,
null)
);
}

@Test
void testOfJenaGraphHandler() throws IOException,
InterruptedException {
Expand All @@ -252,6 +405,31 @@ void testOfJenaGraphHandler() throws IOException,
);
}

/**
* @deprecated covers the deprecated JenaBodyHandlers::ofGraph function. To be removed when removing the function
* from the API.
*/
@Test
void testOfGraphHandler() throws IOException,
InterruptedException {
final Request request = Request.newBuilder()
.uri(URI.create(config.get("rdf_uri") + "/oneTriple"))
.GET()
.build();

final var response = client.send(request, JenaBodyHandlers.ofGraph())
.toCompletableFuture().join();

assertEquals(200, response.statusCode());
final var responseBody = response.body();
assertEquals(1, responseBody.size());
assertTrue(responseBody.contains(
NodeFactory.createURI("http://example.test/s"),
null,
null)
);
}

@Test
void testOfJenaGraphHandlerWithURL() throws IOException, InterruptedException {
final Request request = Request.newBuilder()
Expand All @@ -272,6 +450,30 @@ void testOfJenaGraphHandlerWithURL() throws IOException, InterruptedException {
);
}

/**
* @deprecated covers the deprecated JenaBodyHandlers::ofGraph function. To be removed when removing the function
* from the API.
*/
@Test
void testOfGraphHandlerWithURL() throws IOException, InterruptedException {
final Request request = Request.newBuilder()
.uri(URI.create(config.get("rdf_uri") + "/example"))
.GET()
.build();

final var response = client.send(request, JenaBodyHandlers.ofGraph())
.toCompletableFuture().join();

assertEquals(200, response.statusCode());
final var responseBody = response.body();
assertEquals(7, responseBody.size());
assertTrue(responseBody.contains(
null,
NodeFactory.createURI("http://www.w3.org/ns/pim/space#preferencesFile"),
null)
);
}

@Test
void testOfJenaGraphHandlerError() throws IOException,
InterruptedException {
Expand Down
Loading