mirror of https://github.com/apache/jclouds.git
fixed joyent error handler
This commit is contained in:
parent
01918a02ec
commit
8179713655
|
@ -35,7 +35,6 @@ import org.jclouds.rest.ResourceNotFoundException;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
// TODO: is there error spec someplace? let's type errors, etc.
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class JoyentCloudErrorHandler implements HttpErrorHandler {
|
public class JoyentCloudErrorHandler implements HttpErrorHandler {
|
||||||
public void handleError(HttpCommand command, HttpResponse response) {
|
public void handleError(HttpCommand command, HttpResponse response) {
|
||||||
|
@ -59,6 +58,9 @@ public class JoyentCloudErrorHandler implements HttpErrorHandler {
|
||||||
exception = new ResourceNotFoundException(message, exception);
|
exception = new ResourceNotFoundException(message, exception);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 409:
|
||||||
|
exception = new IllegalStateException(message, exception);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
command.setException(exception);
|
command.setException(exception);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.joyent.cloudapi.v6_5.handlers;
|
package org.jclouds.joyent.cloudapi.v6_5.handlers;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.createMockBuilder;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.reportMatcher;
|
import static org.easymock.EasyMock.reportMatcher;
|
||||||
|
@ -39,9 +39,20 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "unit", testName = "JoyentCloudErrorHandlerTest")
|
@Test(groups = "unit", testName = "JoyentCloudErrorHandlerTest")
|
||||||
public class JoyentCloudErrorHandlerTest {
|
public class JoyentCloudErrorHandlerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test409MakesIllegalStateException() {
|
||||||
|
assertCodeMakes(
|
||||||
|
"POST",
|
||||||
|
URI.create("https://us-east-1.api.joyentcloud.com/my/machines/b7d07c64-ba40-496a-a19a-3f1d028494ff"),
|
||||||
|
409,
|
||||||
|
"HTTP/1.1 409 Conflict",
|
||||||
|
"\"{\"code\":\"InvalidState\",\"message\":\"An incompatible transition has already been queued for this resource\"}\"",
|
||||||
|
IllegalStateException.class);
|
||||||
|
}
|
||||||
|
|
||||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
||||||
Class<? extends Exception> expected) {
|
Class<? extends Exception> expected) {
|
||||||
assertCodeMakes(method, uri, statusCode, message, "text/plain", content, expected);
|
assertCodeMakes(method, uri, statusCode, message, "application/json", content, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
||||||
|
@ -49,7 +60,7 @@ public class JoyentCloudErrorHandlerTest {
|
||||||
|
|
||||||
JoyentCloudErrorHandler function = new JoyentCloudErrorHandler();
|
JoyentCloudErrorHandler function = new JoyentCloudErrorHandler();
|
||||||
|
|
||||||
HttpCommand command = createMockBuilder(HttpCommand.class).createMock();
|
HttpCommand command = createMock(HttpCommand.class);
|
||||||
HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
|
HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
|
HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
|
||||||
response.getPayload().getContentMetadata().setContentType(contentType);
|
response.getPayload().getContentMetadata().setContentType(contentType);
|
||||||
|
|
Loading…
Reference in New Issue