refactored to use consistent setup*Properties methods like expect tt tests

This commit is contained in:
Adrian Cole 2012-01-29 20:23:04 +08:00
parent 93a5bae746
commit f93c495c43
26 changed files with 234 additions and 387 deletions

View File

@ -18,22 +18,11 @@
*/ */
package org.jclouds.cloudloadbalancers; 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.io.IOException;
import java.util.Properties;
import java.util.concurrent.ExecutionException; 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.http.HttpRequest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -79,23 +68,4 @@ public class CloudLoadBalancersAsyncClientTest extends BaseCloudLoadBalancersAsy
} }
protected String provider = "cloudloadbalancers";
@Override
public RestContextSpec<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> 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;
}
} }

View File

@ -18,26 +18,18 @@
*/ */
package org.jclouds.cloudloadbalancers.features; 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.io.IOException;
import java.lang.reflect.Method; 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.LoadBalancerAttributes;
import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.cloudloadbalancers.domain.LoadBalancerAttributes.Builder; import org.jclouds.cloudloadbalancers.domain.LoadBalancerAttributes.Builder;
import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type; import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type;
import org.jclouds.cloudloadbalancers.functions.UnwrapLoadBalancer; import org.jclouds.cloudloadbalancers.functions.UnwrapLoadBalancer;
import org.jclouds.cloudloadbalancers.functions.UnwrapLoadBalancers; import org.jclouds.cloudloadbalancers.functions.UnwrapLoadBalancers;
import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersAsyncClientTest;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ReleasePayloadAndReturn; 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.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -61,7 +53,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie
HttpRequest httpRequest = processor.createRequest(method); HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, 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"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
@ -78,7 +70,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie
HttpRequest httpRequest = processor.createRequest(method, 5); HttpRequest httpRequest = processor.createRequest(method, 5);
assertRequestLineEquals(httpRequest, 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"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
@ -96,7 +88,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie
"HTTP").port(80).virtualIPType(Type.PUBLIC).build()); "HTTP").port(80).virtualIPType(Type.PUBLIC).build());
assertRequestLineEquals(httpRequest, 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"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals( assertPayloadEquals(
httpRequest, httpRequest,
@ -117,7 +109,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie
"HTTP").port(80).virtualIPId(4).build()); "HTTP").port(80).virtualIPId(4).build());
assertRequestLineEquals(httpRequest, 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"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals( assertPayloadEquals(
httpRequest, httpRequest,
@ -138,7 +130,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie
HttpRequest httpRequest = processor.createRequest(method, 2, Builder.name("foo")); HttpRequest httpRequest = processor.createRequest(method, 2, Builder.name("foo"));
assertRequestLineEquals(httpRequest, 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"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, "{\"loadBalancer\":{\"name\":\"foo\"}}", "application/json", false); assertPayloadEquals(httpRequest, "{\"loadBalancer\":{\"name\":\"foo\"}}", "application/json", false);
@ -155,7 +147,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie
HttpRequest httpRequest = processor.createRequest(method, 5); HttpRequest httpRequest = processor.createRequest(method, 5);
assertRequestLineEquals(httpRequest, 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"); assertNonPayloadHeadersEqual(httpRequest, "Accept: */*\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
@ -173,20 +165,4 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie
}; };
} }
protected String provider = "cloudloadbalancers";
@Override
public RestContextSpec<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> 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;
}
} }

View File

@ -30,6 +30,7 @@ import org.jclouds.cloudloadbalancers.domain.LoadBalancerAttributes;
import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest; import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.cloudloadbalancers.domain.NodeRequest; import org.jclouds.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type; import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type;
import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersClientLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;

View File

@ -18,27 +18,19 @@
*/ */
package org.jclouds.cloudloadbalancers.features; 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.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collections; import java.util.Collections;
import java.util.Properties;
import java.util.Set; 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;
import org.jclouds.cloudloadbalancers.domain.NodeAttributes.Builder; import org.jclouds.cloudloadbalancers.domain.NodeAttributes.Builder;
import org.jclouds.cloudloadbalancers.domain.NodeRequest; import org.jclouds.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.cloudloadbalancers.domain.internal.BaseNode.Condition; import org.jclouds.cloudloadbalancers.domain.internal.BaseNode.Condition;
import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersAsyncClientTest;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.ReleasePayloadAndReturn; 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.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -153,20 +145,4 @@ public class NodeAsyncClientTest extends BaseCloudLoadBalancersAsyncClientTest<N
}; };
} }
protected String provider = "cloudloadbalancers";
@Override
public RestContextSpec<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> 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;
}
} }

View File

@ -37,6 +37,7 @@ import org.jclouds.cloudloadbalancers.domain.NodeAttributes;
import org.jclouds.cloudloadbalancers.domain.NodeRequest; import org.jclouds.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.cloudloadbalancers.domain.LoadBalancer.Status; import org.jclouds.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type; import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type;
import org.jclouds.cloudloadbalancers.internal.BaseCloudLoadBalancersClientLiveTest;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -36,6 +36,7 @@ import java.net.UnknownHostException;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
import javax.inject.Singleton;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.cloudservers.config.CloudServersRestClientModule; 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.DailyBackup;
import org.jclouds.cloudservers.domain.RebootType; import org.jclouds.cloudservers.domain.RebootType;
import org.jclouds.cloudservers.domain.WeeklyBackup; import org.jclouds.cloudservers.domain.WeeklyBackup;
import org.jclouds.cloudservers.internal.BaseCloudServersRestClientExpectTest.TestAuthenticationServiceModule;
import org.jclouds.cloudservers.options.CreateServerOptions; import org.jclouds.cloudservers.options.CreateServerOptions;
import org.jclouds.cloudservers.options.CreateSharedIpGroupOptions; import org.jclouds.cloudservers.options.CreateSharedIpGroupOptions;
import org.jclouds.cloudservers.options.ListOptions; import org.jclouds.cloudservers.options.ListOptions;
import org.jclouds.cloudservers.options.RebuildServerOptions; import org.jclouds.cloudservers.options.RebuildServerOptions;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnFalseOn404; import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.UnwrapOnlyJsonValue; 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.AddTimestampQuery;
import org.jclouds.openstack.filters.AuthenticateRequest; 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.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
@ -71,6 +75,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
@ -78,8 +83,9 @@ import com.google.inject.TypeLiteral;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire // NOTE:without testName, this will not call @Before* and fail w/NPE during
@Test(groups = "unit", singleThreaded=true, testName = "CloudServersAsyncClientTest") // surefire
@Test(groups = "unit", singleThreaded = true, testName = "CloudServersAsyncClientTest")
public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyncClient> { public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyncClient> {
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}.getClass(); private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}.getClass();
private static final Class<? extends CreateServerOptions[]> createServerOptionsVarargsClass = new CreateServerOptions[] {} private static final Class<? extends CreateServerOptions[]> createServerOptionsVarargsClass = new CreateServerOptions[] {}
@ -890,11 +896,22 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
@RequiresHttp @RequiresHttp
protected static class TestCloudServersRestClientModule extends CloudServersRestClientModule { protected static class TestCloudServersRestClientModule extends CloudServersRestClientModule {
private TestCloudServersRestClientModule() { private TestCloudServersRestClientModule() {
super(new TestOpenStackAuthenticationModule()); super(new TestAuthenticationServiceModule());
}
@Provides
@Singleton
GetAuth provideGetAuth() {
return new GetAuth(null) {
@Override
public Auth apply(Credentials in) {
return new ParseAuthTest().expected();
}
};
} }
@Override @Override
protected URI provideServerUrl(AuthenticationResponse response) { protected URI provideServerUrl(Auth response) {
return URI.create("http://serverManagementUrl"); return URI.create("http://serverManagementUrl");
} }
@ -904,16 +921,15 @@ public class CloudServersAsyncClientTest extends RestClientTest<CloudServersAsyn
@Override @Override
public RestContextSpec<?, ?> createContextSpec() { public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory(getProperties()).createContextSpec(provider, "user", "password", new Properties()); return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties());
} }
@Override @Override
protected Properties getProperties() { protected Properties setupProperties() {
Properties overrides = new Properties(); Properties overrides = new Properties();
overrides.setProperty(PROPERTY_REGIONS, "US"); overrides.setProperty(PROPERTY_REGIONS, "US");
overrides.setProperty(PROPERTY_API_VERSION, "1"); overrides.setProperty(PROPERTY_API_VERSION, "1");
overrides.setProperty(provider + ".endpoint", "https://auth"); overrides.setProperty(provider + ".endpoint", "https://auth");
overrides.setProperty(provider + ".contextbuilder", CloudServersContextBuilder.class.getName());
return overrides; return overrides;
} }
} }

View File

@ -34,46 +34,21 @@ import com.google.common.collect.ImmutableMultimap;
@Test(groups = "unit", testName = "CloudServersExpectTest") @Test(groups = "unit", testName = "CloudServersExpectTest")
public class CloudServersExpectTest extends BaseCloudServersRestClientExpectTest { public class CloudServersExpectTest extends BaseCloudServersRestClientExpectTest {
HttpRequest initialAuth = HttpRequest.builder().method("GET").endpoint(URI.create("https://auth/v1.0"))
.headers(
ImmutableMultimap.<String, String> 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.<String,String>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() { public void deleteImageReturnsTrueOn200AndFalseOn404() {
HttpRequest deleteImage11 = HttpRequest.builder().method("DELETE").endpoint( 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.<String, String> builder() ImmutableMultimap.<String, String> builder()
.put("X-Auth-Token", authToken).build()).build(); .put("X-Auth-Token", authToken).build()).build();
HttpResponse imageDeleted = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content").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); assert clientWhenImageExists.deleteImage(11);
HttpResponse imageNotFound = HttpResponse.builder().statusCode(404).message("HTTP/1.1 404 Not Found").build(); 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); assert !clientWhenImageDoesntExist.deleteImage(11);
} }

View File

@ -40,134 +40,76 @@ public class RetryOnRenewExpectTest extends BaseCloudServersRestClientExpectTest
@Test @Test
public void testShouldReauthenticateOn401() { 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")) HttpRequest deleteImage = HttpRequest.builder().method("DELETE")
.headers( .endpoint(URI.create("https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/11?now=1257695648897"))
ImmutableMultimap.<String, String> builder() .headers(ImmutableMultimap.<String, String> builder().put("X-Auth-Token", authToken).build()).build();
.put("X-Auth-User", "identity")
.put("X-Auth-Key", "credential")
.put("Accept", "*/*").build()).build();
HttpResponse pleaseRenew = HttpResponse
HttpResponse responseWithUrls = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content") .builder()
.headers(ImmutableMultimap.<String,String>builder() .statusCode(401)
.put("Server", "Apache/2.2.3 (Red Hat)") .message("HTTP/1.1 401 Unauthorized")
.put("vary", "X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass") .payload(
.put("X-Storage-Url", "https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22") Payloads
.put("Cache-Control", "s-maxage=86399") .newStringPayload("[{\"unauthorized\":{\"message\":\"Invalid authentication token. Please renew.\",\"code\":401}}]"))
.put("Content-Type", "text/xml") .build();
.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.<String, String> 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 // second auth uses same creds as initial one
HttpRequest redoAuth = initialAuth; HttpRequest redoAuth = initialAuth;
HttpResponse responseWithUrls2 = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content") String authToken2 = "12345678-9012-47c0-9770-2c5097da25fc";
.headers(ImmutableMultimap.<String,String>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( HttpResponse responseWithUrls2 = HttpResponse
URI.create("https://servers.api.rackspacecloud.com/v1.0/413274/images/11?now=1257695648897")).headers( .Builder.from(responseWithAuth)
ImmutableMultimap.<String, String> builder() .payload(
.put("X-Auth-Token", authToken2).build()).build(); 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.<String, String> builder().put("X-Auth-Token", authToken2).build()).build();
HttpResponse imageDeleted = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content").build(); HttpResponse imageDeleted = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content").build();
CloudServersClient clientWhenImageExists = orderedRequestsSendResponses(initialAuth, responseWithUrls, CloudServersClient clientWhenImageExists = orderedRequestsSendResponses(initialAuth, responseWithAuth,
deleteImage, pleaseRenew, redoAuth, responseWithUrls2, deleteImage2, imageDeleted); deleteImage, pleaseRenew, redoAuth, responseWithUrls2, deleteImage2, imageDeleted);
assert clientWhenImageExists.deleteImage(11); assert clientWhenImageExists.deleteImage(11);
} }
@Test(expectedExceptions=AuthorizationException.class) @Test(expectedExceptions = AuthorizationException.class)
public void testDoesNotReauthenticateOnFatal401() { public void testDoesNotReauthenticateOnFatal401() {
String authToken = "d6245d35-22a0-47c0-9770-2c5097da25fc"; HttpRequest deleteImage = HttpRequest.builder().method("DELETE")
.endpoint(URI.create("https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/11?now=1257695648897"))
.headers(ImmutableMultimap.<String, String> builder().put("X-Auth-Token", authToken).build()).build();
HttpRequest initialAuth = HttpRequest.builder().method("GET").endpoint(URI.create("https://auth/v1.0")) HttpResponse unauthResponse = HttpResponse
.headers( .builder()
ImmutableMultimap.<String, String> builder() .statusCode(401)
.put("X-Auth-User", "identity") .message("HTTP/1.1 401 Unauthorized")
.put("X-Auth-Key", "credential") .payload(
.put("Accept", "*/*").build()).build(); Payloads.newStringPayload("[{\"unauthorized\":{\"message\":\"Fatal unauthorized.\",\"code\":401}}]"))
.build();
CloudServersClient client = orderedRequestsSendResponses(initialAuth, responseWithAuth, deleteImage,
HttpResponse responseWithUrls = HttpResponse.builder().statusCode(204).message("HTTP/1.1 204 No Content") unauthResponse);
.headers(ImmutableMultimap.<String,String>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.<String, String> 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();
CloudServersClient client = orderedRequestsSendResponses(initialAuth, responseWithUrls,
deleteImage, unauthResponse);
client.deleteImage(11); client.deleteImage(11);
} }
// FIXME stack trace shows the AuthorizationException, but it's buried inside a guice TestException // FIXME stack trace shows the AuthorizationException, but it's buried inside
@Test(expectedExceptions=AuthorizationException.class) // a guice TestException
@Test(expectedExceptions = AuthorizationException.class)
public void testDoesNotReauthenticateOnAuthentication401() { public void testDoesNotReauthenticateOnAuthentication401() {
HttpRequest initialAuth = HttpRequest.builder().method("GET").endpoint(URI.create("https://auth/v1.0"))
.headers(
ImmutableMultimap.<String, String> builder()
.put("X-Auth-User", "identity")
.put("X-Auth-Key", "credential")
.put("Accept", "*/*").build()).build();
HttpResponse unauthResponse = HttpResponse
HttpResponse unauthResponse = HttpResponse.builder().statusCode(401) .builder()
.message("HTTP/1.1 401 Unauthorized") .statusCode(401)
.payload(Payloads.newStringPayload("[{\"unauthorized\":{\"message\":\"A different message implying fatal.\",\"code\":401}}]")) .message("HTTP/1.1 401 Unauthorized")
.build(); .payload(
Payloads
.newStringPayload("[{\"unauthorized\":{\"message\":\"A different message implying fatal.\",\"code\":401}}]"))
.build();
CloudServersClient client = requestSendsResponse(initialAuth, unauthResponse); CloudServersClient client = requestSendsResponse(initialAuth, unauthResponse);

View File

@ -29,9 +29,9 @@ import org.jclouds.cloudservers.CloudServersPropertiesBuilder;
import org.jclouds.cloudservers.config.CloudServersRestClientModule; import org.jclouds.cloudservers.config.CloudServersRestClientModule;
import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
import org.jclouds.openstack.filters.AddTimestampQuery; 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 org.jclouds.rest.ConfiguresRestClient;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -42,7 +42,7 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class BaseCloudServersRestClientExpectTest extends BaseRestClientExpectTest<CloudServersClient> { public class BaseCloudServersRestClientExpectTest extends BaseKeyStoneRestClientExpectTest<CloudServersClient> {
public BaseCloudServersRestClientExpectTest() { public BaseCloudServersRestClientExpectTest() {
provider = "cloudservers"; provider = "cloudservers";
@ -52,7 +52,7 @@ public class BaseCloudServersRestClientExpectTest extends BaseRestClientExpectTe
protected Properties setupRestProperties() { protected Properties setupRestProperties() {
Properties overrides = new Properties(); Properties overrides = new Properties();
overrides.setProperty(PROPERTY_REGIONS, "US"); 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 + ".contextbuilder", CloudServersContextBuilder.class.getName());
overrides.setProperty(provider + ".propertiesbuilder", CloudServersPropertiesBuilder.class.getName()); overrides.setProperty(provider + ".propertiesbuilder", CloudServersPropertiesBuilder.class.getName());
return overrides; return overrides;
@ -61,23 +61,14 @@ public class BaseCloudServersRestClientExpectTest extends BaseRestClientExpectTe
protected static final String CONSTANT_DATE = "2009-11-08T15:54:08.897Z"; 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 @Override
protected void configure() { protected void configure() {
super.configure(); super.configure();
} }
@Override
public Supplier<Date> provideCacheBusterDate() {
return new Supplier<Date>() {
public Date get() {
return new SimpleDateFormatDateService().iso8601DateParse(CONSTANT_DATE);
}
};
}
} }
@Override @Override
@ -89,8 +80,16 @@ public class BaseCloudServersRestClientExpectTest extends BaseRestClientExpectTe
@RequiresHttp @RequiresHttp
protected static class TestCloudServersRestClientModule extends CloudServersRestClientModule { protected static class TestCloudServersRestClientModule extends CloudServersRestClientModule {
private TestCloudServersRestClientModule() { private TestCloudServersRestClientModule() {
super(new TestOpenStackAuthenticationModule()); super(new TestAuthenticationServiceModule());
} }
@Override
public Supplier<Date> provideCacheBusterDate() {
return new Supplier<Date>() {
public Date get() {
return new SimpleDateFormatDateService().iso8601DateParse(CONSTANT_DATE);
}
};
}
} }
} }

View File

@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -46,10 +45,11 @@ import org.jclouds.rest.RestContextSpec;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -135,19 +135,14 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
protected String provider = "ec2"; protected String provider = "ec2";
@Override /**
protected Properties getProperties() { * this is only here as "ec2" is not in rest.properties
Properties overrides = new Properties(); */
overrides.setProperty(provider + ".endpoint", "https://ec2.us-east-1.amazonaws.com"); @SuppressWarnings({ "unchecked", "rawtypes" })
overrides.setProperty(provider + ".propertiesbuilder", EC2PropertiesBuilder.class.getName());
overrides.setProperty(provider + ".contextbuilder", EC2ContextBuilder.class.getName());
return overrides;
}
@Override @Override
public RestContextSpec<?, ?> createContextSpec() { public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", return RestContextFactory.<EC2Client, EC2AsyncClient> contextSpec(provider, "https://ec2.us-east-1.amazonaws.com",
new Properties()); EC2AsyncClient.VERSION, "", "", "identity", "credential", EC2Client.class, EC2AsyncClient.class,
(Class) EC2PropertiesBuilder.class, (Class) EC2ContextBuilder.class, ImmutableSet.<Module> of());
} }
} }

View File

@ -788,15 +788,14 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
@Override @Override
public RestContextSpec<?, ?> createContextSpec() { public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory(getProperties()).createContextSpec(provider, "user", "password", new Properties()); return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties());
} }
@Override @Override
protected Properties getProperties() { protected Properties setupProperties() {
Properties overrides = new Properties(); Properties overrides = new Properties();
overrides.setProperty(PROPERTY_API_VERSION, "api-version"); overrides.setProperty(PROPERTY_API_VERSION, "api-version");
overrides.setProperty(provider + ".endpoint", "http://endpoint"); overrides.setProperty(provider + ".endpoint", "http://endpoint");
overrides.setProperty(provider + ".contextbuilder", NovaContextBuilder.class.getName());
return overrides; return overrides;
} }
} }

View File

@ -56,8 +56,8 @@ public class BindAsHostPrefixIfConfiguredNoPathTest extends BaseS3AsyncClientTes
@Override @Override
protected Properties getProperties() { protected Properties setupProperties() {
Properties properties = super.getProperties(); Properties properties = super.setupProperties();
properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false"); properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
return properties; return properties;
} }

View File

@ -45,6 +45,9 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "BindAsHostPrefixIfConfiguredTest") @Test(groups = "unit", testName = "BindAsHostPrefixIfConfiguredTest")
public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest<S3AsyncClient> { public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest<S3AsyncClient> {
public BindAsHostPrefixIfConfiguredTest(){
endpoint = "http://euc/services/Walrus";
}
@Override @Override
protected TypeLiteral<RestAnnotationProcessor<S3AsyncClient>> createTypeLiteral() { protected TypeLiteral<RestAnnotationProcessor<S3AsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<S3AsyncClient>>() { return new TypeLiteral<RestAnnotationProcessor<S3AsyncClient>>() {
@ -93,9 +96,8 @@ public class BindAsHostPrefixIfConfiguredTest extends BaseS3AsyncClientTest<S3As
} }
@Override @Override
protected Properties getProperties() { protected Properties setupProperties() {
Properties properties = super.getProperties(); Properties properties = super.setupProperties();
properties.setProperty("s3.endpoint", "http://euc/services/Walrus");
properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/services/Walrus"); properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/services/Walrus");
properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false"); properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
return properties; return properties;

View File

@ -154,8 +154,9 @@ public class RequestAuthorizeSignatureTest extends BaseS3AsyncClientTest<S3Async
assertEquals(request.getEndpoint().getHost(), "bucket.s3.amazonaws.com"); assertEquals(request.getEndpoint().getHost(), "bucket.s3.amazonaws.com");
} }
protected Properties getProperties() { @Override
Properties overrides = super.getProperties(); protected Properties setupProperties() {
Properties overrides = super.setupProperties();
overrides.setProperty(PROPERTY_SESSION_INTERVAL, 1 + ""); overrides.setProperty(PROPERTY_SESSION_INTERVAL, 1 + "");
return overrides; return overrides;
} }

View File

@ -21,13 +21,13 @@ package org.jclouds.s3.internal;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.s3.S3AsyncClient; import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.S3Client;
import org.jclouds.s3.S3ContextBuilder; import org.jclouds.s3.S3ContextBuilder;
import org.jclouds.s3.S3PropertiesBuilder; import org.jclouds.s3.S3PropertiesBuilder;
import org.jclouds.s3.blobstore.functions.BlobToObject; import org.jclouds.s3.blobstore.functions.BlobToObject;
@ -35,6 +35,9 @@ import org.jclouds.s3.filters.RequestAuthorizeSignature;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -65,20 +68,17 @@ public abstract class BaseS3AsyncClientTest<T extends S3AsyncClient> extends Res
} }
protected String provider = "s3"; protected String provider = "s3";
protected String endpoint = "https://s3.amazonaws.com";
@Override /**
protected Properties getProperties() { * this is only here as "s3" is not in rest.properties
Properties overrides = new Properties(); */
overrides.setProperty(provider + ".endpoint", "https://s3.amazonaws.com"); @SuppressWarnings({ "unchecked", "rawtypes" })
overrides.setProperty(provider + ".propertiesbuilder", S3PropertiesBuilder.class.getName());
overrides.setProperty(provider + ".contextbuilder", S3ContextBuilder.class.getName());
return overrides;
}
@Override @Override
public RestContextSpec<?, ?> createContextSpec() { public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", return RestContextFactory.<S3Client, S3AsyncClient> contextSpec(provider, endpoint,
new Properties()); S3AsyncClient.VERSION, "", "", "identity", "credential", S3Client.class, S3AsyncClient.class,
(Class) S3PropertiesBuilder.class, (Class) S3ContextBuilder.class, ImmutableSet.<Module> of());
} }
} }

View File

@ -77,11 +77,11 @@ public abstract class CommonSwiftClientTest<A extends CommonSwiftAsyncClient> ex
@Override @Override
public RestContextSpec<CommonSwiftClient, CommonSwiftAsyncClient> createContextSpec() { public RestContextSpec<CommonSwiftClient, CommonSwiftAsyncClient> createContextSpec() {
return new RestContextFactory().createContextSpec(provider, "user", "password", new Properties()); return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "user", "password", setupProperties());
} }
@Override @Override
protected Properties getProperties() { protected Properties setupProperties() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(PROPERTY_REGIONS, "US"); properties.setProperty(PROPERTY_REGIONS, "US");
properties.setProperty(PROPERTY_ENDPOINT, "https://auth"); properties.setProperty(PROPERTY_ENDPOINT, "https://auth");

View File

@ -18,11 +18,10 @@
*/ */
package org.jclouds.vcloud.binders; 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.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.EasyMock.verify;
import static org.easymock.classextension.EasyMock.verify;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -32,14 +31,14 @@ import java.util.Properties;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.options.CatalogItemOptions; 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 org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindCatalogItemToXmlPayload} * Tests behavior of {@code BindCatalogItemToXmlPayload}
@ -48,14 +47,13 @@ import com.google.inject.name.Names;
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class BindCatalogItemToXmlPayloadTest { public class BindCatalogItemToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
@Override @Override
protected void configure() { protected void bindConfigurations() {
Properties props = new Properties(); bindProperties(new VCloudPropertiesBuilder(new Properties()).build());
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
} }
}); }));
public void testDefault() throws IOException { public void testDefault() throws IOException {
String expected = "<CatalogItem xmlns=\"http://www.vmware.com/vcloud/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" name=\"myname\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd\"><Description>mydescription</Description><Entity href=\"http://fooentity\"/><Property key=\"foo\">bar</Property></CatalogItem>"; String expected = "<CatalogItem xmlns=\"http://www.vmware.com/vcloud/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" name=\"myname\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd\"><Description>mydescription</Description><Entity href=\"http://fooentity\"/><Property key=\"foo\">bar</Property></CatalogItem>";

View File

@ -18,11 +18,10 @@
*/ */
package org.jclouds.vcloud.binders; 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.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.EasyMock.verify;
import static org.easymock.classextension.EasyMock.verify;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -31,13 +30,13 @@ import java.util.Properties;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.nnsoft.guice.rocoto.Rocoto;
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindDeployVAppParamsToXmlPayload} * Tests behavior of {@code BindDeployVAppParamsToXmlPayload}
@ -46,14 +45,13 @@ import com.google.inject.name.Names;
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class BindDeployVAppParamsToXmlPayloadTest { public class BindDeployVAppParamsToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
@Override @Override
protected void configure() { protected void bindConfigurations() {
Properties props = new Properties(); bindProperties(new VCloudPropertiesBuilder(new Properties()).build());
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
} }
}); }));
public void testPowerOnTrue() throws IOException { public void testPowerOnTrue() throws IOException {
String expected = "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>"; String expected = "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>";

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.vcloud.binders; package org.jclouds.vcloud.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay; 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.domain.network.NetworkConfig;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; 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 org.testng.annotations.Test;
import com.google.common.base.Function; 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.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload} * Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload}
@ -69,7 +68,7 @@ import com.google.inject.name.Names;
public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
Injector createInjector(final URI vAppTemplate, final VAppTemplate value) { Injector createInjector(final URI vAppTemplate, final VAppTemplate value) {
return Guice.createInjector(new AbstractModule() { return Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
@ -88,9 +87,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
} }
@Override @Override
protected void configure() { protected void bindConfigurations() {
Properties props = new Properties(); bindProperties(new VCloudPropertiesBuilder(new Properties()).build());
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -108,7 +106,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
return new ReferenceTypeImpl(null, null, URI return new ReferenceTypeImpl(null, null, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990")); .create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"));
} }
}); }));
} }
public void testDefault() throws IOException { public void testDefault() throws IOException {

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.vcloud.binders; package org.jclouds.vcloud.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
@ -30,13 +29,13 @@ import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.domain.NetworkConnection; import org.jclouds.vcloud.domain.NetworkConnection;
import org.jclouds.vcloud.domain.NetworkConnectionSection; import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.network.IpAddressAllocationMode; 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 org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindNetworkConnectionSectionToXmlPayload} * Tests behavior of {@code BindNetworkConnectionSectionToXmlPayload}
@ -45,14 +44,13 @@ import com.google.inject.name.Names;
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class BindNetworkConnectionSectionToXmlPayloadTest { public class BindNetworkConnectionSectionToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
@Override @Override
protected void configure() { protected void bindConfigurations() {
Properties props = new Properties(); bindProperties(new VCloudPropertiesBuilder(new Properties()).build());
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
} }
}); }));
public void testWithIpAllocationModeNONE() throws IOException { public void testWithIpAllocationModeNONE() throws IOException {

View File

@ -18,11 +18,10 @@
*/ */
package org.jclouds.vcloud.binders; 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.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.EasyMock.verify;
import static org.easymock.classextension.EasyMock.verify;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -31,13 +30,13 @@ import java.util.Properties;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.nnsoft.guice.rocoto.Rocoto;
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindUndeployVAppParamsToXmlPayload} * Tests behavior of {@code BindUndeployVAppParamsToXmlPayload}
@ -46,14 +45,13 @@ import com.google.inject.name.Names;
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class BindUndeployVAppParamsToXmlPayloadTest { public class BindUndeployVAppParamsToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
@Override @Override
protected void configure() { protected void bindConfigurations() {
Properties props = new Properties(); bindProperties(new VCloudPropertiesBuilder(new Properties()).build());
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
} }
}); }));
public void testSaveStateTrue() throws IOException { public void testSaveStateTrue() throws IOException {
String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>"; String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>";

View File

@ -18,10 +18,9 @@
*/ */
package org.jclouds.trmk.vcloud_0_8.binders; 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.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay;
import java.io.IOException; import java.io.IOException;
import java.net.URI; 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;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.NetworkConfig; import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.NetworkConfig;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.nnsoft.guice.rocoto.Rocoto;
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap; 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.Maps;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload} * Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload}
@ -58,12 +57,11 @@ import com.google.inject.name.Names;
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
@Override @Override
protected void configure() { protected void bindConfigurations() {
Properties props = new Properties(); bindProperties(new TerremarkVCloudPropertiesBuilder(new Properties()).build());
Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(), "properties"));
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -73,7 +71,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
ReferenceType provideNetwork() { ReferenceType provideNetwork() {
return new ReferenceTypeImpl(null, null, URI.create("https://vcloud.safesecureweb.com/network/1990")); return new ReferenceTypeImpl(null, null, URI.create("https://vcloud.safesecureweb.com/network/1990"));
} }
}); }));
public void testAllOptions() throws IOException { public void testAllOptions() throws IOException {

View File

@ -18,11 +18,10 @@
*/ */
package org.jclouds.trmk.vcloud_0_8.binders; 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.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.EasyMock.verify;
import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME; 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.http.HttpRequest;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudPropertiesBuilder; 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 org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindNodeConfigurationToXmlPayload} * Tests behavior of {@code BindNodeConfigurationToXmlPayload}
@ -51,19 +49,19 @@ import com.google.inject.name.Names;
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class BindNodeConfigurationToXmlPayloadTest { public class BindNodeConfigurationToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
@Override @Override
protected void configure() { protected void bindConfigurations() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty(PROPERTY_API_VERSION, "0.8a-ext1.6"); properties.setProperty(PROPERTY_API_VERSION, "0.8a-ext1.6");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "vCloudExpressExtensions"); properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "vCloudExpressExtensions");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "1.6"); properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "1.6");
properties.setProperty(PROPERTY_ENDPOINT, "https://services.vcloudexpress.terremark.com/api"); properties.setProperty(PROPERTY_ENDPOINT, "https://services.vcloudexpress.terremark.com/api");
Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(properties).build(), bindProperties(properties);
"properties")); bindProperties(new TerremarkVCloudPropertiesBuilder(properties).build());
} }
}); }));
public void testChangeDescription() throws IOException { public void testChangeDescription() throws IOException {
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>true</Enabled><Description>description</Description></NodeService>"; String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>true</Enabled><Description>description</Description></NodeService>";

View File

@ -18,11 +18,10 @@
*/ */
package org.jclouds.trmk.vcloud_0_8.binders; 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.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.EasyMock.verify;
import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration.Builder.changeNameTo; import static org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration.Builder.changeNameTo;
import java.io.IOException; import java.io.IOException;
@ -34,21 +33,20 @@ import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudPropertiesBuilder; 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.Status;
import org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration; import org.jclouds.trmk.vcloud_0_8.domain.VAppConfiguration;
import org.jclouds.trmk.vcloud_0_8.domain.internal.VAppImpl; import org.jclouds.trmk.vcloud_0_8.domain.internal.VAppImpl;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.nnsoft.guice.rocoto.Rocoto;
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code BindVAppConfigurationToXmlPayload} * Tests behavior of {@code BindVAppConfigurationToXmlPayload}
@ -57,16 +55,13 @@ import com.google.inject.name.Names;
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class BindVAppConfigurationToXmlPayloadTest { public class BindVAppConfigurationToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(Rocoto.expandVariables(new ConfigurationModule() {
@Override @Override
protected void configure() { protected void bindConfigurations() {
Properties props = new Properties(); bindProperties(new TerremarkVCloudPropertiesBuilder(new Properties()).build());
Names
.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(),
"properties"));
} }
}); }));
public void testChangeName() throws IOException { public void testChangeName() throws IOException {
VAppImpl vApp = new VAppImpl("MyAppServer6", URI VAppImpl vApp = new VAppImpl("MyAppServer6", URI

View File

@ -26,6 +26,7 @@ import java.util.Properties;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.BaseRestClientExpectTest.RegisterContext;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -67,13 +68,24 @@ public abstract class RestClientTest<T> extends BaseRestClientTest {
RestContextSpec<?, ?> contextSpec = createContextSpec(); RestContextSpec<?, ?> contextSpec = createContextSpec();
injector = createContextBuilder(contextSpec, injector = createContextBuilder(contextSpec,
ImmutableSet.of(new MockModule(), new NullLoggingModule(), createModule()), getProperties()) ImmutableSet.of(new MockModule(), new NullLoggingModule(), createModule()), setupProperties())
.buildInjector(); .buildInjector();
parserFactory = injector.getInstance(ParseSax.Factory.class); parserFactory = injector.getInstance(ParseSax.Factory.class);
processor = injector.getInstance(Key.get(createTypeLiteral())); 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(); return new Properties();
} }
} }

View File

@ -40,6 +40,7 @@ import org.jclouds.io.Payload;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
@ -89,8 +90,8 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
public void testPutObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, public void testPutObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = AWSS3AsyncClient.class Method method = AWSS3AsyncClient.class.getMethod("putObject", String.class, S3Object.class,
.getMethod("putObject", String.class, S3Object.class, PutObjectOptions[].class); PutObjectOptions[].class);
HttpRequest request = processor.createRequest(method, "bucket", HttpRequest request = processor.createRequest(method, "bucket",
blobToS3Object.apply(BindBlobToMultipartFormTest.TEST_BLOB)); blobToS3Object.apply(BindBlobToMultipartFormTest.TEST_BLOB));
@ -153,11 +154,6 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
}; };
} }
@Override
protected Properties getProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties");
}
public void testInitiateMultipartUpload() throws SecurityException, NegativeArraySizeException, public void testInitiateMultipartUpload() throws SecurityException, NegativeArraySizeException,
NoSuchMethodException { NoSuchMethodException {
Method method = AWSS3AsyncClient.class.getMethod("initiateMultipartUpload", String.class, ObjectMetadata.class, Method method = AWSS3AsyncClient.class.getMethod("initiateMultipartUpload", String.class, ObjectMetadata.class,
@ -293,4 +289,9 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
return new TestAWSS3RestClientModule(); return new TestAWSS3RestClientModule();
} }
@Override
public RestContextSpec<?, ?> createContextSpec() {
Properties props = new Properties();
return new RestContextFactory().createContextSpec(provider, "identity", "credential", props);
}
} }