private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, Class<? extends Exception> expected) { assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected); }
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, String content, Class<? extends Exception> expected) { CloudStackErrorHandler function = Guice.createInjector().getInstance(CloudStackErrorHandler.class); HttpCommand command = createMock(HttpCommand.class); HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build(); HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build(); response.getPayload().getContentMetadata().setContentType(contentType); expect(command.getCurrentRequest()).andReturn(request).atLeastOnce(); command.setException(classEq(expected)); replay(command); function.handleError(command, response); verify(command); }
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, String content, Class<? extends Exception> expected) { CloudStackErrorHandler function = Guice.createInjector().getInstance(CloudStackErrorHandler.class); HttpCommand command = createMock(HttpCommand.class); HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build(); HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build(); response.getPayload().getContentMetadata().setContentType(contentType); expect(command.getCurrentRequest()).andReturn(request).atLeastOnce(); command.setException(classEq(expected)); replay(command); function.handleError(command, response); verify(command); }
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, Class<? extends Exception> expected) { assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected); }
@Test public void test400MakesIllegalArgumentException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 400, "", "Bad Request", IllegalArgumentException.class); }
@Test public void test401MakesAuthorizationException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 401, "", "Unauthorized", AuthorizationException.class); }
@Test public void test404MakesResourceNotFoundException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 404, "", "Not Found", ResourceNotFoundException.class); }
@Test public void test431MakesResourceNotFoundExceptionOnDelete() { assertCodeMakes( "GET", URI.create("https://api.ninefold.com/compute/v1.0/?response=json&command=deleteSSHKeyPair"), 431, "", "{ \"deletekeypairresponse\" : {\"errorcode\" : 431, \"errortext\" : \"A key pair with name 'adriancole-adapter-test-keypair' does not exist for account jclouds in domain id=457\"} }", ResourceNotFoundException.class); }
@Test void test534WithMaximumResourcesMakesInsufficientResourcesException() { assertCodeMakes( "GET", URI.create("http://10.26.26.155:8080/client/api?response=json&command=deployVirtualMachine&zoneid=7dbc4787-ec2f-498d-95f0-848c8c81e5da&templateid=240937c8-d695-419c-9908-5c7b2a07e6f1&serviceofferingid=c376102e-b683-4d43-b583-4eeab4627e65&displayname=bousa-4&name=bousa-4"), 534, "", "{ \"createipforwardingruleresponse\" : {\"errorcode\" : 534, \"errortext\" : \"Maximum number of resources of type 'volume' for account name=jarcec in domain id=1 has been exceeded.\"} }", InsufficientResourcesException.class); }
@Test void test537MakesIllegalStateException() { assertCodeMakes( "GET", URI.create("http://10.26.26.155:8080/client/api?response=json&command=createIpForwardingRule&ipaddressid=37&startport=22&protocol=tcp"), 537, "", "{ \"createipforwardingruleresponse\" : {\"errorcode\" : 537, \"errortext\" : \"There is already firewall rule specified for the ip address id=37\"} }", IllegalStateException.class); }
@Test public void test405MakesIllegalArgumentException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 405, "", "Method Not Allowed", IllegalArgumentException.class); }
@Test public void test431MakesIllegalStateException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 431, "", "Method Not Allowed", IllegalStateException.class); }
@Test public void test531MakesAuthorizationException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 531, "", "Unauthorized", AuthorizationException.class); }
@Test public void test400MakesIllegalArgumentException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 400, "", "Bad Request", IllegalArgumentException.class); }
@Test public void test401MakesAuthorizationException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 401, "", "Unauthorized", AuthorizationException.class); }
@Test void test537MakesIllegalStateException() { assertCodeMakes( "GET", URI.create("http://10.26.26.155:8080/client/api?response=json&command=createIpForwardingRule&ipaddressid=37&startport=22&protocol=tcp"), 537, "", "{ \"createipforwardingruleresponse\" : {\"errorcode\" : 537, \"errortext\" : \"There is already firewall rule specified for the ip address id=37\"} }", IllegalStateException.class); }
@Test public void test409MakesIllegalStateException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 409, "", "Conflict", IllegalStateException.class); }
@Test public void test431MakesIllegalStateException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 431, "", "Method Not Allowed", IllegalStateException.class); }
@Test public void test404MakesResourceNotFoundException() { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 404, "", "Not Found", ResourceNotFoundException.class); }
@Test void test534WithMaximumResourcesMakesInsufficientResourcesException() { assertCodeMakes( "GET", URI.create("http://10.26.26.155:8080/client/api?response=json&command=deployVirtualMachine&zoneid=7dbc4787-ec2f-498d-95f0-848c8c81e5da&templateid=240937c8-d695-419c-9908-5c7b2a07e6f1&serviceofferingid=c376102e-b683-4d43-b583-4eeab4627e65&displayname=bousa-4&name=bousa-4"), 534, "", "{ \"createipforwardingruleresponse\" : {\"errorcode\" : 534, \"errortext\" : \"Maximum number of resources of type 'volume' for account name=jarcec in domain id=1 has been exceeded.\"} }", InsufficientResourcesException.class); }