diff --git a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/ElasticHostsAsyncClient.java b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/ElasticHostsAsyncClient.java index 22e967a9d8..b41c5dbd89 100644 --- a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/ElasticHostsAsyncClient.java +++ b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/ElasticHostsAsyncClient.java @@ -80,6 +80,22 @@ public interface ElasticHostsAsyncClient { @ResponseParser(SplitNewlines.class) ListenableFuture> listStandardDrives(); + /** + * @see ElasticHostsClient#listStandardCds() + */ + @GET + @Path("/drives/standard/cd/list") + @ResponseParser(SplitNewlines.class) + ListenableFuture> listStandardCds(); + + /** + * @see ElasticHostsClient#listStandardImages() + */ + @GET + @Path("/drives/standard/img/list") + @ResponseParser(SplitNewlines.class) + ListenableFuture> listStandardImages(); + /** * @see ElasticHostsClient#listDriveInfo() */ diff --git a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/ElasticHostsClient.java b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/ElasticHostsClient.java index 103a9e9883..9c1d964254 100644 --- a/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/ElasticHostsClient.java +++ b/sandbox/elastichosts/src/main/java/org/jclouds/elastichosts/ElasticHostsClient.java @@ -54,6 +54,20 @@ public interface ElasticHostsClient { */ Set listStandardDrives(); + /** + * list of cd uuids that are in the library + * + * @return or empty set if no cds are found + */ + Set listStandardCds(); + + /** + * list of image uuids that are in the library + * + * @return or empty set if no images are found + */ + Set listStandardImages(); + /** * Get all drives info * diff --git a/sandbox/elastichosts/src/test/java/org/jclouds/elastichosts/ElasticHostsAsyncClientTest.java b/sandbox/elastichosts/src/test/java/org/jclouds/elastichosts/ElasticHostsAsyncClientTest.java index 854441387b..a183686169 100644 --- a/sandbox/elastichosts/src/test/java/org/jclouds/elastichosts/ElasticHostsAsyncClientTest.java +++ b/sandbox/elastichosts/src/test/java/org/jclouds/elastichosts/ElasticHostsAsyncClientTest.java @@ -102,6 +102,36 @@ public class ElasticHostsAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.com/drives/standard/cd/list HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + } + + public void testListStandardImages() throws SecurityException, NoSuchMethodException, IOException { + Method method = ElasticHostsAsyncClient.class.getMethod("listStandardImages"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.com/drives/standard/img/list HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + } + public void testListDriveInfo() throws SecurityException, NoSuchMethodException, IOException { Method method = ElasticHostsAsyncClient.class.getMethod("listDriveInfo"); GeneratedHttpRequest httpRequest = processor.createRequest(method); @@ -279,6 +309,7 @@ public class ElasticHostsAsyncClientTest extends RestClientTest drives = client.listStandardCds(); + assertNotNull(drives); + } + + @Test + public void testListStandardImages() throws Exception { + Set drives = client.listStandardImages(); + assertNotNull(drives); + } + @Test public void testGetDrive() throws Exception { for (String driveUUID : client.listDrives()) { @@ -132,11 +147,12 @@ public class ElasticHostsClientLiveTest { private String prefix = System.getProperty("user.name") + ".test"; private DriveInfo info; + private DriveInfo info2; @Test public void testCreate() throws Exception { try { - findAndDestroyDrive(); + findAndDestroyDrive(prefix); } catch (Exception e) { } @@ -149,12 +165,25 @@ public class ElasticHostsClientLiveTest { } - public void testWeCanReadAndWriteToDrive() { - // TODO put a bunch of bytes and then read them back. + @Test(dependsOnMethods = "testCreate") + public void testWeCanReadAndWriteToDrive() throws IOException { + client.writeDrive(info.getUuid(), Payloads.newStringPayload("foo")); + assertEquals(Utils.toStringAndClose(client.readDrive(info.getUuid()).getInput()), "foo"); } - public void testWeCopyADriveContentsViaGzip() { - // TODO gzip source to destination, then gunzip back to source and assert equiv + @Test(dependsOnMethods = "testWeCanReadAndWriteToDrive") + public void testWeCopyADriveContentsViaGzip() throws IOException { + try { + findAndDestroyDrive(prefix + "2"); + } catch (Exception e) { + + } + info2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1024 * 1024l).build()); + client.imageDrive(info.getUuid(), info2.getUuid()); + + // TODO block until complete + System.err.println("state " + client.getDriveInfo(info2.getUuid())); + assertEquals(Utils.toStringAndClose(client.readDrive(info2.getUuid()).getInput()), "foo"); } @@ -166,6 +195,7 @@ public class ElasticHostsClientLiveTest { new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous") .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")) .tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar")).build()); + assertNotNull(info2.getUuid(), info.getUuid()); assertEquals(info.getName(), "rediculous"); assertEquals(info.getClaimType(), ClaimType.SHARED); @@ -177,12 +207,12 @@ public class ElasticHostsClientLiveTest { @Test(dependsOnMethods = "testSetDriveData") public void testDestroyDrive() throws Exception { - findAndDestroyDrive(); + findAndDestroyDrive(prefix); assertEquals(client.getDriveInfo(info.getUuid()), null); } - protected void findAndDestroyDrive() { + protected void findAndDestroyDrive(final String prefix) { DriveInfo drive = Iterables.find(client.listDriveInfo(), new Predicate() { @Override