Search in sources :

Example 1 with Grantee

use of com.qcloud.cos.model.Grantee in project cos-java-sdk-v5 by tencentyun.

the class CreateDeleteHeadBucketTest method testCreateDeleteBucketPublicReadWrite.

@Test
public void testCreateDeleteBucketPublicReadWrite() throws Exception {
    if (!judgeUserInfoValid()) {
        return;
    }
    try {
        String bucketName = String.format("java-pubrw-%s", appid);
        CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
        createBucketRequest.setCannedAcl(CannedAccessControlList.PublicReadWrite);
        AccessControlList accessControlList = new AccessControlList();
        Grantee grantee = new UinGrantee("730123456");
        accessControlList.grantPermission(grantee, Permission.Write);
        createBucketRequest.setAccessControlList(accessControlList);
        Bucket bucket = cosclient.createBucket(createBucketRequest);
        assertEquals(bucketName, bucket.getName());
        assertTrue(cosclient.doesBucketExist(bucketName));
        BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(bucketName);
        assertEquals(BucketVersioningConfiguration.OFF, bucketVersioningConfiguration.getStatus());
        cosclient.deleteBucket(bucketName);
        // 删除bucket后, 由于server端有缓存 需要稍后查询, 这里sleep 5 秒
        Thread.sleep(5000L);
        assertFalse(cosclient.doesBucketExist(bucketName));
    } catch (CosServiceException cse) {
        fail(cse.toString());
    }
}
Also used : CannedAccessControlList(com.qcloud.cos.model.CannedAccessControlList) AccessControlList(com.qcloud.cos.model.AccessControlList) UinGrantee(com.qcloud.cos.model.UinGrantee) UinGrantee(com.qcloud.cos.model.UinGrantee) Grantee(com.qcloud.cos.model.Grantee) CosServiceException(com.qcloud.cos.exception.CosServiceException) Bucket(com.qcloud.cos.model.Bucket) CreateBucketRequest(com.qcloud.cos.model.CreateBucketRequest) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) Test(org.junit.Test)

Aggregations

CosServiceException (com.qcloud.cos.exception.CosServiceException)1 AccessControlList (com.qcloud.cos.model.AccessControlList)1 Bucket (com.qcloud.cos.model.Bucket)1 BucketVersioningConfiguration (com.qcloud.cos.model.BucketVersioningConfiguration)1 CannedAccessControlList (com.qcloud.cos.model.CannedAccessControlList)1 CreateBucketRequest (com.qcloud.cos.model.CreateBucketRequest)1 Grantee (com.qcloud.cos.model.Grantee)1 UinGrantee (com.qcloud.cos.model.UinGrantee)1 Test (org.junit.Test)1