mirror of https://github.com/apache/jclouds.git
Issue 428: fixed and verified UnsupportedOperationException propagates
This commit is contained in:
parent
a9a46e0f49
commit
890c34bc5b
|
@ -76,7 +76,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
|||
error = utils.parseAWSErrorFromContent(request, response);
|
||||
if (error != null) {
|
||||
message = error.getMessage();
|
||||
exception = new AWSResponseException(command, response, error);
|
||||
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.jclouds.Constants;
|
|||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.RunNodesException;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.predicates.NodePredicates;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
|
@ -90,9 +91,10 @@ public class TestCanRecreateTagLiveTest {
|
|||
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
|
||||
|
||||
try {
|
||||
context.getComputeService().runNodesWithTag(tag, 1);
|
||||
Template template = context.getComputeService().templateBuilder().locationId("us-west-1").build();
|
||||
context.getComputeService().runNodesWithTag(tag, 1, template);
|
||||
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
|
||||
context.getComputeService().runNodesWithTag(tag, 1);
|
||||
context.getComputeService().runNodesWithTag(tag, 1, template);
|
||||
} catch (RunNodesException e) {
|
||||
System.err.println(e.getNodeErrors().keySet());
|
||||
Throwables.propagate(e);
|
||||
|
|
|
@ -544,11 +544,14 @@ public class Utils {
|
|||
return (Exception) throwable;
|
||||
}
|
||||
}
|
||||
Throwables.propagateIfInstanceOf(exception, IllegalStateException.class);
|
||||
Throwables.propagateIfInstanceOf(exception, IllegalArgumentException.class);
|
||||
Throwables.propagateIfInstanceOf(exception, AuthorizationException.class);
|
||||
Throwables.propagateIfInstanceOf(exception, ResourceNotFoundException.class);
|
||||
Throwables.propagateIfInstanceOf(exception, HttpResponseException.class);
|
||||
for (Class<Exception> propagatableExceptionType : new Class[] { IllegalStateException.class,
|
||||
UnsupportedOperationException.class, IllegalArgumentException.class, AuthorizationException.class,
|
||||
ResourceNotFoundException.class, HttpResponseException.class }) {
|
||||
Throwable throwable = getFirstThrowableOfType(exception, propagatableExceptionType);
|
||||
if (throwable != null) {
|
||||
throw (Exception) throwable;
|
||||
}
|
||||
}
|
||||
Throwables.throwCause(exception, true);
|
||||
return exception;
|
||||
}
|
||||
|
|
|
@ -164,41 +164,73 @@ public class UtilsTest {
|
|||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testPropagateStandardExceptionIllegalStateException() throws Exception {
|
||||
Exception e = new IllegalStateException();
|
||||
assertEquals(
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)),
|
||||
e);
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testPropagateStandardExceptionIllegalArgumentException() throws Exception {
|
||||
Exception e = new IllegalArgumentException();
|
||||
assertEquals(
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)),
|
||||
e);
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||
public void testPropagateStandardExceptionUnsupportedOperationException() throws Exception {
|
||||
Exception e = new UnsupportedOperationException();
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testPropagateStandardExceptionAuthorizationException() throws Exception {
|
||||
Exception e = new AuthorizationException();
|
||||
assertEquals(
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)),
|
||||
e);
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testPropagateStandardExceptionResourceNotFoundException() throws Exception {
|
||||
Exception e = new ResourceNotFoundException();
|
||||
assertEquals(
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)),
|
||||
e);
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testPropagateStandardExceptionIllegalStateExceptionNestedInHttpResponseException() throws Exception {
|
||||
Exception e = new IllegalStateException();
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException(
|
||||
"goo", createNiceMock(HttpCommand.class), null, e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testPropagateStandardExceptionIllegalArgumentExceptionNestedInHttpResponseException() throws Exception {
|
||||
Exception e = new IllegalArgumentException();
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException(
|
||||
"goo", createNiceMock(HttpCommand.class), null, e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||
public void testPropagateStandardExceptionUnsupportedOperationExceptionNestedInHttpResponseException()
|
||||
throws Exception {
|
||||
Exception e = new UnsupportedOperationException();
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException(
|
||||
"goo", createNiceMock(HttpCommand.class), null, e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testPropagateStandardExceptionAuthorizationExceptionNestedInHttpResponseException() throws Exception {
|
||||
Exception e = new AuthorizationException();
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException(
|
||||
"goo", createNiceMock(HttpCommand.class), null, e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testPropagateStandardExceptionResourceNotFoundExceptionNestedInHttpResponseException() throws Exception {
|
||||
Exception e = new ResourceNotFoundException();
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException(
|
||||
"goo", createNiceMock(HttpCommand.class), null, e));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = HttpResponseException.class)
|
||||
public void testPropagateStandardExceptionHttpResponseException() throws Exception {
|
||||
Exception e = new HttpResponseException("goo", createNiceMock(HttpCommand.class), null);
|
||||
assertEquals(
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)),
|
||||
e);
|
||||
Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue