use of com.aliyun.oss.model.SetObjectAclRequest in project aliyun-oss-java-sdk by aliyun.
the class ObjectVersionTest method testObjectAcl.
@Test
public void testObjectAcl() {
String key = "version-test-set-object-acl";
long inputStreamLength = 1024;
try {
InputStream instream = genFixedLengthInputStream(inputStreamLength);
ObjectMetadata metadata = new ObjectMetadata();
PutObjectResult putResult = ossClient.putObject(bucketName, key, instream, metadata);
Assert.assertNotNull(putResult.getVersionId());
String versionId1 = putResult.getVersionId();
instream = genFixedLengthInputStream(inputStreamLength);
putResult = ossClient.putObject(bucketName, key, instream, metadata);
Assert.assertNotNull(putResult.getVersionId());
String versionId2 = putResult.getVersionId();
// Set version1 'PublicRead'
SetObjectAclRequest setObjectAclRequest = new SetObjectAclRequest(bucketName, key, versionId1, CannedAccessControlList.PublicRead);
ossClient.setObjectAcl(setObjectAclRequest);
// Set version2 'Private'
setObjectAclRequest = new SetObjectAclRequest(bucketName, key, versionId2).withCannedACL(CannedAccessControlList.Private);
ossClient.setObjectAcl(setObjectAclRequest);
// Check acl of object version1
GenericRequest genericRequest = new GenericRequest(bucketName, key, versionId1);
ObjectAcl objectAcl = ossClient.getObjectAcl(genericRequest);
Assert.assertEquals(ObjectPermission.PublicRead, objectAcl.getPermission());
Assert.assertNotNull(objectAcl.getVersionId());
Assert.assertEquals(64, objectAcl.getVersionId().length());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.SetObjectAclRequest in project aliyun-oss-java-sdk by aliyun.
the class ObjectAclTest method testUnormalSetObjectAcl.
@Test
public void testUnormalSetObjectAcl() {
try {
// Set non-existent object
final String nonexistentObject = "unormal-set-object-acl";
try {
SetObjectAclRequest request = new SetObjectAclRequest(bucketName, nonexistentObject).withCannedACL(CannedAccessControlList.Default);
request.setCannedACL(CannedAccessControlList.Private);
ossClient.setObjectAcl(request);
Assert.fail("Set object acl should not be successful");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.NO_SUCH_KEY, e.getErrorCode());
Assert.assertTrue(e.getMessage().startsWith(NO_SUCH_KEY_ERR));
}
// Set unknown permission
final String unknownPermission = "UnknownPermission";
try {
ObjectPermission permission = ObjectPermission.parsePermission(unknownPermission);
Assert.assertEquals(ObjectPermission.Unknown, permission);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
Aggregations