use of com.qcloud.cos.model.GroupGrantee in project cos-java-sdk-v5 by tencentyun.
the class AclTest method GetAclForNewPubReadBucket.
@Test
public void GetAclForNewPubReadBucket() throws InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
String aclTestBucketName = null;
try {
aclTestBucketName = "javasdkacltest-" + appid;
CreateBucketRequest createBucketRequest = new CreateBucketRequest(aclTestBucketName);
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
cosclient.createBucket(createBucketRequest);
AccessControlList aclGet = cosclient.getBucketAcl(aclTestBucketName);
assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.PublicRead);
assertNotNull(aclGet.getOwner());
assertNotNull(aclGet.getOwner().getId());
assertNotNull(aclGet.getOwner().getDisplayName());
assertEquals(2, aclGet.getGrantsAsList().size());
Grant firstGrant = aclGet.getGrantsAsList().get(0);
assertEquals(Permission.Read.toString(), firstGrant.getPermission().toString());
assertTrue(firstGrant.getGrantee() instanceof GroupGrantee);
Grant secondGrant = aclGet.getGrantsAsList().get(1);
assertEquals(Permission.FullControl.toString(), secondGrant.getPermission().toString());
assertTrue(secondGrant.getGrantee() instanceof UinGrantee);
// set to PublicReadWrite acl and get canned acl compare
Thread.sleep(5000);
cosclient.setBucketAcl(aclTestBucketName, CannedAccessControlList.PublicReadWrite);
aclGet = cosclient.getBucketAcl(aclTestBucketName);
assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.PublicReadWrite);
// set to private and get canned acl compare
Thread.sleep(5000);
cosclient.setBucketAcl(aclTestBucketName, CannedAccessControlList.Private);
aclGet = cosclient.getBucketAcl(aclTestBucketName);
assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.Private);
} finally {
if (aclTestBucketName != null) {
cosclient.deleteBucket(aclTestBucketName);
aclTestBucketName = null;
}
}
}
Aggregations