Challenge extends AcmeJsonResource { public Status getStatus() { return getJSON().get(KEY_STATUS).asStatus(); } Challenge(Login login, JSON data); String getType(); Status getStatus(); @Nullable Instant getValidated(); @Nullable Problem getError(); void trigger();  }
@Test public void testUpdate() throws Exception { TestableConnectionProvider provider = new TestableConnectionProvider() { @Override public int sendSignedPostAsGetRequest(URL url, Login login) { assertThat(url, is(locationUrl)); return HttpURLConnection.HTTP_OK; } @Override public JSON readJsonResponse() { return getJSON("updateHttpChallengeResponse"); } @Override public void handleRetryAfter(String message) { } }; Login login = provider.createLogin(); Challenge challenge = new Http01Challenge(login, getJSON("triggerHttpChallengeResponse")); challenge.update(); assertThat(challenge.getStatus(), is(Status.VALID)); assertThat(challenge.getLocation(), is(locationUrl)); provider.close(); }
@Test public void testUpdateRetryAfter() throws Exception { final Instant retryAfter = Instant.now().plus(Duration.ofSeconds(30)); TestableConnectionProvider provider = new TestableConnectionProvider() { @Override public int sendSignedPostAsGetRequest(URL url, Login login) { assertThat(url, is(locationUrl)); return HttpURLConnection.HTTP_OK; } @Override public JSON readJsonResponse() { return getJSON("updateHttpChallengeResponse"); } @Override public void handleRetryAfter(String message) throws AcmeException { throw new AcmeRetryAfterException(message, retryAfter); } }; Login login = provider.createLogin(); Challenge challenge = new Http01Challenge(login, getJSON("triggerHttpChallengeResponse")); try { challenge.update(); fail("Expected AcmeRetryAfterException"); } catch (AcmeRetryAfterException ex) { assertThat(ex.getRetryAfter(), is(retryAfter)); } assertThat(challenge.getStatus(), is(Status.VALID)); assertThat(challenge.getLocation(), is(locationUrl)); provider.close(); }