diff --git a/apis/sts/src/test/java/org/jclouds/aws/filters/FormSignerTest.java b/apis/sts/src/test/java/org/jclouds/aws/filters/FormSignerTest.java index fe980fc4fa..bf724fa855 100644 --- a/apis/sts/src/test/java/org/jclouds/aws/filters/FormSignerTest.java +++ b/apis/sts/src/test/java/org/jclouds/aws/filters/FormSignerTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.filters; +import static javax.ws.rs.HttpMethod.GET; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; import static org.testng.Assert.assertEquals; @@ -43,7 +44,6 @@ import com.google.inject.AbstractModule; import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.name.Names; - /** * Tests behavior of {@code FormSigner} * @@ -76,7 +76,7 @@ public class FormSignerTest { public static FormSigner staticCredentialsFilter = filter(new Credentials("identity", "credential")); - HttpRequest request = HttpRequest.builder().method("GET") + HttpRequest request = HttpRequest.builder().method(GET) .endpoint("http://localhost") .addHeader(HttpHeaders.HOST, "localhost") .addFormParam("Action", "DescribeImages") diff --git a/apis/sts/src/test/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandlerTest.java b/apis/sts/src/test/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandlerTest.java index 2d2ab66673..a9b28d47e7 100644 --- a/apis/sts/src/test/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandlerTest.java +++ b/apis/sts/src/test/java/org/jclouds/aws/handlers/AWSClientErrorRetryHandlerTest.java @@ -17,7 +17,9 @@ * under the License. */ package org.jclouds.aws.handlers; - +import static javax.ws.rs.HttpMethod.PUT; +import static javax.ws.rs.core.Response.Status.CONFLICT; +import static javax.ws.rs.core.Response.Status.UNAUTHORIZED; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; @@ -54,7 +56,7 @@ public class AWSClientErrorRetryHandlerTest { AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler, ImmutableSet. of()); - assert !retry.shouldRetryRequest(command, HttpResponse.builder().statusCode(401).build()); + assert !retry.shouldRetryRequest(command, HttpResponse.builder().statusCode(UNAUTHORIZED.getStatusCode()).build()); verify(utils, backoffLimitedRetryHandler, command); @@ -72,10 +74,10 @@ public class AWSClientErrorRetryHandlerTest { BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class); HttpCommand command = createMock(HttpCommand.class); - HttpRequest putBucket = HttpRequest.builder().method("PUT") + HttpRequest putBucket = HttpRequest.builder().method(PUT) .endpoint("https://adriancole-blobstore113.s3.amazonaws.com/").build(); - HttpResponse operationAborted = HttpResponse.builder().statusCode(409) + HttpResponse operationAborted = HttpResponse.builder().statusCode(CONFLICT.getStatusCode()) .payload(Payloads.newStringPayload(String.format("%s", code))).build(); expect(command.getCurrentRequest()).andReturn(putBucket); diff --git a/apis/sts/src/test/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContentTest.java b/apis/sts/src/test/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContentTest.java index 8c4dd4705e..ae7b8de0f6 100644 --- a/apis/sts/src/test/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContentTest.java +++ b/apis/sts/src/test/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContentTest.java @@ -17,7 +17,12 @@ * under the License. */ package org.jclouds.aws.handlers; - +import static javax.ws.rs.HttpMethod.GET; +import static javax.ws.rs.HttpMethod.POST; +import static javax.ws.rs.HttpMethod.PUT; +import static javax.ws.rs.core.MediaType.TEXT_PLAIN; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.CONFLICT; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; @@ -51,46 +56,46 @@ public class ParseAWSErrorFromXmlContentTest { @Test public void test400WithNotFoundSetsResourceNotFoundException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", "Monster.NotFound", ResourceNotFoundException.class); } @Test public void test400WithCloudBridgeNotFoundSetsResourceNotFoundException() { - assertCodeMakes("POST", URI.create("https://api.greenqloud.com/"), 400, "", + assertCodeMakes(POST, URI.create("https://api.greenqloud.com/"), BAD_REQUEST.getStatusCode(), "", "Client.InvalidInstanceID.NotFound", ResourceNotFoundException.class); } @Test public void test400WithInvalidIdIllegalArgumentException() { - assertCodeMakes("POST", URI.create("https://ec2.us-east-1.amazonaws.com"), 400, "HTTP/1.1 400", "", + assertCodeMakes(POST, URI.create("https://ec2.us-east-1.amazonaws.com"), BAD_REQUEST.getStatusCode(), "HTTP/1.1 400", "", "Invalid id: \"asdaasdsa\" (expecting \"ami-...\")", IllegalArgumentException.class); } @Test public void test400WithLoadBalancerNotFoundSetsResourceNotFoundException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", "LoadBalancerNotFound", ResourceNotFoundException.class); } @Test public void test400WithSecurityGroupNotFoundForProjectSetsResourceNotFoundException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", "SecurityGroupNotFoundForProject", ResourceNotFoundException.class); } @Test public void test400WithUnsupportedCodeMakesUnsupportedOperationException() { - assertCodeMakes("POST", URI.create("https://ec2.us-west-1.amazonaws.com/"), 400, "", + assertCodeMakes(POST, URI.create("https://ec2.us-west-1.amazonaws.com/"), BAD_REQUEST.getStatusCode(), "", "UnsupportedOperation", UnsupportedOperationException.class); } @Test public void test400WithAddressLimitExceededCodeMakesInsufficientResourcesException() { assertCodeMakes( - "POST", + POST, URI.create("https://ec2.us-east-1.amazonaws.com/"), - 400, + BAD_REQUEST.getStatusCode(), "", "AddressLimitExceededToo many addresses allocatedc14f531a-cc35-4b48-8149-2655c7e6dc76", InsufficientResourcesException.class); @@ -98,25 +103,25 @@ public class ParseAWSErrorFromXmlContentTest { @Test public void test400WithInUseCodeSetsIllegalStateException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", "InvalidPlacementGroup.InUse", IllegalStateException.class); } @Test public void test400WithUnknownSetsResourceNotFoundException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", "InvalidPlacementGroup.Unknown", ResourceNotFoundException.class); } @Test public void test400WithIncorrectStateSetsIllegalStateException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", "IncorrectState", IllegalStateException.class); } @Test public void test400WithInUseSetsIllegalStateException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", "text/plain", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", TEXT_PLAIN, "The placement group 'jclouds#adriancoleec2cccluster#us-east-1' is in use and may not be deleted.", IllegalStateException.class); } @@ -124,9 +129,9 @@ public class ParseAWSErrorFromXmlContentTest { @Test public void test409SetsIllegalStateException() { assertCodeMakes( - "PUT", + PUT, URI.create("https://adriancole-blobstore011.s3.amazonaws.com/"), - 409, + CONFLICT.getStatusCode(), "", "OperationAbortedA conflicting conditional operation is currently in progress against this resource. Please try again.F716E81C3D814E59SDprHxWzG/YXzanVnV7VTz/wP+6fRt1dS+q00kH1rz248YOOSddkFiTXF04XtqNO", IllegalStateException.class); @@ -134,19 +139,19 @@ public class ParseAWSErrorFromXmlContentTest { @Test public void test400WithInvalidGroupDuplicateIllegalStateException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "application/unknown", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), BAD_REQUEST.getReasonPhrase(), "application/unknown", "InvalidGroup.Duplicate", IllegalStateException.class); } @Test public void test400WithInvalidKeyPairGroupDuplicateIllegalStateException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "application/unknown", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), BAD_REQUEST.getReasonPhrase(), "application/unknown", "InvalidKeyPair.Duplicate", IllegalStateException.class); } @Test public void test400WithTextPlainIllegalArgumentException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "text/plain", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), BAD_REQUEST.getReasonPhrase(), TEXT_PLAIN, "Failure: 400 Bad Request\nFailed to bind the following fields\nMonitoring.Enabled = true\n\n\n", IllegalArgumentException.class); } @@ -154,9 +159,9 @@ public class ParseAWSErrorFromXmlContentTest { @Test public void test400WithGroupAlreadyExistsEucalyptusIllegalStateException() { assertCodeMakes( - "GET", + GET, URI.create("https://amazonaws.com/foo"), - 400, + BAD_REQUEST.getStatusCode(), "", "Groups\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists\nError adding network group: group named jclouds#eucrun#Eucalyptus already existse0133975-3bc5-456d-9753-1d61b27e07e9", IllegalStateException.class); @@ -164,13 +169,13 @@ public class ParseAWSErrorFromXmlContentTest { @Test public void test400WithAuthFailureSetsAuthorizationException() { - assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", + assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "", "AuthFailure", AuthorizationException.class); } @Test public void test400WithCloudBridgeAuthFailureSetsAuthorizationException() { - assertCodeMakes("POST", URI.create("https://api.greenqloud.com/"), 400, "", + assertCodeMakes(POST, URI.create("https://api.greenqloud.com/"), BAD_REQUEST.getStatusCode(), "", "Client.AuthFailure", AuthorizationException.class); } diff --git a/apis/sts/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java b/apis/sts/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java index 70c5c16f5d..a68587889f 100644 --- a/apis/sts/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java +++ b/apis/sts/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java @@ -17,7 +17,8 @@ * under the License. */ package org.jclouds.aws.util; - +import static javax.ws.rs.core.MediaType.TEXT_PLAIN; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; @@ -63,7 +64,7 @@ public class AWSUtilsTest { } HttpResponse response(InputStream content) { - HttpResponse response = HttpResponse.builder().statusCode(400) + HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()) .message("boa") .payload(content) .addHeader("x-amz-request-id", "requestid") @@ -77,7 +78,7 @@ public class AWSUtilsTest { */ @Test public void testNoExceptionWhenNoPayload() { - HttpResponse response = HttpResponse.builder().statusCode(400).build(); + HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()).build(); assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response)); } @@ -86,8 +87,8 @@ public class AWSUtilsTest { */ @Test public void testNoExceptionParsingTextPlain() { - HttpResponse response = HttpResponse.builder().statusCode(400).payload("foo bar").build(); - response.getPayload().getContentMetadata().setContentType("text/plain"); + HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()).payload("foo bar").build(); + response.getPayload().getContentMetadata().setContentType(TEXT_PLAIN); assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response)); } diff --git a/apis/sts/src/test/java/org/jclouds/sts/STSApiExpectTest.java b/apis/sts/src/test/java/org/jclouds/sts/STSApiExpectTest.java index 8d0f14e80e..cdda8c72ac 100644 --- a/apis/sts/src/test/java/org/jclouds/sts/STSApiExpectTest.java +++ b/apis/sts/src/test/java/org/jclouds/sts/STSApiExpectTest.java @@ -17,7 +17,9 @@ * under the License. */ package org.jclouds.sts; - +import static com.google.common.net.HttpHeaders.HOST; +import static javax.ws.rs.HttpMethod.POST; +import static javax.ws.rs.core.Response.Status.OK; import static org.jclouds.sts.options.AssumeRoleOptions.Builder.externalId; import static org.jclouds.sts.options.FederatedUserOptions.Builder.policy; import static org.jclouds.sts.options.SessionCredentialsOptions.Builder.serialNumber; @@ -39,9 +41,9 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "STSApiExpectTest") public class STSApiExpectTest extends BaseSTSApiExpectTest { - HttpRequest createTemporaryCredentials = HttpRequest.builder().method("POST") + HttpRequest createTemporaryCredentials = HttpRequest.builder().method(POST) .endpoint("https://sts.amazonaws.com/") - .addHeader("Host", "sts.amazonaws.com") + .addHeader(HOST, "sts.amazonaws.com") .addFormParam("Action", "GetSessionToken") .addFormParam("Signature", "ntC%2BPKAcmYTJ5Py5tjICG4KX5y00Pl2L0XJrLbSgLEs%3D") .addFormParam("SignatureMethod", "HmacSHA256") @@ -50,7 +52,7 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest { .addFormParam("Version", "2011-06-15") .addFormParam("AWSAccessKeyId", "identity").build(); - HttpResponse createTemporaryCredentialsResponse = HttpResponse.builder().statusCode(200) + HttpResponse createTemporaryCredentialsResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/session_token.xml", "text/xml")).build(); public void testCreateTemporaryCredentialsWhenResponseIs2xx() { @@ -62,9 +64,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest { new GetSessionTokenResponseTest().expected().toString()); } - HttpRequest createTemporaryCredentialsWithOptions = HttpRequest.builder().method("POST") + HttpRequest createTemporaryCredentialsWithOptions = HttpRequest.builder().method(POST) .endpoint("https://sts.amazonaws.com/") - .addHeader("Host", "sts.amazonaws.com") + .addHeader(HOST, "sts.amazonaws.com") .addFormParam("Action", "GetSessionToken") .addFormParam("DurationSeconds", "900") .addFormParam("SerialNumber", "YourMFADeviceSerialNumber") @@ -86,9 +88,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest { new GetSessionTokenResponseTest().expected().toString()); } - HttpRequest assumeRole = HttpRequest.builder().method("POST") + HttpRequest assumeRole = HttpRequest.builder().method(POST) .endpoint("https://sts.amazonaws.com/") - .addHeader("Host", "sts.amazonaws.com") + .addHeader(HOST, "sts.amazonaws.com") .addFormParam("Action", "AssumeRole") .addFormParam("RoleArn", "arn:aws:iam::123456789012:role/demo") .addFormParam("RoleSessionName", "Bob") @@ -99,7 +101,7 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest { .addFormParam("Version", "2011-06-15") .addFormParam("AWSAccessKeyId", "identity").build(); - HttpResponse assumeRoleResponse = HttpResponse.builder().statusCode(200) + HttpResponse assumeRoleResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/assume_role.xml", "text/xml")).build(); public void testAssumeRoleWhenResponseIs2xx() { @@ -112,9 +114,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest { String policy = "{\"Statement\":[{\"Sid\":\"Stmt1\",\"Effect\":\"Allow\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}"; - HttpRequest assumeRoleWithOptions = HttpRequest.builder().method("POST") + HttpRequest assumeRoleWithOptions = HttpRequest.builder().method(POST) .endpoint("https://sts.amazonaws.com/") - .addHeader("Host", "sts.amazonaws.com") + .addHeader(HOST, "sts.amazonaws.com") .addFormParam("Action", "AssumeRole") .addFormParam("DurationSeconds", "900") .addFormParam("ExternalId", "123ABC") @@ -138,9 +140,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest { new AssumeRoleResponseTest().expected().toString()); } - HttpRequest createFederatedUser = HttpRequest.builder().method("POST") + HttpRequest createFederatedUser = HttpRequest.builder().method(POST) .endpoint("https://sts.amazonaws.com/") - .addHeader("Host", "sts.amazonaws.com") + .addHeader(HOST, "sts.amazonaws.com") .addFormParam("Action", "GetFederationToken") .addFormParam("Name", "Bob") .addFormParam("Signature", "Z7AtGK4X9IAx/zMtLD7baNiyltNl%2BF%2BSHqjIGUidzOc%3D") @@ -150,7 +152,7 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest { .addFormParam("Version", "2011-06-15") .addFormParam("AWSAccessKeyId", "identity").build(); - HttpResponse createFederatedUserResponse = HttpResponse.builder().statusCode(200) + HttpResponse createFederatedUserResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/federation_token.xml", "text/xml")).build(); public void testCreateFederatedUserWhenResponseIs2xx() { @@ -161,9 +163,9 @@ public class STSApiExpectTest extends BaseSTSApiExpectTest { .expected().toString()); } - HttpRequest createFederatedUserWithOptions = HttpRequest.builder().method("POST") + HttpRequest createFederatedUserWithOptions = HttpRequest.builder().method(POST) .endpoint("https://sts.amazonaws.com/") - .addHeader("Host", "sts.amazonaws.com") + .addHeader(HOST, "sts.amazonaws.com") .addFormParam("Action", "GetFederationToken") .addFormParam("DurationSeconds", "900") .addFormParam("Name", "Bob")