MapHttp4xxCodesToExceptions implements Fallback<Object> { @Override public ListenableFuture<Object> create(Throwable t) throws Exception { return immediateFuture(createOrPropagate(t)); } @Inject  MapHttp4xxCodesToExceptions(PropagateIfRetryAfter propagateIfRetryAfter); @Override ListenableFuture<Object> create(Throwable t); @Override Object createOrPropagate(Throwable t);  }
@Test(expectedExceptions = AuthorizationException.class) public void test401ToAuthorizationException() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder().statusCode(401).build())); }
@Test(expectedExceptions = AuthorizationException.class) public void test403ToAuthorizationException() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder().statusCode(403).build())); }
@Test(expectedExceptions = ResourceNotFoundException.class) public void test404ToResourceNotFoundException() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder().statusCode(404).build())); }
@Test(expectedExceptions = IllegalStateException.class) public void test409ToIllegalStateException() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder().statusCode(409).build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry now") public void testHttpResponseExceptionWithRetryAfterDate() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 GMT").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 700 seconds") public void testHttpResponseExceptionWithRetryAfterOffset() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "700").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 86400 seconds") public void testHttpResponseExceptionWithRetryAfterPastIsZero() throws Exception { fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Sun, 2 Jan 2000 00:00:00 GMT").build())); }