/** * Test that memento binary descriptions are also LDP resources. */ @Test @DisplayName("Test that memento binary descriptions are also LDP resources") default void testMementoBinaryDescriptionLdpResource() { getMementos().forEach((memento, date) -> { final String description = getDescription(memento); assertNotNull(description, "No describedby Link header!"); try (final Response res = target(description).request().accept("text/turtle").head()) { assertAll("Check LDP headers", checkMementoLdpHeaders(res, LDP.RDFSource)); } }); } }
/** * Build a list of all Mementos. * @return the resource mementos */ default Map<String, String> getMementos() { final Map<String, String> mementos = new HashMap<>(); try (final Response res = target(getBinaryLocation()).request().head()) { getLinks(res).stream().filter(link -> link.getRel().equals("memento")) .filter(l -> l.getParams().containsKey("datetime")) .forEach(link -> mementos.put(link.getUri().toString(), link.getParams().get("datetime"))); } return mementos; }
/** * Test that memento resources are also LDP resources. */ @Test @DisplayName("Test that memento resources are also LDP resources") default void testMementoLdpResource() { getMementos().forEach((memento, date) -> { try (final Response res = target(memento).request().head()) { assertAll("Check LDP headers", checkMementoLdpHeaders(res, LDP.NonRDFSource)); } }); }
/** * Check the link headers on a binary description Memento. */ @Test @DisplayName("Test the link canonical header") default void testCanonicalHeaderDescriptions() { getMementos().forEach((memento, date) -> { final String description = getDescription(memento); if (isNull(description)) { fail("Could not find description link header!"); } try (final Response res = target(description).request().accept("text/turtle").head()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a valid response"); assertTrue(getLinks(res).stream().filter(link -> link.getRel().equals("canonical")) .anyMatch(link -> link.getUri().toString().equals(memento + "&ext=description")), "Check for a rel=canonical Link header"); assertTrue(getLinks(res).stream().filter(link -> link.getRel().equals("describes")) .anyMatch(link -> link.getUri().toString().equals(memento)), "Check for a rel=describes Link header"); } }); }
/** * Test the content of a binary memento resource. */ @Test @DisplayName("Test the content of memento resources") default void testMementoContent() { final Map<String, String> mementos = getMementos(); final Map<String, String> responses = new HashMap<>(); mementos.forEach((memento, date) -> { try (final Response res = target(memento).request().get()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a valid response"); responses.put(memento, readEntityAsString(res.getEntity())); } }); assertEquals(3L, responses.size(), "Check for 3 mementos"); responses.forEach((response, content) -> assertTrue(content.startsWith("This is a text file."), "Check the binary content of the mementos")); assertEquals(3L, responses.values().size(), "Check the number of Memento responses"); final Set<String> values = new HashSet<>(responses.values()); assertEquals(3L, values.size(), "Check the number of distinct Memento responses"); }
/** * Test that memento resources are also LDP resources. */ @Test @DisplayName("Test that memento resources are also LDP resources") default void testMementoLdpResource() { getMementos().forEach((memento, date) -> { try (final Response res = target(memento).request().head()) { assertAll("Check LDP headers", checkMementoLdpHeaders(res, LDP.NonRDFSource)); } }); }
/** * Check the link headers on a binary description Memento. */ @Test @DisplayName("Test the link canonical header") default void testCanonicalHeaderDescriptions() { getMementos().forEach((memento, date) -> { final String description = getDescription(memento); if (isNull(description)) { fail("Could not find description link header!"); } try (final Response res = target(description).request().accept("text/turtle").head()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a valid response"); assertTrue(getLinks(res).stream().filter(link -> link.getRel().equals("canonical")) .anyMatch(link -> link.getUri().toString().equals(memento + "&ext=description")), "Check for a rel=canonical Link header"); assertTrue(getLinks(res).stream().filter(link -> link.getRel().equals("describes")) .anyMatch(link -> link.getUri().toString().equals(memento)), "Check for a rel=describes Link header"); } }); }
/** * Test the content of a binary memento resource. */ @Test @DisplayName("Test the content of memento resources") default void testMementoContent() { final Map<String, String> mementos = getMementos(); final Map<String, String> responses = new HashMap<>(); mementos.forEach((memento, date) -> { try (final Response res = target(memento).request().get()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a valid response"); responses.put(memento, readEntityAsString(res.getEntity())); } }); assertEquals(3L, responses.size(), "Check for 3 mementos"); responses.forEach((response, content) -> assertTrue(content.startsWith("This is a text file."), "Check the binary content of the mementos")); assertEquals(3L, responses.values().size(), "Check the number of Memento responses"); final Set<String> values = new HashSet<>(responses.values()); assertEquals(3L, values.size(), "Check the number of distinct Memento responses"); }
/** * Test that memento binary descriptions are also LDP resources. */ @Test @DisplayName("Test that memento binary descriptions are also LDP resources") default void testMementoBinaryDescriptionLdpResource() { getMementos().forEach((memento, date) -> { final String description = getDescription(memento); assertNotNull(description, "No describedby Link header!"); try (final Response res = target(description).request().accept("text/turtle").head()) { assertAll("Check LDP headers", checkMementoLdpHeaders(res, LDP.RDFSource)); } }); } }
/** * Check the link headers on a binary Memento. */ @Test @DisplayName("Test the link canonical header") default void testCanonicalHeader() { getMementos().forEach((memento, date) -> { try (final Response res = target(memento).request().head()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a valid response"); assertTrue(getLinks(res).stream().filter(link -> link.getRel().equals("canonical")) .anyMatch(link -> link.getUri().toString().equals(memento)), "Check for a rel=canonical Link header"); assertTrue(getLinks(res).stream().filter(link -> link.getRel().equals("describedby")) .anyMatch(link -> link.getUri().toString().equals(memento + "&ext=description")), "Check for a rel=describedby Link header"); } }); }
/** * Build a list of all Mementos. * @return the resource mementos */ default Map<String, String> getMementos() { final Map<String, String> mementos = new HashMap<>(); try (final Response res = target(getBinaryLocation()).request().head()) { getLinks(res).stream().filter(link -> link.getRel().equals("memento")) .filter(l -> l.getParams().containsKey("datetime")) .forEach(link -> mementos.put(link.getUri().toString(), link.getParams().get("datetime"))); } return mementos; }
/** * Check the link headers on a binary Memento. */ @Test @DisplayName("Test the link canonical header") default void testCanonicalHeader() { getMementos().forEach((memento, date) -> { try (final Response res = target(memento).request().head()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a valid response"); assertTrue(getLinks(res).stream().filter(link -> link.getRel().equals("canonical")) .anyMatch(link -> link.getUri().toString().equals(memento)), "Check for a rel=canonical Link header"); assertTrue(getLinks(res).stream().filter(link -> link.getRel().equals("describedby")) .anyMatch(link -> link.getUri().toString().equals(memento + "&ext=description")), "Check for a rel=describedby Link header"); } }); }