From e50f16c576c2cd692326da2302525635d9415ec3 Mon Sep 17 00:00:00 2001 From: adriancole Date: Tue, 9 Apr 2013 20:37:07 -0700 Subject: [PATCH] use more constants in dynect tests --- .../GetJobRedirectionRetryHandler.java | 4 +- .../jclouds/dynect/v3/DynectApiMockTest.java | 14 ++-- .../v3/features/RecordApiExpectTest.java | 65 ++++++++++--------- .../v3/features/SessionApiExpectTest.java | 13 ++-- .../dynect/v3/features/ZoneApiExpectTest.java | 33 +++++----- .../dynect/v3/filters/SessionManagerTest.java | 18 +++-- ...tJobRedirectionRetryHandlerExpectTest.java | 10 +-- .../v3/internal/BaseDynECTExpectTest.java | 13 ++-- 8 files changed, 92 insertions(+), 78 deletions(-) diff --git a/providers/dynect/src/main/java/org/jclouds/dynect/v3/handlers/GetJobRedirectionRetryHandler.java b/providers/dynect/src/main/java/org/jclouds/dynect/v3/handlers/GetJobRedirectionRetryHandler.java index 905297ba56..f8d08963fc 100644 --- a/providers/dynect/src/main/java/org/jclouds/dynect/v3/handlers/GetJobRedirectionRetryHandler.java +++ b/providers/dynect/src/main/java/org/jclouds/dynect/v3/handlers/GetJobRedirectionRetryHandler.java @@ -17,8 +17,8 @@ * under the License. */ package org.jclouds.dynect.v3.handlers; - import static com.google.common.net.HttpHeaders.LOCATION; +import static javax.ws.rs.HttpMethod.GET; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import javax.inject.Inject; @@ -55,7 +55,7 @@ public class GetJobRedirectionRetryHandler extends RedirectionRetryHandler { String location = response.getFirstHeaderOrNull(LOCATION); if (location != null && location.indexOf("Job") != -1) { HttpRequest getRequest = command.getCurrentRequest().toBuilder() - .method("GET") + .method(GET) .payload((Payload) null).build(); command.setCurrentRequest(getRequest); } diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java index d6066cec3a..aee77e51a3 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java @@ -19,6 +19,7 @@ package org.jclouds.dynect.v3; import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; +import static javax.ws.rs.core.Response.Status.OK; import static org.jclouds.Constants.PROPERTY_MAX_RETRIES; import java.io.IOException; @@ -35,7 +36,6 @@ import com.google.common.collect.ImmutableSet; import com.google.inject.Module; import com.google.mockwebserver.MockResponse; import com.google.mockwebserver.MockWebServer; - /** * * @author Adrian Cole @@ -64,8 +64,8 @@ public class DynectApiMockTest { @Test(expectedExceptions = JobStillRunningException.class, expectedExceptionsMessageRegExp = "This session already has a job running") public void test200OnFailureThrowsExceptionWithoutRetryWhenJobRunning() throws IOException, InterruptedException { MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setResponseCode(200).setBody(session)); - server.enqueue(new MockResponse().setResponseCode(200).setBody(running)); + server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(session)); + server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(running)); server.play(); DynECTApi api = mockDynectApi(server.getUrl("/").toString()); @@ -83,8 +83,8 @@ public class DynectApiMockTest { public void test200OnFailureThrowsExceptionWithoutRetryWhenOperationBlocked() throws IOException, InterruptedException { MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setResponseCode(200).setBody(session)); - server.enqueue(new MockResponse().setResponseCode(200).setBody(taskBlocking)); + server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(session)); + server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(taskBlocking)); server.play(); DynECTApi api = mockDynectApi(server.getUrl("/").toString()); @@ -101,8 +101,8 @@ public class DynectApiMockTest { @Test(expectedExceptions = TargetExistsException.class, expectedExceptionsMessageRegExp = "Name already exists") public void test200OnFailureThrowsExceptionWithoutRetryOnNameExists() throws IOException, InterruptedException { MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setResponseCode(200).setBody(session)); - server.enqueue(new MockResponse().setResponseCode(200).setBody(targetExists)); + server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(session)); + server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(targetExists)); server.play(); DynECTApi api = mockDynectApi(server.getUrl("/").toString()); diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiExpectTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiExpectTest.java index 4a216a81ed..9850570156 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiExpectTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiExpectTest.java @@ -17,10 +17,13 @@ * under the License. */ package org.jclouds.dynect.v3.features; - import static com.google.common.net.HttpHeaders.ACCEPT; import static com.google.common.net.HttpHeaders.CONTENT_TYPE; +import static javax.ws.rs.HttpMethod.DELETE; +import static javax.ws.rs.HttpMethod.GET; +import static javax.ws.rs.HttpMethod.POST; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static javax.ws.rs.core.Response.Status.OK; import static org.jclouds.dynect.v3.domain.RecordId.recordIdBuilder; import static org.jclouds.dynect.v3.domain.rdata.AData.a; import static org.testng.Assert.assertEquals; @@ -55,13 +58,13 @@ import org.testng.annotations.Test; */ @Test(groups = "unit", testName = "RecordApiExpectTest") public class RecordApiExpectTest extends BaseDynECTApiExpectTest { - HttpRequest getSOA = HttpRequest.builder().method("GET") + HttpRequest getSOA = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/SOARecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse soaResponse = HttpResponse.builder().statusCode(200) + HttpResponse soaResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_soa.json", APPLICATION_JSON)).build(); RecordId soaId = recordIdBuilder() @@ -81,13 +84,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getRecordApiForZone("jclouds.org").get(soaId)); } - HttpRequest getAAAA = HttpRequest.builder().method("GET") + HttpRequest getAAAA = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/AAAARecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse aaaaResponse = HttpResponse.builder().statusCode(200) + HttpResponse aaaaResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_aaaa.json", APPLICATION_JSON)).build(); RecordId aaaaId = recordIdBuilder() @@ -107,13 +110,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getRecordApiForZone("jclouds.org").getAAAA(aaaaId.getFQDN(), aaaaId.getId())); } - HttpRequest getA = HttpRequest.builder().method("GET") + HttpRequest getA = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/ARecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse aResponse = HttpResponse.builder().statusCode(200) + HttpResponse aResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_a.json", APPLICATION_JSON)).build(); RecordId aId = recordIdBuilder() @@ -133,13 +136,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getRecordApiForZone("jclouds.org").getA(aId.getFQDN(), aId.getId())); } - HttpRequest getCNAME = HttpRequest.builder().method("GET") + HttpRequest getCNAME = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/CNAMERecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse cnameResponse = HttpResponse.builder().statusCode(200) + HttpResponse cnameResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_cname.json", APPLICATION_JSON)).build(); RecordId cnameId = recordIdBuilder() @@ -159,13 +162,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getRecordApiForZone("jclouds.org").getCNAME(cnameId.getFQDN(), cnameId.getId())); } - HttpRequest getMX = HttpRequest.builder().method("GET") + HttpRequest getMX = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/MXRecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse mxResponse = HttpResponse.builder().statusCode(200) + HttpResponse mxResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_mx.json", APPLICATION_JSON)).build(); RecordId mxId = recordIdBuilder() @@ -185,13 +188,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getRecordApiForZone("jclouds.org").getMX(mxId.getFQDN(), mxId.getId())); } - HttpRequest getNS = HttpRequest.builder().method("GET") + HttpRequest getNS = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/NSRecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse nsResponse = HttpResponse.builder().statusCode(200) + HttpResponse nsResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_ns.json", APPLICATION_JSON)).build(); RecordId nsId = recordIdBuilder() @@ -211,13 +214,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getRecordApiForZone("jclouds.org").getNS(nsId.getFQDN(), nsId.getId())); } - HttpRequest getPTR = HttpRequest.builder().method("GET") + HttpRequest getPTR = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/PTRRecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse ptrResponse = HttpResponse.builder().statusCode(200) + HttpResponse ptrResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_ptr.json", APPLICATION_JSON)).build(); RecordId ptrId = recordIdBuilder() @@ -248,13 +251,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getRecordApiForZone("jclouds.org").getSOA(soaId.getFQDN(), soaId.getId())); } - HttpRequest getSPF = HttpRequest.builder().method("GET") + HttpRequest getSPF = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/SPFRecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse spfResponse = HttpResponse.builder().statusCode(200) + HttpResponse spfResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_spf.json", APPLICATION_JSON)).build(); RecordId spfId = recordIdBuilder() @@ -269,13 +272,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { new GetSPFRecordResponseTest().expected().toString()); } - HttpRequest getSRV = HttpRequest.builder().method("GET") + HttpRequest getSRV = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/SRVRecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse srvResponse = HttpResponse.builder().statusCode(200) + HttpResponse srvResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_srv.json", APPLICATION_JSON)).build(); RecordId srvId = recordIdBuilder() @@ -290,13 +293,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { new GetSRVRecordResponseTest().expected().toString()); } - HttpRequest getSSHFP = HttpRequest.builder().method("GET") + HttpRequest getSSHFP = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/SSHFPRecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse sshfpResponse = HttpResponse.builder().statusCode(200) + HttpResponse sshfpResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_sshfp.json", APPLICATION_JSON)).build(); RecordId sshfpId = recordIdBuilder() @@ -311,13 +314,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { new GetSSHFPRecordResponseTest().expected().toString()); } - HttpRequest getTXT = HttpRequest.builder().method("GET") + HttpRequest getTXT = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/TXTRecord/jclouds.org/jclouds.org/50976579") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse txtResponse = HttpResponse.builder().statusCode(200) + HttpResponse txtResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_record_txt.json", APPLICATION_JSON)).build(); RecordId txtId = recordIdBuilder() @@ -337,13 +340,13 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getRecordApiForZone("jclouds.org").getTXT(txtId.getFQDN(), txtId.getId())); } - HttpRequest list = HttpRequest.builder().method("GET") + HttpRequest list = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/AllRecord/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse listResponse = HttpResponse.builder().statusCode(200) + HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/list_records.json", APPLICATION_JSON)).build(); public void testListWhenResponseIs2xx() { @@ -352,7 +355,7 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { new ListRecordsResponseTest().expected().toString()); } - HttpRequest listByFQDN = HttpRequest.builder().method("GET") + HttpRequest listByFQDN = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/AllRecord/jclouds.org/www.foo.com") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) @@ -369,7 +372,7 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertTrue(fail.getRecordApiForZone("jclouds.org").listByFQDN("www.foo.com").isEmpty()); } - HttpRequest listByFQDNAndType = HttpRequest.builder().method("GET") + HttpRequest listByFQDNAndType = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/ARecord/jclouds.org/www.foo.com") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) @@ -386,7 +389,7 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertTrue(fail.getRecordApiForZone("jclouds.org").listByFQDNAndType("www.foo.com", "A").isEmpty()); } - HttpRequest create = HttpRequest.builder().method("POST") + HttpRequest create = HttpRequest.builder().method(POST) .endpoint("https://api2.dynect.net/REST/ARecord/jclouds.org/www.jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) @@ -394,7 +397,7 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { .payload(stringPayload("{\"rdata\":{\"address\":\"1.1.1.1\"},\"ttl\":86400}")) .build(); - HttpResponse createResponse = HttpResponse.builder().statusCode(200) + HttpResponse createResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/new_record.json", APPLICATION_JSON)).build(); public void testCreateWhenResponseIs2xx() { @@ -408,14 +411,14 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest { assertEquals(success.getRecordApiForZone("jclouds.org").scheduleCreate(record), Job.success(285372440l)); } - HttpRequest delete = HttpRequest.builder().method("DELETE") + HttpRequest delete = HttpRequest.builder().method(DELETE) .endpoint("https://api2.dynect.net/REST/ARecord/jclouds.org/www.jclouds.org/285372440") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) + HttpResponse deleteResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/delete_record.json", APPLICATION_JSON)).build(); RecordId id = recordIdBuilder() diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/SessionApiExpectTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/SessionApiExpectTest.java index f648d61cc1..7d5ac11526 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/SessionApiExpectTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/SessionApiExpectTest.java @@ -17,9 +17,11 @@ * under the License. */ package org.jclouds.dynect.v3.features; - import static com.google.common.net.HttpHeaders.CONTENT_TYPE; +import static javax.ws.rs.HttpMethod.DELETE; +import static javax.ws.rs.HttpMethod.GET; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static javax.ws.rs.core.Response.Status.OK; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; @@ -31,7 +33,6 @@ import org.jclouds.dynect.v3.parse.CreateSessionResponseTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; - /** * @author Adrian Cole */ @@ -47,13 +48,13 @@ public class SessionApiExpectTest extends BaseDynECTApiExpectTest { new CreateSessionResponseTest().expected().toString()); } - HttpRequest isValid = HttpRequest.builder().method("GET") + HttpRequest isValid = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/Session") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse validResponse = HttpResponse.builder().statusCode(200) + HttpResponse validResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/session_valid.json", APPLICATION_JSON)).build(); HttpResponse invalidResponse = HttpResponse.builder().statusCode(400) @@ -69,13 +70,13 @@ public class SessionApiExpectTest extends BaseDynECTApiExpectTest { assertFalse(apiWhenInvalid.getSessionApi().isValid(authToken)); } - HttpRequest logout = HttpRequest.builder().method("DELETE") + HttpRequest logout = HttpRequest.builder().method(DELETE) .endpoint("https://api2.dynect.net/REST/Session") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse logoutResponse = HttpResponse.builder().statusCode(200) + HttpResponse logoutResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/logout.json", APPLICATION_JSON)).build(); public void testLogout() { diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiExpectTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiExpectTest.java index e6cf359975..30e19e35fb 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiExpectTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/features/ZoneApiExpectTest.java @@ -17,10 +17,14 @@ * under the License. */ package org.jclouds.dynect.v3.features; - import static com.google.common.net.HttpHeaders.ACCEPT; import static com.google.common.net.HttpHeaders.CONTENT_TYPE; +import static javax.ws.rs.HttpMethod.DELETE; +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.APPLICATION_JSON; +import static javax.ws.rs.core.Response.Status.OK; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; @@ -35,19 +39,18 @@ import org.jclouds.dynect.v3.parse.ListZonesResponseTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; - /** * @author Adrian Cole */ @Test(groups = "unit", testName = "ZoneApiExpectTest") public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { - HttpRequest get = HttpRequest.builder().method("GET") + HttpRequest get = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse getResponse = HttpResponse.builder().statusCode(200) + HttpResponse getResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/get_zone.json", APPLICATION_JSON)).build(); public void testGetWhenResponseIs2xx() { @@ -56,7 +59,7 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { new GetZoneResponseTest().expected().toString()); } - HttpRequest create = HttpRequest.builder().method("POST") + HttpRequest create = HttpRequest.builder().method(POST) .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) @@ -64,7 +67,7 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { .payload(stringPayload("{\"rname\":\"jimmy@jclouds.org\",\"serial_style\":\"increment\",\"ttl\":3600}")) .build(); - HttpResponse createResponse = HttpResponse.builder().statusCode(200) + HttpResponse createResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/new_zone.json", APPLICATION_JSON)).build(); public void testCreateWhenResponseIs2xx() { @@ -85,13 +88,13 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getZoneApi().get("jclouds.org")); } - HttpRequest list = HttpRequest.builder().method("GET") + HttpRequest list = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/Zone") .addHeader("API-Version", "3.3.8") .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse listResponse = HttpResponse.builder().statusCode(200) + HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/list_zones.json", APPLICATION_JSON)).build(); public void testListWhenResponseIs2xx() { @@ -100,14 +103,14 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { new ListZonesResponseTest().expected().toString()); } - HttpRequest deleteChanges = HttpRequest.builder().method("DELETE") + HttpRequest deleteChanges = HttpRequest.builder().method(DELETE) .endpoint("https://api2.dynect.net/REST/ZoneChanges/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse deleteChangesResponse = HttpResponse.builder().statusCode(200) + HttpResponse deleteChangesResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/delete_zone_changes.json", APPLICATION_JSON)).build(); public void testDeleteChangesWhenResponseIs2xx() { @@ -116,14 +119,14 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { new DeleteZoneChangesResponseTest().expected().toString()); } - HttpRequest delete = HttpRequest.builder().method("DELETE") + HttpRequest delete = HttpRequest.builder().method(DELETE) .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader("Auth-Token", authToken).build(); - HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) + HttpResponse deleteResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/delete_zone.json", APPLICATION_JSON)).build(); public void testDeleteWhenResponseIs2xx() { @@ -137,7 +140,7 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { assertNull(fail.getZoneApi().delete("jclouds.org")); } - HttpRequest publish = HttpRequest.builder().method("PUT") + HttpRequest publish = HttpRequest.builder().method(PUT) .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader("Auth-Token", authToken) @@ -150,7 +153,7 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { new GetZoneResponseTest().expected().toString()); } - HttpRequest freeze = HttpRequest.builder().method("PUT") + HttpRequest freeze = HttpRequest.builder().method(PUT) .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) @@ -164,7 +167,7 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest { new DeleteZoneResponseTest().expected().toString()); } - HttpRequest thaw = HttpRequest.builder().method("PUT") + HttpRequest thaw = HttpRequest.builder().method(PUT) .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/filters/SessionManagerTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/filters/SessionManagerTest.java index 6c0715823f..66f25aea55 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/filters/SessionManagerTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/filters/SessionManagerTest.java @@ -18,6 +18,8 @@ */ package org.jclouds.dynect.v3.filters; +import static javax.ws.rs.core.Response.Status.FORBIDDEN; +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.expectLastCall; @@ -38,14 +40,16 @@ import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.cache.LoadingCache; - /** * @author Adrian Cole */ @Test(groups = "unit", testName = "SessionManagerTest") public class SessionManagerTest { - SessionCredentials creds = SessionCredentials.builder().customerName("customer").userName("robbie") - .password("password").build(); + SessionCredentials creds = SessionCredentials.builder() + .customerName("customer") + .userName("robbie") + .password("password").build(); + Session session = Session.forTokenAndVersion("token", "version"); public void testAlreadySessionCredentials() { @@ -68,7 +72,7 @@ public class SessionManagerTest { @SuppressWarnings("unchecked") @Test - public void test401ShouldInvalidateSessionAndRetry() { + public void testUnauthorizedShouldInvalidateSessionAndRetry() { HttpCommand command = createMock(HttpCommand.class); Supplier creds = createMock(Supplier.class); LoadingCache sessionCache = createMock(LoadingCache.class); @@ -82,7 +86,7 @@ public class SessionManagerTest { replay(creds, sessionCache, sessionApi, command); - HttpResponse response = HttpResponse.builder().statusCode(401).build(); + HttpResponse response = HttpResponse.builder().statusCode(UNAUTHORIZED.getStatusCode()).build(); SessionManager retry = new SessionManager(creds, sessionCache, sessionApi); @@ -93,7 +97,7 @@ public class SessionManagerTest { @SuppressWarnings("unchecked") @Test - public void test403ShouldNotInvalidateSessionOrRetry() { + public void testForbiddenShouldNotInvalidateSessionOrRetry() { HttpCommand command = createMock(HttpCommand.class); Supplier creds = createMock(Supplier.class); LoadingCache sessionCache = createMock(LoadingCache.class); @@ -101,7 +105,7 @@ public class SessionManagerTest { replay(creds, sessionCache, sessionApi, command); - HttpResponse response = HttpResponse.builder().statusCode(403).build(); + HttpResponse response = HttpResponse.builder().statusCode(FORBIDDEN.getStatusCode()).build(); SessionManager retry = new SessionManager(creds, sessionCache, sessionApi); diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/handlers/GetJobRedirectionRetryHandlerExpectTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/handlers/GetJobRedirectionRetryHandlerExpectTest.java index 40dd90118a..2476bde8aa 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/handlers/GetJobRedirectionRetryHandlerExpectTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/handlers/GetJobRedirectionRetryHandlerExpectTest.java @@ -17,11 +17,13 @@ * under the License. */ package org.jclouds.dynect.v3.handlers; - import static com.google.common.net.HttpHeaders.ACCEPT; import static com.google.common.net.HttpHeaders.CONTENT_TYPE; import static com.google.common.net.HttpHeaders.LOCATION; +import static javax.ws.rs.HttpMethod.GET; +import static javax.ws.rs.HttpMethod.PUT; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static javax.ws.rs.core.Response.Status.TEMPORARY_REDIRECT; import org.jclouds.dynect.v3.DynECTApi; import org.jclouds.dynect.v3.internal.BaseDynECTApiExpectTest; @@ -38,7 +40,7 @@ public class GetJobRedirectionRetryHandlerExpectTest extends BaseDynECTApiExpect public void testRedirectOnJobLocationSwitchesToGETAndNoPayload() { - HttpRequest thaw = HttpRequest.builder().method("PUT") + HttpRequest thaw = HttpRequest.builder().method(PUT) .endpoint("https://api2.dynect.net/REST/Zone/jclouds.org") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) @@ -47,11 +49,11 @@ public class GetJobRedirectionRetryHandlerExpectTest extends BaseDynECTApiExpect .build(); HttpResponse redirectResponse = HttpResponse.builder() - .statusCode(317) + .statusCode(TEMPORARY_REDIRECT.getStatusCode()) .addHeader(LOCATION, "https://api2.dynect.net/REST/Job/1234") .build(); - HttpRequest job = HttpRequest.builder().method("GET") + HttpRequest job = HttpRequest.builder().method(GET) .endpoint("https://api2.dynect.net/REST/Job/1234") .addHeader("API-Version", "3.3.8") .addHeader(ACCEPT, APPLICATION_JSON) diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/internal/BaseDynECTExpectTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/internal/BaseDynECTExpectTest.java index 89ed0a5770..9dd5fd0c87 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/internal/BaseDynECTExpectTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/internal/BaseDynECTExpectTest.java @@ -17,8 +17,10 @@ * under the License. */ package org.jclouds.dynect.v3.internal; - +import static javax.ws.rs.HttpMethod.POST; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; import org.jclouds.dynect.v3.config.DynECTRestClientModule; import org.jclouds.http.HttpRequest; @@ -70,9 +72,8 @@ public class BaseDynECTExpectTest extends BaseRestApiExpectTest { protected String authToken = "FFFFFFFFFF"; - protected HttpRequest createSession = HttpRequest - .builder() - .method("POST") + protected HttpRequest createSession = HttpRequest.builder() + .method(POST) .endpoint("https://api2.dynect.net/REST/Session") .addHeader("API-Version", "3.3.8") .payload( @@ -80,8 +81,8 @@ public class BaseDynECTExpectTest extends BaseRestApiExpectTest { "{\"customer_name\":\"jclouds\",\"user_name\":\"joe\",\"password\":\"letmein\"}", APPLICATION_JSON)) .build(); - protected HttpResponse createSessionResponse = HttpResponse.builder().statusCode(200) + protected HttpResponse createSessionResponse = HttpResponse.builder().statusCode(OK.getStatusCode()) .payload(payloadFromResourceWithContentType("/create_session.json", APPLICATION_JSON)).build(); - protected HttpResponse notFound = HttpResponse.builder().statusCode(404).build(); + protected HttpResponse notFound = HttpResponse.builder().statusCode(NOT_FOUND.getStatusCode()).build(); }