From 12cb9055b6ec8c1696bdd9172496d4371e234a8f Mon Sep 17 00:00:00 2001 From: jamurty Date: Mon, 4 May 2009 18:57:05 +0000 Subject: [PATCH] Implemented bucket listing method listAllBucketsImpl for JetS3t-compatible service, as practice to get my feet wet. git-svn-id: http://jclouds.googlecode.com/svn/trunk@249 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../aws/s3/jets3t/JCloudsS3Service.java | 25 +++++++++++++++-- .../aws/s3/jets3t/JCloudsS3ServiceTest.java | 27 +++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java b/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java index 1630b32b3e..1f66006156 100644 --- a/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java +++ b/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java @@ -23,7 +23,9 @@ */ package org.jclouds.aws.s3.jets3t; +import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -203,8 +205,27 @@ public class JCloudsS3Service extends S3Service { @Override protected S3Bucket[] listAllBucketsImpl() throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); + try { + List jcBucketList = + connection.getBuckets().get( + requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); + + ArrayList jsBucketList = + new ArrayList(); + for (org.jclouds.aws.s3.domain.S3Bucket jcBucket: jcBucketList) { + org.jets3t.service.model.S3Bucket jsBucket = + new org.jets3t.service.model.S3Bucket(jcBucket.getName()); + jsBucket.setOwner(new org.jets3t.service.model.S3Owner( + jcBucket.getCanonicalUser().getId(), + jcBucket.getCanonicalUser().getDisplayName())); + jsBucketList.add(jsBucket); + } + return (org.jets3t.service.model.S3Bucket[]) jsBucketList.toArray( + new org.jets3t.service.model.S3Bucket[jsBucketList.size()]); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3ServiceException("error listing buckets", e); + } } @Override diff --git a/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceTest.java b/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceTest.java index ae6d0e2e25..c3164edeae 100644 --- a/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceTest.java +++ b/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceTest.java @@ -26,6 +26,8 @@ package org.jclouds.aws.s3.jets3t; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; +import java.util.Iterator; +import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -183,8 +185,29 @@ public class JCloudsS3ServiceTest extends S3IntegrationTest { } @Test - public void testListAllBucketsImpl() { - fail("Not yet implemented"); + public void testListAllBucketsImpl() + throws InterruptedException, ExecutionException, TimeoutException, S3ServiceException { + // Ensure there is at least 1 bucket in S3 account to list and compare. + String bucketName = bucketPrefix + ".testListAllBucketsImplString"; + org.jclouds.aws.s3.domain.S3Bucket jcloudsBucket = createBucket(bucketName); + + S3Bucket[] jsBuckets = service.listAllBuckets(); + + List jcBuckets = client.getBuckets().get(10, TimeUnit.SECONDS); + + assert jsBuckets.length == jcBuckets.size(); + + Iterator jcBucketsIter = jcBuckets.iterator(); + for (S3Bucket jsBucket: jsBuckets) { + assert jcBucketsIter.hasNext(); + + org.jclouds.aws.s3.domain.S3Bucket jcBucket = jcBucketsIter.next(); + assert jsBucket.getName().equals(jcBucket.getName()); + assert jsBucket.getOwner().getId().equals(jcBucket.getCanonicalUser().getId()); + assert jsBucket.getOwner().getDisplayName().equals(jcBucket.getCanonicalUser().getDisplayName()); + } + + client.deleteBucket(jcloudsBucket); } @Test