mirror of https://github.com/apache/jclouds.git
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
This commit is contained in:
parent
032cd8717c
commit
12cb9055b6
|
@ -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<org.jclouds.aws.s3.domain.S3Bucket> jcBucketList =
|
||||
connection.getBuckets().get(
|
||||
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS);
|
||||
|
||||
ArrayList<org.jets3t.service.model.S3Bucket> jsBucketList =
|
||||
new ArrayList<org.jets3t.service.model.S3Bucket>();
|
||||
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.<S3ServiceException> rethrowIfRuntimeOrSameType(e);
|
||||
throw new S3ServiceException("error listing buckets", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<org.jclouds.aws.s3.domain.S3Bucket> jcBuckets = client.getBuckets().get(10, TimeUnit.SECONDS);
|
||||
|
||||
assert jsBuckets.length == jcBuckets.size();
|
||||
|
||||
Iterator<org.jclouds.aws.s3.domain.S3Bucket> 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
|
||||
|
|
Loading…
Reference in New Issue