/** * Create a simple indirect container. * @param memberLocation the member resource to use * @return the location of the new LDP-IC */ default String createSimpleIndirectContainer(final String memberLocation) { final String content = getResourceAsString(INDIRECT_CONTAINER) + membershipResource(getContainerLocation() + memberLocation); // POST an LDP-DC try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(content, TEXT_TURTLE))) { assertAll("Check POSTing an LDP-IC", checkRdfResponse(res, LDP.IndirectContainer, null)); return res.getLocation().toString(); } } }
/** * 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 a member resource 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 triple"); 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(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(containerContent, TEXT_TURTLE))) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Expected LDP:BasicContainer type not present in response"); setContainerLocation(res.getLocation().toString()); setMemberLocation(getContainerLocation() + "/member"); + membershipResource(getMemberLocation()); try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(content, TEXT_TURTLE))) { "Expected LDP:IndirectContainer type not present in response"); setIndirectContainerLocation(res.getLocation().toString()); 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");
try (final Response res = target(getMemberLocation()).request().get()) { assertAll("Check the member LDP-RS", 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 for no ldp:member"); etag1 = res.getEntityTag(); assertTrue(etag1.isWeak(), "Check that the ETag is weak"); try (final Response res = target(getIndirectContainerLocation()).request().get()) { assertAll("Check the container resource", checkRdfResponse(res, LDP.IndirectContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertFalse(g.contains(rdf.createIRI(getIndirectContainerLocation()), LDP.contains, null), "Check for no ldp:contains property"); etag4 = res.getEntityTag(); try (final Response res = target(getIndirectContainerLocation()).request() .post(entity(childContent, TEXT_TURTLE))) { assertAll("Check POSTing a child resource", checkRdfResponse(res, LDP.RDFSource, null)); child1 = res.getLocation().toString(); assertTrue(child1.startsWith(getIndirectContainerLocation()), "Check the Location header"); assertTrue(child1.length() > getIndirectContainerLocation().length(), "Re-check the Location header"); try (final Response res = target(getIndirectContainerLocation()).request() .post(entity(childContent, TEXT_TURTLE))) { assertAll("Check POSTing a child resource", checkRdfResponse(res, LDP.RDFSource, null)); child2 = res.getLocation().toString(); assertTrue(child2.startsWith(getIndirectContainerLocation()), "Check the Location header"); assertTrue(child2.length() > getIndirectContainerLocation().length(), "Re-check the Location header"); try (final Response res = target(getMemberLocation()).request().get()) {
/** * Test updating an indirect container with no member relation property. */ @Test @DisplayName("Test updating an indirect container with no member relation property") default void testUpdateIndirectContainerMissingMemberRelation() { final String location = createSimpleIndirectContainer(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 foaf: <http://xmlns.com/foaf/0.1/> \n" + "PREFIX dc: <http://purl.org/dc/terms/> \n\n" + "<> skos:prefLabel \"Indirect Container\"@eng ; " + " ldp:membershipResource <" + getContainerLocation() + MEMBER_RESOURCE2 + "> ; " + " ldp:insertedContentRelation foaf:primaryTopic ; " + " dc:description \"This is an Indirect Container for testing.\"@eng ."; // PUT an LDP-DC try (final Response res = target(location).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Missing member property results in 4xx"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "Check that a missing memberRelation results in an InvalidCardinality constraint"); } }
/** * Test updating an indirect container with no member resource. */ @Test @DisplayName("Test updating an indirect container with no member resource") default void testUpdateIndirectContainerMissingMemberResource() { final String location = createSimpleIndirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString(INDIRECT_CONTAINER); // PUT an LDP-DC try (final Response res = target(location).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "no membershipResource results in 4xx"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "A missing membershipResource property results in an InvalidCardinality constraint"); } }
try (final Response res = target().request() .header(LINK, fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build()) .header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(containerContent, TEXT_TURTLE))) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Expected LDP:BasicContainer type not present in response"); setContainerLocation(res.getLocation().toString()); setMemberLocation(getContainerLocation() + "/member"); + membershipResource(getMemberLocation()); try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(content, TEXT_TURTLE))) { "Expected LDP:IndirectContainer type not present in response"); setIndirectContainerLocation(res.getLocation().toString()); 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");
try (final Response res = target(getMemberLocation()).request().get()) { assertAll("Check the member LDP-RS", 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 for no ldp:member"); etag1 = res.getEntityTag(); assertTrue(etag1.isWeak(), "Check that the ETag is weak"); try (final Response res = target(getIndirectContainerLocation()).request().get()) { assertAll("Check the container resource", checkRdfResponse(res, LDP.IndirectContainer, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertFalse(g.contains(rdf.createIRI(getIndirectContainerLocation()), LDP.contains, null), "Check for no ldp:contains property"); etag4 = res.getEntityTag(); try (final Response res = target(getIndirectContainerLocation()).request() .post(entity(childContent, TEXT_TURTLE))) { assertAll("Check POSTing a child resource", checkRdfResponse(res, LDP.RDFSource, null)); child1 = res.getLocation().toString(); assertTrue(child1.startsWith(getIndirectContainerLocation()), "Check the Location header"); assertTrue(child1.length() > getIndirectContainerLocation().length(), "Re-check the Location header"); try (final Response res = target(getIndirectContainerLocation()).request() .post(entity(childContent, TEXT_TURTLE))) { assertAll("Check POSTing a child resource", checkRdfResponse(res, LDP.RDFSource, null)); child2 = res.getLocation().toString(); assertTrue(child2.startsWith(getIndirectContainerLocation()), "Check the Location header"); assertTrue(child2.length() > getIndirectContainerLocation().length(), "Re-check the Location header"); try (final Response res = target(getMemberLocation()).request().get()) {
/** * Test updating an indirect container with no member relation property. */ @Test @DisplayName("Test updating an indirect container with no member relation property") default void testUpdateIndirectContainerMissingMemberRelation() { final String location = createSimpleIndirectContainer(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 foaf: <http://xmlns.com/foaf/0.1/> \n" + "PREFIX dc: <http://purl.org/dc/terms/> \n\n" + "<> skos:prefLabel \"Indirect Container\"@eng ; " + " ldp:membershipResource <" + getContainerLocation() + MEMBER_RESOURCE2 + "> ; " + " ldp:insertedContentRelation foaf:primaryTopic ; " + " dc:description \"This is an Indirect Container for testing.\"@eng ."; // PUT an LDP-DC try (final Response res = target(location).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Missing member property results in 4xx"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "Check that a missing memberRelation results in an InvalidCardinality constraint"); } }
/** * Test updating an indirect container with no member resource. */ @Test @DisplayName("Test updating an indirect container with no member resource") default void testUpdateIndirectContainerMissingMemberResource() { final String location = createSimpleIndirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString(INDIRECT_CONTAINER); // PUT an LDP-DC try (final Response res = target(location).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "no membershipResource results in 4xx"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "A missing membershipResource property results in an InvalidCardinality constraint"); } }
/** * Create a simple indirect container. * @param memberLocation the member resource to use * @return the location of the new LDP-IC */ default String createSimpleIndirectContainer(final String memberLocation) { final String content = getResourceAsString(INDIRECT_CONTAINER) + membershipResource(getContainerLocation() + memberLocation); // POST an LDP-DC try (final Response res = target(getContainerLocation()).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .post(entity(content, TEXT_TURTLE))) { assertAll("Check POSTing an LDP-IC", checkRdfResponse(res, LDP.IndirectContainer, null)); return res.getLocation().toString(); } } }
/** * 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 a member resource 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 triple"); assertTrue(g.contains(identifier, LDP.member, null) || g.contains(identifier, DC.relation, null), "Check for either an ldp:member or dc:relation triple"); } }
/** * Test creating an indirect container via PUT. */ @Test @DisplayName("Test creating an indirect container via PUT") default void testCreateIndirectContainerViaPut() { final String content = getResourceAsString(INDIRECT_CONTAINER) + membershipResource(getContainerLocation() + MEMBER_RESOURCE2); // PUT an LDP-IC try (final Response res = target(getContainerLocation() + "/indirectcontainer-put").request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertAll("Check PUTting an LDP-IC", checkRdfResponse(res, LDP.IndirectContainer, null)); } }
/** * 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 a member resource 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 triple"); assertFalse(g.contains(identifier, DC.relation, null), "Check for no dc:relation triple"); } }
/** * Test updating an indirect container via PUT. */ @Test @DisplayName("Test updating an indirect container via PUT") default void testUpdateIndirectContainerViaPut() { final String location = createSimpleIndirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString("/indirectContainerInverse.ttl") + membershipResource(getContainerLocation() + MEMBER_RESOURCE2); // PUT an LDP-IC try (final Response res = target(location).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertAll("Check replacing an LDP-IC via PUT", checkRdfResponse(res, LDP.IndirectContainer, null)); } }
/** * 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 a member resource 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 triple"); assertFalse(g.contains(identifier, DC.relation, null), "Check for no dc:relation triple"); } }
/** * Test creating an indirect container via PUT. */ @Test @DisplayName("Test creating an indirect container via PUT") default void testCreateIndirectContainerViaPut() { final String content = getResourceAsString(INDIRECT_CONTAINER) + membershipResource(getContainerLocation() + MEMBER_RESOURCE2); // PUT an LDP-IC try (final Response res = target(getContainerLocation() + "/indirectcontainer-put").request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertAll("Check PUTting an LDP-IC", checkRdfResponse(res, LDP.IndirectContainer, null)); } }
/** * Test updating an indirect container via PUT. */ @Test @DisplayName("Test updating an indirect container via PUT") default void testUpdateIndirectContainerViaPut() { final String location = createSimpleIndirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString("/indirectContainerInverse.ttl") + membershipResource(getContainerLocation() + MEMBER_RESOURCE2); // PUT an LDP-IC try (final Response res = target(location).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertAll("Check replacing an LDP-IC via PUT", checkRdfResponse(res, LDP.IndirectContainer, null)); } }
/** * Test updating an indirect container with too many membership resources. */ @Test @DisplayName("Test updating an indirect container with too many membership resources") default void testUpdateIndirectContainerMultipleMemberResources() { final String location = createSimpleIndirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString(INDIRECT_CONTAINER) + membershipResource(getContainerLocation() + MEMBER_RESOURCE2) + membershipResource(getContainerLocation() + "/member3"); // PUT an LDP-DC try (final Response res = target(location).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Check for a 4xx response"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "Check for an InvalidCardinality contraint IRI"); } }
/** * Test updating an indirect container with too many membership resources. */ @Test @DisplayName("Test updating an indirect container with too many membership resources") default void testUpdateIndirectContainerMultipleMemberResources() { final String location = createSimpleIndirectContainer(MEMBER_RESOURCE2); final String content = getResourceAsString(INDIRECT_CONTAINER) + membershipResource(getContainerLocation() + MEMBER_RESOURCE2) + membershipResource(getContainerLocation() + "/member3"); // PUT an LDP-DC try (final Response res = target(location).request() .header(LINK, fromUri(LDP.IndirectContainer.getIRIString()).rel(TYPE).build()) .put(entity(content, TEXT_TURTLE))) { assertEquals(CLIENT_ERROR, res.getStatusInfo().getFamily(), "Check for a 4xx response"); assertTrue(getLinks(res).stream().anyMatch(hasConstrainedBy(Trellis.InvalidCardinality)), "Check for an InvalidCardinality contraint IRI"); } }