From f93c495c4369f7a5636c35ef84a48baeb5cd00ab Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 29 Jan 2012 20:23:04 +0800 Subject: [PATCH] refactored to use consistent setup*Properties methods like expect tt tests --- .../CloudLoadBalancersAsyncClientTest.java | 32 +--- .../features/LoadBalancerAsyncClientTest.java | 40 +---- .../features/LoadBalancerClientLiveTest.java | 1 + .../features/NodeAsyncClientTest.java | 26 +-- .../features/NodeClientLiveTest.java | 1 + .../CloudServersAsyncClientTest.java | 34 +++- .../cloudservers/CloudServersExpectTest.java | 31 +--- .../handlers/RetryOnRenewExpectTest.java | 166 ++++++------------ .../BaseCloudServersRestClientExpectTest.java | 33 ++-- .../ec2/services/BaseEC2AsyncClientTest.java | 23 +-- .../openstack/nova/NovaAsyncClientTest.java | 5 +- ...indAsHostPrefixIfConfiguredNoPathTest.java | 4 +- .../BindAsHostPrefixIfConfiguredTest.java | 8 +- .../RequestAuthorizeSignatureTest.java | 5 +- .../s3/internal/BaseS3AsyncClientTest.java | 24 +-- .../swift/CommonSwiftClientTest.java | 4 +- .../BindCatalogItemToXmlPayloadTest.java | 20 +-- .../BindDeployVAppParamsToXmlPayloadTest.java | 20 +-- ...ateVAppTemplateParamsToXmlPayloadTest.java | 14 +- ...workConnectionSectionToXmlPayloadTest.java | 14 +- ...indUndeployVAppParamsToXmlPayloadTest.java | 22 ++- ...ateVAppTemplateParamsToXmlPayloadTest.java | 18 +- ...BindNodeConfigurationToXmlPayloadTest.java | 22 ++- ...BindVAppConfigurationToXmlPayloadTest.java | 23 +-- .../java/org/jclouds/rest/RestClientTest.java | 16 +- .../jclouds/aws/s3/AWSS3AsyncClientTest.java | 15 +- 26 files changed, 234 insertions(+), 387 deletions(-) diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersAsyncClientTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersAsyncClientTest.java index 1c1121b75e..dbc7a26c93 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersAsyncClientTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/CloudLoadBalancersAsyncClientTest.java @@ -18,22 +18,11 @@ */ package org.jclouds.cloudloadbalancers; -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.cloudloadbalancers.reference.RackspaceConstants.PROPERTY_ACCOUNT_ID; -import static org.jclouds.cloudloadbalancers.reference.Region.DFW; -import static org.jclouds.location.reference.LocationConstants.ENDPOINT; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - import java.io.IOException; -import java.util.Properties; import java.util.concurrent.ExecutionException; -import org.jclouds.cloudloadbalancers.features.BaseCloudLoadBalancersAsyncClientTest; +import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersAsyncClientTest; import org.jclouds.http.HttpRequest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -79,23 +68,4 @@ public class CloudLoadBalancersAsyncClientTest extends BaseCloudLoadBalancersAsy } - protected String provider = "cloudloadbalancers"; - - @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory(getProperties()).createContextSpec(provider, "user", "password", new Properties()); - } - - @Override - protected Properties getProperties() { - Properties overrides = new Properties(); - overrides.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com"); - overrides.setProperty(PROPERTY_API_VERSION, "1"); - overrides.setProperty(PROPERTY_REGIONS, "DFW"); - overrides.setProperty(PROPERTY_REGION + "." + DFW + "." + ENDPOINT, String - .format("https://dfw.loadbalancers.api.rackspacecloud.com/v{%s}/{%s}", PROPERTY_API_VERSION, - PROPERTY_ACCOUNT_ID)); - overrides.setProperty(provider + ".contextbuilder", CloudLoadBalancersContextBuilder.class.getName()); - return overrides; - } } diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClientTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClientTest.java index 32fb688b04..bacd9bb7f5 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClientTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClientTest.java @@ -18,26 +18,18 @@ */ package org.jclouds.cloudloadbalancers.features; -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - import java.io.IOException; import java.lang.reflect.Method; -import java.util.Properties; -import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient; -import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient; -import org.jclouds.cloudloadbalancers.CloudLoadBalancersContextBuilder; import org.jclouds.cloudloadbalancers.domain.LoadBalancerAttributes; -import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest; import org.jclouds.cloudloadbalancers.domain.LoadBalancerAttributes.Builder; +import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest; import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type; import org.jclouds.cloudloadbalancers.functions.UnwrapLoadBalancer; import org.jclouds.cloudloadbalancers.functions.UnwrapLoadBalancers; +import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersAsyncClientTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -61,7 +53,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie HttpRequest httpRequest = processor.createRequest(method); assertRequestLineEquals(httpRequest, - "GET https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers HTTP/1.1"); + "GET https://lon.loadbalancers.api.rackspacecloud.com/v1.0/10001786/loadbalancers HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertPayloadEquals(httpRequest, null, null, false); @@ -78,7 +70,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie HttpRequest httpRequest = processor.createRequest(method, 5); assertRequestLineEquals(httpRequest, - "GET https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/5 HTTP/1.1"); + "GET https://lon.loadbalancers.api.rackspacecloud.com/v1.0/10001786/loadbalancers/5 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertPayloadEquals(httpRequest, null, null, false); @@ -96,7 +88,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie "HTTP").port(80).virtualIPType(Type.PUBLIC).build()); assertRequestLineEquals(httpRequest, - "POST https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers HTTP/1.1"); + "POST https://lon.loadbalancers.api.rackspacecloud.com/v1.0/10001786/loadbalancers HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertPayloadEquals( httpRequest, @@ -117,7 +109,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie "HTTP").port(80).virtualIPId(4).build()); assertRequestLineEquals(httpRequest, - "POST https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers HTTP/1.1"); + "POST https://lon.loadbalancers.api.rackspacecloud.com/v1.0/10001786/loadbalancers HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertPayloadEquals( httpRequest, @@ -138,7 +130,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie HttpRequest httpRequest = processor.createRequest(method, 2, Builder.name("foo")); assertRequestLineEquals(httpRequest, - "PUT https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/2 HTTP/1.1"); + "PUT https://lon.loadbalancers.api.rackspacecloud.com/v1.0/10001786/loadbalancers/2 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertPayloadEquals(httpRequest, "{\"loadBalancer\":{\"name\":\"foo\"}}", "application/json", false); @@ -155,7 +147,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie HttpRequest httpRequest = processor.createRequest(method, 5); assertRequestLineEquals(httpRequest, - "DELETE https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/5 HTTP/1.1"); + "DELETE https://lon.loadbalancers.api.rackspacecloud.com/v1.0/10001786/loadbalancers/5 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: */*\n"); assertPayloadEquals(httpRequest, null, null, false); @@ -173,20 +165,4 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie }; } - protected String provider = "cloudloadbalancers"; - - @Override - public RestContextSpec createContextSpec() { - return new RestContextFactory(getProperties()).createContextSpec(provider, "user", "password", new Properties()); - } - - @Override - protected Properties getProperties() { - Properties overrides = new Properties(); - overrides.setProperty(PROPERTY_REGIONS, "US"); - overrides.setProperty(PROPERTY_API_VERSION, "1"); - overrides.setProperty(provider + ".endpoint", "https://auth"); - overrides.setProperty(provider + ".contextbuilder", CloudLoadBalancersContextBuilder.class.getName()); - return overrides; - } } diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java index 7b925a3671..e11bda0e72 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java @@ -30,6 +30,7 @@ import org.jclouds.cloudloadbalancers.domain.LoadBalancerAttributes; import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest; import org.jclouds.cloudloadbalancers.domain.NodeRequest; import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type; +import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersClientLiveTest; import org.testng.annotations.Test; import com.google.common.collect.Iterables; diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/NodeAsyncClientTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/NodeAsyncClientTest.java index 3a8f43049f..caf4bf7915 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/NodeAsyncClientTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/NodeAsyncClientTest.java @@ -18,27 +18,19 @@ */ package org.jclouds.cloudloadbalancers.features; -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; - import java.io.IOException; import java.lang.reflect.Method; import java.util.Collections; -import java.util.Properties; import java.util.Set; -import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient; -import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient; -import org.jclouds.cloudloadbalancers.CloudLoadBalancersContextBuilder; import org.jclouds.cloudloadbalancers.domain.NodeAttributes; import org.jclouds.cloudloadbalancers.domain.NodeAttributes.Builder; import org.jclouds.cloudloadbalancers.domain.NodeRequest; import org.jclouds.cloudloadbalancers.domain.internal.BaseNode.Condition; +import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersAsyncClientTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -153,20 +145,4 @@ public class NodeAsyncClientTest extends BaseCloudLoadBalancersAsyncClientTest createContextSpec() { - return new RestContextFactory(getProperties()).createContextSpec(provider, "user", "password", new Properties()); - } - - @Override - protected Properties getProperties() { - Properties overrides = new Properties(); - overrides.setProperty(PROPERTY_REGIONS, "US"); - overrides.setProperty(PROPERTY_API_VERSION, "1"); - overrides.setProperty(provider + ".endpoint", "https://auth"); - overrides.setProperty(provider + ".contextbuilder", CloudLoadBalancersContextBuilder.class.getName()); - return overrides; - } } diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/NodeClientLiveTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/NodeClientLiveTest.java index a3fdb0989b..5a905a3689 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/NodeClientLiveTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/features/NodeClientLiveTest.java @@ -37,6 +37,7 @@ import org.jclouds.cloudloadbalancers.domain.NodeAttributes; import org.jclouds.cloudloadbalancers.domain.NodeRequest; import org.jclouds.cloudloadbalancers.domain.LoadBalancer.Status; import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type; +import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersClientLiveTest; import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersAsyncClientTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersAsyncClientTest.java index e77564c7e3..fe4b7529ff 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersAsyncClientTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersAsyncClientTest.java @@ -36,6 +36,7 @@ import java.net.UnknownHostException; import java.util.Date; import java.util.Properties; +import javax.inject.Singleton; import javax.ws.rs.core.MediaType; import org.jclouds.cloudservers.config.CloudServersRestClientModule; @@ -43,20 +44,23 @@ import org.jclouds.cloudservers.domain.BackupSchedule; import org.jclouds.cloudservers.domain.DailyBackup; import org.jclouds.cloudservers.domain.RebootType; import org.jclouds.cloudservers.domain.WeeklyBackup; +import org.jclouds.cloudservers.internal.BaseCloudServersRestClientExpectTest.TestAuthenticationServiceModule; import org.jclouds.cloudservers.options.CreateServerOptions; import org.jclouds.cloudservers.options.CreateSharedIpGroupOptions; import org.jclouds.cloudservers.options.ListOptions; import org.jclouds.cloudservers.options.RebuildServerOptions; +import org.jclouds.domain.Credentials; import org.jclouds.http.HttpRequest; import org.jclouds.http.RequiresHttp; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReturnFalseOn404; import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.UnwrapOnlyJsonValue; -import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse; -import org.jclouds.openstack.TestOpenStackAuthenticationModule; import org.jclouds.openstack.filters.AddTimestampQuery; import org.jclouds.openstack.filters.AuthenticateRequest; +import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule.GetAuth; +import org.jclouds.openstack.keystone.v1_1.domain.Auth; +import org.jclouds.openstack.keystone.v1_1.parse.ParseAuthTest; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; @@ -71,6 +75,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.inject.Module; +import com.google.inject.Provides; import com.google.inject.TypeLiteral; /** @@ -78,8 +83,9 @@ import com.google.inject.TypeLiteral; * * @author Adrian Cole */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", singleThreaded=true, testName = "CloudServersAsyncClientTest") +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", singleThreaded = true, testName = "CloudServersAsyncClientTest") public class CloudServersAsyncClientTest extends RestClientTest { private static final Class listOptionsVarargsClass = new ListOptions[] {}.getClass(); private static final Class createServerOptionsVarargsClass = new CreateServerOptions[] {} @@ -890,11 +896,22 @@ public class CloudServersAsyncClientTest extends RestClientTest createContextSpec() { - return new RestContextFactory(getProperties()).createContextSpec(provider, "user", "password", new Properties()); + return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties()); } @Override - protected Properties getProperties() { + protected Properties setupProperties() { Properties overrides = new Properties(); overrides.setProperty(PROPERTY_REGIONS, "US"); overrides.setProperty(PROPERTY_API_VERSION, "1"); overrides.setProperty(provider + ".endpoint", "https://auth"); - overrides.setProperty(provider + ".contextbuilder", CloudServersContextBuilder.class.getName()); return overrides; } } diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersExpectTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersExpectTest.java index 7c7a2ae6d1..00878df18b 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersExpectTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersExpectTest.java @@ -34,46 +34,21 @@ import com.google.common.collect.ImmutableMultimap; @Test(groups = "unit", testName = "CloudServersExpectTest") public class CloudServersExpectTest extends BaseCloudServersRestClientExpectTest { - HttpRequest initialAuth = HttpRequest.builder().method("GET").endpoint(URI.create("https://auth/v1.0")) - .headers( - ImmutableMultimap. builder() - .put("X-Auth-User", "identity") - .put("X-Auth-Key", "credential") - .put("Accept", "*/*").build()).build(); - - String authToken = "d6245d35-22a0-47c0-9770-2c5097da25fc"; - - HttpResponse responseWithUrls = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content") - .headers(ImmutableMultimap.builder() - .put("Server", "Apache/2.2.3 (Red Hat)") - .put("vary", "X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass") - .put("X-Storage-Url", "https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") - .put("Cache-Control", "s-maxage=86399") - .put("Content-Type", "text/xml") - .put("Date", "Tue, 10 Jan 2012 22:08:47 GMT") - .put("X-Auth-Token", authToken) - .put("X-Server-Management-Url","https://servers.api.rackspacecloud.com/v1.0/413274") - .put("X-Storage-Token", authToken) - .put("Connection", "Keep-Alive") - .put("X-CDN-Management-Url", "https://cdn1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") - .put("Content-Length", "0") - .build()).build(); - public void deleteImageReturnsTrueOn200AndFalseOn404() { HttpRequest deleteImage11 = HttpRequest.builder().method("DELETE").endpoint( - URI.create("https://servers.api.rackspacecloud.com/v1.0/413274/images/11?now=1257695648897")).headers( + URI.create("https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/11?now=1257695648897")).headers( ImmutableMultimap. builder() .put("X-Auth-Token", authToken).build()).build(); HttpResponse imageDeleted = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content").build(); - CloudServersClient clientWhenImageExists = requestsSendResponses(initialAuth, responseWithUrls, deleteImage11, imageDeleted); + CloudServersClient clientWhenImageExists = requestsSendResponses(initialAuth, responseWithAuth, deleteImage11, imageDeleted); assert clientWhenImageExists.deleteImage(11); HttpResponse imageNotFound = HttpResponse.builder().statusCode(404).message("HTTP/1.1 404 Not Found").build(); - CloudServersClient clientWhenImageDoesntExist = requestsSendResponses(initialAuth, responseWithUrls, deleteImage11, imageNotFound); + CloudServersClient clientWhenImageDoesntExist = requestsSendResponses(initialAuth, responseWithAuth, deleteImage11, imageNotFound); assert !clientWhenImageDoesntExist.deleteImage(11); } diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/handlers/RetryOnRenewExpectTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/handlers/RetryOnRenewExpectTest.java index 1f4d2ce184..3ac5c99ff7 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/handlers/RetryOnRenewExpectTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/handlers/RetryOnRenewExpectTest.java @@ -40,137 +40,79 @@ public class RetryOnRenewExpectTest extends BaseCloudServersRestClientExpectTest @Test public void testShouldReauthenticateOn401() { - String authToken = "d6245d35-22a0-47c0-9770-2c5097da25fc"; - String authToken2 = "12345678-9012-47c0-9770-2c5097da25fc"; - - HttpRequest initialAuth = HttpRequest.builder().method("GET").endpoint(URI.create("https://auth/v1.0")) - .headers( - ImmutableMultimap. builder() - .put("X-Auth-User", "identity") - .put("X-Auth-Key", "credential") - .put("Accept", "*/*").build()).build(); - - - HttpResponse responseWithUrls = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content") - .headers(ImmutableMultimap.builder() - .put("Server", "Apache/2.2.3 (Red Hat)") - .put("vary", "X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass") - .put("X-Storage-Url", "https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") - .put("Cache-Control", "s-maxage=86399") - .put("Content-Type", "text/xml") - .put("Date", "Tue, 10 Jan 2012 22:08:47 GMT") - .put("X-Auth-Token", authToken) - .put("X-Server-Management-Url","https://servers.api.rackspacecloud.com/v1.0/413274") - .put("X-Storage-Token", authToken) - .put("Connection", "Keep-Alive") - .put("X-CDN-Management-Url", "https://cdn1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") - .put("Content-Length", "0") - .build()).build(); - - HttpRequest deleteImage = HttpRequest.builder().method("DELETE").endpoint( - URI.create("https://servers.api.rackspacecloud.com/v1.0/413274/images/11?now=1257695648897")).headers( - ImmutableMultimap. builder() - .put("X-Auth-Token", authToken).build()).build(); - HttpResponse pleaseRenew = HttpResponse.builder().statusCode(401) - .message("HTTP/1.1 401 Unauthorized") - .payload(Payloads.newStringPayload("[{\"unauthorized\":{\"message\":\"Invalid authentication token. Please renew.\",\"code\":401}}]")) - .build(); - + HttpRequest deleteImage = HttpRequest.builder().method("DELETE") + .endpoint(URI.create("https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/11?now=1257695648897")) + .headers(ImmutableMultimap. builder().put("X-Auth-Token", authToken).build()).build(); + + HttpResponse pleaseRenew = HttpResponse + .builder() + .statusCode(401) + .message("HTTP/1.1 401 Unauthorized") + .payload( + Payloads + .newStringPayload("[{\"unauthorized\":{\"message\":\"Invalid authentication token. Please renew.\",\"code\":401}}]")) + .build(); + // second auth uses same creds as initial one HttpRequest redoAuth = initialAuth; - HttpResponse responseWithUrls2 = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content") - .headers(ImmutableMultimap.builder() - .put("Server", "Apache/2.2.3 (Red Hat)") - .put("vary", "X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass") - .put("X-Storage-Url", "https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") - .put("Cache-Control", "s-maxage=86399") - .put("Content-Type", "text/xml") - .put("Date", "Tue, 10 Jan 2012 22:08:47 GMT") - .put("X-Auth-Token", authToken2) - .put("X-Server-Management-Url","https://servers.api.rackspacecloud.com/v1.0/413274") - .put("X-Storage-Token", authToken2) - .put("Connection", "Keep-Alive") - .put("X-CDN-Management-Url", "https://cdn1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") - .put("Content-Length", "0") - .build()).build(); - - HttpRequest deleteImage2 = HttpRequest.builder().method("DELETE").endpoint( - URI.create("https://servers.api.rackspacecloud.com/v1.0/413274/images/11?now=1257695648897")).headers( - ImmutableMultimap. builder() - .put("X-Auth-Token", authToken2).build()).build(); + String authToken2 = "12345678-9012-47c0-9770-2c5097da25fc"; + + HttpResponse responseWithUrls2 = HttpResponse + .Builder.from(responseWithAuth) + .payload( + Payloads.newPayload(responseWithAuth.getPayload().getRawContent().toString() + .replace(authToken, authToken2))).build(); + + HttpRequest deleteImage2 = HttpRequest.builder().method("DELETE") + .endpoint(URI.create("https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/11?now=1257695648897")) + .headers(ImmutableMultimap. builder().put("X-Auth-Token", authToken2).build()).build(); HttpResponse imageDeleted = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content").build(); - CloudServersClient clientWhenImageExists = orderedRequestsSendResponses(initialAuth, responseWithUrls, - deleteImage, pleaseRenew, redoAuth, responseWithUrls2, deleteImage2, imageDeleted); - + CloudServersClient clientWhenImageExists = orderedRequestsSendResponses(initialAuth, responseWithAuth, + deleteImage, pleaseRenew, redoAuth, responseWithUrls2, deleteImage2, imageDeleted); + assert clientWhenImageExists.deleteImage(11); } - @Test(expectedExceptions=AuthorizationException.class) + @Test(expectedExceptions = AuthorizationException.class) public void testDoesNotReauthenticateOnFatal401() { - String authToken = "d6245d35-22a0-47c0-9770-2c5097da25fc"; - - HttpRequest initialAuth = HttpRequest.builder().method("GET").endpoint(URI.create("https://auth/v1.0")) - .headers( - ImmutableMultimap. builder() - .put("X-Auth-User", "identity") - .put("X-Auth-Key", "credential") - .put("Accept", "*/*").build()).build(); - - - HttpResponse responseWithUrls = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content") - .headers(ImmutableMultimap.builder() - .put("Server", "Apache/2.2.3 (Red Hat)") - .put("vary", "X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass") - .put("X-Storage-Url", "https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") - .put("Cache-Control", "s-maxage=86399") - .put("Content-Type", "text/xml") - .put("Date", "Tue, 10 Jan 2012 22:08:47 GMT") - .put("X-Auth-Token", authToken) - .put("X-Server-Management-Url","https://servers.api.rackspacecloud.com/v1.0/413274") - .put("X-Storage-Token", authToken) - .put("Connection", "Keep-Alive") - .put("X-CDN-Management-Url", "https://cdn1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") - .put("Content-Length", "0") - .build()).build(); - - HttpRequest deleteImage = HttpRequest.builder().method("DELETE").endpoint( - URI.create("https://servers.api.rackspacecloud.com/v1.0/413274/images/11?now=1257695648897")).headers( - ImmutableMultimap. builder() - .put("X-Auth-Token", authToken).build()).build(); + HttpRequest deleteImage = HttpRequest.builder().method("DELETE") + .endpoint(URI.create("https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/11?now=1257695648897")) + .headers(ImmutableMultimap. builder().put("X-Auth-Token", authToken).build()).build(); - HttpResponse unauthResponse = HttpResponse.builder().statusCode(401) - .message("HTTP/1.1 401 Unauthorized") - .payload(Payloads.newStringPayload("[{\"unauthorized\":{\"message\":\"Fatal unauthorized.\",\"code\":401}}]")) - .build(); + HttpResponse unauthResponse = HttpResponse + .builder() + .statusCode(401) + .message("HTTP/1.1 401 Unauthorized") + .payload( + Payloads.newStringPayload("[{\"unauthorized\":{\"message\":\"Fatal unauthorized.\",\"code\":401}}]")) + .build(); + + CloudServersClient client = orderedRequestsSendResponses(initialAuth, responseWithAuth, deleteImage, + unauthResponse); - CloudServersClient client = orderedRequestsSendResponses(initialAuth, responseWithUrls, - deleteImage, unauthResponse); - client.deleteImage(11); } - // FIXME stack trace shows the AuthorizationException, but it's buried inside a guice TestException - @Test(expectedExceptions=AuthorizationException.class) + // FIXME stack trace shows the AuthorizationException, but it's buried inside + // a guice TestException + @Test(expectedExceptions = AuthorizationException.class) public void testDoesNotReauthenticateOnAuthentication401() { - HttpRequest initialAuth = HttpRequest.builder().method("GET").endpoint(URI.create("https://auth/v1.0")) - .headers( - ImmutableMultimap. builder() - .put("X-Auth-User", "identity") - .put("X-Auth-Key", "credential") - .put("Accept", "*/*").build()).build(); - - - HttpResponse unauthResponse = HttpResponse.builder().statusCode(401) - .message("HTTP/1.1 401 Unauthorized") - .payload(Payloads.newStringPayload("[{\"unauthorized\":{\"message\":\"A different message implying fatal.\",\"code\":401}}]")) - .build(); + + HttpResponse unauthResponse = HttpResponse + .builder() + .statusCode(401) + .message("HTTP/1.1 401 Unauthorized") + .payload( + Payloads + .newStringPayload("[{\"unauthorized\":{\"message\":\"A different message implying fatal.\",\"code\":401}}]")) + .build(); CloudServersClient client = requestSendsResponse(initialAuth, unauthResponse); - + client.deleteImage(11); } } diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/internal/BaseCloudServersRestClientExpectTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/internal/BaseCloudServersRestClientExpectTest.java index 94050b8790..d3a4a03d5f 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/internal/BaseCloudServersRestClientExpectTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/internal/BaseCloudServersRestClientExpectTest.java @@ -29,9 +29,9 @@ import org.jclouds.cloudservers.CloudServersPropertiesBuilder; import org.jclouds.cloudservers.config.CloudServersRestClientModule; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.http.RequiresHttp; -import org.jclouds.openstack.config.OpenStackAuthenticationModule; import org.jclouds.openstack.filters.AddTimestampQuery; -import org.jclouds.rest.BaseRestClientExpectTest; +import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule; +import org.jclouds.openstack.keystone.v1_1.internal.BaseKeyStoneRestClientExpectTest; import org.jclouds.rest.ConfiguresRestClient; import com.google.common.base.Supplier; @@ -42,7 +42,7 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class BaseCloudServersRestClientExpectTest extends BaseRestClientExpectTest { +public class BaseCloudServersRestClientExpectTest extends BaseKeyStoneRestClientExpectTest { public BaseCloudServersRestClientExpectTest() { provider = "cloudservers"; @@ -52,7 +52,7 @@ public class BaseCloudServersRestClientExpectTest extends BaseRestClientExpectTe protected Properties setupRestProperties() { Properties overrides = new Properties(); overrides.setProperty(PROPERTY_REGIONS, "US"); - overrides.setProperty(provider + ".endpoint", "https://auth"); + overrides.setProperty(provider + ".endpoint", endpoint); overrides.setProperty(provider + ".contextbuilder", CloudServersContextBuilder.class.getName()); overrides.setProperty(provider + ".propertiesbuilder", CloudServersPropertiesBuilder.class.getName()); return overrides; @@ -61,23 +61,14 @@ public class BaseCloudServersRestClientExpectTest extends BaseRestClientExpectTe protected static final String CONSTANT_DATE = "2009-11-08T15:54:08.897Z"; /** - * override so that we can control the timestamp used in {@link AddTimestampQuery} + * override so that we can control the timestamp used in + * {@link AddTimestampQuery} */ - static class TestOpenStackAuthenticationModule extends OpenStackAuthenticationModule { + public static class TestAuthenticationServiceModule extends AuthenticationServiceModule { @Override protected void configure() { super.configure(); } - - @Override - public Supplier provideCacheBusterDate() { - return new Supplier() { - public Date get() { - return new SimpleDateFormatDateService().iso8601DateParse(CONSTANT_DATE); - } - }; - } - } @Override @@ -89,8 +80,16 @@ public class BaseCloudServersRestClientExpectTest extends BaseRestClientExpectTe @RequiresHttp protected static class TestCloudServersRestClientModule extends CloudServersRestClientModule { private TestCloudServersRestClientModule() { - super(new TestOpenStackAuthenticationModule()); + super(new TestAuthenticationServiceModule()); } + @Override + public Supplier provideCacheBusterDate() { + return new Supplier() { + public Date get() { + return new SimpleDateFormatDateService().iso8601DateParse(CONSTANT_DATE); + } + }; + } } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java index baed7f0880..dff62b2aba 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.net.URI; import java.util.Map; -import java.util.Properties; import javax.inject.Singleton; @@ -46,10 +45,11 @@ import org.jclouds.rest.RestContextSpec; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.inject.Module; import com.google.inject.Provides; @@ -135,19 +135,14 @@ public abstract class BaseEC2AsyncClientTest extends RestClientTest { protected String provider = "ec2"; - @Override - protected Properties getProperties() { - Properties overrides = new Properties(); - overrides.setProperty(provider + ".endpoint", "https://ec2.us-east-1.amazonaws.com"); - overrides.setProperty(provider + ".propertiesbuilder", EC2PropertiesBuilder.class.getName()); - overrides.setProperty(provider + ".contextbuilder", EC2ContextBuilder.class.getName()); - return overrides; - } - + /** + * this is only here as "ec2" is not in rest.properties + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public RestContextSpec createContextSpec() { - return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", - new Properties()); + return RestContextFactory. contextSpec(provider, "https://ec2.us-east-1.amazonaws.com", + EC2AsyncClient.VERSION, "", "", "identity", "credential", EC2Client.class, EC2AsyncClient.class, + (Class) EC2PropertiesBuilder.class, (Class) EC2ContextBuilder.class, ImmutableSet. of()); } - } diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java index e382409fc5..4726502b5c 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java @@ -788,15 +788,14 @@ public class NovaAsyncClientTest extends RestClientTest { @Override public RestContextSpec createContextSpec() { - return new RestContextFactory(getProperties()).createContextSpec(provider, "user", "password", new Properties()); + return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties()); } @Override - protected Properties getProperties() { + protected Properties setupProperties() { Properties overrides = new Properties(); overrides.setProperty(PROPERTY_API_VERSION, "api-version"); overrides.setProperty(provider + ".endpoint", "http://endpoint"); - overrides.setProperty(provider + ".contextbuilder", NovaContextBuilder.class.getName()); return overrides; } } diff --git a/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredNoPathTest.java b/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredNoPathTest.java index b4daa5c1ce..09ef24a2bb 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredNoPathTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredNoPathTest.java @@ -56,8 +56,8 @@ public class BindAsHostPrefixIfConfiguredNoPathTest extends BaseS3AsyncClientTes @Override - protected Properties getProperties() { - Properties properties = super.getProperties(); + protected Properties setupProperties() { + Properties properties = super.setupProperties(); properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false"); return properties; } diff --git a/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredTest.java b/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredTest.java index a71b488422..489b3bc09f 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfiguredTest.java @@ -45,6 +45,9 @@ import com.google.inject.TypeLiteral; @Test(groups = "unit", testName = "BindAsHostPrefixIfConfiguredTest") public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest { + public BindAsHostPrefixIfConfiguredTest(){ + endpoint = "http://euc/services/Walrus"; + } @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { @@ -93,9 +96,8 @@ public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest extends Res } protected String provider = "s3"; + protected String endpoint = "https://s3.amazonaws.com"; - @Override - protected Properties getProperties() { - Properties overrides = new Properties(); - overrides.setProperty(provider + ".endpoint", "https://s3.amazonaws.com"); - overrides.setProperty(provider + ".propertiesbuilder", S3PropertiesBuilder.class.getName()); - overrides.setProperty(provider + ".contextbuilder", S3ContextBuilder.class.getName()); - return overrides; - } - + /** + * this is only here as "s3" is not in rest.properties + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public RestContextSpec createContextSpec() { - return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", - new Properties()); + return RestContextFactory. contextSpec(provider, endpoint, + S3AsyncClient.VERSION, "", "", "identity", "credential", S3Client.class, S3AsyncClient.class, + (Class) S3PropertiesBuilder.class, (Class) S3ContextBuilder.class, ImmutableSet. of()); } } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java index b721c380bb..7e0508faff 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java @@ -77,11 +77,11 @@ public abstract class CommonSwiftClientTest ex @Override public RestContextSpec createContextSpec() { - return new RestContextFactory().createContextSpec(provider, "user", "password", new Properties()); + return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties()); } @Override - protected Properties getProperties() { + protected Properties setupProperties() { Properties properties = new Properties(); properties.setProperty(PROPERTY_REGIONS, "US"); properties.setProperty(PROPERTY_ENDPOINT, "https://auth"); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayloadTest.java index bb614b49a1..28d506bd0c 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayloadTest.java @@ -18,11 +18,10 @@ */ package org.jclouds.vcloud.binders; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; -import static org.easymock.classextension.EasyMock.verify; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import java.io.IOException; import java.net.URI; @@ -32,14 +31,14 @@ import java.util.Properties; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.options.CatalogItemOptions; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.name.Names; /** * Tests behavior of {@code BindCatalogItemToXmlPayload} @@ -48,14 +47,13 @@ import com.google.inject.name.Names; */ @Test(groups = "unit") public class BindCatalogItemToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() { @Override - protected void configure() { - Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); + protected void bindConfigurations() { + bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); } - }); + })); public void testDefault() throws IOException { String expected = "mydescriptionbar"; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayloadTest.java index 88dcd28b85..fbece0ba68 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayloadTest.java @@ -18,11 +18,10 @@ */ package org.jclouds.vcloud.binders; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; -import static org.easymock.classextension.EasyMock.verify; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import java.io.IOException; import java.net.URI; @@ -31,13 +30,13 @@ import java.util.Properties; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; import com.google.common.collect.Maps; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.name.Names; /** * Tests behavior of {@code BindDeployVAppParamsToXmlPayload} @@ -46,14 +45,13 @@ import com.google.inject.name.Names; */ @Test(groups = "unit") public class BindDeployVAppParamsToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() { @Override - protected void configure() { - Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); + protected void bindConfigurations() { + bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); } - }); + })); public void testPowerOnTrue() throws IOException { String expected = ""; diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index d77d684bd3..c5647b7ce8 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.vcloud.binders; -import static com.google.common.base.Preconditions.checkNotNull; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; @@ -44,6 +43,8 @@ import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; import com.google.common.base.Function; @@ -54,11 +55,9 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Provides; -import com.google.inject.name.Names; /** * Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload} @@ -69,7 +68,7 @@ import com.google.inject.name.Names; public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { Injector createInjector(final URI vAppTemplate, final VAppTemplate value) { - return Guice.createInjector(new AbstractModule() { + return Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() { @SuppressWarnings("unused") @Provides @@ -88,9 +87,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { } @Override - protected void configure() { - Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); + protected void bindConfigurations() { + bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); } @SuppressWarnings("unused") @@ -108,7 +106,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { return new ReferenceTypeImpl(null, null, URI .create("https://vcenterprise.bluelock.com/api/v1.0/network/1990")); } - }); + })); } public void testDefault() throws IOException { diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayloadTest.java index 5286f571de..2975f56af1 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayloadTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.vcloud.binders; -import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -30,13 +29,13 @@ import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.domain.NetworkConnection; import org.jclouds.vcloud.domain.NetworkConnectionSection; import org.jclouds.vcloud.domain.network.IpAddressAllocationMode; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.name.Names; /** * Tests behavior of {@code BindNetworkConnectionSectionToXmlPayload} @@ -45,14 +44,13 @@ import com.google.inject.name.Names; */ @Test(groups = "unit") public class BindNetworkConnectionSectionToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() { @Override - protected void configure() { - Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); + protected void bindConfigurations() { + bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); } - }); + })); public void testWithIpAllocationModeNONE() throws IOException { diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayloadTest.java index bf8c30fcf5..123a07fc14 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayloadTest.java @@ -18,11 +18,10 @@ */ package org.jclouds.vcloud.binders; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; -import static org.easymock.classextension.EasyMock.verify; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import java.io.IOException; import java.net.URI; @@ -31,13 +30,13 @@ import java.util.Properties; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; import com.google.common.collect.Maps; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.name.Names; /** * Tests behavior of {@code BindUndeployVAppParamsToXmlPayload} @@ -46,15 +45,14 @@ import com.google.inject.name.Names; */ @Test(groups = "unit") public class BindUndeployVAppParamsToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() { @Override - protected void configure() { - Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); + protected void bindConfigurations() { + bindProperties(new VCloudPropertiesBuilder(new Properties()).build()); } - }); - + })); + public void testSaveStateTrue() throws IOException { String expected = ""; diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index 69fdacdd52..aae71237d5 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -18,10 +18,9 @@ */ package org.jclouds.trmk.vcloud_0_8.binders; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.EasyMock.replay; import java.io.IOException; import java.net.URI; @@ -38,6 +37,8 @@ import org.jclouds.trmk.vcloud_0_8.endpoints.Network; import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions; import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.NetworkConfig; import org.jclouds.util.Strings2; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; import com.google.common.collect.HashMultimap; @@ -45,11 +46,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Provides; -import com.google.inject.name.Names; /** * Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload} @@ -58,12 +57,11 @@ import com.google.inject.name.Names; */ @Test(groups = "unit") public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() { @Override - protected void configure() { - Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(), "properties")); + protected void bindConfigurations() { + bindProperties(new TerremarkVCloudPropertiesBuilder(new Properties()).build()); } @SuppressWarnings("unused") @@ -73,7 +71,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { ReferenceType provideNetwork() { return new ReferenceTypeImpl(null, null, URI.create("https://vcloud.safesecureweb.com/network/1990")); } - }); + })); public void testAllOptions() throws IOException { diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindNodeConfigurationToXmlPayloadTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindNodeConfigurationToXmlPayloadTest.java index 1c24f27324..a4473b2e81 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindNodeConfigurationToXmlPayloadTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindNodeConfigurationToXmlPayloadTest.java @@ -18,11 +18,10 @@ */ package org.jclouds.trmk.vcloud_0_8.binders; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; -import static org.easymock.classextension.EasyMock.verify; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME; @@ -35,14 +34,13 @@ import java.util.Properties; import org.jclouds.http.HttpRequest; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudPropertiesBuilder; -import org.jclouds.trmk.vcloud_0_8.binders.BindNodeConfigurationToXmlPayload; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.name.Names; /** * Tests behavior of {@code BindNodeConfigurationToXmlPayload} @@ -51,19 +49,19 @@ import com.google.inject.name.Names; */ @Test(groups = "unit") public class BindNodeConfigurationToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() { @Override - protected void configure() { + protected void bindConfigurations() { Properties properties = new Properties(); properties.setProperty(PROPERTY_API_VERSION, "0.8a-ext1.6"); properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "vCloudExpressExtensions"); properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "1.6"); properties.setProperty(PROPERTY_ENDPOINT, "https://services.vcloudexpress.terremark.com/api"); - Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(properties).build(), - "properties")); + bindProperties(properties); + bindProperties(new TerremarkVCloudPropertiesBuilder(properties).build()); } - }); + })); public void testChangeDescription() throws IOException { String expectedPayload = "willietruedescription"; diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindVAppConfigurationToXmlPayloadTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindVAppConfigurationToXmlPayloadTest.java index 31b96bb652..c60e0514a5 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindVAppConfigurationToXmlPayloadTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindVAppConfigurationToXmlPayloadTest.java @@ -18,11 +18,10 @@ */ package org.jclouds.trmk.vcloud_0_8.binders; -import static com.google.common.base.Preconditions.checkNotNull; +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; -import static org.easymock.classextension.EasyMock.verify; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import static org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration.Builder.changeNameTo; import java.io.IOException; @@ -34,21 +33,20 @@ import org.jclouds.cim.ResourceAllocationSettingData; import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudPropertiesBuilder; -import org.jclouds.trmk.vcloud_0_8.binders.BindVAppConfigurationToXmlPayload; import org.jclouds.trmk.vcloud_0_8.domain.Status; import org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration; import org.jclouds.trmk.vcloud_0_8.domain.internal.VAppImpl; import org.jclouds.util.Strings2; +import org.nnsoft.guice.rocoto.Rocoto; +import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.name.Names; /** * Tests behavior of {@code BindVAppConfigurationToXmlPayload} @@ -57,16 +55,13 @@ import com.google.inject.name.Names; */ @Test(groups = "unit") public class BindVAppConfigurationToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() { @Override - protected void configure() { - Properties props = new Properties(); - Names - .bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(), - "properties")); + protected void bindConfigurations() { + bindProperties(new TerremarkVCloudPropertiesBuilder(new Properties()).build()); } - }); + })); public void testChangeName() throws IOException { VAppImpl vApp = new VAppImpl("MyAppServer6", URI diff --git a/core/src/test/java/org/jclouds/rest/RestClientTest.java b/core/src/test/java/org/jclouds/rest/RestClientTest.java index 627f07d3d5..f8124e7c81 100644 --- a/core/src/test/java/org/jclouds/rest/RestClientTest.java +++ b/core/src/test/java/org/jclouds/rest/RestClientTest.java @@ -26,6 +26,7 @@ import java.util.Properties; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseSax; import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.rest.BaseRestClientExpectTest.RegisterContext; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -67,13 +68,24 @@ public abstract class RestClientTest extends BaseRestClientTest { RestContextSpec contextSpec = createContextSpec(); injector = createContextBuilder(contextSpec, - ImmutableSet.of(new MockModule(), new NullLoggingModule(), createModule()), getProperties()) + ImmutableSet.of(new MockModule(), new NullLoggingModule(), createModule()), setupProperties()) .buildInjector(); parserFactory = injector.getInstance(ParseSax.Factory.class); processor = injector.getInstance(Key.get(createTypeLiteral())); } - protected Properties getProperties() { + /** + * override this when the provider or api is not located in rest.properties and you are not using + * the {@link RegisterContext} annotation on your tests. + */ + protected Properties setupRestProperties() { + return RestContextFactory.getPropertiesFromResource("/rest.properties"); + } + + /** + * override this to supply context-specific parameters during tests. + */ + protected Properties setupProperties() { return new Properties(); } } \ No newline at end of file diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3AsyncClientTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3AsyncClientTest.java index a2af01bb2a..d102c254f5 100644 --- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3AsyncClientTest.java +++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/AWSS3AsyncClientTest.java @@ -40,6 +40,7 @@ import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestContextFactory; +import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; @@ -89,8 +90,8 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest createContextSpec() { + Properties props = new Properties(); + return new RestContextFactory().createContextSpec(provider, "identity", "credential", props); + } }