diff --git a/src/test/java/com/swancommunity/owid/DatedKeyFetchTest.java b/src/test/java/com/swancommunity/owid/DatedKeyFetchTest.java index 7305ac3..bdef059 100644 --- a/src/test/java/com/swancommunity/owid/DatedKeyFetchTest.java +++ b/src/test/java/com/swancommunity/owid/DatedKeyFetchTest.java @@ -871,13 +871,18 @@ void aKeyAnsweredWithItsSpanIsHeldForTheWholeSpan() @Test void aRecentMinuteIsServedWhereTheCreatorStatedTheSpan() throws IOException, OwidException { - KeyEndPoint endPoint = endPoint(KeyEndPoint.Answer.SCHEDULE); - Instant now = Instant.now(); - DatedPublicKey current = KeyFixtures.schedule().keyInForce(now); - assumeTrue(current != null - && KeyFixtures.schedule().nextStartAfter(current) != null, - "the fixture schedule has no key after the one in force now"); - long started = Io.minutesSinceBase(now); + long started = Io.minutesSinceBase(Instant.now()); + long day = 24 * 60; + // One key covering the day either side of now, so the span the + // creator states holds every minute asked about whenever the test + // runs. + KeyEndPoint endPoint = KeyEndPoint.start(KeyEndPoint.Answer.GIVEN, + Endpoints.publicKeyAnswer( + KeyFixtures.scheduledKeys().get(0).pem(), + Io.baseDate().plus(Duration.ofMinutes(started - day)), + Io.baseDate().plus(Duration.ofMinutes(started + day)), + null)); + this.started.add(endPoint); pemAt(urlFor(endPoint, started - 1), KeyFixtures.IDENTIFIER_DOMAIN); pemAt(urlFor(endPoint, started), KeyFixtures.IDENTIFIER_DOMAIN); pemAt(urlFor(endPoint, started - 10), KeyFixtures.IDENTIFIER_DOMAIN); diff --git a/src/test/java/com/swancommunity/owid/KeyEndPoint.java b/src/test/java/com/swancommunity/owid/KeyEndPoint.java index 7722d64..2c20553 100644 --- a/src/test/java/com/swancommunity/owid/KeyEndPoint.java +++ b/src/test/java/com/swancommunity/owid/KeyEndPoint.java @@ -81,7 +81,13 @@ enum Answer { * A redirect to somewhere else, which a client must not follow. * Started with {@link #start(Answer, String)} naming where. */ - REDIRECT + REDIRECT, + + /** + * The body given, whatever the request asks for. Started with + * {@link #start(Answer, String)} naming the body. + */ + GIVEN } private final HttpServer server; @@ -107,9 +113,10 @@ static KeyEndPoint start(final Answer answer) /** * Starts an end point serving what the answer says, redirecting to - * the URL given where the answer is {@link Answer#REDIRECT}. + * the URL given where the answer is {@link Answer#REDIRECT} and + * answering with the body given where it is {@link Answer#GIVEN}. */ - static KeyEndPoint start(final Answer answer, final String redirectTo) + static KeyEndPoint start(final Answer answer, final String given) throws IOException, OwidException { final PublicKeySchedule schedule = KeyFixtures.schedule(); HttpServer server = HttpServer.create(new InetSocketAddress( @@ -124,14 +131,16 @@ public void handle(HttpExchange exchange) throws IOException { String format = parameter(query, "format"); endPoint.dates.add(date); if (answer == Answer.REDIRECT) { - exchange.getResponseHeaders().set("Location", redirectTo); + exchange.getResponseHeaders().set("Location", given); exchange.sendResponseHeaders(302, -1); exchange.close(); return; } Endpoints.Response response; try { - response = body(schedule, answer, date, format); + response = answer == Answer.GIVEN + ? new Endpoints.Response(200, given) + : body(schedule, answer, date, format); } catch (OwidException fault) { exchange.sendResponseHeaders(500, -1); exchange.close();