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