/** * Check a response for expected LDP Link headers. * @param res the Response object * @param ldpType the LDP Resource type * @return a Stream of executable assertions */ default Stream<Executable> checkMementoLdpHeaders(final Response res, final IRI ldpType) { return of( () -> assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful response"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(LDP.Resource)), "Check that the response is an LDP Resource"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(ldpType)), "Check that the response is an " + ldpType)); }
/** * Check a response for expected LDP Link headers. * @param res the Response object * @param ldpType the LDP Resource type * @return a Stream of executable assertions */ default Stream<Executable> checkMementoLdpHeaders(final Response res, final IRI ldpType) { return of( () -> assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful response"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(LDP.Resource)), "Check that the response is an LDP Resource"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(ldpType)), "Check that the response is an " + ldpType)); }
/** * Check for a successful creation response. * @param res the response * @param ldpType the expected type * @return the location of the new resource */ default String checkCreateResponseAssumptions(final Response res, final IRI ldpType) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of " + ldpType + " appears not to be supported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(ldpType)), "New resource was not of the expected " + ldpType + " type"); return res.getLocation().toString(); }
/** * Check for a successful creation response. * @param res the response * @param ldpType the expected type * @return the location of the new resource */ default String checkCreateResponseAssumptions(final Response res, final IRI ldpType) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of " + ldpType + " appears not to be supported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(ldpType)), "New resource was not of the expected " + ldpType + " type"); return res.getLocation().toString(); }
/** * Check a Non-RDF response. * @param res the response * @param mediaType the content-type of the resource, or null if no content-type is expected * @return a stream of testable assertions */ default Stream<Executable> checkNonRdfResponse(final Response res, final MediaType mediaType) { return Stream.of( () -> assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful response"), () -> assertTrue(isNull(mediaType) || res.getMediaType().isCompatible(mediaType), "Check for a compatible mediaType, if one exists"), () -> assertTrue(isNull(mediaType) || mediaType.isCompatible(res.getMediaType()), "Check again for a compatible mediaType, if one exists"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(LDP.Resource)), "Check for the presence of an ldp:Resource Link header"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(LDP.NonRDFSource)), "Check for the presence of an ldp:NonRDFSource Link header"), () -> assertFalse(getLinks(res).stream().anyMatch(hasType(LDP.RDFSource)), "Check for the absence of an ldp:RDFSource Link header")); }
/** * Check a Non-RDF response. * @param res the response * @param mediaType the content-type of the resource, or null if no content-type is expected * @return a stream of testable assertions */ default Stream<Executable> checkNonRdfResponse(final Response res, final MediaType mediaType) { return Stream.of( () -> assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful response"), () -> assertTrue(isNull(mediaType) || res.getMediaType().isCompatible(mediaType), "Check for a compatible mediaType, if one exists"), () -> assertTrue(isNull(mediaType) || mediaType.isCompatible(res.getMediaType()), "Check again for a compatible mediaType, if one exists"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(LDP.Resource)), "Check for the presence of an ldp:Resource Link header"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(LDP.NonRDFSource)), "Check for the presence of an ldp:NonRDFSource Link header"), () -> assertFalse(getLinks(res).stream().anyMatch(hasType(LDP.RDFSource)), "Check for the absence of an ldp:RDFSource Link header")); }
/** * Check an RDF response. * @param res the response * @param ldpType the expected LDP type * @param mediaType the media type, or null if no content-type is expected * @return a stream of testable assertions */ default Stream<Executable> checkRdfResponse(final Response res, final IRI ldpType, final MediaType mediaType) { return Stream.of( () -> assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful response"), () -> assertTrue(isNull(mediaType) || res.getMediaType().isCompatible(mediaType), "Check for a compatible mediaType, if one is present"), () -> assertTrue(isNull(mediaType) || mediaType.isCompatible(res.getMediaType()), "Check again for a compatible mediaType, if one is present"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(LDP.Resource)), "Check for the presence of a ldp:Resource Link header"), () -> assertFalse(getLinks(res).stream().anyMatch(hasType(LDP.NonRDFSource)), "Check that no ldp:NonRDFSource Link header is present"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(ldpType)), "Check for an appropriate LDP Link header")); }
/** * Check an RDF response. * @param res the response * @param ldpType the expected LDP type * @param mediaType the media type, or null if no content-type is expected * @return a stream of testable assertions */ default Stream<Executable> checkRdfResponse(final Response res, final IRI ldpType, final MediaType mediaType) { return Stream.of( () -> assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful response"), () -> assertTrue(isNull(mediaType) || res.getMediaType().isCompatible(mediaType), "Check for a compatible mediaType, if one is present"), () -> assertTrue(isNull(mediaType) || mediaType.isCompatible(res.getMediaType()), "Check again for a compatible mediaType, if one is present"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(LDP.Resource)), "Check for the presence of a ldp:Resource Link header"), () -> assertFalse(getLinks(res).stream().anyMatch(hasType(LDP.NonRDFSource)), "Check that no ldp:NonRDFSource Link header is present"), () -> assertTrue(getLinks(res).stream().anyMatch(hasType(ldpType)), "Check for an appropriate LDP Link header")); }
assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of BasicContainer appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.BasicContainer)), "Expected LDP:BasicContainer type not present in response"); assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of IndirectContainer appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.IndirectContainer)), "Expected LDP:IndirectContainer type not present in response"); assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of RDFSource appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.RDFSource)), "Expected LDP:RDFSource type not present in response");
assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of BasicContainer appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.BasicContainer)), "New resource was not of expected BasicContainer type"); 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"); .post(entity(simpleContent, TEXT_TURTLE))) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), dcUnsupported); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.DirectContainer)), notDcType);
assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of BasicContainer appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.BasicContainer)), "New resource was not of expected BasicContainer type"); 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"); .post(entity(simpleContent, TEXT_TURTLE))) { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), dcUnsupported); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.DirectContainer)), notDcType);
assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of BasicContainer appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.BasicContainer)), "Expected LDP:BasicContainer type not present in response"); assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of IndirectContainer appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.IndirectContainer)), "Expected LDP:IndirectContainer type not present in response"); assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()), "Creation of RDFSource appears to be unsupported"); assumeTrue(getLinks(res).stream().anyMatch(hasType(LDP.RDFSource)), "Expected LDP:RDFSource type not present in response");
/** * 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 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"); } }