/** * Initialize Basic Containment tests. */ @BeforeAll @DisplayName("Initialize Basic Containment tests") default void beforeAllTests() { // POST an LDP-BC try (final Response res = target().request() .header(SLUG, generateRandomValue(getClass().getSimpleName())) .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .post(entity(getResourceAsString(BASIC_CONTAINER), TEXT_TURTLE))) { setContainerLocation(checkCreateResponseAssumptions(res, LDP.BasicContainer)); } }
/** * Initialize Basic Containment tests. */ @BeforeAll @DisplayName("Initialize Basic Containment tests") default void beforeAllTests() { // POST an LDP-BC try (final Response res = target().request() .header(SLUG, generateRandomValue(getClass().getSimpleName())) .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .post(entity(getResourceAsString(BASIC_CONTAINER), TEXT_TURTLE))) { setContainerLocation(checkCreateResponseAssumptions(res, LDP.BasicContainer)); } }
/** * Test fetching a basic container. */ @Test @DisplayName("Test fetching a basic container") default void testGetContainer() { final RDF rdf = getInstance(); try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check an LDP-BC response", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getContainerLocation()); assertAll("Check the RDF graph", checkRdfGraph(g, identifier)); assertTrue(res.getEntityTag().isWeak(), "Verify that the ETag is weak"); } }
try (final Response res = target(getContainerLocation()).request().post(entity("", TEXT_TURTLE))) { assertAll("Check for an LDP-RS", checkRdfResponse(res, LDP.RDFSource, null)); childResource = res.getLocation().toString(); try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check for an LDP-BC", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final IRI identifier = rdf.createIRI(getContainerLocation()); try (final Response res = target(childResource).request().delete()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check the response type"); try (final Response res = target(childResource).request().get()) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Check for an expected error"); try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check the parent container", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
/** * Test fetching a basic container. */ @Test @DisplayName("Test fetching a basic container") default void testGetContainer() { final RDF rdf = getInstance(); try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check an LDP-BC response", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getContainerLocation()); assertAll("Check the RDF graph", checkRdfGraph(g, identifier)); assertTrue(res.getEntityTag().isWeak(), "Verify that the ETag is weak"); } }
try (final Response res = target(getContainerLocation()).request().post(entity("", TEXT_TURTLE))) { assertAll("Check for an LDP-RS", checkRdfResponse(res, LDP.RDFSource, null)); childResource = res.getLocation().toString(); try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check for an LDP-BC", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final IRI identifier = rdf.createIRI(getContainerLocation()); try (final Response res = target(childResource).request().delete()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check the response type"); try (final Response res = target(childResource).request().get()) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Check for an expected error"); try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check the parent container", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
/** * Test with ldp:PreferMinimalContainer Prefer header. */ @Test @DisplayName("Test with ldp:PreferMinimalContainer Prefer header") default void testGetEmptyContainer() { final RDF rdf = getInstance(); try (final Response res = target(getContainerLocation()).request().header(PREFER, "return=representation; include=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) { assertAll("Check a container response", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final IRI identifier = rdf.createIRI(getContainerLocation()); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertAll("Check the graph for triples", checkRdfGraph(g, identifier)); assertFalse(g.contains(identifier, LDP.contains, null), "Verify that no ldp:contains triples are present"); } }
/** * Test with ldp:PreferMinimalContainer Prefer header. */ @Test @DisplayName("Test with ldp:PreferMinimalContainer Prefer header") default void testGetEmptyContainer() { final RDF rdf = getInstance(); try (final Response res = target(getContainerLocation()).request().header(PREFER, "return=representation; include=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) { assertAll("Check a container response", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final IRI identifier = rdf.createIRI(getContainerLocation()); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertAll("Check the graph for triples", checkRdfGraph(g, identifier)); assertFalse(g.contains(identifier, LDP.contains, null), "Verify that no ldp:contains triples are present"); } }
/** * Test with ldp:PreferMinimalContainer Prefer header. */ @Test @DisplayName("Test with ldp:PreferMinimalContainer Prefer header") default void testGetInverseEmptyContainer() { final RDF rdf = getInstance(); try (final Response res = target(getContainerLocation()).request().header(PREFER, "return=representation; omit=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) { assertAll("Check a container response", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getContainerLocation()); assertFalse(g.contains(identifier, DC.description, null), "Check for no dc:description triple"); assertFalse(g.contains(identifier, SKOS.prefLabel, null), "Check for no skos:prefLabel triple"); assertTrue(g.contains(identifier, LDP.contains, null), "Check for an ldp:contains triple"); } }
/** * Test with ldp:PreferMinimalContainer Prefer header. */ @Test @DisplayName("Test with ldp:PreferMinimalContainer Prefer header") default void testGetInverseEmptyContainer() { final RDF rdf = getInstance(); try (final Response res = target(getContainerLocation()).request().header(PREFER, "return=representation; omit=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) { assertAll("Check a container response", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getContainerLocation()); assertFalse(g.contains(identifier, DC.description, null), "Check for no dc:description triple"); assertFalse(g.contains(identifier, SKOS.prefLabel, null), "Check for no skos:prefLabel triple"); assertTrue(g.contains(identifier, LDP.contains, null), "Check for an ldp:contains triple"); } }
try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .post(entity(containerContent, TEXT_TURTLE))) { try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check the LDP-BC again", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .post(entity(containerContent, TEXT_TURTLE))) { try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check the LDP-BC again", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
/** * Test creating a child resource via PUT. */ @Test @DisplayName("Test creating a child resource via PUT") default void testCreateContainerViaPut() { final RDF rdf = getInstance(); final String containerContent = getResourceAsString(BASIC_CONTAINER); final String child4 = getContainerLocation() + "/child4"; // First fetch the container headers to get the initial ETag final EntityTag initialETag = getETag(getContainerLocation()); try (final Response res = target(child4).request() .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .put(entity(containerContent, TEXT_TURTLE))) { assertAll("Check PUTting an LDP-BC", checkRdfResponse(res, LDP.BasicContainer, null)); } // Now fetch the resource try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check an LDP-BC after PUT", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getContainerLocation()); final EntityTag etag = res.getEntityTag(); assertAll("Check the resulting graph", checkRdfGraph(g, identifier)); assertFalse(g.contains(identifier, LDP.contains, rdf.createIRI(child4)), "Check for an ldp:contains triple"); assertTrue(etag.isWeak(), "Check for a weak ETag"); assertEquals(initialETag, etag, "Check ETags"); } }
try (final Response res = target(getContainerLocation()).request().header("Slug", "child5") .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .post(entity(containerContent, TEXT_TURTLE))) { try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check GETting the new resource", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
/** * Test creating a child resource via PUT. */ @Test @DisplayName("Test creating a child resource via PUT") default void testCreateContainerViaPut() { final RDF rdf = getInstance(); final String containerContent = getResourceAsString(BASIC_CONTAINER); final String child4 = getContainerLocation() + "/child4"; // First fetch the container headers to get the initial ETag final EntityTag initialETag = getETag(getContainerLocation()); try (final Response res = target(child4).request() .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .put(entity(containerContent, TEXT_TURTLE))) { assertAll("Check PUTting an LDP-BC", checkRdfResponse(res, LDP.BasicContainer, null)); } // Now fetch the resource try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check an LDP-BC after PUT", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getContainerLocation()); final EntityTag etag = res.getEntityTag(); assertAll("Check the resulting graph", checkRdfGraph(g, identifier)); assertFalse(g.contains(identifier, LDP.contains, rdf.createIRI(child4)), "Check for an ldp:contains triple"); assertTrue(etag.isWeak(), "Check for a weak ETag"); assertEquals(initialETag, etag, "Check ETags"); } }
try (final Response res = target(getContainerLocation()).request().header("Slug", "child5") .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .post(entity(containerContent, TEXT_TURTLE))) { try (final Response res = target(getContainerLocation()).request().get()) { assertAll("Check GETting the new resource", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);