/** * Initialize Binary tests. */ @BeforeAll @DisplayName("Initialize Binary tests") default void beforeAllTests() { // POST an LDP-NR try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(CONTENT, TEXT_PLAIN))) { setResourceLocation(checkCreateResponseAssumptions(res, LDP.NonRDFSource)); } }
/** * Test that the SHA digest is generated. */ @Test @DisplayName("Test that the SHA digest is generated") default void testBinaryWantDigestSha() { // Test the SHA-1 algorithm try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "SHA,MD5").get()) { assertAll("Check binary with SHA-1 digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertEquals("sha=Z5pg2cWB1IqkKKMjh57cQKAeKp0=", res.getHeaderString(DIGEST), "Check the SHA digest value"); } }
/** * Test creating a new binary via POST. */ @Test @DisplayName("Test creating a new binary via POST") default void testPostBinary() { // POST an LDP-NR try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(CONTENT, TEXT_PLAIN))) { assertAll("Check POSTing LDP-NR", checkNonRdfResponse(res, null)); final String resource = res.getLocation().toString(); assertTrue(resource.startsWith(getBaseURL()), "Check the response location"); assertTrue(resource.length() > getBaseURL().length(), "Check for a nested response location"); } }
/** * Test that the binary appears in the parent container. */ @Test @DisplayName("Test that the binary appears in the parent container") default void testBinaryIsInContainer() { final RDF rdf = getInstance(); // Test the root container, verifying that the containment triple exists try (final Response res = target().request().get()) { assertAll("Check binary in container", checkRdfResponse(res, LDP.BasicContainer, null)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.contains(rdf.createIRI(getBaseURL()), LDP.contains, rdf.createIRI(getResourceLocation())), "Check for an ldp:contains triple"); } }
final String descriptionLocation = getDescription(getResourceLocation()); if (isNull(descriptionLocation)) { fail("No describedby Link header!"); try (final Response res = target(descriptionLocation).request().accept("text/turtle").get()) { assertAll("Check an LDP-NR description", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); size = g.size(); descriptionETag = res.getEntityTag(); try (final Response res = target(descriptionLocation).request().method("PATCH", entity("INSERT { <> <http://purl.org/dc/terms/title> \"Title\" } WHERE {}", APPLICATION_SPARQL_UPDATE))) { assertAll("Check PATCHing LDP-NR description", checkRdfResponse(res, LDP.RDFSource, null)); await().until(() -> !descriptionETag.equals(getETag(descriptionLocation))); try (final Response res = target(descriptionLocation).request().accept("text/turtle").get()) { assertAll("Check the new LDP-NR description", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.size() > size, "Check the graph size is greater than " + size); assertTrue(g.contains(rdf.createIRI(getResourceLocation()), DC.title, rdf.createLiteral("Title")), "Check for a dc:title triple"); assertNotEquals(descriptionETag, res.getEntityTag(), "Check that the ETag values are different"); try (final Response res = target(getResourceLocation()).request().get()) { assertAll("Check the LDP-NR", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertEquals(CONTENT, readEntityAsString(res.getEntity()), "Check for an expected binary content value");
/** * Test that the binary appears in the parent container. */ @Test @DisplayName("Test that the binary appears in the parent container") default void testBinaryIsInContainer() { final RDF rdf = getInstance(); // Test the root container, verifying that the containment triple exists try (final Response res = target().request().get()) { assertAll("Check binary in container", checkRdfResponse(res, LDP.BasicContainer, null)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.contains(rdf.createIRI(getBaseURL()), LDP.contains, rdf.createIRI(getResourceLocation())), "Check for an ldp:contains triple"); } }
final String descriptionLocation = getDescription(getResourceLocation()); if (isNull(descriptionLocation)) { fail("No describedby Link header!"); try (final Response res = target(descriptionLocation).request().accept("text/turtle").get()) { assertAll("Check an LDP-NR description", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); size = g.size(); descriptionETag = res.getEntityTag(); try (final Response res = target(descriptionLocation).request().method("PATCH", entity("INSERT { <> <http://purl.org/dc/terms/title> \"Title\" } WHERE {}", APPLICATION_SPARQL_UPDATE))) { assertAll("Check PATCHing LDP-NR description", checkRdfResponse(res, LDP.RDFSource, null)); await().until(() -> !descriptionETag.equals(getETag(descriptionLocation))); try (final Response res = target(descriptionLocation).request().accept("text/turtle").get()) { assertAll("Check the new LDP-NR description", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.size() > size, "Check the graph size is greater than " + size); assertTrue(g.contains(rdf.createIRI(getResourceLocation()), DC.title, rdf.createLiteral("Title")), "Check for a dc:title triple"); assertNotEquals(descriptionETag, res.getEntityTag(), "Check that the ETag values are different"); try (final Response res = target(getResourceLocation()).request().get()) { assertAll("Check the LDP-NR", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertEquals(CONTENT, readEntityAsString(res.getEntity()), "Check for an expected binary content value");
/** * Test fetching a binary description. */ @Test @DisplayName("Test fetching a binary description") default void testGetBinaryDescription() { final EntityTag etag = getETag(getResourceLocation()); // Fetch the description try (final Response res = target(getResourceLocation()).request().accept("text/turtle").get()) { assertAll("Check binary description", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.size() >= 0L, "Assert that the graph isn't empty"); assertTrue(res.getEntityTag().isWeak(), "Check for a weak ETag"); assertNotEquals(etag, res.getEntityTag(), "Check for different ETag values"); } }
/** * Test that the SHA digest is generated. */ @Test @DisplayName("Test that the SHA digest is generated") default void testBinaryWantDigestSha() { // Test the SHA-1 algorithm try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "SHA,MD5").get()) { assertAll("Check binary with SHA-1 digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertEquals("sha=Z5pg2cWB1IqkKKMjh57cQKAeKp0=", res.getHeaderString(DIGEST), "Check the SHA digest value"); } }
/** * Test creating a new binary via POST. */ @Test @DisplayName("Test creating a new binary via POST") default void testPostBinary() { // POST an LDP-NR try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(CONTENT, TEXT_PLAIN))) { assertAll("Check POSTing LDP-NR", checkNonRdfResponse(res, null)); final String resource = res.getLocation().toString(); assertTrue(resource.startsWith(getBaseURL()), "Check the response location"); assertTrue(resource.length() > getBaseURL().length(), "Check for a nested response location"); } }
/** * Initialize Binary tests. */ @BeforeAll @DisplayName("Initialize Binary tests") default void beforeAllTests() { // POST an LDP-NR try (final Response res = target().request().header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(CONTENT, TEXT_PLAIN))) { setResourceLocation(checkCreateResponseAssumptions(res, LDP.NonRDFSource)); } }
/** * Test fetching a binary description. */ @Test @DisplayName("Test fetching a binary description") default void testGetBinaryDescription() { final EntityTag etag = getETag(getResourceLocation()); // Fetch the description try (final Response res = target(getResourceLocation()).request().accept("text/turtle").get()) { assertAll("Check binary description", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE)); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertTrue(g.size() >= 0L, "Assert that the graph isn't empty"); assertTrue(res.getEntityTag().isWeak(), "Check for a weak ETag"); assertNotEquals(etag, res.getEntityTag(), "Check for different ETag values"); } }
/** * Test that the SHA-256 digest is generated. */ @Test @DisplayName("Test that the SHA-256 digest is generated") default void testBinaryWantDigestSha256() { // Test the SHA-256 algorithm try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "SHA-256").get()) { assertAll("Check binary with SHA-256 digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertEquals("sha-256=wZXqBpAjgZLSoADF419CRpJCurDcagOwnb/8VAiiQXA=", res.getHeaderString(DIGEST), "Check the SHA-256 digest value"); } }
/** * Test creating a new binary via POST with a digest header. */ @Test @DisplayName("Test creating a new binary via POST with a digest header") default void testPostBinaryWithDigest() { // POST an LDP-NR try (final Response res = target().request().header(DIGEST, "md5=bUMuG430lSc5B2PWyoNIgA==") .header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(CONTENT, TEXT_PLAIN))) { assertAll("Check POSTing LDP-NR with digest", checkNonRdfResponse(res, null)); final String resource = res.getLocation().toString(); assertTrue(resource.startsWith(getBaseURL()), "Check the response location"); assertTrue(resource.length() > getBaseURL().length(), "Check for a nested response location"); } }
/** * Test that an unknown digest is ignored. */ @Test @DisplayName("Test that an unknown digest is ignored") default void testBinaryWantDigestUnknown() { // Test an unknown digest algorithm try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "FOO").get()) { assertAll("Check binary with unknown digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertNull(res.getHeaderString(DIGEST), "Check that no Digest header is present"); } } }
/** * Test creating a new binary via POST with a digest header. */ @Test @DisplayName("Test creating a new binary via POST with a digest header") default void testPostBinaryWithDigest() { // POST an LDP-NR try (final Response res = target().request().header(DIGEST, "md5=bUMuG430lSc5B2PWyoNIgA==") .header(SLUG, generateRandomValue(getClass().getSimpleName())) .post(entity(CONTENT, TEXT_PLAIN))) { assertAll("Check POSTing LDP-NR with digest", checkNonRdfResponse(res, null)); final String resource = res.getLocation().toString(); assertTrue(resource.startsWith(getBaseURL()), "Check the response location"); assertTrue(resource.length() > getBaseURL().length(), "Check for a nested response location"); } }
/** * Test that an unknown digest is ignored. */ @Test @DisplayName("Test that an unknown digest is ignored") default void testBinaryWantDigestUnknown() { // Test an unknown digest algorithm try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "FOO").get()) { assertAll("Check binary with unknown digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertNull(res.getHeaderString(DIGEST), "Check that no Digest header is present"); } } }
/** * Test that the SHA-256 digest is generated. */ @Test @DisplayName("Test that the SHA-256 digest is generated") default void testBinaryWantDigestSha256() { // Test the SHA-256 algorithm try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "SHA-256").get()) { assertAll("Check binary with SHA-256 digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertEquals("sha-256=wZXqBpAjgZLSoADF419CRpJCurDcagOwnb/8VAiiQXA=", res.getHeaderString(DIGEST), "Check the SHA-256 digest value"); } }
/** * Test fetching a binary resource. */ @Test @DisplayName("Test fetching a binary resource") default void testGetBinary() { // Fetch the resource try (final Response res = target(getResourceLocation()).request().get()) { assertAll("Check binary resource", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertEquals(CONTENT, readEntityAsString(res.getEntity()), "Check for matching content"); assertFalse(res.getEntityTag().isWeak(), "Check for a strong ETag"); } }
/** * Test fetching a binary resource. */ @Test @DisplayName("Test fetching a binary resource") default void testGetBinary() { // Fetch the resource try (final Response res = target(getResourceLocation()).request().get()) { assertAll("Check binary resource", checkNonRdfResponse(res, TEXT_PLAIN_TYPE)); assertEquals(CONTENT, readEntityAsString(res.getEntity()), "Check for matching content"); assertFalse(res.getEntityTag().isWeak(), "Check for a strong ETag"); } }