@Test public void testApply() throws Throwable { Invocation invocation = new Invocation(new Object(), Object.class.getMethod("toString")); AmazonDynamoDBErrorFault fault = new AmazonDynamoDBErrorFault(); boolean applied = fault.apply(invocation); assertFalse(invocation.proceeded()); assertFalse(applied); invocation = new Invocation(mock(AmazonDynamoDB.class), AmazonDynamoDB.class.getMethod("getItem", GetItemRequest.class)); fault = new AmazonDynamoDBErrorFault(); fault.setStatusCode(503); applied = fault.apply(invocation); assertFalse(invocation.proceeded()); assertThat(invocation.throwable(), instanceOf(AmazonDynamoDBException.class)); AmazonDynamoDBException exception = (AmazonDynamoDBException) invocation.throwable(); assertThat(exception.getStatusCode(), is(503)); assertThat(exception.getErrorCode(), is("ServiceUnavailable")); assertThat(exception.getServiceName(), is("AmazonDynamoDBv2")); assertTrue(applied); invocation = new Invocation(mock(AmazonDynamoDB.class), AmazonDynamoDB.class.getMethod("getItem", GetItemRequest.class)); fault = new AmazonDynamoDBErrorFault(); fault.setStatusCode(400); fault.setErrorCode("AccessDeniedException"); applied = fault.apply(invocation); assertFalse(invocation.proceeded()); assertThat(invocation.throwable(), instanceOf(AmazonDynamoDBException.class)); exception = (AmazonDynamoDBException) invocation.throwable(); assertThat(exception.getStatusCode(), is(400)); assertThat(exception.getErrorCode(), is("AccessDeniedException")); assertThat(exception.getServiceName(), is("AmazonDynamoDBv2")); assertTrue(applied); }
@Override public boolean apply(final Invocation invocation) throws Throwable { if (!(invocation.target() instanceof AmazonDynamoDB)) { return false; } final Map<String, Class<? extends AmazonServiceException>> map = EXCEPTIONS.get(statusCode); String errorCode = (this.errorCode == null) ? map.keySet().iterator().next() : this.errorCode; final Class<? extends AmazonServiceException> clazz = map.get(errorCode); final Constructor<? extends AmazonServiceException> constructor = clazz.getConstructor(String.class); final AmazonServiceException exception = constructor.newInstance(MESSAGE); exception.setStatusCode(statusCode); exception.setErrorCode(errorCode); exception.setServiceName("AmazonDynamoDBv2"); invocation.throwable(exception); return true; }
AmazonDynamoDBErrorFault extends Fault implements Validator, Interceptor { @Override public boolean apply(final Invocation invocation) throws Throwable { if (!(invocation.target() instanceof AmazonDynamoDB)) { return false; } final Map<String, Class<? extends AmazonServiceException>> map = EXCEPTIONS.get(statusCode); String errorCode = (this.errorCode == null) ? map.keySet().iterator().next() : this.errorCode; final Class<? extends AmazonServiceException> clazz = map.get(errorCode); final Constructor<? extends AmazonServiceException> constructor = clazz.getConstructor(String.class); final AmazonServiceException exception = constructor.newInstance(MESSAGE); exception.setStatusCode(statusCode); exception.setErrorCode(errorCode); exception.setServiceName("AmazonDynamoDBv2"); invocation.throwable(exception); return true; } }
AmazonDynamoDBErrorFault extends Fault implements Validator, Interceptor { @Override public boolean apply(final Invocation invocation) throws Throwable { if (!(invocation.target() instanceof AmazonDynamoDB)) { return false; } final Map<String, Class<? extends AmazonServiceException>> map = EXCEPTIONS.get(statusCode); String errorCode = (this.errorCode == null) ? map.keySet().iterator().next() : this.errorCode; final Class<? extends AmazonServiceException> clazz = map.get(errorCode); final Constructor<? extends AmazonServiceException> constructor = clazz.getConstructor(String.class); final AmazonServiceException exception = constructor.newInstance(MESSAGE); exception.setStatusCode(statusCode); exception.setErrorCode(errorCode); exception.setServiceName("AmazonDynamoDBv2"); invocation.throwable(exception); return true; }  }
AmazonDynamoDBErrorFault extends Fault implements Validator, Interceptor { @Override public boolean apply(final Invocation invocation) throws Throwable { if (!(invocation.target() instanceof AmazonDynamoDB)) { return false; } final Map<String, Class<? extends AmazonServiceException>> map = EXCEPTIONS.get(statusCode); String errorCode = (this.errorCode == null) ? map.keySet().iterator().next() : this.errorCode; final Class<? extends AmazonServiceException> clazz = map.get(errorCode); final Constructor<? extends AmazonServiceException> constructor = clazz.getConstructor(String.class); final AmazonServiceException exception = constructor.newInstance(MESSAGE); exception.setStatusCode(statusCode); exception.setErrorCode(errorCode); exception.setServiceName("AmazonDynamoDBv2"); invocation.throwable(exception); return true; }  @Override Set<Violation> validate(); Integer getStatusCode(); void setStatusCode(final Integer statusCode); String getErrorCode(); void setErrorCode(final String errorCode); @Override boolean apply(final Invocation invocation); }
AmazonDynamoDBErrorFault extends Fault implements Validator, Interceptor { @Override public boolean apply(final Invocation invocation) throws Throwable { if (!(invocation.target() instanceof AmazonDynamoDB)) { return false; } final Map<String, Class<? extends AmazonServiceException>> map = EXCEPTIONS.get(statusCode); String errorCode = (this.errorCode == null) ? map.keySet().iterator().next() : this.errorCode; final Class<? extends AmazonServiceException> clazz = map.get(errorCode); final Constructor<? extends AmazonServiceException> constructor = clazz.getConstructor(String.class); final AmazonServiceException exception = constructor.newInstance(MESSAGE); exception.setStatusCode(statusCode); exception.setErrorCode(errorCode); exception.setServiceName("AmazonDynamoDBv2"); invocation.throwable(exception); return true; }  @Override Set<Violation> validate(); Integer getStatusCode(); void setStatusCode(final Integer statusCode); String getErrorCode(); void setErrorCode(final String errorCode); @Override boolean apply(final Invocation invocation);  }