/** * Create an Annotation resource. * @return the location of the new resource */ default String createAnnotationResource() { // POST an LDP-RS try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(getResourceAsString(ANNOTATION_RESOURCE), TEXT_TURTLE))) { assertAll("Check for an LDP-RS", checkRdfResponse(res, LDP.RDFSource, null)); return res.getLocation().toString(); } } }
/** * Create an Annotation resource. * @return the location of the new resource */ default String createAnnotationResource() { // POST an LDP-RS try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(getResourceAsString(ANNOTATION_RESOURCE), TEXT_TURTLE))) { assertAll("Check for an LDP-RS", checkRdfResponse(res, LDP.RDFSource, null)); return res.getLocation().toString(); } } }
/** * Initialize the RDF tests. */ @BeforeAll @DisplayName("Initialize RDF tests") default void beforeAllTests() { 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))) { setResourceLocation(checkCreateResponseAssumptions(res, LDP.RDFSource)); } }
/** * Initialize the RDF tests. */ @BeforeAll @DisplayName("Initialize RDF tests") default void beforeAllTests() { 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))) { setResourceLocation(checkCreateResponseAssumptions(res, LDP.RDFSource)); } }
/** * 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"); } }
@Test public void testGetResourceAsString() { assertTrue(TestUtils.getResourceAsString("/annotation.ttl").contains("<> a oa:Annotation"), "Check the resource loader works as expected"); }
/** * 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 receiving a creation event message in an indirect container. */ @Test @DisplayName("Test receiving a JMS creation message from a LDP-IC") default void testReceiveCreateMessageIC() { final String agent = "http://example.com/sam#i"; // POST an LDP-RS try (final Response res = target(getIndirectContainerLocation()).request() .header(AUTHORIZATION, buildJwt(agent, getJwtSecret())) .post(entity(getResourceAsString("/childResource.ttl"), TEXT_TURTLE))) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful POST in an LDP-IC"); assertAll("Check the LDP-IC parent", checkResourceParentLdpIC(res.getLocation().toString(), agent, AS.Create, LDP.RDFSource, LDP.Container)); } }
@Test public void testGetResourceAsStringNull() { assertNull(TestUtils.getResourceAsString("/non-existent-resource.ttl"), "Check loading a non-existent resource"); }
/** * 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(); } } }
/** * 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"); } }
/** * 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 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)); } }
/** * 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 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)); } }
/** * 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 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)); } }