use of com.aliyun.oss.model.ObjectAcl in project aliyun-oss-java-sdk by aliyun.
the class ObjectAclTest method testNormalSetObjectAcl.
@Test
public void testNormalSetObjectAcl() {
final String key = "normal-set-object-acl";
// 128KB
final long inputStreamLength = 128 * 1024;
try {
InputStream instream = genFixedLengthInputStream(inputStreamLength);
ossClient.putObject(bucketName, key, instream);
for (CannedAccessControlList acl : ACLS) {
ossClient.setObjectAcl(bucketName, key, acl);
ObjectAcl returnedAcl = ossClient.getObjectAcl(bucketName, key);
Assert.assertEquals(acl.toString(), returnedAcl.getPermission().toString());
Assert.assertEquals(returnedAcl.getRequestId().length(), REQUEST_ID_LEN);
OSSObject object = ossClient.getObject(bucketName, key);
Assert.assertEquals(inputStreamLength, object.getObjectMetadata().getContentLength());
Assert.assertEquals(object.getRequestId().length(), REQUEST_ID_LEN);
object.getObjectContent().close();
}
// Set to default acl again
ossClient.setObjectAcl(bucketName, key, CannedAccessControlList.Default);
ObjectAcl returnedAcl = ossClient.getObjectAcl(bucketName, key);
Assert.assertEquals(ObjectPermission.Default, returnedAcl.getPermission());
Assert.assertEquals(returnedAcl.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.ObjectAcl in project aliyun-oss-java-sdk by aliyun.
the class ObjectAclTest method testPutObjectWithACLHeader.
@Test
public void testPutObjectWithACLHeader() throws IOException {
final String key = "put-object-with-acl-header";
// 128KB
final long inputStreamLength = 128 * 1024;
try {
InputStream instream = genFixedLengthInputStream(inputStreamLength);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setObjectAcl(CannedAccessControlList.PublicRead);
ossClient.putObject(bucketName, key, instream, metadata);
OSSObject o = ossClient.getObject(bucketName, key);
Assert.assertEquals(key, o.getKey());
Assert.assertEquals(o.getRequestId().length(), REQUEST_ID_LEN);
// Verify uploaded objects acl
ObjectAcl returnedACL = ossClient.getObjectAcl(bucketName, key);
Assert.assertEquals(ObjectPermission.PublicRead, returnedACL.getPermission());
Assert.assertEquals(returnedACL.getRequestId().length(), REQUEST_ID_LEN);
Assert.assertEquals(o.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.ObjectAcl in project aliyun-oss-java-sdk by aliyun.
the class ObjectAclTest method testUploadMultipartsWithAclHeader.
@Test
public void testUploadMultipartsWithAclHeader() {
final String key = "normal-upload-multiparts-with-acl-header";
// 128KB
final int partSize = 128 * 1024;
final int partCount = 10;
try {
// Initial multipart upload
String uploadId = claimUploadId(ossClient, bucketName, key);
// Upload parts
List<PartETag> partETags = new ArrayList<PartETag>();
for (int i = 0; i < partCount; i++) {
InputStream instream = genFixedLengthInputStream(partSize);
UploadPartRequest uploadPartRequest = new UploadPartRequest();
uploadPartRequest.setBucketName(bucketName);
uploadPartRequest.setKey(key);
uploadPartRequest.setInputStream(instream);
uploadPartRequest.setPartNumber(i + 1);
uploadPartRequest.setPartSize(partSize);
uploadPartRequest.setUploadId(uploadId);
UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
Assert.assertEquals(uploadPartResult.getRequestId().length(), REQUEST_ID_LEN);
partETags.add(uploadPartResult.getPartETag());
}
// Complete multipart upload
CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key, uploadId, partETags);
completeMultipartUploadRequest.setObjectACL(CannedAccessControlList.PublicRead);
CompleteMultipartUploadResult completeMultipartUploadResult = ossClient.completeMultipartUpload(completeMultipartUploadRequest);
Assert.assertEquals(composeLocation(ossClient, OSS_TEST_ENDPOINT, bucketName, key), completeMultipartUploadResult.getLocation());
Assert.assertEquals(bucketName, completeMultipartUploadResult.getBucketName());
Assert.assertEquals(key, completeMultipartUploadResult.getKey());
Assert.assertEquals(calcMultipartsETag(partETags), completeMultipartUploadResult.getETag());
Assert.assertEquals(completeMultipartUploadResult.getRequestId().length(), REQUEST_ID_LEN);
// Get uploaded object
OSSObject o = ossClient.getObject(bucketName, key);
final long objectSize = partCount * partSize;
Assert.assertEquals(objectSize, o.getObjectMetadata().getContentLength());
Assert.assertEquals(calcMultipartsETag(partETags), o.getObjectMetadata().getETag());
// Verify uploaded objects acl
ObjectAcl returnedACL = ossClient.getObjectAcl(bucketName, key);
Assert.assertEquals(ObjectPermission.PublicRead, returnedACL.getPermission());
Assert.assertEquals(returnedACL.getRequestId().length(), REQUEST_ID_LEN);
Assert.assertEquals(o.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.ObjectAcl in project aliyun-oss-java-sdk by aliyun.
the class ObjectAclTest method testIgnoredObjectAclHeader.
@Test
public void testIgnoredObjectAclHeader() {
final String dummyKey = "test-ignored-object-acl-header";
try {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setObjectAcl(null);
ossClient.putObject(bucketName, dummyKey, new ByteArrayInputStream(new byte[0]), metadata);
ObjectAcl objectAcl = ossClient.getObjectAcl(bucketName, dummyKey);
Assert.assertEquals(ObjectPermission.Default, objectAcl.getPermission());
Assert.assertEquals(objectAcl.getRequestId().length(), REQUEST_ID_LEN);
metadata.setObjectAcl(CannedAccessControlList.Private);
ossClient.putObject(bucketName, dummyKey, new ByteArrayInputStream(new byte[0]), metadata);
objectAcl = ossClient.getObjectAcl(bucketName, dummyKey);
Assert.assertEquals(ObjectPermission.Private, objectAcl.getPermission());
Assert.assertEquals(objectAcl.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.ObjectAcl in project aliyun-oss-java-sdk by aliyun.
the class ObjectAclTest method testUnormalGetObjectAcl.
@Test
public void testUnormalGetObjectAcl() {
// Get non-existent object acl
final String nonexistentObject = "unormal-get-object-acl";
try {
ossClient.getObjectAcl(bucketName, nonexistentObject);
Assert.fail("Get 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));
}
// Get object using default acl
final String objectUsingDefaultAcl = "object-using-default-acl";
// 128KB
final long inputStreamLength = 128 * 1024;
try {
InputStream instream = genFixedLengthInputStream(inputStreamLength);
ossClient.putObject(bucketName, objectUsingDefaultAcl, instream);
ObjectAcl returnedACL = ossClient.getObjectAcl(bucketName, objectUsingDefaultAcl);
Assert.assertEquals(ObjectPermission.Default, returnedACL.getPermission());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
Aggregations