/** * 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(getResourceLocation()).request().get()) { 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; }
/** * 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(getResourceLocation()).request().get()) { 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 the presence of a datetime header for each memento. */ @Test @DisplayName("Test the presence of a datetime header for each memento") default void testMementoAcceptDateTimeHeader() { getMementos().forEach((memento, date) -> { final String location; try (final Response res = target(getResourceLocation()).request().header(ACCEPT_DATETIME, date).head()) { if (REDIRECTION.equals(res.getStatusInfo().getFamily())) { location = res.getLocation().toString(); } else { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily())); location = getResourceLocation(); } } try (final Response res = target(location).request().header(ACCEPT_DATETIME, date).head()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful memento request"); final ZonedDateTime zdt = ZonedDateTime.parse(date, RFC_1123_DATE_TIME); assertEquals(zdt, ZonedDateTime.parse(res.getHeaderString(MEMENTO_DATETIME), RFC_1123_DATE_TIME), "Check that the memento-datetime header is correct"); } }); }
/** * Test the presence of a datetime header for each memento. */ @Test @DisplayName("Test the presence of a datetime header for each memento") default void testMementoAcceptDateTimeHeader() { getMementos().forEach((memento, date) -> { final String location; try (final Response res = target(getResourceLocation()).request().header(ACCEPT_DATETIME, date).head()) { if (REDIRECTION.equals(res.getStatusInfo().getFamily())) { location = res.getLocation().toString(); } else { assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily())); location = getResourceLocation(); } } try (final Response res = target(location).request().header(ACCEPT_DATETIME, date).head()) { assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful memento request"); final ZonedDateTime zdt = ZonedDateTime.parse(date, RFC_1123_DATE_TIME); assertEquals(zdt, ZonedDateTime.parse(res.getHeaderString(MEMENTO_DATETIME), RFC_1123_DATE_TIME), "Check that the memento-datetime header is correct"); } }); }
final IRI subject = rdf.createIRI(getResourceLocation()); final List<IRI> urls = mementos.keySet().stream().sorted().map(rdf::createIRI).collect(toList()); assertEquals(3L, urls.size(), "Check that three mementos were found");
final IRI subject = rdf.createIRI(getResourceLocation()); final List<IRI> urls = mementos.keySet().stream().sorted().map(rdf::createIRI).collect(toList()); assertEquals(3L, urls.size(), "Check that three mementos were found");