Rename to AcmeRateLimitedException

pull/55/head
Richard Körber 2017-08-13 14:08:37 +02:00
parent 27bd913891
commit 7c88a2cdac
4 changed files with 18 additions and 18 deletions

View File

@ -47,7 +47,7 @@ import org.shredzone.acme4j.Session;
import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.exception.AcmeNetworkException; import org.shredzone.acme4j.exception.AcmeNetworkException;
import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.exception.AcmeRateLimitExceededException; import org.shredzone.acme4j.exception.AcmeRateLimitedException;
import org.shredzone.acme4j.exception.AcmeRetryAfterException; import org.shredzone.acme4j.exception.AcmeRetryAfterException;
import org.shredzone.acme4j.exception.AcmeServerException; import org.shredzone.acme4j.exception.AcmeServerException;
import org.shredzone.acme4j.exception.AcmeUnauthorizedException; import org.shredzone.acme4j.exception.AcmeUnauthorizedException;
@ -422,7 +422,7 @@ public class DefaultConnection implements Connection {
if ("rateLimited".equals(error)) { if ("rateLimited".equals(error)) {
Optional<Instant> retryAfter = getRetryAfterHeader(); Optional<Instant> retryAfter = getRetryAfterHeader();
Collection<URI> rateLimits = getLinks("urn:ietf:params:acme:documentation"); Collection<URI> rateLimits = getLinks("urn:ietf:params:acme:documentation");
return new AcmeRateLimitExceededException(problem, retryAfter.orElse(null), rateLimits); return new AcmeRateLimitedException(problem, retryAfter.orElse(null), rateLimits);
} }
return new AcmeServerException(problem); return new AcmeServerException(problem);

View File

@ -23,14 +23,14 @@ import org.shredzone.acme4j.Problem;
/** /**
* An exception that is thrown when a rate limit was exceeded. * An exception that is thrown when a rate limit was exceeded.
*/ */
public class AcmeRateLimitExceededException extends AcmeServerException { public class AcmeRateLimitedException extends AcmeServerException {
private static final long serialVersionUID = 4150484059796413069L; private static final long serialVersionUID = 4150484059796413069L;
private final Instant retryAfter; private final Instant retryAfter;
private final Collection<URI> documents; private final Collection<URI> documents;
/** /**
* Creates a new {@link AcmeRateLimitExceededException}. * Creates a new {@link AcmeRateLimitedException}.
* *
* @param problem * @param problem
* {@link Problem} that caused the exception * {@link Problem} that caused the exception
@ -40,7 +40,7 @@ public class AcmeRateLimitExceededException extends AcmeServerException {
* @param documents * @param documents
* URIs pointing to documents about the rate limit that was hit * URIs pointing to documents about the rate limit that was hit
*/ */
public AcmeRateLimitExceededException(Problem problem, Instant retryAfter, Collection<URI> documents) { public AcmeRateLimitedException(Problem problem, Instant retryAfter, Collection<URI> documents) {
super(problem); super(problem);
this.retryAfter = retryAfter; this.retryAfter = retryAfter;
this.documents = this.documents =

View File

@ -46,7 +46,7 @@ import org.shredzone.acme4j.Session;
import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.exception.AcmeNetworkException; import org.shredzone.acme4j.exception.AcmeNetworkException;
import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.exception.AcmeRateLimitExceededException; import org.shredzone.acme4j.exception.AcmeRateLimitedException;
import org.shredzone.acme4j.exception.AcmeRetryAfterException; import org.shredzone.acme4j.exception.AcmeRetryAfterException;
import org.shredzone.acme4j.exception.AcmeServerException; import org.shredzone.acme4j.exception.AcmeServerException;
import org.shredzone.acme4j.exception.AcmeUnauthorizedException; import org.shredzone.acme4j.exception.AcmeUnauthorizedException;
@ -481,10 +481,10 @@ public class DefaultConnectionTest {
} }
/** /**
* Test if an {@link AcmeRateLimitExceededException} is thrown on an acme problem. * Test if an {@link AcmeRateLimitedException} is thrown on an acme problem.
*/ */
@Test @Test
public void testAcceptThrowsRateLimitExceededException() throws Exception { public void testAcceptThrowsRateLimitedException() throws Exception {
String jsonData = "{\"type\":\"urn:ietf:params:acme:error:rateLimited\",\"detail\":\"Too many invocations\"}"; String jsonData = "{\"type\":\"urn:ietf:params:acme:error:rateLimited\",\"detail\":\"Too many invocations\"}";
Map<String, List<String>> linkHeader = new HashMap<>(); Map<String, List<String>> linkHeader = new HashMap<>();
@ -504,7 +504,7 @@ public class DefaultConnectionTest {
conn.conn = mockUrlConnection; conn.conn = mockUrlConnection;
conn.accept(HttpURLConnection.HTTP_OK); conn.accept(HttpURLConnection.HTTP_OK);
fail("Expected to fail"); fail("Expected to fail");
} catch (AcmeRateLimitExceededException ex) { } catch (AcmeRateLimitedException ex) {
assertThat(ex.getType(), is(URI.create("urn:ietf:params:acme:error:rateLimited"))); assertThat(ex.getType(), is(URI.create("urn:ietf:params:acme:error:rateLimited")));
assertThat(ex.getMessage(), is("Too many invocations")); assertThat(ex.getMessage(), is("Too many invocations"));
assertThat(ex.getRetryAfter(), is(retryAfter)); assertThat(ex.getRetryAfter(), is(retryAfter));
@ -512,7 +512,7 @@ public class DefaultConnectionTest {
assertThat(ex.getDocuments().size(), is(1)); assertThat(ex.getDocuments().size(), is(1));
assertThat(ex.getDocuments().iterator().next(), is(URI.create("https://example.com/rates.pdf"))); assertThat(ex.getDocuments().iterator().next(), is(URI.create("https://example.com/rates.pdf")));
} catch (AcmeException ex) { } catch (AcmeException ex) {
fail("Expected an AcmeRateLimitExceededException"); fail("Expected an AcmeRateLimitedException");
} }
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Content-Type"); verify(mockUrlConnection, atLeastOnce()).getHeaderField("Content-Type");

View File

@ -27,15 +27,15 @@ import org.junit.Test;
import org.shredzone.acme4j.Problem; import org.shredzone.acme4j.Problem;
/** /**
* Unit tests for {@link AcmeRateLimitExceededException}. * Unit tests for {@link AcmeRateLimitedException}.
*/ */
public class AcmeRateLimitExceededExceptionTest { public class AcmeRateLimitedExceptionTest {
/** /**
* Test that parameters are correctly returned. * Test that parameters are correctly returned.
*/ */
@Test @Test
public void testAcmeRateLimitExceededException() { public void testAcmeRateLimitedException() {
URI type = URI.create("urn:ietf:params:acme:error:rateLimited"); URI type = URI.create("urn:ietf:params:acme:error:rateLimited");
String detail = "Too many requests per minute"; String detail = "Too many requests per minute";
Instant retryAfter = Instant.now().plus(Duration.ofMinutes(1)); Instant retryAfter = Instant.now().plus(Duration.ofMinutes(1));
@ -45,8 +45,8 @@ public class AcmeRateLimitExceededExceptionTest {
Problem problem = createProblem(type, detail, null); Problem problem = createProblem(type, detail, null);
AcmeRateLimitExceededException ex AcmeRateLimitedException ex
= new AcmeRateLimitExceededException(problem, retryAfter, documents); = new AcmeRateLimitedException(problem, retryAfter, documents);
assertThat(ex.getType(), is(type)); assertThat(ex.getType(), is(type));
assertThat(ex.getMessage(), is(detail)); assertThat(ex.getMessage(), is(detail));
@ -58,14 +58,14 @@ public class AcmeRateLimitExceededExceptionTest {
* Test that optional parameters are null-safe. * Test that optional parameters are null-safe.
*/ */
@Test @Test
public void testNullAcmeRateLimitExceededException() { public void testNullAcmeRateLimitedException() {
URI type = URI.create("urn:ietf:params:acme:error:rateLimited"); URI type = URI.create("urn:ietf:params:acme:error:rateLimited");
String detail = "Too many requests per minute"; String detail = "Too many requests per minute";
Problem problem = createProblem(type, detail, null); Problem problem = createProblem(type, detail, null);
AcmeRateLimitExceededException ex AcmeRateLimitedException ex
= new AcmeRateLimitExceededException(problem, null, null); = new AcmeRateLimitedException(problem, null, null);
assertThat(ex.getType(), is(type)); assertThat(ex.getType(), is(type));
assertThat(ex.getMessage(), is(detail)); assertThat(ex.getMessage(), is(detail));