Merge pull request #1514 from jclouds/use-more-constants

use more constants in tests
This commit is contained in:
Adrian Cole 2013-04-09 23:33:01 -07:00
commit 3c34aeb112
38 changed files with 613 additions and 507 deletions

View File

@ -17,20 +17,21 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.DELETE;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.MediaType.WILDCARD;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.AccessRule;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.AccessRuleWithId;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.AccessRuleApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
@ -47,7 +48,7 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/accesslist-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/accesslist-list.json")).build()
).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000);
Iterable<AccessRuleWithId> accessList = api.list();
@ -59,8 +60,8 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
AccessRuleApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("POST").endpoint(endpoint).payload(payloadFromResource("/accesslist-create.json")).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(POST).endpoint(endpoint).payload(payloadFromResource("/accesslist-create.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000);
AccessRule accessRule1 = AccessRule.deny("206.160.163.21");
@ -76,8 +77,8 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
AccessRuleApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.delete(23));
@ -88,8 +89,8 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
AccessRuleApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000);
List<Integer> accessRuleIds = ImmutableList.<Integer> of(23, 24);
@ -101,8 +102,8 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
AccessRuleApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.deleteAll());

View File

@ -17,19 +17,20 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.DELETE;
import static javax.ws.rs.HttpMethod.PUT;
import static javax.ws.rs.core.MediaType.WILDCARD;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.ConnectionThrottle;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.ConnectionApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
@ -44,7 +45,7 @@ public class ConnectionApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/connectionthrottle-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/connectionthrottle-get.json")).build()
).getConnectionApiForZoneAndLoadBalancer("DFW", 2000);
ConnectionThrottle connectionThrottle = api.getConnectionThrottle();
@ -57,7 +58,7 @@ public class ConnectionApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/connectionthrottle-get-deleted.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/connectionthrottle-get-deleted.json")).build()
).getConnectionApiForZoneAndLoadBalancer("DFW", 2000);
ConnectionThrottle connectionThrottle = api.getConnectionThrottle();
@ -69,8 +70,8 @@ public class ConnectionApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
ConnectionApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/connectionthrottle-create.json")).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(PUT).endpoint(endpoint).payload(payloadFromResource("/connectionthrottle-create.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getConnectionApiForZoneAndLoadBalancer("DFW", 2000);
api.createOrUpdateConnectionThrottle(getConnectionThrottle());
@ -90,8 +91,8 @@ public class ConnectionApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
ConnectionApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getConnectionApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.deleteConnectionThrottle());
@ -103,7 +104,7 @@ public class ConnectionApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/connectionlogging-enable.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/connectionlogging-enable.json")).build()
).getConnectionApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.isConnectionLogging());
@ -114,8 +115,8 @@ public class ConnectionApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
ConnectionApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/connectionlogging-enable.json")).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(PUT).endpoint(endpoint).payload(payloadFromResource("/connectionlogging-enable.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getConnectionApiForZoneAndLoadBalancer("DFW", 2000);
api.enableConnectionLogging();
@ -126,8 +127,8 @@ public class ConnectionApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<
ConnectionApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/connectionlogging-disable.json")).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(PUT).endpoint(endpoint).payload(payloadFromResource("/connectionlogging-disable.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getConnectionApiForZoneAndLoadBalancer("DFW", 2000);
api.disableConnectionLogging();

View File

@ -17,14 +17,14 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static javax.ws.rs.HttpMethod.PUT;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.ContentCachingApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
@ -39,7 +39,7 @@ public class ContentCachingApiExpectTest extends BaseCloudLoadBalancerApiExpectT
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/contentcaching-enable.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/contentcaching-enable.json")).build()
).getContentCachingApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.isContentCaching());
@ -50,8 +50,8 @@ public class ContentCachingApiExpectTest extends BaseCloudLoadBalancerApiExpectT
ContentCachingApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/contentcaching-enable.json")).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(PUT).endpoint(endpoint).payload(payloadFromResource("/contentcaching-enable.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getContentCachingApiForZoneAndLoadBalancer("DFW", 2000);
api.enable();
@ -62,8 +62,8 @@ public class ContentCachingApiExpectTest extends BaseCloudLoadBalancerApiExpectT
ContentCachingApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/contentcaching-disable.json")).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(PUT).endpoint(endpoint).payload(payloadFromResource("/contentcaching-disable.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getContentCachingApiForZoneAndLoadBalancer("DFW", 2000);
api.disable();

View File

@ -17,18 +17,20 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.DELETE;
import static javax.ws.rs.HttpMethod.PUT;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.WILDCARD;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.ErrorPageApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
@ -55,8 +57,8 @@ public class ErrorPageApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<C
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder()
.statusCode(200)
.payload(payloadFromStringWithContentType("{\"errorpage\":{\"content\":\"" + contentEscaped + "\"}}", MediaType.APPLICATION_JSON))
.statusCode(OK.getStatusCode())
.payload(payloadFromStringWithContentType("{\"errorpage\":{\"content\":\"" + contentEscaped + "\"}}", APPLICATION_JSON))
.build()
).getErrorPageApiForZoneAndLoadBalancer("DFW", 2000);
@ -70,12 +72,12 @@ public class ErrorPageApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<C
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
.method("PUT")
.method(PUT)
.endpoint(endpoint)
.replaceHeader("Accept", MediaType.WILDCARD)
.payload(payloadFromStringWithContentType("{\"errorpage\":{\"content\":\"" + contentEscaped + "\"}}", MediaType.APPLICATION_JSON))
.replaceHeader(ACCEPT, WILDCARD)
.payload(payloadFromStringWithContentType("{\"errorpage\":{\"content\":\"" + contentEscaped + "\"}}", APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(200).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getErrorPageApiForZoneAndLoadBalancer("DFW", 2000);
api.create(contentEscaped);
@ -86,8 +88,8 @@ public class ErrorPageApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<C
ErrorPageApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getErrorPageApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.delete());

View File

@ -17,19 +17,20 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.DELETE;
import static javax.ws.rs.HttpMethod.PUT;
import static javax.ws.rs.core.MediaType.WILDCARD;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.HealthMonitor;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.HealthMonitorApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
@ -44,7 +45,7 @@ public class HealthMonitorApiExpectTest extends BaseCloudLoadBalancerApiExpectTe
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/healthmonitor-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/healthmonitor-get.json")).build()
).getHealthMonitorApiForZoneAndLoadBalancer("DFW", 2000);
HealthMonitor healthMonitor = api.get();
@ -57,7 +58,7 @@ public class HealthMonitorApiExpectTest extends BaseCloudLoadBalancerApiExpectTe
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/healthmonitor-get-deleted.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/healthmonitor-get-deleted.json")).build()
).getHealthMonitorApiForZoneAndLoadBalancer("DFW", 2000);
HealthMonitor healthMonitor = api.get();
@ -69,8 +70,8 @@ public class HealthMonitorApiExpectTest extends BaseCloudLoadBalancerApiExpectTe
HealthMonitorApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/healthmonitor-create.json")).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(PUT).endpoint(endpoint).payload(payloadFromResource("/healthmonitor-create.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getHealthMonitorApiForZoneAndLoadBalancer("DFW", 2000);
api.createOrUpdate(getConnectHealthMonitor());
@ -81,8 +82,8 @@ public class HealthMonitorApiExpectTest extends BaseCloudLoadBalancerApiExpectTe
HealthMonitorApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getHealthMonitorApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.delete());

View File

@ -17,25 +17,29 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.DELETE;
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.MediaType.WILDCARD;
import static javax.ws.rs.core.Response.Status.ACCEPTED;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.Set;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.CreateLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.Metadata;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.CreateLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.Metadata;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.functions.ParseLoadBalancerTest;
import org.jclouds.rackspace.cloudloadbalancers.v1.functions.ParseLoadBalancersTest;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
@ -56,7 +60,7 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancers-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/loadbalancers-list.json")).build()
).getLoadBalancerApiForZone("DFW");
Set<LoadBalancer> loadBalancers = api.list().concat().toSet();
@ -69,7 +73,7 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancer-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/loadbalancer-get.json")).build()
).getLoadBalancerApiForZone("DFW");
LoadBalancer loadBalancer = api.get(2000);
@ -82,11 +86,11 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
.method("POST")
.method(POST)
.payload(payloadFromResource("/loadbalancer-create.json"))
.endpoint(endpoint)
.build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancer-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/loadbalancer-get.json")).build()
).getLoadBalancerApiForZone("DFW");
AddNode addNode1 = AddNode.builder()
@ -122,8 +126,8 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").payload(payloadFromResource("/loadbalancer-update.json")).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(202).payload("").build()
authenticatedGET().method(PUT).payload(payloadFromResource("/loadbalancer-update.json")).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(ACCEPTED.getStatusCode()).payload("").build()
).getLoadBalancerApiForZone("DFW");
UpdateLoadBalancer updateLB = UpdateLoadBalancer.builder()
@ -142,11 +146,11 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
.method("DELETE")
.replaceHeader("Accept", MediaType.WILDCARD)
.method(DELETE)
.replaceHeader(ACCEPT, WILDCARD)
.endpoint(endpoint)
.build(),
HttpResponse.builder().statusCode(202).payload("").build()
HttpResponse.builder().statusCode(ACCEPTED.getStatusCode()).payload("").build()
).getLoadBalancerApiForZone("DFW");
api.delete(2000);
@ -158,7 +162,7 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/metadata-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/metadata-list.json")).build()
).getLoadBalancerApiForZone("DFW");
Metadata metadata = api.getMetadata(2000);
@ -171,10 +175,10 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
.method("POST")
.method(POST)
.endpoint(endpoint)
.payload(payloadFromResourceWithContentType("/metadata-create.json", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/metadata-list.json")).build()
.payload(payloadFromResourceWithContentType("/metadata-create.json", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/metadata-list.json")).build()
).getLoadBalancerApiForZone("DFW");
Metadata metadata = api.createMetadata(2000, getExpectedMetadata());
@ -186,8 +190,8 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getLoadBalancerApiForZone("DFW");
assertTrue(api.deleteMetadatum(2000, 23));
@ -198,8 +202,8 @@ public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTes
LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getLoadBalancerApiForZone("DFW");

View File

@ -17,22 +17,25 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.DELETE;
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.MediaType.WILDCARD;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.Set;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.Metadata;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateNode;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
@ -51,7 +54,7 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nodes-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/nodes-list.json")).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Set<Node> nodes = api.list().concat().toSet();
@ -64,7 +67,7 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/node-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/node-get.json")).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Node node = api.get(410);
@ -77,11 +80,11 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
.method("POST")
.payload(payloadFromResourceWithContentType("/nodes-add.json", MediaType.APPLICATION_JSON))
.method(POST)
.payload(payloadFromResourceWithContentType("/nodes-add.json", APPLICATION_JSON))
.endpoint(endpoint)
.build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nodes-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/nodes-list.json")).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
AddNode addNode1 = AddNode.builder()
@ -117,8 +120,8 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").payload(payloadFromResource("/node-update.json")).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(PUT).payload(payloadFromResource("/node-update.json")).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
UpdateNode updateNode = UpdateNode.builder()
@ -135,8 +138,8 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).replaceHeader(ACCEPT, WILDCARD).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
api.remove(410);
@ -147,8 +150,8 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).replaceHeader(ACCEPT, WILDCARD).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Set<Integer> nodeIds = ImmutableSortedSet.<Integer> of(410, 411);
@ -162,7 +165,7 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/metadata-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/metadata-list.json")).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Metadata metadata = api.getMetadata(410);
@ -175,10 +178,10 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
.method("POST")
.method(POST)
.endpoint(endpoint)
.payload(payloadFromResourceWithContentType("/metadata-create.json", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/metadata-list.json")).build()
.payload(payloadFromResourceWithContentType("/metadata-create.json", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/metadata-list.json")).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Metadata metadata = api.createMetadata(410, getExpectedMetadata());
@ -190,8 +193,8 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.deleteMetadatum(410, 23));
@ -202,8 +205,8 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudL
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import java.net.URI;
@ -31,7 +31,6 @@ import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancerStats;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancerUsage;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.Protocol;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.ReportApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.functions.DateParser;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
@ -62,7 +61,7 @@ public class ReportApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<Clou
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/report-billable-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/report-billable-list.json")).build()
).getReportApiForZone("DFW");
FluentIterable<LoadBalancer> loadBalancers = api.listBillableLoadBalancers(aWeekAgo, today).concat();
@ -88,7 +87,7 @@ public class ReportApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<Clou
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/report-historical-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/report-historical-get.json")).build()
).getReportApiForZone("DFW");
HistoricalUsage historicalUsage = api.getHistoricalUsage(aWeekAgo, today);
@ -116,7 +115,7 @@ public class ReportApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<Clou
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/report-loadbalancerusage-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/report-loadbalancerusage-list.json")).build()
).getReportApiForZone("DFW");
FluentIterable<LoadBalancerUsage> loadBalancerUsages = api.listLoadBalancerUsage(2000, aWeekAgo, today).concat();
@ -130,7 +129,7 @@ public class ReportApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<Clou
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/report-loadbalancerusage-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/report-loadbalancerusage-list.json")).build()
).getReportApiForZone("DFW");
FluentIterable<LoadBalancerUsage> loadBalancerUsages = api.listCurrentLoadBalancerUsage(2000).concat();
@ -144,7 +143,7 @@ public class ReportApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<Clou
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/report-loadbalancerstats-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/report-loadbalancerstats-get.json")).build()
).getReportApiForZone("DFW");
LoadBalancerStats loadBalancerStats = api.getLoadBalancerStats(2000);
@ -163,7 +162,7 @@ public class ReportApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<Clou
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/report-protocols-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/report-protocols-list.json")).build()
).getReportApiForZone("DFW");
Iterable<Protocol> protocols = api.listProtocols();
@ -177,7 +176,7 @@ public class ReportApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<Clou
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/report-algorithms-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/report-algorithms-list.json")).build()
).getReportApiForZone("DFW");
Iterable<String> algorithms = api.listAlgorithms();

View File

@ -17,20 +17,23 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.DELETE;
import static javax.ws.rs.HttpMethod.PUT;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.WILDCARD;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.SSLTermination;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.SSLTerminationApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
@ -47,7 +50,7 @@ public class SSLTerminationApiExpectTest extends BaseCloudLoadBalancerApiExpectT
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/ssltermination-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/ssltermination-get.json")).build()
).getSSLTerminationApiForZoneAndLoadBalancer("DFW", 2000);
SSLTermination sslTermination = api.get();
@ -60,7 +63,7 @@ public class SSLTerminationApiExpectTest extends BaseCloudLoadBalancerApiExpectT
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(404).build()
HttpResponse.builder().statusCode(NOT_FOUND.getStatusCode()).build()
).getSSLTerminationApiForZoneAndLoadBalancer("DFW", 2000);
SSLTermination sslTermination = api.get();
@ -73,11 +76,11 @@ public class SSLTerminationApiExpectTest extends BaseCloudLoadBalancerApiExpectT
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
.method("PUT")
.method(PUT)
.endpoint(endpoint)
.payload(payloadFromResourceWithContentType("/ssltermination-create.json", MediaType.APPLICATION_JSON))
.payload(payloadFromResourceWithContentType("/ssltermination-create.json", APPLICATION_JSON))
.build(),
HttpResponse.builder().statusCode(200).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getSSLTerminationApiForZoneAndLoadBalancer("DFW", 2000);
api.createOrUpdate(getSSLTermination());
@ -88,8 +91,8 @@ public class SSLTerminationApiExpectTest extends BaseCloudLoadBalancerApiExpectT
SSLTerminationApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getSSLTerminationApiForZoneAndLoadBalancer("DFW", 2000);
assertTrue(api.delete());

View File

@ -17,7 +17,9 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static javax.ws.rs.HttpMethod.DELETE;
import static javax.ws.rs.HttpMethod.PUT;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
@ -26,7 +28,6 @@ import java.net.URI;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.SessionPersistence;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.SessionPersistenceApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
@ -41,7 +42,7 @@ public class SessionPersistenceApiExpectTest extends BaseCloudLoadBalancerApiExp
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/sessionpersistence-get.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/sessionpersistence-get.json")).build()
).getSessionPersistenceApiForZoneAndLoadBalancer("DFW", 2000);
SessionPersistence sessionPersistence = api.get();
@ -54,7 +55,7 @@ public class SessionPersistenceApiExpectTest extends BaseCloudLoadBalancerApiExp
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/sessionpersistence-get-deleted.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/sessionpersistence-get-deleted.json")).build()
).getSessionPersistenceApiForZoneAndLoadBalancer("DFW", 2000);
SessionPersistence sessionPersistence = api.get();
@ -66,8 +67,8 @@ public class SessionPersistenceApiExpectTest extends BaseCloudLoadBalancerApiExp
SessionPersistenceApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/sessionpersistence-create.json")).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(PUT).endpoint(endpoint).payload(payloadFromResource("/sessionpersistence-create.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getSessionPersistenceApiForZoneAndLoadBalancer("DFW", 2000);
api.create(SessionPersistence.HTTP_COOKIE);
@ -78,8 +79,8 @@ public class SessionPersistenceApiExpectTest extends BaseCloudLoadBalancerApiExp
SessionPersistenceApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getSessionPersistenceApiForZoneAndLoadBalancer("DFW", 2000);
api.delete();

View File

@ -17,19 +17,20 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.DELETE;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.MediaType.WILDCARD;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.VirtualIPWithId;
import org.jclouds.rackspace.cloudloadbalancers.v1.features.VirtualIPApi;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
@ -46,7 +47,7 @@ public class VirtualIPApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<C
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/virtualips-list.json")).build()
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/virtualips-list.json")).build()
).getVirtualIPApiForZoneAndLoadBalancer("DFW", 2000);
Iterable<VirtualIPWithId> virtualIPs = api.list();
@ -58,8 +59,8 @@ public class VirtualIPApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<C
VirtualIPApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("POST").endpoint(endpoint).payload(payloadFromResource("/virtualips-create.json")).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/virtualips-create-response.json")).build()
authenticatedGET().method(POST).endpoint(endpoint).payload(payloadFromResource("/virtualips-create.json")).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/virtualips-create-response.json")).build()
).getVirtualIPApiForZoneAndLoadBalancer("DFW", 2000);
api.create(VirtualIP.publicIPv6());
@ -70,8 +71,8 @@ public class VirtualIPApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<C
VirtualIPApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getVirtualIPApiForZoneAndLoadBalancer("DFW", 2000);
api.delete(23);
@ -82,8 +83,8 @@ public class VirtualIPApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<C
VirtualIPApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).replaceHeader("Accept", MediaType.WILDCARD).build(),
HttpResponse.builder().statusCode(200).build()
authenticatedGET().method(DELETE).endpoint(endpoint).replaceHeader(ACCEPT, WILDCARD).build(),
HttpResponse.builder().statusCode(OK.getStatusCode()).build()
).getVirtualIPApiForZoneAndLoadBalancer("DFW", 2000);
List<Integer> virtualIPIds = ImmutableList.<Integer> of(23, 24);

View File

@ -17,11 +17,12 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.handlers;
import static javax.ws.rs.HttpMethod.GET;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import java.net.URI;
import org.jclouds.http.handlers.BaseHttpErrorHandlerTest;
import org.jclouds.rackspace.cloudloadbalancers.v1.handlers.ParseCloudLoadBalancersErrorFromHttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
@ -33,11 +34,11 @@ import org.testng.annotations.Test;
public class ParseCloudLoadBalancersErrorFromHttpResponseTest extends
BaseHttpErrorHandlerTest<ParseCloudLoadBalancersErrorFromHttpResponse> {
@Test
public void test404NotFound() {
public void testNotFound() {
assertCodeMakes(
"GET",
GET,
URI.create("https://ord.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/2000"),
404,
NOT_FOUND.getStatusCode(),
"Not Found",
"<itemNotFound code=\"404\" xmlns=\"http://docs.openstack.org/loadbalancers/api/v1.0\">\n <message>Object not Found</message>\n</itemNotFound>",
ResourceNotFoundException.class, "loadbalancers 2000 not found");

View File

@ -17,8 +17,9 @@
* under the License.
*/
package org.jclouds.rackspace.cloudloadbalancers.v1.internal;
import javax.ws.rs.core.MediaType;
import static com.google.common.net.HttpHeaders.ACCEPT;
import static javax.ws.rs.HttpMethod.GET;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
@ -53,8 +54,8 @@ public class BaseCloudLoadBalancerApiExpectTest<T> extends BaseRestApiExpectTest
protected HttpRequest.Builder<?> authenticatedGET() {
return HttpRequest.builder()
.method("GET")
.addHeader("Accept", MediaType.APPLICATION_JSON)
.method(GET)
.addHeader(ACCEPT, APPLICATION_JSON)
.addHeader("X-Auth-Token", authToken);
}
}

View File

@ -18,6 +18,10 @@
*/
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.assertNull;
@ -33,15 +37,14 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "Route53ApiExpectTest")
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.build();
HttpResponse getChangeResponse = HttpResponse.builder().statusCode(200)
HttpResponse getChangeResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/change.xml", "text/xml")).build();
public void testGetChangeWhenResponseIs2xx() {

View File

@ -17,7 +17,11 @@
* under the License.
*/
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.assertNull;
@ -39,17 +43,17 @@ import com.google.common.collect.ImmutableSet;
*/
@Test(groups = "unit", testName = "HostedZoneApiExpectTest")
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.payload(
payloadFromStringWithContentType(
"<CreateHostedZoneRequest xmlns=\"https://route53.amazonaws.com/doc/2012-02-29/\"><Name>jclouds.org.</Name><CallerReference>expect</CallerReference></CreateHostedZoneRequest>",
"application/xml")).build();
HttpResponse createResponse = HttpResponse.builder().statusCode(200)
HttpResponse createResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/new_zone.xml", "text/xml")).build();
public void testCreateWithReferenceWhenResponseIs2xx() {
@ -58,10 +62,10 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.payload(
payloadFromStringWithContentType(
@ -74,14 +78,14 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.build();
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
HttpResponse getResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/hosted_zone.xml", "text/xml")).build();
public void testGetWhenResponseIs2xx() {
@ -95,14 +99,14 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/hosted_zones.xml", "text/xml")).build();
public void testListWhenResponseIs2xx() {
@ -118,10 +122,10 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.build();
@ -132,7 +136,7 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
}
public void testList2PagesWhenResponseIs2xx() {
HttpResponse noMore = HttpResponse.builder().statusCode(200)
HttpResponse noMore = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromStringWithContentType("<ListHostedZonesResponse />", "text/xml")).build();
Route53Api success = requestsSendResponses(list, listResponse, listAt, noMore);
@ -142,12 +146,12 @@ public class HostedZoneApiExpectTest extends BaseRoute53ApiExpectTest {
HttpRequest delete = HttpRequest.builder().method("DELETE")
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1XTHCPEFRWV1X")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
HttpResponse deleteResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/change.xml", "text/xml")).build();
public void testDeleteWhenResponseIs2xx() {

View File

@ -17,7 +17,12 @@
* under the License.
*/
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 org.jclouds.http.HttpRequest;
@ -41,14 +46,14 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "unit", testName = "ResourceResourceRecordSetApiExpectTest")
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.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();
public void testCreateWhenResponseIs2xx() {
@ -57,10 +62,10 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.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\\]")
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();
Route53Api fails = requestSendsResponse(apply, batchErrorFound);
@ -87,19 +92,19 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
.build());
}
HttpRequest list = HttpRequest.builder().method("GET")
HttpRequest list = HttpRequest.builder().method(GET)
.endpoint("https://route53.amazonaws.com/2012-02-29/hostedzone/Z1PA6795UKMFR9/rrset")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.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();
public void testListWhenResponseIs2xx() {
Route53Api success = requestSendsResponse(list, listResponse);
assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().get(0).toString(), new ListResourceRecordSetsResponseTest().expected()
.toString());
assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().get(0).toString(),
new ListResourceRecordSetsResponseTest().expected().toString());
}
// 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());
}
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate).build();
public void testListAtWhenResponseIs2xx() {
@ -122,10 +127,10 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate).build();
public void testListAtNameAndTypeWhenResponseIs2xx() {
@ -136,24 +141,28 @@ public class ResourceRecordSetApiExpectTest extends BaseRoute53ApiExpectTest {
}
public void testList2PagesWhenResponseIs2xx() {
HttpResponse noMore = HttpResponse.builder().statusCode(200)
HttpResponse noMore = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromStringWithContentType("<ListResourceRecordSetsResponse />", "text/xml")).build();
Route53Api success = requestsSendResponses(list, listResponse, listAtNameAndType, noMore);
assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().concat().toSet(), new ListResourceRecordSetsResponseTest().expected()
.toSet());
assertEquals(success.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().concat().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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", authForDate)
.payload(payloadFromResourceWithContentType("/delete_rrs_request.xml", "application/xml")).build();
public void testDeleteWhenResponseIs2xx() {
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());
}
}

View File

@ -18,8 +18,11 @@
*/
package org.jclouds.route53.handlers;
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.util.Strings2.toStringAndClose;
import static org.testng.Assert.assertEquals;
@ -38,7 +41,6 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
/**
*
* @author Adrian Cole
@ -47,17 +49,17 @@ import com.google.inject.Guice;
public class Route53ErrorHandlerTest {
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")
.addHeader("Host", "route53.amazonaws.com")
.addHeader("Date", "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader(HOST, "route53.amazonaws.com")
.addHeader(DATE, "Mon, 21 Jan 02013 19:29:03 -0800")
.addHeader("X-Amzn-Authorization", "AWS3-HTTPS AWSAccessKeyId=identity,Algorithm=HmacSHA256,Signature=pylxNiLcrsjNRZOsxyT161JCwytVPHyc2rFfmNCuZKI=")
.payload(payloadFromResource("/batch_rrs_request.xml")).build();
HttpCommand command = new HttpCommand(request);
@Test
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();
function.handleError(command, response);
@ -71,7 +73,7 @@ public class Route53ErrorHandlerTest {
@Test
public void testDeleteNotFound() throws IOException {
HttpResponse response = HttpResponse.builder().statusCode(400)
HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode())
.payload(
payloadFromStringWithContentType(
"<ErrorResponse><Error><Type>Sender</Type><Code>InvalidChangeBatch</Code>"

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.route53.internal;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import org.jclouds.date.DateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ConfiguresHttpApi;
@ -25,7 +27,6 @@ import org.jclouds.rest.internal.BaseRestApiExpectTest;
import org.jclouds.route53.config.Route53HttpApiModule;
import com.google.inject.Module;
/**
*
* @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=";
@Override

View File

@ -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")

View File

@ -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.<String> 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("<Error><Code>%s</Code></Error>", code))).build();
expect(command.getCurrentRequest()).andReturn(putBucket);

View File

@ -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(), "",
"<Error><Code>Monster.NotFound</Code></Error>", 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(), "",
"<Error><Code>Client.InvalidInstanceID.NotFound</Code></Error>", 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(), "",
"<Error><Code>LoadBalancerNotFound</Code></Error>", 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(), "",
"<Error><Code>SecurityGroupNotFoundForProject</Code></Error>", 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(), "",
"<Error><Code>UnsupportedOperation</Code></Error>", UnsupportedOperationException.class);
}
@Test
public void test400WithAddressLimitExceededCodeMakesInsufficientResourcesException() {
assertCodeMakes(
"POST",
POST,
URI.create("https://ec2.us-east-1.amazonaws.com/"),
400,
BAD_REQUEST.getStatusCode(),
"",
"<Response><Errors><Error><Code>AddressLimitExceeded</Code><Message>Too many addresses allocated</Message></Error></Errors><RequestID>c14f531a-cc35-4b48-8149-2655c7e6dc76</RequestID></Response>",
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(), "",
"<Error><Code>InvalidPlacementGroup.InUse</Code></Error>", 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(), "",
"<Error><Code>InvalidPlacementGroup.Unknown</Code></Error>", 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(), "",
"<Error><Code>IncorrectState</Code></Error>", 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(),
"",
"<Error><Code>OperationAborted</Code><Message>A conflicting conditional operation is currently in progress against this resource. Please try again.</Message><RequestId>F716E81C3D814E59</RequestId><HostId>SDprHxWzG/YXzanVnV7VTz/wP+6fRt1dS+q00kH1rz248YOOSddkFiTXF04XtqNO</HostId></Error>",
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",
"<Error><Code>InvalidGroup.Duplicate</Code></Error>", 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",
"<Error><Code>InvalidKeyPair.Duplicate</Code></Error>", 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(),
"",
"<?xml version=\"1.0\"?><Response><Errors><Error><Code>Groups</Code><Message>\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists</Message></Error></Errors><RequestID>e0133975-3bc5-456d-9753-1d61b27e07e9</RequestID></Response>",
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(), "",
"<Error><Code>AuthFailure</Code></Error>", 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(), "",
"<Error><Code>Client.AuthFailure</Code></Error>", AuthorizationException.class);
}

View File

@ -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));
}

View File

@ -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")

View File

@ -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);
}

View File

@ -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());

View File

@ -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()

View File

@ -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() {

View File

@ -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)

View File

@ -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<Credentials> creds = createMock(Supplier.class);
LoadingCache<Credentials, Session> 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<Credentials> creds = createMock(Supplier.class);
LoadingCache<Credentials, Session> 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);

View File

@ -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)

View File

@ -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.DynECTHttpApiModule;
import org.jclouds.http.HttpRequest;
@ -70,9 +72,8 @@ public class BaseDynECTExpectTest<T> extends BaseRestApiExpectTest<T> {
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<T> extends BaseRestApiExpectTest<T> {
"{\"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();
}

View File

@ -17,7 +17,9 @@
* under the License.
*/
package org.jclouds.ultradns.ws;
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.testng.Assert.assertEquals;
import org.jclouds.http.HttpRequest;
@ -32,12 +34,12 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "UltraDNSWSApiExpectTest")
public class UltraDNSWSApiExpectTest extends BaseUltraDNSWSApiExpectTest {
HttpRequest getCurrentAccount = HttpRequest.builder().method("POST")
HttpRequest getCurrentAccount = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/get_current_account.xml", "application/xml")).build();
HttpResponse getCurrentAccountResponse = HttpResponse.builder().statusCode(200)
HttpResponse getCurrentAccountResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/account.xml", "application/xml")).build();
public void testGetCurrentAccountWhenResponseIs2xx() {

View File

@ -17,7 +17,10 @@
* under the License.
*/
package org.jclouds.ultradns.ws.features;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.OK;
import static org.jclouds.ultradns.ws.domain.ResourceRecord.rrBuilder;
import static org.testng.Assert.assertEquals;
@ -32,17 +35,18 @@ import org.jclouds.ultradns.ws.parse.GetResourceRecordsOfResourceRecordResponseT
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ResourceRecordApiExpectTest")
public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
HttpRequest create = HttpRequest.builder().method("POST")
HttpRequest create = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/create_rr.xml", "application/xml")).build();
HttpResponse createResponse = HttpResponse.builder().statusCode(200)
HttpResponse createResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/rr_created.xml", "application/xml")).build();
ResourceRecord record = rrBuilder().name("mail.jclouds.org.")
@ -56,7 +60,7 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
success.getResourceRecordApiForZone("jclouds.org.").create(record);
}
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(500)
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResourceWithContentType("/rr_already_exists.xml", "application/xml")).build();
@Test(expectedExceptions = ResourceAlreadyExistsException.class, expectedExceptionsMessageRegExp = "Resource Record of type 15 with these attributes already exists in the system.")
@ -65,12 +69,12 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
already.getResourceRecordApiForZone("jclouds.org.").create(record);
}
HttpRequest update = HttpRequest.builder().method("POST")
HttpRequest update = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/update_rr.xml", "application/xml")).build();
HttpResponse updateResponse = HttpResponse.builder().statusCode(200)
HttpResponse updateResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/rr_updated.xml", "application/xml")).build();
public void testUpdateWhenResponseIs2xx() {
@ -78,12 +82,12 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
success.getResourceRecordApiForZone("jclouds.org.").update("04053D8E57C7931F", record);
}
HttpRequest list = HttpRequest.builder().method("POST")
HttpRequest list = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_records.xml", "application/xml")).build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/records.xml", "application/xml")).build();
public void testListWhenResponseIs2xx() {
@ -94,7 +98,7 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
new GetResourceRecordsOfResourceRecordResponseTest().expected().toString());
}
HttpResponse zoneDoesntExist = HttpResponse.builder().message("Server Error").statusCode(500)
HttpResponse zoneDoesntExist = HttpResponse.builder().message("Server Error").statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/zone_doesnt_exist.xml")).build();
@Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Zone does not exist in the system.")
@ -103,9 +107,9 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
notFound.getResourceRecordApiForZone("jclouds.org.").list();
}
HttpRequest listByName = HttpRequest.builder().method("POST")
HttpRequest listByName = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_records_by_name.xml", "application/xml")).build();
public void testListByNameWhenResponseIs2xx() {
@ -116,9 +120,9 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
new GetResourceRecordsOfResourceRecordResponseTest().expected().toString());
}
HttpRequest listByNameAndType = HttpRequest.builder().method("POST")
HttpRequest listByNameAndType = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_records_by_name_and_type.xml", "application/xml")).build();
public void testListByNameAndTypeWhenResponseIs2xx() {
@ -133,9 +137,9 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
new GetResourceRecordsOfResourceRecordResponseTest().expected().toString());
}
HttpRequest delete = HttpRequest.builder().method("POST")
HttpRequest delete = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/delete_rr.xml", "application/xml")).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404)
@ -146,7 +150,7 @@ public class ResourceRecordApiExpectTest extends BaseUltraDNSWSApiExpectTest {
success.getZoneApi().delete("04053D8E57C7931F");
}
HttpResponse rrDoesntExist = HttpResponse.builder().message("Server Error").statusCode(500)
HttpResponse rrDoesntExist = HttpResponse.builder().message("Server Error").statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/rr_doesnt_exist.xml")).build();
public void testDeleteWhenResponseRRNotFound() {

View File

@ -17,7 +17,10 @@
* under the License.
*/
package org.jclouds.ultradns.ws.features;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.HttpRequest;
@ -34,17 +37,17 @@ import org.testng.annotations.Test;
*/
@Test(groups = "unit", testName = "RoundRobinPoolApiExpectTest")
public class RoundRobinPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
HttpRequest createA = HttpRequest.builder().method("POST")
HttpRequest createA = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/create_rrpool_a.xml", "application/xml")).build();
HttpRequest createAAAA = HttpRequest.builder().method("POST")
HttpRequest createAAAA = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/create_rrpool_aaaa.xml", "application/xml")).build();
HttpResponse createResponse = HttpResponse.builder().statusCode(200)
HttpResponse createResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/rrpool_created.xml", "application/xml")).build();
public void testCreateAWhenResponseIs2xx() {
@ -57,7 +60,7 @@ public class RoundRobinPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
assertEquals(success.getRoundRobinPoolApiForZone("jclouds.org.").createAAAAPoolForHostname("www.jclouds.org.", "foo"), "060339AA04175655");
}
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(500)
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResourceWithContentType("/lbpool_already_exists.xml", "application/xml")).build();
@Test(expectedExceptions = ResourceAlreadyExistsException.class, expectedExceptionsMessageRegExp = "Pool already created for this host name : www.rrpool.adrianc.rrpool.ultradnstest.jclouds.org.")
@ -66,12 +69,12 @@ public class RoundRobinPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
already.getRoundRobinPoolApiForZone("jclouds.org.").createAPoolForHostname("www.jclouds.org.", "foo");
}
HttpRequest list = HttpRequest.builder().method("POST")
HttpRequest list = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_rrpools.xml", "application/xml")).build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/rrpools.xml", "application/xml")).build();
public void testListWhenResponseIs2xx() {
@ -82,12 +85,12 @@ public class RoundRobinPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
new GetRRLoadBalancingPoolsByZoneResponseTest().expected().toString());
}
HttpRequest listRecords = HttpRequest.builder().method("POST")
HttpRequest listRecords = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_rrrecords.xml", "application/xml")).build();
HttpResponse listRecordsResponse = HttpResponse.builder().statusCode(200)
HttpResponse listRecordsResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/records.xml", "application/xml")).build();
public void testListRecordsWhenResponseIs2xx() {
@ -98,9 +101,9 @@ public class RoundRobinPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
new GetResourceRecordsOfResourceRecordResponseTest().expected().toString());
}
HttpRequest delete = HttpRequest.builder().method("POST")
HttpRequest delete = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/delete_lbpool.xml", "application/xml")).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404)
@ -111,7 +114,7 @@ public class RoundRobinPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
success.getRoundRobinPoolApiForZone("jclouds.org.").delete("04053D8E57C7931F");
}
HttpResponse poolDoesntExist = HttpResponse.builder().message("Server Epoolor").statusCode(500)
HttpResponse poolDoesntExist = HttpResponse.builder().message("Server Epoolor").statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/lbpool_doesnt_exist.xml")).build();
public void testDeleteWhenResponseRRNotFound() {

View File

@ -17,7 +17,10 @@
* under the License.
*/
package org.jclouds.ultradns.ws.features;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
@ -28,18 +31,17 @@ import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest;
import org.jclouds.ultradns.ws.parse.GetAllTasksResponseTest;
import org.jclouds.ultradns.ws.parse.GetStatusForTaskResponseResponseTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "TaskApiExpectTest")
public class TaskApiExpectTest extends BaseUltraDNSWSApiExpectTest {
HttpRequest runTest = HttpRequest.builder().method("POST")
HttpRequest runTest = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/run_test.xml", "application/xml")).build();
HttpResponse runTestResponse = HttpResponse.builder().statusCode(200)
HttpResponse runTestResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/taskid.xml", "application/xml")).build();
public void testRunTestWhenResponseIs2xx() {
@ -48,12 +50,12 @@ public class TaskApiExpectTest extends BaseUltraDNSWSApiExpectTest {
assertEquals(success.getTaskApi().runTest("foo").toString(), "8d7a1725-4f4a-4b70-affa-f01dcce1526e");
}
HttpRequest get = HttpRequest.builder().method("POST")
HttpRequest get = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/get_task.xml", "application/xml")).build();
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
HttpResponse getResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/task.xml", "application/xml")).build();
public void testGetWhenResponseIs2xx() {
@ -64,7 +66,7 @@ public class TaskApiExpectTest extends BaseUltraDNSWSApiExpectTest {
new GetStatusForTaskResponseResponseTest().expected().toString());
}
HttpResponse taskDoesntExist = HttpResponse.builder().message("Server Error").statusCode(500)
HttpResponse taskDoesntExist = HttpResponse.builder().message("Server Error").statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/task_doesnt_exist.xml")).build();
public void testGetWhenResponseError2401() {
@ -72,12 +74,12 @@ public class TaskApiExpectTest extends BaseUltraDNSWSApiExpectTest {
assertNull(notFound.getTaskApi().get("0b40c7dd-748d-4c49-8506-26f0c7d2ea9c"));
}
HttpRequest clear = HttpRequest.builder().method("POST")
HttpRequest clear = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/clear_task.xml", "application/xml")).build();
HttpResponse clearResponse = HttpResponse.builder().statusCode(200)
HttpResponse clearResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/task.xml", "application/xml")).build();
public void testClearWhenResponseIs2xx() {
@ -90,12 +92,12 @@ public class TaskApiExpectTest extends BaseUltraDNSWSApiExpectTest {
notFound.getTaskApi().clear("0b40c7dd-748d-4c49-8506-26f0c7d2ea9c");
}
HttpRequest list = HttpRequest.builder().method("POST")
HttpRequest list = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_tasks.xml", "application/xml")).build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/tasks.xml", "application/xml")).build();
public void testListWhenResponseIs2xx() {

View File

@ -17,7 +17,10 @@
* under the License.
*/
package org.jclouds.ultradns.ws.features;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
@ -32,18 +35,17 @@ import org.jclouds.ultradns.ws.parse.GetPoolRecordSpecResponseTest;
import org.jclouds.ultradns.ws.parse.GetTCLoadBalancingPoolsByZoneResponseTest;
import org.jclouds.ultradns.ws.parse.GetTCPoolRecordsResponseTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "TrafficControllerPoolApiExpectTest")
public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest {
HttpRequest create = HttpRequest.builder().method("POST")
HttpRequest create = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/create_tcpool.xml", "application/xml")).build();
HttpResponse createResponse = HttpResponse.builder().statusCode(200)
HttpResponse createResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/tcpool_created.xml", "application/xml")).build();
public void testCreateWhenResponseIs2xx() {
@ -51,7 +53,7 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").createPoolForHostname("www.jclouds.org.", "foo"), "060339AA0417567A");
}
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(500)
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResourceWithContentType("/lbpool_already_exists.xml", "application/xml")).build();
@Test(expectedExceptions = ResourceAlreadyExistsException.class, expectedExceptionsMessageRegExp = "Pool already created for this host name : www.rrpool.adrianc.rrpool.ultradnstest.jclouds.org.")
@ -60,12 +62,12 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
already.getTrafficControllerPoolApiForZone("jclouds.org.").createPoolForHostname("www.jclouds.org.", "foo");
}
HttpRequest list = HttpRequest.builder().method("POST")
HttpRequest list = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_tcpools.xml", "application/xml")).build();
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
HttpResponse listResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/tcpools.xml", "application/xml")).build();
public void testListWhenResponseIs2xx() {
@ -75,12 +77,12 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
new GetTCLoadBalancingPoolsByZoneResponseTest().expected().toString());
}
HttpRequest listRecords = HttpRequest.builder().method("POST")
HttpRequest listRecords = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_tcrecords.xml", "application/xml")).build();
HttpResponse listRecordsResponse = HttpResponse.builder().statusCode(200)
HttpResponse listRecordsResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/tcrecords.xml", "application/xml")).build();
public void testListRecordsWhenResponseIs2xx() {
@ -91,12 +93,12 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
new GetTCPoolRecordsResponseTest().expected().toString());
}
HttpRequest getNameByDName = HttpRequest.builder().method("POST")
HttpRequest getNameByDName = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/get_tcpool_by_dname.xml", "application/xml")).build();
HttpResponse getNameByDNameResponse = HttpResponse.builder().statusCode(200)
HttpResponse getNameByDNameResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/tcpool_name.xml", "application/xml")).build();
public void testGetNameByDNameWhenResponseIs2xx() {
@ -104,7 +106,7 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").getNameByDName("www.foo.com."), "foo");
}
HttpResponse poolDoesntExist = HttpResponse.builder().message("Server Epoolor").statusCode(500)
HttpResponse poolDoesntExist = HttpResponse.builder().message("Server Epoolor").statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/lbpool_doesnt_exist.xml")).build();
public void testGetNameByDNameWhenResponseNotFound() {
@ -112,9 +114,9 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
assertNull(notFound.getTrafficControllerPoolApiForZone("jclouds.org.").getNameByDName("www.foo.com."));
}
HttpRequest delete = HttpRequest.builder().method("POST")
HttpRequest delete = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/delete_lbpool.xml", "application/xml")).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404)
@ -130,12 +132,12 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
notFound.getTrafficControllerPoolApiForZone("jclouds.org.").delete("04053D8E57C7931F");
}
HttpRequest createRecord = HttpRequest.builder().method("POST")
HttpRequest createRecord = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/create_tcrecord.xml", "application/xml")).build();
HttpResponse createRecordResponse = HttpResponse.builder().statusCode(200)
HttpResponse createRecordResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/tcrecord_created.xml", "application/xml")).build();
public void testCreateRecordWhenResponseIs2xx() {
@ -143,9 +145,9 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
assertEquals(success.getTrafficControllerPoolApiForZone("jclouds.org.").addRecordToPoolWithTTL("1.2.3.4", "04053D8E57C7931F", 300), "06063DAC54F8D3D9");
}
HttpRequest createRecordWithWeight = HttpRequest.builder().method("POST")
HttpRequest createRecordWithWeight = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/create_tcrecord_weight.xml", "application/xml")).build();
public void testCreateRecordWithWeightWhenResponseIs2xx() {
@ -155,7 +157,7 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
"04053D8E57C7931F", 300, 0), "06063DAC54F8D3D9");
}
HttpResponse recordAlreadyCreated = HttpResponse.builder().statusCode(500)
HttpResponse recordAlreadyCreated = HttpResponse.builder().statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResourceWithContentType("/tcrecord_already_exists.xml", "application/xml")).build();
@Test(expectedExceptions = ResourceAlreadyExistsException.class, expectedExceptionsMessageRegExp = "Resource Record of type 1 with these attributes already exists in the system.")
@ -164,12 +166,12 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
already.getTrafficControllerPoolApiForZone("jclouds.org.").addRecordToPoolWithTTL("1.2.3.4", "04053D8E57C7931F", 300);
}
HttpRequest getRecordSpec = HttpRequest.builder().method("POST")
HttpRequest getRecordSpec = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/get_poolrecordspec.xml", "application/xml")).build();
HttpResponse getRecordSpecResponse = HttpResponse.builder().statusCode(200)
HttpResponse getRecordSpecResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/poolrecordspec.xml", "application/xml")).build();
public void testGetRecordSpecWhenResponseIs2xx() {
@ -178,7 +180,7 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
new GetPoolRecordSpecResponseTest().expected());
}
HttpResponse recordDoesntExist = HttpResponse.builder().message("Server Error").statusCode(500)
HttpResponse recordDoesntExist = HttpResponse.builder().message("Server Error").statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/tcrecord_doesnt_exist.xml")).build();
public void testGetRecordSpecWhenResponseNotFound() {
@ -192,14 +194,14 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
.weight(98)
.failOverDelay(0)
.threshold(1)
.ttl(200).build();
.ttl(OK.getStatusCode()).build();
HttpRequest updateRecord = HttpRequest.builder().method("POST")
HttpRequest updateRecord = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/update_poolrecord.xml", "application/xml")).build();
HttpResponse updateRecordResponse = HttpResponse.builder().statusCode(200)
HttpResponse updateRecordResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/poolrecord_updated.xml", "application/xml")).build();
public void testUpdateRecordWhenResponseIs2xx() {
@ -213,9 +215,9 @@ public class TrafficControllerPoolApiExpectTest extends BaseUltraDNSWSApiExpectT
notFound.getTrafficControllerPoolApiForZone("jclouds.org.").updateRecord("04053D8E57C7931F", update);
}
HttpRequest deleteRecord = HttpRequest.builder().method("POST")
HttpRequest deleteRecord = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/delete_tcrecord.xml", "application/xml")).build();
HttpResponse deleteRecordResponse = HttpResponse.builder().statusCode(404)

View File

@ -17,7 +17,10 @@
* under the License.
*/
package org.jclouds.ultradns.ws.features;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.OK;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
@ -31,18 +34,17 @@ import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest;
import org.jclouds.ultradns.ws.parse.GetGeneralPropertiesForZoneResponseTest;
import org.jclouds.ultradns.ws.parse.GetZonesOfAccountResponseTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ZoneApiExpectTest")
public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
HttpRequest create = HttpRequest.builder().method("POST")
HttpRequest create = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/create_zone.xml", "application/xml")).build();
HttpResponse createResponse = HttpResponse.builder().statusCode(200)
HttpResponse createResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/zone_created.xml", "application/xml")).build();
public void testCreateWhenResponseIs2xx() {
@ -50,7 +52,7 @@ public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
success.getZoneApi().createInAccount("jclouds.org.", "AAAAAAAAAAAAAAAA");
}
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(500)
HttpResponse alreadyCreated = HttpResponse.builder().statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResourceWithContentType("/zone_already_exists.xml", "application/xml")).build();
@Test(expectedExceptions = ResourceAlreadyExistsException.class, expectedExceptionsMessageRegExp = "Zone already exists in the system.")
@ -59,12 +61,12 @@ public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
already.getZoneApi().createInAccount("jclouds.org.", "AAAAAAAAAAAAAAAA");
}
HttpRequest get = HttpRequest.builder().method("POST")
HttpRequest get = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/get_zone.xml", "application/xml")).build();
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
HttpResponse getResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/zoneproperties.xml", "application/xml")).build();
public void testGetWhenResponseIs2xx() {
@ -75,7 +77,7 @@ public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
new GetGeneralPropertiesForZoneResponseTest().expected().toString());
}
HttpResponse zoneDoesntExist = HttpResponse.builder().message("Server Error").statusCode(500)
HttpResponse zoneDoesntExist = HttpResponse.builder().message("Server Error").statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/zone_doesnt_exist.xml")).build();
public void testGetWhenResponseError2401() {
@ -83,12 +85,12 @@ public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
assertNull(notFound.getZoneApi().get("jclouds.org."));
}
HttpRequest listByAccount = HttpRequest.builder().method("POST")
HttpRequest listByAccount = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_zones_by_account.xml", "application/xml")).build();
HttpResponse listByAccountResponse = HttpResponse.builder().statusCode(200)
HttpResponse listByAccountResponse = HttpResponse.builder().statusCode(OK.getStatusCode())
.payload(payloadFromResourceWithContentType("/zones.xml", "application/xml")).build();
public void testListByAccountWhenResponseIs2xx() {
@ -99,7 +101,7 @@ public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
new GetZonesOfAccountResponseTest().expected().toString());
}
HttpResponse accountDoesntExist = HttpResponse.builder().message("Server Error").statusCode(500)
HttpResponse accountDoesntExist = HttpResponse.builder().message("Server Error").statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/account_doesnt_exist.xml")).build();
@Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Account not found in the system. ID: AAAAAAAAAAAAAAAA")
@ -108,9 +110,9 @@ public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
notFound.getZoneApi().listByAccount("AAAAAAAAAAAAAAAA");
}
HttpRequest listByAccountAndType = HttpRequest.builder().method("POST")
HttpRequest listByAccountAndType = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/list_zones_by_account_and_type.xml", "application/xml")).build();
public void testListByAccountAndTypeWhenResponseIs2xx() {
@ -127,9 +129,9 @@ public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
notFound.getZoneApi().listByAccountAndType("AAAAAAAAAAAAAAAA", Type.PRIMARY);
}
HttpRequest delete = HttpRequest.builder().method("POST")
HttpRequest delete = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/delete_zone.xml", "application/xml")).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404)

View File

@ -17,8 +17,10 @@
* under the License.
*/
package org.jclouds.ultradns.ws.handlers;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.net.HttpHeaders.HOST;
import static javax.ws.rs.HttpMethod.POST;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static org.jclouds.rest.internal.BaseRestApiExpectTest.payloadFromStringWithContentType;
import static org.jclouds.util.Strings2.toStringAndClose;
import static org.testng.Assert.assertEquals;
@ -36,7 +38,6 @@ import org.jclouds.ultradns.ws.UltraDNSWSResponseException;
import org.testng.annotations.Test;
import com.google.inject.Guice;
/**
*
* @author Adrian Cole
@ -48,12 +49,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode0SetsUltraDNSWSResponseException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/list_tasks.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/list_tasks.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/server_fault.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/server_fault.xml")).build();
function.handleError(command, response);
@ -67,12 +71,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode0ForDescriptionMatchingCannotFindSetsResourceNotFoundException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/list_tasks.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/list_tasks.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/task_doesnt_exist.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/task_doesnt_exist.xml")).build();
function.handleError(command, response);
@ -88,13 +95,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode2401SetsResourceNotFoundException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/list_zones_by_account.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/list_zones_by_account.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/account_doesnt_exist.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/account_doesnt_exist.xml")).build();
function.handleError(command, response);
@ -110,12 +119,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode1801SetsResourceNotFoundException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/get_zone.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/get_zone.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/zone_doesnt_exist.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/zone_doesnt_exist.xml")).build();
function.handleError(command, response);
@ -131,12 +143,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode2103SetsResourceNotFoundException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/delete_rr.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/delete_rr.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/rr_doesnt_exist.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/rr_doesnt_exist.xml")).build();
function.handleError(command, response);
@ -152,12 +167,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode1802SetsResourceAlreadyExistsException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/create_zone.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/create_zone.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/zone_already_exists.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/zone_already_exists.xml")).build();
function.handleError(command, response);
@ -173,12 +191,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode2111SetsResourceAlreadyExistsException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/create_rr.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/create_rr.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/rr_already_exists.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/rr_already_exists.xml")).build();
function.handleError(command, response);
@ -197,12 +218,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode2911SetsResourceNotFoundException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/delete_lbpool.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/delete_lbpool.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/lbpool_doesnt_exist.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/lbpool_doesnt_exist.xml")).build();
function.handleError(command, response);
@ -218,12 +242,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode2912SetsResourceAlreadyExistsException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/create_rrpool_a.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/create_rrpool_a.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/lbpool_already_exists.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/lbpool_already_exists.xml")).build();
function.handleError(command, response);
@ -242,12 +269,15 @@ public class UltraDNSWSErrorHandlerTest {
@Test
public void testCode3101SetsResourceNotFoundException() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST")
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader("Host", "ultra-api.ultradns.com:8443").payload(payloadFromResource("/delete_tcrecord.xml")).build();
HttpRequest request = HttpRequest.builder().method(POST)
.endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.addHeader(HOST, "ultra-api.ultradns.com:8443")
.payload(payloadFromResource("/delete_tcrecord.xml")).build();
HttpCommand command = new HttpCommand(request);
HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
.payload(payloadFromResource("/tcrecord_doesnt_exist.xml")).build();
HttpResponse response = HttpResponse.builder()
.message(INTERNAL_SERVER_ERROR.getReasonPhrase())
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
.payload(payloadFromResource("/tcrecord_doesnt_exist.xml")).build();
function.handleError(command, response);