use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.
the class ListBucketsTest method testUnormalListBuckets.
@Test
public void testUnormalListBuckets() {
final String nonexistentBucketNamePrefix = "nonexistent-bucket-name-prefix-";
try {
// List all existing buckets prefix with 'nonexistent-bucket-name-prefix-'
BucketList bucketList = ossClient.listBuckets(nonexistentBucketNamePrefix, null, null);
Assert.assertEquals(0, bucketList.getBucketList().size());
// Set 'max-keys' equal zero(MUST be between 1 and 1000)
bucketList = ossClient.listBuckets(null, null, 0);
Assert.fail("List bucket should not be successful");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_ARGUMENT, e.getErrorCode());
}
}
use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.
the class ListBucketsTest method testNormalListBuckets.
@Test
public void testNormalListBuckets() {
final String bucketNamePrefix = BUCKET_NAME_PREFIX + "normal-list-buckets-";
try {
List<Bucket> returnedBuckets = ossClient.listBuckets();
for (Bucket bkt : returnedBuckets) {
if (bkt.getName().startsWith(bucketNamePrefix)) {
ossClient.deleteBucket(bkt.getName());
}
}
waitForCacheExpiration(5);
List<String> existingBuckets = new ArrayList<String>();
returnedBuckets = ossClient.listBuckets();
for (Bucket bkt : returnedBuckets) {
if (bkt.getName().startsWith(bucketNamePrefix)) {
existingBuckets.add(bkt.getName());
}
}
int remaindingAllowed = MAX_BUCKETS_ALLOWED - existingBuckets.size();
List<String> newlyBuckets = new ArrayList<String>();
for (int i = 0; i < remaindingAllowed; i++) {
String bucketName = bucketNamePrefix + i;
try {
ossClient.createBucket(bucketName);
newlyBuckets.add(bucketName);
waitForCacheExpiration(5);
String loc = ossClient.getBucketLocation(bucketName);
Assert.assertEquals(OSS_TEST_REGION, loc);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
waitForCacheExpiration(5);
// List all existing buckets
returnedBuckets = ossClient.listBuckets();
existingBuckets.clear();
for (Bucket bkt : returnedBuckets) {
if (bkt.getName().startsWith(bucketNamePrefix)) {
existingBuckets.add(bkt.getName());
}
}
Assert.assertEquals(MAX_BUCKETS_ALLOWED, existingBuckets.size());
// List all existing buckets prefix with 'normal-list-buckets-'
BucketList bucketList = ossClient.listBuckets(bucketNamePrefix, null, null);
Assert.assertEquals(remaindingAllowed, bucketList.getBucketList().size());
for (Bucket bkt : bucketList.getBucketList()) {
Assert.assertTrue(bkt.getName().startsWith(bucketNamePrefix));
}
// List 'max-keys' buckets each time
final int maxKeys = 3;
bucketList = ossClient.listBuckets(bucketNamePrefix, null, maxKeys);
Assert.assertTrue(bucketList.getBucketList().size() <= 3);
returnedBuckets.clear();
returnedBuckets.addAll(bucketList.getBucketList());
while (bucketList.isTruncated()) {
bucketList = ossClient.listBuckets(new ListBucketsRequest(bucketNamePrefix, bucketList.getNextMarker(), maxKeys));
Assert.assertTrue(bucketList.getBucketList().size() <= 3);
returnedBuckets.addAll(bucketList.getBucketList());
}
Assert.assertEquals(remaindingAllowed, returnedBuckets.size());
for (Bucket bkt : returnedBuckets) {
Assert.assertTrue(bkt.getName().startsWith(bucketNamePrefix));
}
for (String bkt : newlyBuckets) {
ossClient.deleteBucket(bkt);
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.
the class OSSBucketOperation method listBuckets.
/**
* List all my buckets.
*/
public List<Bucket> listBuckets() throws OSSException, ClientException {
BucketList bucketList = listBuckets(new ListBucketsRequest(null, null, null));
List<Bucket> buckets = bucketList.getBucketList();
while (bucketList.isTruncated()) {
bucketList = listBuckets(new ListBucketsRequest(null, bucketList.getNextMarker(), null));
buckets.addAll(bucketList.getBucketList());
}
return buckets;
}
use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.
the class OSSResponseParserTest method testParseListBucket.
@Test
public void testParseListBucket() throws Exception {
String filename = "listBucket.xml";
InputStream in = getInputStream(filename);
BucketList bucketList = ResponseParsers.parseListBucket(in);
assertEquals(null, bucketList.getPrefix());
assertEquals(null, bucketList.getMarker());
assertEquals(null, bucketList.getMaxKeys());
assertEquals(false, bucketList.isTruncated());
assertEquals(null, bucketList.getNextMarker());
List<Bucket> buckets = bucketList.getBucketList();
Bucket bucket1 = buckets.get(0);
Assert.assertEquals("51744", bucket1.getOwner().getId());
Assert.assertEquals("51744", bucket1.getOwner().getDisplayName());
Assert.assertEquals("pacjux7y1b86pmtu7g8d6b7z-test-bucket", bucket1.getName());
Assert.assertEquals(DateUtil.parseIso8601Date("2012-02-09T01:49:38.000Z"), bucket1.getCreationDate());
Bucket bucket2 = buckets.get(1);
Assert.assertEquals("51744", bucket2.getOwner().getId());
Assert.assertEquals("51744", bucket2.getOwner().getDisplayName());
Assert.assertEquals("ganshumantest", bucket2.getName());
Assert.assertEquals(DateUtil.parseIso8601Date("2012-02-09T06:38:47.000Z"), bucket2.getCreationDate());
in.close();
filename = "listBucketTruncated.xml";
in = getInputStream(filename);
bucketList = ResponseParsers.parseListBucket(in);
assertEquals("asdasdasdasd", bucketList.getPrefix());
assertEquals("asdasdasd", bucketList.getMarker());
assertEquals(Integer.valueOf(1), bucketList.getMaxKeys());
assertEquals(true, bucketList.isTruncated());
assertEquals("asdasdasdasdasd", bucketList.getNextMarker());
buckets = bucketList.getBucketList();
bucket1 = buckets.get(0);
Assert.assertEquals("51744", bucket1.getOwner().getId());
Assert.assertEquals("51744", bucket1.getOwner().getDisplayName());
Assert.assertEquals("asdasdasdasd", bucket1.getName());
Assert.assertEquals("osslocation", bucket1.getLocation());
Assert.assertEquals(DateUtil.parseIso8601Date("2014-05-15T11:18:32.000Z"), bucket1.getCreationDate());
in.close();
}
use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.
the class BucketListTest method testBucketList.
@Test
public void testBucketList() {
BucketList bucketList = new BucketList();
bucketList.setPrefix("prefix");
bucketList.setMarker("marker");
bucketList.setMaxKeys(Integer.valueOf(6));
bucketList.setTruncated(true);
bucketList.setNextMarker("nextMarker");
List<Bucket> buckets = new ArrayList<Bucket>();
Bucket bucket = new Bucket();
bucket.setName("name");
bucket.setLocation("osslocation");
buckets.add(bucket);
bucketList.setBucketList(buckets);
assertEquals("prefix", bucketList.getPrefix());
assertEquals("marker", bucketList.getMarker());
assertEquals(6, bucketList.getMaxKeys().intValue());
assertEquals("nextMarker", bucketList.getNextMarker());
assertEquals(true, bucketList.isTruncated());
assertEquals(1, bucketList.getBucketList().size());
buckets = bucketList.getBucketList();
bucket = buckets.get(0);
assertEquals("name", bucket.getName());
assertEquals("osslocation", bucket.getLocation());
}
Aggregations