Search in sources :

Example 6 with BucketList

use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.

the class BucketInfoTest method testListBucketWithBid.

@Test
public void testListBucketWithBid() {
    try {
        ListBucketsRequest listBucketsRequest = new ListBucketsRequest();
        listBucketsRequest.setPrefix(bucketName);
        listBucketsRequest.setMaxKeys(1);
        listBucketsRequest.setBid("26842");
        BucketList buckets = ossClient.listBuckets(listBucketsRequest);
        Assert.assertEquals(buckets.getBucketList().size(), 1);
        Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : ListBucketsRequest(com.aliyun.oss.model.ListBucketsRequest) BucketList(com.aliyun.oss.model.BucketList) Test(org.junit.Test)

Example 7 with BucketList

use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.

the class TestBase method listAllBuckets.

protected static List<String> listAllBuckets(OSSClient client, String bucketPrefix) {
    List<String> bkts = new ArrayList<String>();
    String nextMarker = null;
    BucketList bucketList = null;
    do {
        ListBucketsRequest listBucketsRequest = new ListBucketsRequest(bucketPrefix, nextMarker, ListBucketsRequest.MAX_RETURNED_KEYS);
        bucketList = client.listBuckets(listBucketsRequest);
        nextMarker = bucketList.getNextMarker();
        for (Bucket b : bucketList.getBucketList()) {
            bkts.add(b.getName());
        }
    } while (bucketList.isTruncated());
    return bkts;
}
Also used : Bucket(com.aliyun.oss.model.Bucket) ListBucketsRequest(com.aliyun.oss.model.ListBucketsRequest) ArrayList(java.util.ArrayList) BucketList(com.aliyun.oss.model.BucketList)

Example 8 with BucketList

use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.

the class BucketReplicationTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    if (replicationClient == null) {
        replicationClient = new OSSClientBuilder().build(OSS_TEST_REPLICATION_ENDPOINT, OSS_TEST_REPLICATION_ACCESS_KEY_ID, OSS_TEST_REPLICATION_ACCESS_KEY_SECRET);
        replicationClient.createBucket(targetBucketName);
        BucketList buckets = replicationClient.listBuckets(targetBucketName, "", 100);
        Assert.assertEquals(1, buckets.getBucketList().size());
    }
}
Also used : BucketList(com.aliyun.oss.model.BucketList) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) BeforeClass(org.junit.BeforeClass)

Example 9 with BucketList

use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.

the class CreateBucketTest method testPutWithStorageType.

@Ignore
public void testPutWithStorageType() {
    final String bucketName = "bucket-with-storage-type";
    CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
    createBucketRequest.setStorageClass(StorageClass.IA);
    try {
        ossClient.createBucket(createBucketRequest);
        AccessControlList returnedAcl = ossClient.getBucketAcl(bucketName);
        Set<Grant> grants = returnedAcl.getGrants();
        Assert.assertEquals(0, grants.size());
        BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
        Assert.assertEquals(1, buckets.getBucketList().size());
        Assert.assertEquals(StorageClass.IA, buckets.getBucketList().get(0).getStorageClass());
    } catch (Exception ex) {
        Assert.fail(ex.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : AccessControlList(com.aliyun.oss.model.AccessControlList) CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) Grant(com.aliyun.oss.model.Grant) CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) BucketList(com.aliyun.oss.model.BucketList) OSSException(com.aliyun.oss.OSSException) Ignore(org.junit.Ignore)

Example 10 with BucketList

use of com.aliyun.oss.model.BucketList in project aliyun-oss-java-sdk by aliyun.

the class CreateBucketTest method testPutWithStorageTypeModify.

@Ignore
public void testPutWithStorageTypeModify() {
    final String bucketName = "bucket-with-storage-type-modify";
    CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
    try {
        ossClient.createBucket(createBucketRequest);
        BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
        Assert.assertEquals(1, buckets.getBucketList().size());
        Assert.assertEquals(StorageClass.Standard, buckets.getBucketList().get(0).getStorageClass());
        try {
            createBucketRequest.setStorageClass(StorageClass.IA);
            ossClient.createBucket(createBucketRequest);
            Assert.fail("Create bucket should not be successful.");
        } catch (OSSException oe) {
            Assert.assertEquals(OSSErrorCode.BUCKET_ALREADY_EXISTS, oe.getErrorCode());
            Assert.assertTrue(oe.getMessage().startsWith(MODIFY_STORAGE_TYPE_ERR));
        }
    } catch (Exception ex) {
        Assert.fail(ex.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) OSSException(com.aliyun.oss.OSSException) BucketList(com.aliyun.oss.model.BucketList) OSSException(com.aliyun.oss.OSSException) Ignore(org.junit.Ignore)

Aggregations

BucketList (com.aliyun.oss.model.BucketList)16 Test (org.junit.Test)9 OSSException (com.aliyun.oss.OSSException)8 Bucket (com.aliyun.oss.model.Bucket)6 CreateBucketRequest (com.aliyun.oss.model.CreateBucketRequest)6 ListBucketsRequest (com.aliyun.oss.model.ListBucketsRequest)5 ArrayList (java.util.ArrayList)4 AccessControlList (com.aliyun.oss.model.AccessControlList)3 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)3 Grant (com.aliyun.oss.model.Grant)3 Ignore (org.junit.Ignore)3 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)1 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 Owner (com.aliyun.oss.model.Owner)1 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1 BeforeClass (org.junit.BeforeClass)1