/** * Create a simple direct container. * @param memberResource the member resource to use * @return the location of the new LDP-DC */ default String createSimpleDirectContainer(final String memberResource) { final String content = getResourceAsString(DIRECT_CONTAINER_IS_PART_OF) + membershipResource(getContainerLocation() + memberResource); // POST an LDP-DC try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(content, TEXT_TURTLE))) { assertAll("Check POSTing an LDP-DC", checkRdfResponse(res, LDP.DirectContainer, null)); return res.getLocation().toString(); } } }
final String rsLocation; final String directContainerInverse = getResourceAsString(DIRECT_CONTAINER_INVERSE) + membershipResource(getMemberLocation()); try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(directContainerInverse, TEXT_TURTLE))) { assertAll("Check creating an LDP-DC", checkRdfResponse(res, LDP.DirectContainer, null)); try (final Response res = target(dcLocation).request().post(entity("", TEXT_TURTLE))) { assertAll("Check creating an LDP-RS", checkRdfResponse(res, LDP.RDFSource, null)); rsLocation = res.getLocation().toString(); try (final Response res = target(rsLocation).request().get()) { assertAll("Check the LDP-RS", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getMemberLocation()); assertTrue(g.contains(rdf.createIRI(rsLocation), DC.isPartOf, identifier), "Check that dc:isPartOf is present in the graph");
/** * Test with ldp:PreferMinimalContainer Prefer header. */ @Test @DisplayName("Test with ldp:PreferMinimalContainer Prefer header") default void testGetInverseEmptyMember() { final RDF rdf = getInstance(); try (final Response res = target(getMemberLocation()).request().header(PREFER, "return=representation; omit=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) { assertAll("Check the LDP-RS with Prefer", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getMemberLocation()); assertFalse(g.contains(identifier, SKOS.prefLabel, null), "Check for no skos:prefLabel triples"); assertTrue(g.contains(identifier, LDP.member, null) || g.contains(identifier, DC.relation, null), "Check for either an ldp:member or dc:relation triple"); } }
try (final Response res = target().request() .header(SLUG, generateRandomValue(getClass().getSimpleName())) .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .post(entity(containerContent, TEXT_TURTLE))) { "New resource was not of expected BasicContainer type"); setContainerLocation(res.getLocation().toString()); setMemberLocation(getContainerLocation() + MEMBER_RESOURCE1); try (final Response res = target(getMemberLocation()).request().put(entity(containerContent, TEXT_TURTLE))) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of RDFSource appears to be unsupported"); + membershipResource(MEMBER_RESOURCE_HASH); try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(simpleContent, TEXT_TURTLE))) { assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.DirectContainer)), notDcType); setDirectContainerLocation(res.getLocation().toString());
/** * Test fetch a self-contained direct container. */ @Test @DisplayName("Test fetch a self-contained direct container") default void testSimpleDirectContainer() { final RDF rdf = getInstance(); final String memberContent = getResourceAsString(SIMPLE_RESOURCE); final String child; // POST an LDP-RS try (final Response res = target(getDirectContainerLocation()).request() .post(entity(memberContent, TEXT_TURTLE))) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of RDFSource appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.RDFSource)), "New resource was not of expected RDFSource type"); child = res.getLocation().toString(); } // Fetch the member resource try (final Response res = target(getDirectContainerLocation()).request().get()) { assertAll("Check the member resource", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.contains(rdf.createIRI(getDirectContainerLocation()), LDP.contains, rdf.createIRI(child)), "Verify an ldp:contains triple"); assertTrue(g.contains(rdf.createIRI(getDirectContainerLocation() + MEMBER_RESOURCE_HASH), LDP.member, rdf.createIRI(child)), "Verify a member triple"); } }
/** * Test updating a direct container with no member relation property. */ @Test @DisplayName("Test updating a direct container with no member relation property") default void testUpdateDirectContainerMissingMemberRelation() { final String dcLocation = createSimpleDirectContainer(MEMBER_RESOURCE2); final String content = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> \n" + "PREFIX ldp: <http://www.w3.org/ns/ldp#> \n" + "PREFIX dc: <http://purl.org/dc/terms/> \n\n" + "<> skos:prefLabel \"Direct Container\"@eng ; " + " ldp:membershipResource <" + getContainerLocation() + MEMBER_RESOURCE2 + "> ; " + " dc:description \"This is a Direct Container for testing.\"@eng ."; // PUT an LDP-DC try (final Response res = target(dcLocation).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Confirm that a 4xx error is returned"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "Confirm that the trellis:InvalidCardinality constraint IRI is referenced"); } }
/** * Test updating a direct container with no member resource. */ @Test @DisplayName("Test updating a direct container with no member resource") default void testUpdateDirectContainerMissingMemberResource() { final String dcLocation = createSimpleDirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString("/directContainer.ttl"); // PUT an LDP-DC try (final Response res = target(dcLocation).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Verify that a 4xx status is returned"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "Make sure that an InvalidCardinality constraint is referenced"); } }
try (final Response res = target().request() .header(SLUG, generateRandomValue(getClass().getSimpleName())) .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .post(entity(containerContent, TEXT_TURTLE))) { "New resource was not of expected BasicContainer type"); setContainerLocation(res.getLocation().toString()); setMemberLocation(getContainerLocation() + MEMBER_RESOURCE1); try (final Response res = target(getMemberLocation()).request().put(entity(containerContent, TEXT_TURTLE))) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of RDFSource appears to be unsupported"); + membershipResource(MEMBER_RESOURCE_HASH); try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(simpleContent, TEXT_TURTLE))) { assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.DirectContainer)), notDcType); setDirectContainerLocation(res.getLocation().toString());
/** * Test with ldp:PreferMinimalContainer Prefer header. */ @Test @DisplayName("Test with ldp:PreferMinimalContainer Prefer header") default void testGetEmptyMember() { final RDF rdf = getInstance(); try (final Response res = target(getMemberLocation()).request().header(PREFER, "return=representation; include=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) { assertAll("Check the LDP-RS with Prefer", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getMemberLocation()); assertTrue(g.contains(identifier, SKOS.prefLabel, null), "Check for a skos:prefLabel triple"); assertFalse(g.contains(identifier, LDP.member, null), "Check for no ldp:member triples"); assertFalse(g.contains(identifier, DC.relation, null), "Check for no dc:relation triples"); } }
/** * Test fetch a self-contained direct container. */ @Test @DisplayName("Test fetch a self-contained direct container") default void testSimpleDirectContainer() { final RDF rdf = getInstance(); final String memberContent = getResourceAsString(SIMPLE_RESOURCE); final String child; // POST an LDP-RS try (final Response res = target(getDirectContainerLocation()).request() .post(entity(memberContent, TEXT_TURTLE))) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of RDFSource appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.RDFSource)), "New resource was not of expected RDFSource type"); child = res.getLocation().toString(); } // Fetch the member resource try (final Response res = target(getDirectContainerLocation()).request().get()) { assertAll("Check the member resource", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.contains(rdf.createIRI(getDirectContainerLocation()), LDP.contains, rdf.createIRI(child)), "Verify an ldp:contains triple"); assertTrue(g.contains(rdf.createIRI(getDirectContainerLocation() + MEMBER_RESOURCE_HASH), LDP.member, rdf.createIRI(child)), "Verify a member triple"); } }
/** * Test updating a direct container with no member relation property. */ @Test @DisplayName("Test updating a direct container with no member relation property") default void testUpdateDirectContainerMissingMemberRelation() { final String dcLocation = createSimpleDirectContainer(MEMBER_RESOURCE2); final String content = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> \n" + "PREFIX ldp: <http://www.w3.org/ns/ldp#> \n" + "PREFIX dc: <http://purl.org/dc/terms/> \n\n" + "<> skos:prefLabel \"Direct Container\"@eng ; " + " ldp:membershipResource <" + getContainerLocation() + MEMBER_RESOURCE2 + "> ; " + " dc:description \"This is a Direct Container for testing.\"@eng ."; // PUT an LDP-DC try (final Response res = target(dcLocation).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Confirm that a 4xx error is returned"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "Confirm that the trellis:InvalidCardinality constraint IRI is referenced"); } }
/** * Test updating a direct container with no member resource. */ @Test @DisplayName("Test updating a direct container with no member resource") default void testUpdateDirectContainerMissingMemberResource() { final String dcLocation = createSimpleDirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString("/directContainer.ttl"); // PUT an LDP-DC try (final Response res = target(dcLocation).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Verify that a 4xx status is returned"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "Make sure that an InvalidCardinality constraint is referenced"); } }
/** * Create a simple direct container. * @param memberResource the member resource to use * @return the location of the new LDP-DC */ default String createSimpleDirectContainer(final String memberResource) { final String content = getResourceAsString(DIRECT_CONTAINER_IS_PART_OF) + membershipResource(getContainerLocation() + memberResource); // POST an LDP-DC try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(content, TEXT_TURTLE))) { assertAll("Check POSTing an LDP-DC", checkRdfResponse(res, LDP.DirectContainer, null)); return res.getLocation().toString(); } } }
final String rsLocation; final String directContainerInverse = getResourceAsString(DIRECT_CONTAINER_INVERSE) + membershipResource(getMemberLocation()); try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(directContainerInverse, TEXT_TURTLE))) { assertAll("Check creating an LDP-DC", checkRdfResponse(res, LDP.DirectContainer, null)); try (final Response res = target(dcLocation).request().post(entity("", TEXT_TURTLE))) { assertAll("Check creating an LDP-RS", checkRdfResponse(res, LDP.RDFSource, null)); rsLocation = res.getLocation().toString(); try (final Response res = target(rsLocation).request().get()) { assertAll("Check the LDP-RS", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getMemberLocation()); assertTrue(g.contains(rdf.createIRI(rsLocation), DC.isPartOf, identifier), "Check that dc:isPartOf is present in the graph");
/** * Test with ldp:PreferMinimalContainer Prefer header. */ @Test @DisplayName("Test with ldp:PreferMinimalContainer Prefer header") default void testGetInverseEmptyMember() { final RDF rdf = getInstance(); try (final Response res = target(getMemberLocation()).request().header(PREFER, "return=representation; omit=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) { assertAll("Check the LDP-RS with Prefer", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getMemberLocation()); assertFalse(g.contains(identifier, SKOS.prefLabel, null), "Check for no skos:prefLabel triples"); assertTrue(g.contains(identifier, LDP.member, null) || g.contains(identifier, DC.relation, null), "Check for either an ldp:member or dc:relation triple"); } }
/** * Test updating a direct container via PUT. */ @Test @DisplayName("Test updating a direct container via PUT") default void testUpdateDirectContainerViaPut() { final String dcLocation = createSimpleDirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString("/directContainerIsPartOf.ttl") + membershipResource(getContainerLocation() + MEMBER_RESOURCE1); // PUT an LDP-DC try (final Response res = target(dcLocation).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertAll("Check PUTting a container resource", checkRdfResponse(res, LDP.DirectContainer, null)); } }
+ membershipResource(getMemberLocation()); try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(content, TEXT_TURTLE))) { assertAll("Check the LDP-DC was created", checkRdfResponse(res, LDP.DirectContainer, null)); dcLocation = res.getLocation().toString(); try (final Response res = target(getMemberLocation()).request().get()) { assertAll("Check the member resource", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertFalse(g.contains(rdf.createIRI(getMemberLocation()), LDP.member, null), "Check that an ldp:contains triple is not present"); etag1 = res.getEntityTag(); try (final Response res = target(dcLocation).request().get()) { assertAll("Check the container resource", checkRdfResponse(res, LDP.DirectContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertFalse(g.contains(rdf.createIRI(dcLocation), LDP.contains, null), "Check that the given ldp:contains triple isn't present"); try (final Response res = target(dcLocation).request().post(entity(childContent, TEXT_TURTLE))) { assertAll("Check POSTing a child", checkRdfResponse(res, LDP.RDFSource, null)); child1 = res.getLocation().toString(); assertTrue(child1.startsWith(dcLocation), "Check the Location header"); try (final Response res = target(dcLocation).request().post(entity(childContent, TEXT_TURTLE))) { assertAll("Check POSTing a child", checkRdfResponse(res, LDP.RDFSource, null)); child2 = res.getLocation().toString();
/** * Test with ldp:PreferMinimalContainer Prefer header. */ @Test @DisplayName("Test with ldp:PreferMinimalContainer Prefer header") default void testGetEmptyMember() { final RDF rdf = getInstance(); try (final Response res = target(getMemberLocation()).request().header(PREFER, "return=representation; include=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) { assertAll("Check the LDP-RS with Prefer", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); final IRI identifier = rdf.createIRI(getMemberLocation()); assertTrue(g.contains(identifier, SKOS.prefLabel, null), "Check for a skos:prefLabel triple"); assertFalse(g.contains(identifier, LDP.member, null), "Check for no ldp:member triples"); assertFalse(g.contains(identifier, DC.relation, null), "Check for no dc:relation triples"); } }
/** * Test creating a direct container via PUT. */ @Test @DisplayName("Test creating a direct container via PUT") default void testCreateDirectContainerViaPut() { final String other2 = getContainerLocation() + "/other2"; final String content = getResourceAsString(DIRECT_CONTAINER) + membershipResource(getContainerLocation() + MEMBER_RESOURCE2); // PUT an LDP-DC try (final Response res = target(other2).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertAll("Check PUTting a container resource", checkRdfResponse(res, LDP.DirectContainer, null)); } }
+ membershipResource(getMemberLocation()); try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.DirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(content, TEXT_TURTLE))) { assertAll("Check the LDP-DC was created", checkRdfResponse(res, LDP.DirectContainer, null)); dcLocation = res.getLocation().toString(); try (final Response res = target(getMemberLocation()).request().get()) { assertAll("Check the member resource", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertFalse(g.contains(rdf.createIRI(getMemberLocation()), LDP.member, null), "Check that an ldp:contains triple is not present"); etag1 = res.getEntityTag(); try (final Response res = target(dcLocation).request().get()) { assertAll("Check the container resource", checkRdfResponse(res, LDP.DirectContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertFalse(g.contains(rdf.createIRI(dcLocation), LDP.contains, null), "Check that the given ldp:contains triple isn't present"); try (final Response res = target(dcLocation).request().post(entity(childContent, TEXT_TURTLE))) { assertAll("Check POSTing a child", checkRdfResponse(res, LDP.RDFSource, null)); child1 = res.getLocation().toString(); assertTrue(child1.startsWith(dcLocation), "Check the Location header"); try (final Response res = target(dcLocation).request().post(entity(childContent, TEXT_TURTLE))) { assertAll("Check POSTing a child", checkRdfResponse(res, LDP.RDFSource, null)); child2 = res.getLocation().toString();