/** * Test POSTing an RDF resource. */ @Test @DisplayName("Test POSTing an RDF resource") default void testPostRDF() { final String content = getResourceAsString(SIMPLE_RESOURCE); // POST an LDP-RS try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(content, TEXT_TURTLE))) { assertAll("Check POSTing an RDF resource", checkRdfResponse(res, LDP.RDFSource, null)); final String location = res.getLocation().toString(); assertTrue(location.startsWith(getBaseURL()), "Check the Location header"); assertTrue(location.length() > getBaseURL().length(), "Re-check the Location header"); } }
/** * Test POSTing an RDF resource. */ @Test @DisplayName("Test POSTing an RDF resource") default void testPostRDF() { final String content = getResourceAsString(SIMPLE_RESOURCE); // POST an LDP-RS try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(content, TEXT_TURTLE))) { assertAll("Check POSTing an RDF resource", checkRdfResponse(res, LDP.RDFSource, null)); final String location = res.getLocation().toString(); assertTrue(location.startsWith(getBaseURL()), "Check the Location header"); assertTrue(location.length() > getBaseURL().length(), "Re-check the Location header"); } }
/** * Verify that the correct containment triples exist. */ @Test @DisplayName("Verify that the correct containment triples exist") default void testRdfContainment() { final RDF rdf = getInstance(); // Test the root container, verifying that the containment triple exists try (final Response res = target().request().get()) { assertAll("Check a container resource", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.contains(rdf.createIRI(getBaseURL()), LDP.contains, rdf.createIRI(getResourceLocation())), "Check for an ldp:contains property"); } }
/** * Verify that the correct containment triples exist. */ @Test @DisplayName("Verify that the correct containment triples exist") default void testRdfContainment() { final RDF rdf = getInstance(); // Test the root container, verifying that the containment triple exists try (final Response res = target().request().get()) { assertAll("Check a container resource", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.contains(rdf.createIRI(getBaseURL()), LDP.contains, rdf.createIRI(getResourceLocation())), "Check for an ldp:contains property"); } }
/** * Test fetching an RDF resource. */ @Test @DisplayName("Test fetching an RDF resource") default void testGetRDF() { final RDF rdf = getInstance(); // Fetch the new resource try (final Response res = target(getResourceLocation()).request().get()) { assertAll("Check an LDP-RS resource", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertEquals(3L, g.size(), "Check the size of the resulting graph"); final IRI identifier = rdf.createIRI(getResourceLocation()); assertTrue(g.contains(identifier, type, SKOS.Concept), "Check for a rdf:type triple"); assertTrue(g.contains(identifier, SKOS.prefLabel, rdf.createLiteral("Resource Name", "eng")), "Check for a skos:prefLabel triple"); assertTrue(g.contains(identifier, DC.subject, rdf.createIRI("http://example.org/subject/1")), "Check for a dc:subject triple"); assertTrue(res.getEntityTag().isWeak(), "Check that the ETag is weak"); } }
/** * Test fetching an RDF resource. */ @Test @DisplayName("Test fetching an RDF resource") default void testGetRDF() { final RDF rdf = getInstance(); // Fetch the new resource try (final Response res = target(getResourceLocation()).request().get()) { assertAll("Check an LDP-RS resource", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertEquals(3L, g.size(), "Check the size of the resulting graph"); final IRI identifier = rdf.createIRI(getResourceLocation()); assertTrue(g.contains(identifier, type, SKOS.Concept), "Check for a rdf:type triple"); assertTrue(g.contains(identifier, SKOS.prefLabel, rdf.createLiteral("Resource Name", "eng")), "Check for a skos:prefLabel triple"); assertTrue(g.contains(identifier, DC.subject, rdf.createIRI("http://example.org/subject/1")), "Check for a dc:subject triple"); assertTrue(res.getEntityTag().isWeak(), "Check that the ETag is weak"); } }
/** * Test modifying an RDF document via PATCH. */ @Test @DisplayName("Test modifying an RDF document via PATCH") default void testPatchRDF() { final RDF rdf = getInstance(); final EntityTag initialETag = getETag(getResourceLocation()); // Patch the resource try (final Response res = target(getResourceLocation()).request().method("PATCH", entity("INSERT { <> a <http://www.w3.org/ns/ldp#Container> ; " + "<http://purl.org/dc/terms/title> \"Title\" } WHERE {}", APPLICATION_SPARQL_UPDATE))) { assertAll("Check an LDP-RS resource", checkRdfResponse(res, LDP.RDFSource, null)); } await().until(() -> !initialETag.equals(getETag(getResourceLocation()))); // Fetch the updated resource try (final Response res = target(getResourceLocation()).request().accept("application/n-triples").get()) { assertAll("Check an updated resource", checkRdfResponse(res, LDP.RDFSource, APPLICATION_N_TRIPLES_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), NTRIPLES); assertEquals(4L, g.size(), "Check the graph size"); assertTrue(g.contains(rdf.createIRI(getResourceLocation()), DC.title, rdf.createLiteral("Title")), "Check for a dc:title triple"); assertTrue(res.getEntityTag().isWeak(), "Check that the ETag is weak"); assertNotEquals(initialETag, res.getEntityTag(), "Compare the first and second ETags"); } }
/** * Test modifying an RDF document via PATCH. */ @Test @DisplayName("Test modifying an RDF document via PATCH") default void testPatchRDF() { final RDF rdf = getInstance(); final EntityTag initialETag = getETag(getResourceLocation()); // Patch the resource try (final Response res = target(getResourceLocation()).request().method("PATCH", entity("INSERT { <> a <http://www.w3.org/ns/ldp#Container> ; " + "<http://purl.org/dc/terms/title> \"Title\" } WHERE {}", APPLICATION_SPARQL_UPDATE))) { assertAll("Check an LDP-RS resource", checkRdfResponse(res, LDP.RDFSource, null)); } await().until(() -> !initialETag.equals(getETag(getResourceLocation()))); // Fetch the updated resource try (final Response res = target(getResourceLocation()).request().accept("application/n-triples").get()) { assertAll("Check an updated resource", checkRdfResponse(res, LDP.RDFSource, APPLICATION_N_TRIPLES_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), NTRIPLES); assertEquals(4L, g.size(), "Check the graph size"); assertTrue(g.contains(rdf.createIRI(getResourceLocation()), DC.title, rdf.createLiteral("Title")), "Check for a dc:title triple"); assertTrue(res.getEntityTag().isWeak(), "Check that the ETag is weak"); assertNotEquals(initialETag, res.getEntityTag(), "Compare the first and second ETags"); } }