use more constants in route53 tests

This commit is contained in:
adriancole 2013-04-09 20:10:20 -07:00
parent c23ea656c6
commit 55ba435b55
5 changed files with 84 additions and 65 deletions

View File

@ -18,6 +18,10 @@
*/ */
package org.jclouds.route53; package org.jclouds.route53;
import static com.google.common.net.HttpHeaders.DATE;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.GET;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull; import static org.testng.Assert.assertNull;
@ -33,15 +37,14 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "Route53ApiExpectTest") @Test(groups = "unit", testName = "Route53ApiExpectTest")
public class Route53ApiExpectTest extends BaseRoute53ApiExpectTest { public class Route53ApiExpectTest extends BaseRoute53ApiExpectTest {
HttpRequest getChange = HttpRequest.builder().method("GET") HttpRequest getChange = HttpRequest.builder().method(GET)
.endpoint("https://route53.amazonaws.com/2012-02-29/change/C2682N5HXP0BZ4") .endpoint("https://route53.amazonaws.com/2012-02-29/change/C2682N5HXP0BZ4")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.build(); .build();
HttpResponse getChangeResponse = HttpResponse.builder().statusCode(200) HttpResponse getChangeResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/change.xml", "text/xml")).build(); .payload(payloadFromResourceWithContentType("/change.xml", "text/xml")).build();
public void testGetChangeWhenResponseIs2xx() { public void testGetChangeWhenResponseIs2xx() {

View File

@ -17,7 +17,11 @@
* under the License. * under the License.
*/ */
package org.jclouds.route53.features; package org.jclouds.route53.features;
import static com.google.common.net.HttpHeaders.DATE;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.GET;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull; import static org.testng.Assert.assertNull;
@ -39,17 +43,17 @@ import com.google.common.collect.ImmutableSet;
*/ */
@Test(groups = "unit", testName = "HostedZoneApiExpectTest") @Test(groups = "unit", testName = "HostedZoneApiExpectTest")
public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest { public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
HttpRequest createWithReference = HttpRequest.builder().method("POST") HttpRequest createWithReference = HttpRequest.builder().method(POST)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.payload( .payload(
payloadFromStringWithContentType( payloadFromStringWithContentType(
"<CreateHostedZoneRequest xmlns=\"https://route53.amazonaws.com/doc/2012-02-29/\"><Name>jclouds.org.</Name><CallerReference>expect</CallerReference></CreateHostedZoneRequest>", "<CreateHostedZoneRequest xmlns=\"https://route53.amazonaws.com/doc/2012-02-29/\"><Name>jclouds.org.</Name><CallerReference>expect</CallerReference></CreateHostedZoneRequest>",
"application/xml")).build(); "application/xml")).build();
HttpResponse createResponse = HttpResponse.builder().statusCode(200) HttpResponse createResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/new_zone.xml", "text/xml")).build(); .payload(payloadFromResourceWithContentType("/new_zone.xml", "text/xml")).build();
public void testCreateWithReferenceWhenResponseIs2xx() { public void testCreateWithReferenceWhenResponseIs2xx() {
@ -58,10 +62,10 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
new CreateHostedZoneResponseTest().expected().toString()); new CreateHostedZoneResponseTest().expected().toString());
} }
HttpRequest createWithReferenceAndComment = HttpRequest.builder().method("POST") HttpRequest createWithReferenceAndComment = HttpRequest.builder().method(POST)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.payload( .payload(
payloadFromStringWithContentType( payloadFromStringWithContentType(
@ -74,14 +78,14 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
new CreateHostedZoneResponseTest().expected().toString()); new CreateHostedZoneResponseTest().expected().toString());
} }
HttpRequest get = HttpRequest.builder().method("GET") HttpRequest get = HttpRequest.builder().method(GET)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1XTHCPEFRWV1X") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1XTHCPEFRWV1X")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.build(); .build();
HttpResponse getResponse = HttpResponse.builder().statusCode(200) HttpResponse getResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/hosted_zone.xml", "text/xml")).build(); .payload(payloadFromResourceWithContentType("/hosted_zone.xml", "text/xml")).build();
public void testGetWhenResponseIs2xx() { public void testGetWhenResponseIs2xx() {
@ -95,14 +99,14 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
assertNull(fail.getHostedZoneApi().get("Z1XTHCPEFRWV1X")); assertNull(fail.getHostedZoneApi().get("Z1XTHCPEFRWV1X"));
} }
HttpRequest list = HttpRequest.builder().method("GET") HttpRequest list = HttpRequest.builder().method(GET)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.build(); .build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200) HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/hosted_zones.xml", "text/xml")).build(); .payload(payloadFromResourceWithContentType("/hosted_zones.xml", "text/xml")).build();
public void testListWhenResponseIs2xx() { public void testListWhenResponseIs2xx() {
@ -118,10 +122,10 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
assertEquals(fail.getHostedZoneApi().list().get(0).toSet(), ImmutableSet.of()); assertEquals(fail.getHostedZoneApi().list().get(0).toSet(), ImmutableSet.of());
} }
HttpRequest listAt = HttpRequest.builder().method("GET") HttpRequest listAt = HttpRequest.builder().method(GET)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone?marker=Z333333YYYYYYY") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone?marker=Z333333YYYYYYY")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.build(); .build();
@ -132,7 +136,7 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
} }
public void testList2PagesWhenResponseIs2xx() { public void testList2PagesWhenResponseIs2xx() {
HttpResponse noMore = HttpResponse.builder().statusCode(200) HttpResponse noMore = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromStringWithContentType("<ListHostedZonesResponse />", "text/xml")).build(); .payload(payloadFromStringWithContentType("<ListHostedZonesResponse />", "text/xml")).build();
Route53Api success = requestsSendResponses(list, listResponse, listAt, noMore); Route53Api success = requestsSendResponses(list, listResponse, listAt, noMore);
@ -142,12 +146,12 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
HttpRequest delete = HttpRequest.builder().method("DELETE") HttpRequest delete = HttpRequest.builder().method("DELETE")
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1XTHCPEFRWV1X") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1XTHCPEFRWV1X")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.build(); .build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) HttpResponse deleteResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/change.xml", "text/xml")).build(); .payload(payloadFromResourceWithContentType("/change.xml", "text/xml")).build();
public void testDeleteWhenResponseIs2xx() { public void testDeleteWhenResponseIs2xx() {

View File

@ -17,7 +17,12 @@
* under the License. * under the License.
*/ */
package org.jclouds.route53.features; package org.jclouds.route53.features;
import static com.google.common.net.HttpHeaders.DATE;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.GET;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -41,14 +46,14 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "unit", testName = "ResourceResourceRecordSetApiExpectTest") @Test(groups = "unit", testName = "ResourceResourceRecordSetApiExpectTest")
public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest { public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
HttpRequest create = HttpRequest.builder().method("POST") HttpRequest create = HttpRequest.builder().method(POST)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.payload(payloadFromResourceWithContentType("/create_rrs_request.xml", "application/xml")).build(); .payload(payloadFromResourceWithContentType("/create_rrs_request.xml", "application/xml")).build();
HttpResponse jobResponse = HttpResponse.builder().statusCode(200) HttpResponse jobResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/change.xml", "text/xml")).build(); .payload(payloadFromResourceWithContentType("/change.xml", "text/xml")).build();
public void testCreateWhenResponseIs2xx() { public void testCreateWhenResponseIs2xx() {
@ -57,10 +62,10 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
new GetChangeResponseTest().expected().toString()); new GetChangeResponseTest().expected().toString());
} }
HttpRequest apply = HttpRequest.builder().method("POST") HttpRequest apply = HttpRequest.builder().method(POST)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.payload(payloadFromResourceWithContentType("/batch_rrs_request.xml", "application/xml")).build(); .payload(payloadFromResourceWithContentType("/batch_rrs_request.xml", "application/xml")).build();
@ -76,7 +81,7 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
@Test(expectedExceptions = InvalidChangeBatchException.class, expectedExceptionsMessageRegExp = "\\[Tried to create resource record set duplicate.example.com. type A, but it already exists, Tried to delete resource record set noexist.example.com. type A, but it was not found\\]") @Test(expectedExceptions = InvalidChangeBatchException.class, expectedExceptionsMessageRegExp = "\\[Tried to create resource record set duplicate.example.com. type A, but it already exists, Tried to delete resource record set noexist.example.com. type A, but it was not found\\]")
public void testApplyWhenResponseIs4xx() { public void testApplyWhenResponseIs4xx() {
HttpResponse batchErrorFound = HttpResponse.builder().statusCode(400) HttpResponse batchErrorFound = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode())
.payload(payloadFromResourceWithContentType("/invalid_change_batch.xml", "application/xml")).build(); .payload(payloadFromResourceWithContentType("/invalid_change_batch.xml", "application/xml")).build();
Route53Api fails = requestSendsResponse(apply, batchErrorFound); Route53Api fails = requestSendsResponse(apply, batchErrorFound);
@ -87,19 +92,19 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
.build()); .build());
} }
HttpRequest list = HttpRequest.builder().method("GET") HttpRequest list = HttpRequest.builder().method(GET)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate).build(); .addHeader("X-Amzn-Authorization", authForDate).build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200) HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/rrsets.xml", "text/xml")).build(); .payload(payloadFromResourceWithContentType("/rrsets.xml", "text/xml")).build();
public void testListWhenResponseIs2xx() { public void testListWhenResponseIs2xx() {
Route53Api success = requestSendsResponse(list, listResponse); Route53Api success = requestSendsResponse(list, listResponse);
assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().get(0).toString(), new ListResourceRecordSetsResponseTest().expected() assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().get(0).toString(),
.toString()); new ListResourceRecordSetsResponseTest().expected().toString());
} }
// TODO: this should really be an empty set // TODO: this should really be an empty set
@ -109,10 +114,10 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
assertEquals(fail.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().get(0).toSet(), ImmutableSet.of()); assertEquals(fail.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().get(0).toSet(), ImmutableSet.of());
} }
HttpRequest listAt = HttpRequest.builder().method("GET") HttpRequest listAt = HttpRequest.builder().method(GET)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset?name=testdoc2.example.com") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset?name=testdoc2.example.com")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate).build(); .addHeader("X-Amzn-Authorization", authForDate).build();
public void testListAtWhenResponseIs2xx() { public void testListAtWhenResponseIs2xx() {
@ -122,10 +127,10 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
new ListResourceRecordSetsResponseTest().expected().toString()); new ListResourceRecordSetsResponseTest().expected().toString());
} }
HttpRequest listAtNameAndType = HttpRequest.builder().method("GET") HttpRequest listAtNameAndType = HttpRequest.builder().method(GET)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset?name=testdoc2.example.com&type=NS") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset?name=testdoc2.example.com&type=NS")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate).build(); .addHeader("X-Amzn-Authorization", authForDate).build();
public void testListAtNameAndTypeWhenResponseIs2xx() { public void testListAtNameAndTypeWhenResponseIs2xx() {
@ -136,24 +141,28 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
} }
public void testList2PagesWhenResponseIs2xx() { public void testList2PagesWhenResponseIs2xx() {
HttpResponse noMore = HttpResponse.builder().statusCode(200) HttpResponse noMore = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromStringWithContentType("<ListResourceRecordSetsResponse />", "text/xml")).build(); .payload(payloadFromStringWithContentType("<ListResourceRecordSetsResponse />", "text/xml")).build();
Route53Api success = requestsSendResponses(list, listResponse, listAtNameAndType, noMore); Route53Api success = requestsSendResponses(list, listResponse, listAtNameAndType, noMore);
assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().concat().toSet(), new ListResourceRecordSetsResponseTest().expected() assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().concat().toSet(),
.toSet()); new ListResourceRecordSetsResponseTest().expected().toSet());
} }
HttpRequest delete = HttpRequest.builder().method("POST") HttpRequest delete = HttpRequest.builder().method(POST)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate) .addHeader("X-Amzn-Authorization", authForDate)
.payload(payloadFromResourceWithContentType("/delete_rrs_request.xml", "application/xml")).build(); .payload(payloadFromResourceWithContentType("/delete_rrs_request.xml", "application/xml")).build();
public void testDeleteWhenResponseIs2xx() { public void testDeleteWhenResponseIs2xx() {
Route53Api success = requestSendsResponse(delete, jobResponse); Route53Api success = requestSendsResponse(delete, jobResponse);
assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").create(ResourceRecordSet.builder().name("jclouds.org.").type("TXT").ttl(0).add("my texts").build()).toString(), assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").create(ResourceRecordSet.builder()
.name("jclouds.org.")
.type("TXT")
.ttl(0)
.add("my texts").build()).toString(),
new GetChangeResponseTest().expected().toString()); new GetChangeResponseTest().expected().toString());
} }
} }

View File

@ -18,8 +18,11 @@
*/ */
package org.jclouds.route53.handlers; package org.jclouds.route53.handlers;
import static com.google.common.base.Throwables.propagate; import static com.google.common.base.Throwables.propagate;
import static com.google.common.net.HttpHeaders.DATE;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static org.jclouds.rest.internal.BaseRestApiExpectTest.payloadFromStringWithContentType; import static org.jclouds.rest.internal.BaseRestApiExpectTest.payloadFromStringWithContentType;
import static org.jclouds.util.Strings2.toStringAndClose; import static org.jclouds.util.Strings2.toStringAndClose;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -38,7 +41,6 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice; import com.google.inject.Guice;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -47,17 +49,17 @@ import com.google.inject.Guice;
public class Route53ErrorHandlerTest { public class Route53ErrorHandlerTest {
Route53ErrorHandler function = Guice.createInjector(new SaxParserModule()).getInstance(Route53ErrorHandler.class); Route53ErrorHandler function = Guice.createInjector(new SaxParserModule()).getInstance(Route53ErrorHandler.class);
HttpRequest request = HttpRequest.builder().method("POST") HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset") .endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset")
.addHeader("Host", "route53.amazonaws.com") .addHeader(HOST, "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800") .addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", "AWS3-HTTPS AWSAccessKeyId=identity,Algorithm=HmacSHA256,Signature=pylxNiLcrsjNRZOsxyT161JCwytVPHyc2rFfmNCuZKI=") .addHeader("X-Amzn-Authorization", "AWS3-HTTPS AWSAccessKeyId=identity,Algorithm=HmacSHA256,Signature=pylxNiLcrsjNRZOsxyT161JCwytVPHyc2rFfmNCuZKI=")
.payload(payloadFromResource("/batch_rrs_request.xml")).build(); .payload(payloadFromResource("/batch_rrs_request.xml")).build();
HttpCommand command = new HttpCommand(request); HttpCommand command = new HttpCommand(request);
@Test @Test
public void testInvalidChangeBatchException() throws IOException { public void testInvalidChangeBatchException() throws IOException {
HttpResponse response = HttpResponse.builder().statusCode(400) HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode())
.payload(payloadFromResource("/invalid_change_batch.xml")).build(); .payload(payloadFromResource("/invalid_change_batch.xml")).build();
function.handleError(command, response); function.handleError(command, response);
@ -71,7 +73,7 @@ public class Route53ErrorHandlerTest {
@Test @Test
public void testDeleteNotFound() throws IOException { public void testDeleteNotFound() throws IOException {
HttpResponse response = HttpResponse.builder().statusCode(400) HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode())
.payload( .payload(
payloadFromStringWithContentType( payloadFromStringWithContentType(
"<ErrorResponse><Error><Type>Sender</Type><Code>InvalidChangeBatch</Code>" "<ErrorResponse><Error><Type>Sender</Type><Code>InvalidChangeBatch</Code>"

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.route53.internal; package org.jclouds.route53.internal;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
@ -25,7 +27,6 @@ import org.jclouds.rest.internal.BaseRestApiExpectTest;
import org.jclouds.route53.config.Route53RestClientModule; import org.jclouds.route53.config.Route53RestClientModule;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -45,7 +46,7 @@ public class BaseRoute53ExpectTest<T> extends BaseRestApiExpectTest<T> {
} }
} }
protected final HttpResponse notFound = HttpResponse.builder().statusCode(404).build(); protected final HttpResponse notFound = HttpResponse.builder().statusCode(NOT_FOUND.getStatusCode()).build();
protected final String authForDate = "AWS3-HTTPS AWSAccessKeyId=identity,Algorithm=HmacSHA256,Signature=pylxNiLcrsjNRZOsxyT161JCwytVPHyc2rFfmNCuZKI="; protected final String authForDate = "AWS3-HTTPS AWSAccessKeyId=identity,Algorithm=HmacSHA256,Signature=pylxNiLcrsjNRZOsxyT161JCwytVPHyc2rFfmNCuZKI=";
@Override @Override