Search in sources :

Example 1 with BucketList

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

the class CreateBucketTest method testPutWithStorageTypeAndLocation.

@Test
public void testPutWithStorageTypeAndLocation() {
    final String bucketName = "bucket-with-storage-and-location";
    CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
    createBucketRequest.setStorageClass(StorageClass.Standard);
    createBucketRequest.setLocationConstraint(OSS_TEST_REGION);
    try {
        ossClient.createBucket(createBucketRequest);
        AccessControlList returnedAcl = ossClient.getBucketAcl(bucketName);
        Set<Grant> grants = returnedAcl.getGrants();
        Assert.assertEquals(0, grants.size());
        System.out.println(returnedAcl.toString());
        BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
        Assert.assertEquals(1, buckets.getBucketList().size());
        Assert.assertEquals(StorageClass.Standard, buckets.getBucketList().get(0).getStorageClass());
        Assert.assertEquals(OSS_TEST_REGION, buckets.getBucketList().get(0).getLocation());
        Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
    } 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) Test(org.junit.Test)

Example 2 with BucketList

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

the class CreateBucketTest method testPutWithStorageTypeCompatibility.

@Test
public void testPutWithStorageTypeCompatibility() {
    final String bucketName = "bucket-with-storage-type-compatibility";
    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());
        Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
    } catch (Exception ex) {
        Assert.fail(ex.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) BucketList(com.aliyun.oss.model.BucketList) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 3 with BucketList

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

the class CreateBucketTest method testPutWithDefaultStorageType.

@Test
public void testPutWithDefaultStorageType() {
    final String bucketName = "bucket-with-default-storage-type";
    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());
        Assert.assertEquals(buckets.getRequestId().length(), REQUEST_ID_LEN);
    } catch (Exception ex) {
        Assert.fail(ex.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) BucketList(com.aliyun.oss.model.BucketList) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 4 with BucketList

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

the class CreateBucketTest method testPutWithStorageTypeFunc.

@Ignore
public void testPutWithStorageTypeFunc() {
    final String bucketName = "bucket-with-storage-type-func";
    try {
        ossClient.createBucket(new CreateBucketRequest(bucketName).withStorageType(StorageClass.IA));
        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 5 with BucketList

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

the class BucketInfoTest method testListBucketWithEndpoint.

@Test
public void testListBucketWithEndpoint() {
    try {
        ListBucketsRequest listBucketsRequest = new ListBucketsRequest();
        listBucketsRequest.setPrefix(bucketName);
        listBucketsRequest.setMaxKeys(1);
        BucketList buckets = ossClient.listBuckets(listBucketsRequest);
        Assert.assertEquals(buckets.getBucketList().size(), 1);
        Assert.assertNotNull(buckets.getBucketList().get(0).getExtranetEndpoint());
        Assert.assertNotNull(buckets.getBucketList().get(0).getIntranetEndpoint());
        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)

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