From 238fbceaaa1f25c0c9b11fb728fd8efa75716161 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 15 Oct 2012 08:46:26 -0700 Subject: [PATCH] additional test for EU create snapshot --- .../java/org/jclouds/ec2/domain/Volume.java | 12 ++++- .../EC2ElasticBlockStoreClientExpectTest.java | 46 ++++++++++++++----- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Volume.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Volume.java index f264e1847b..966a6ae440 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/Volume.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/Volume.java @@ -38,6 +38,10 @@ import com.google.common.collect.ImmutableSet; */ public class Volume implements Comparable { + public Builder toBuilder() { + return builder().fromVolume(this); + } + /** * Specifies whether the instance's Amazon EBS volumes are stopped or terminated when the * instance is shut down. @@ -146,7 +150,13 @@ public class Volume implements Comparable { public Volume build() { return new Volume(region, id, size, snapshotId, availabilityZone, status, createTime, attachments); - } + } + + public Builder fromVolume(Volume in) { + return region(in.region).id(in.id).size(in.size).snapshotId(in.snapshotId) + .availabilityZone(in.availabilityZone).status(in.status).createTime(in.createTime) + .attachments(in.attachments); + } } private final String region; diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/EC2ElasticBlockStoreClientExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/EC2ElasticBlockStoreClientExpectTest.java index 3a0e92410e..4ef1fd8c0c 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/EC2ElasticBlockStoreClientExpectTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/EC2ElasticBlockStoreClientExpectTest.java @@ -35,7 +35,16 @@ import com.google.common.collect.ImmutableMap.Builder; */ @Test(groups = "unit", testName = "EC2ElasticBlockStoreClientExpectTest") public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ExpectTest { - + Volume creating = Volume.builder() + .id("vol-2a21e543") + .status(Volume.Status.CREATING) + .availabilityZone("us-east-1a") + .region("us-east-1") + .id("vol-2a21e543") + .size(1) + .createTime(dateService.iso8601DateParse("2009-12-28T05:42:53.000Z")) + .build(); + public void testCreateVolumeInAvailabilityZone() { Builder builder = ImmutableMap.builder(); builder.put(describeRegionsRequest, describeRegionsResponse); @@ -51,18 +60,31 @@ public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ExpectTest builder = ImmutableMap.builder(); + builder.put(describeRegionsRequest, describeRegionsResponse); + builder.putAll(describeAvailabilityZonesRequestResponse); + builder.put( + formSigner.filter(HttpRequest.builder() + .method("POST") + .endpoint("https://ec2." + region + ".amazonaws.com/") + .addHeader("Host", "ec2." + region + ".amazonaws.com") + .addFormParam("Action", "CreateVolume") + .addFormParam("AvailabilityZone", "eu-west-1a") + .addFormParam("Size", "1") + .addFormParam("SnapshotId", "snap-8b7ffbdd").build()), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/created_volume.xml")).build()); + + ElasticBlockStoreClient client = requestsSendResponses(builder.build()).getElasticBlockStoreServices(); + assertEquals(client.createVolumeFromSnapshotInAvailabilityZone(region + "a", 1, "snap-8b7ffbdd"), creating.toBuilder().region(region).build()); + } }