mirror of https://github.com/apache/jclouds.git
refactored ec2 tests so that they can be used in aws-ec2
This commit is contained in:
parent
c37c0b9ecc
commit
9d75aa353d
|
@ -18,14 +18,9 @@
|
|||
*/
|
||||
package org.jclouds.ec2.compute;
|
||||
import static org.jclouds.ec2.compute.options.EC2TemplateOptions.Builder.blockUntilRunning;
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.ec2.compute.internal.BaseEC2ComputeServiceExpectTest;
|
||||
|
@ -45,168 +40,6 @@ import com.google.common.collect.Iterables;
|
|||
@Test(groups = "unit", testName = "EC2ComputeServiceExpectTest")
|
||||
public class EC2ComputeServiceExpectTest extends BaseEC2ComputeServiceExpectTest {
|
||||
|
||||
static String region = "us-east-1";
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties properties = super.setupProperties();
|
||||
properties.setProperty(PROPERTY_REGIONS, region);
|
||||
properties.setProperty(provider + ".template", "osDescriptionMatches=.*fedora.*");
|
||||
return properties;
|
||||
}
|
||||
|
||||
private HttpRequest describeAvailabilityZonesRequest;
|
||||
private HttpResponse describeAvailabilityZonesResponse;
|
||||
private HttpRequest describeImagesRequest;
|
||||
private HttpResponse describeImagesResponse;
|
||||
private HttpRequest createKeyPairRequest;
|
||||
private HttpResponse createKeyPairResponse;
|
||||
private HttpRequest createSecurityGroupRequest;
|
||||
private HttpResponse createSecurityGroupResponse;
|
||||
private HttpRequest describeSecurityGroupRequest;
|
||||
private HttpResponse describeSecurityGroupResponse;
|
||||
private HttpRequest authorizeSecurityGroupIngressRequest22;
|
||||
private HttpResponse authorizeSecurityGroupIngressResponse;
|
||||
private HttpRequest authorizeSecurityGroupIngressRequestGroup;
|
||||
private HttpRequest runInstancesRequest;
|
||||
private HttpResponse runInstancesResponse;
|
||||
private HttpRequest describeInstanceRequest;
|
||||
private HttpResponse describeInstanceResponse;
|
||||
private HttpRequest describeImageRequest;
|
||||
|
||||
public EC2ComputeServiceExpectTest() {
|
||||
describeAvailabilityZonesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeAvailabilityZones").build());
|
||||
|
||||
describeAvailabilityZonesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/availabilityZones-" + region + ".xml", MediaType.APPLICATION_XML)).build();
|
||||
describeImagesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeImages").build());
|
||||
|
||||
describeImagesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/describe_images.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
createKeyPairRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "CreateKeyPair")
|
||||
.addFormParam("KeyName", "jclouds#test#0").build());
|
||||
|
||||
createKeyPairResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/create_keypair.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
createSecurityGroupRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "CreateSecurityGroup")
|
||||
.addFormParam("GroupDescription", "jclouds#test")
|
||||
.addFormParam("GroupName", "jclouds#test").build());
|
||||
|
||||
createSecurityGroupResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/created_securitygroup.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
describeSecurityGroupRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeSecurityGroups")
|
||||
.addFormParam("GroupName.1", "jclouds#test").build());
|
||||
|
||||
describeSecurityGroupResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/new_securitygroup.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
authorizeSecurityGroupIngressRequest22 =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "AuthorizeSecurityGroupIngress")
|
||||
.addFormParam("CidrIp", "0.0.0.0/0")
|
||||
.addFormParam("FromPort", "22")
|
||||
.addFormParam("ToPort", "22")
|
||||
.addFormParam("GroupName", "jclouds#test")
|
||||
.addFormParam("IpProtocol", "tcp").build());
|
||||
|
||||
authorizeSecurityGroupIngressRequestGroup =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "AuthorizeSecurityGroupIngress")
|
||||
.addFormParam("SourceSecurityGroupName", "jclouds#test")
|
||||
.addFormParam("SourceSecurityGroupOwnerId", "993194456877")
|
||||
.addFormParam("GroupName", "jclouds#test").build());
|
||||
|
||||
authorizeSecurityGroupIngressResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/authorize_securitygroup_ingress_response.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
|
||||
runInstancesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "RunInstances")
|
||||
.addFormParam("ImageId", "ami-be3adfd7")
|
||||
.addFormParam("InstanceType", "m1.small")
|
||||
.addFormParam("KeyName", "jclouds#test#0")
|
||||
.addFormParam("MaxCount", "1")
|
||||
.addFormParam("MinCount", "1")
|
||||
.addFormParam("SecurityGroup.1", "jclouds#test").build());
|
||||
|
||||
runInstancesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/new_instance.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
describeInstanceRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeInstances")
|
||||
.addFormParam("InstanceId.1", "i-2baa5550").build());
|
||||
|
||||
describeInstanceResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/describe_instances_running-1.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
//TODO: duplicate.. shouldn't need this
|
||||
describeImageRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("ImageId.1", "ami-aecd60c7")
|
||||
.addFormParam("Action", "DescribeImages").build());
|
||||
}
|
||||
|
||||
public void testCreateNodeWithGeneratedKeyPairAndOverriddenLoginUser() throws Exception {
|
||||
Builder<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder();
|
||||
requestResponseMap.put(describeRegionsRequest, describeRegionsResponse);
|
||||
|
@ -255,5 +88,4 @@ public class EC2ComputeServiceExpectTest extends BaseEC2ComputeServiceExpectTest
|
|||
assertNotNull(node.getCredentials().getPrivateKey());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -42,5 +42,4 @@ public abstract class BaseEC2ComputeServiceContextExpectTest<T> extends BaseEC2C
|
|||
return createInjector(fn, module, props).getInstance(ComputeServiceContext.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,10 +19,186 @@
|
|||
|
||||
package org.jclouds.ec2.compute.internal;
|
||||
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
public class BaseEC2ComputeServiceExpectTest extends BaseEC2ComputeServiceContextExpectTest<ComputeService> {
|
||||
public abstract class BaseEC2ComputeServiceExpectTest extends BaseEC2ComputeServiceContextExpectTest<ComputeService> {
|
||||
protected String region;
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties properties = super.setupProperties();
|
||||
properties.setProperty(PROPERTY_REGIONS, region);
|
||||
properties.setProperty(provider + ".template", "osDescriptionMatches=.*fedora.*");
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected HttpRequest describeAvailabilityZonesRequest;
|
||||
protected HttpResponse describeAvailabilityZonesResponse;
|
||||
protected HttpRequest describeImagesRequest;
|
||||
protected HttpResponse describeImagesResponse;
|
||||
protected HttpRequest createKeyPairRequest;
|
||||
protected HttpResponse createKeyPairResponse;
|
||||
protected HttpRequest createSecurityGroupRequest;
|
||||
protected HttpResponse createSecurityGroupResponse;
|
||||
protected HttpRequest describeSecurityGroupRequest;
|
||||
protected HttpResponse describeSecurityGroupResponse;
|
||||
protected HttpRequest authorizeSecurityGroupIngressRequest22;
|
||||
protected HttpResponse authorizeSecurityGroupIngressResponse;
|
||||
protected HttpRequest authorizeSecurityGroupIngressRequestGroup;
|
||||
protected HttpRequest runInstancesRequest;
|
||||
protected HttpResponse runInstancesResponse;
|
||||
protected HttpRequest describeInstanceRequest;
|
||||
protected HttpResponse describeInstanceResponse;
|
||||
protected HttpRequest describeImageRequest;
|
||||
|
||||
public BaseEC2ComputeServiceExpectTest() {
|
||||
region = "us-east-1";
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
protected void setupDefaultRequests() {
|
||||
super.setupDefaultRequests();
|
||||
describeAvailabilityZonesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeAvailabilityZones").build());
|
||||
|
||||
describeAvailabilityZonesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/availabilityZones-" + region + ".xml", MediaType.APPLICATION_XML)).build();
|
||||
describeImagesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeImages").build());
|
||||
|
||||
describeImagesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/describe_images.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
createKeyPairRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "CreateKeyPair")
|
||||
.addFormParam("KeyName", "jclouds#test#0").build());
|
||||
|
||||
createKeyPairResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/create_keypair.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
createSecurityGroupRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "CreateSecurityGroup")
|
||||
.addFormParam("GroupDescription", "jclouds#test")
|
||||
.addFormParam("GroupName", "jclouds#test").build());
|
||||
|
||||
createSecurityGroupResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/created_securitygroup.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
describeSecurityGroupRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeSecurityGroups")
|
||||
.addFormParam("GroupName.1", "jclouds#test").build());
|
||||
|
||||
describeSecurityGroupResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/new_securitygroup.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
authorizeSecurityGroupIngressRequest22 =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "AuthorizeSecurityGroupIngress")
|
||||
.addFormParam("CidrIp", "0.0.0.0/0")
|
||||
.addFormParam("FromPort", "22")
|
||||
.addFormParam("ToPort", "22")
|
||||
.addFormParam("GroupName", "jclouds#test")
|
||||
.addFormParam("IpProtocol", "tcp").build());
|
||||
|
||||
authorizeSecurityGroupIngressRequestGroup =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "AuthorizeSecurityGroupIngress")
|
||||
.addFormParam("SourceSecurityGroupName", "jclouds#test")
|
||||
.addFormParam("SourceSecurityGroupOwnerId", "993194456877")
|
||||
.addFormParam("GroupName", "jclouds#test").build());
|
||||
|
||||
authorizeSecurityGroupIngressResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/authorize_securitygroup_ingress_response.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
runInstancesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "RunInstances")
|
||||
.addFormParam("ImageId", "ami-be3adfd7")
|
||||
.addFormParam("InstanceType", "m1.small")
|
||||
.addFormParam("KeyName", "jclouds#test#0")
|
||||
.addFormParam("MaxCount", "1")
|
||||
.addFormParam("MinCount", "1")
|
||||
.addFormParam("SecurityGroup.1", "jclouds#test").build());
|
||||
|
||||
runInstancesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/new_instance.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
describeInstanceRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeInstances")
|
||||
.addFormParam("InstanceId.1", "i-2baa5550").build());
|
||||
|
||||
describeInstanceResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/describe_instances_running-1.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
//TODO: duplicate.. shouldn't need this
|
||||
describeImageRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("ImageId.1", "ami-aecd60c7")
|
||||
.addFormParam("Action", "DescribeImages").build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeService apply(ComputeServiceContext input) {
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.jclouds.location.Region;
|
|||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||
import org.jclouds.location.functions.ZoneToEndpoint;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -51,7 +52,10 @@ import com.google.inject.TypeLiteral;
|
|||
public class EC2RestClientModuleExpectTest extends BaseEC2ClientExpectTest<Injector> {
|
||||
private Injector injector;
|
||||
|
||||
public EC2RestClientModuleExpectTest() {
|
||||
@BeforeClass
|
||||
@Override
|
||||
protected void setupDefaultRequests() {
|
||||
super.setupDefaultRequests();
|
||||
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse> builder();
|
||||
builder.put(describeRegionsRequest, describeRegionsResponse);
|
||||
builder.putAll(describeAvailabilityZonesRequestResponse);
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.ec2.features;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.ec2.EC2Api;
|
||||
|
@ -42,10 +41,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
@Test(groups = "unit")
|
||||
public class TagApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
|
||||
|
||||
public TagApiExpectTest() {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TagApi
|
||||
* @see SinceApiVersion
|
||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.ec2.features;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.jclouds.ec2.EC2Api;
|
||||
import org.jclouds.ec2.internal.BaseEC2ApiExpectTest;
|
||||
import org.jclouds.ec2.parse.GetPasswordDataResponseTest;
|
||||
|
@ -36,10 +34,6 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = "unit", testName = "WindowsApiExpectTest")
|
||||
public class WindowsApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
|
||||
|
||||
public WindowsApiExpectTest() {
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
}
|
||||
|
||||
HttpRequest get = HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2.us-east-1.amazonaws.com/")
|
||||
|
|
|
@ -39,7 +39,7 @@ public abstract class BaseEC2ClientExpectTest<T> extends BaseEC2ExpectTest<T> {
|
|||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
// predicatable node names
|
||||
// predictable node names
|
||||
final AtomicInteger suffix = new AtomicInteger();
|
||||
bind(new TypeLiteral<Supplier<String>>() {
|
||||
}).toInstance(new Supplier<String>() {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.ec2.internal;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
|
@ -28,11 +29,13 @@ import org.jclouds.date.internal.SimpleDateFormatDateService;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.internal.BaseRestClientExpectTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
|
||||
protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z";
|
||||
|
@ -41,25 +44,28 @@ public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
|
|||
|
||||
protected FormSigner formSigner;
|
||||
|
||||
protected HttpRequest describeRegionsRequest = HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2.us-east-1.amazonaws.com/")
|
||||
.addHeader("Host", "ec2.us-east-1.amazonaws.com")
|
||||
.payload(payloadFromStringWithContentType(
|
||||
"Action=DescribeRegions&Signature=s5OXKqaaeKhJW5FVrRntuMsUL4Ed5fjzgUWeukU96ko%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
MediaType.APPLICATION_FORM_URLENCODED)).build();
|
||||
protected HttpRequest describeRegionsRequest;
|
||||
|
||||
protected HttpResponse describeRegionsResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/regionEndpoints-all.xml", MediaType.APPLICATION_XML))
|
||||
.build();
|
||||
|
||||
protected final Map<HttpRequest, HttpResponse> describeAvailabilityZonesRequestResponse;
|
||||
|
||||
protected Map<HttpRequest, HttpResponse> describeAvailabilityZonesRequestResponse;
|
||||
|
||||
public BaseEC2ExpectTest() {
|
||||
provider = "ec2";
|
||||
formSigner = createInjector(Functions.forMap(ImmutableMap.<HttpRequest, HttpResponse> of()),
|
||||
createModule(), setupProperties()).getInstance(FormSigner.class);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
protected void setupDefaultRequests() {
|
||||
Injector injector = createInjector(Functions.forMap(ImmutableMap.<HttpRequest, HttpResponse> of()),
|
||||
createModule(), setupProperties());
|
||||
formSigner = injector.getInstance(FormSigner.class);
|
||||
describeRegionsRequest = formSigner.filter(HttpRequest.builder().method("POST")
|
||||
.endpoint("https://ec2.us-east-1.amazonaws.com/").addHeader("Host", "ec2.us-east-1.amazonaws.com")
|
||||
.addFormParam("Action", "DescribeRegions").build());
|
||||
|
||||
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse> builder();
|
||||
for (String region : ImmutableSet.of("ap-northeast-1", "ap-southeast-1", "eu-west-1", "sa-east-1", "us-east-1", "us-west-1", "us-west-2")){
|
||||
builder.put(
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.aws.ec2.compute.internal;
|
||||
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY;
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.jclouds.aws.ec2.config.AWSEC2RestClientModule;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.ec2.compute.internal.BaseEC2ComputeServiceExpectTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests the compute service abstraction of the EC2 api.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public abstract class BaseAWSEC2ComputeServiceExpectTest extends BaseEC2ComputeServiceExpectTest {
|
||||
|
||||
public BaseAWSEC2ComputeServiceExpectTest() {
|
||||
provider = "aws-ec2";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties properties = super.setupProperties();
|
||||
// zero out cluster image query for now
|
||||
properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, "");
|
||||
properties.setProperty(PROPERTY_EC2_GENERATE_INSTANCE_NAMES, "false");
|
||||
return properties;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
protected void setupDefaultRequests() {
|
||||
super.setupDefaultRequests();
|
||||
|
||||
describeImagesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeImages")
|
||||
.addFormParam("Filter.1.Name", "owner-id")
|
||||
.addFormParam("Filter.1.Value.1", "137112412989")
|
||||
.addFormParam("Filter.1.Value.2", "801119661308")
|
||||
.addFormParam("Filter.1.Value.3", "063491364108")
|
||||
.addFormParam("Filter.1.Value.4", "099720109477")
|
||||
.addFormParam("Filter.1.Value.5", "411009282317")
|
||||
.addFormParam("Filter.2.Name", "state")
|
||||
.addFormParam("Filter.2.Value.1", "available")
|
||||
.addFormParam("Filter.3.Name", "image-type")
|
||||
.addFormParam("Filter.3.Value.1", "machine").build());
|
||||
}
|
||||
|
||||
@ConfiguresRestClient
|
||||
protected static class TestAWSEC2RestClientModule extends AWSEC2RestClientModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
// predicatable node names
|
||||
final AtomicInteger suffix = new AtomicInteger();
|
||||
bind(new TypeLiteral<Supplier<String>>() {
|
||||
}).toInstance(new Supplier<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return suffix.getAndIncrement() + "";
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Provides
|
||||
protected String provideTimeStamp(DateService dateService) {
|
||||
return CONSTANT_DATE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new TestAWSEC2RestClientModule();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue