use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testModifyExistingBucketLocation.
@Test
public void testModifyExistingBucketLocation() {
final String bucketName = "modify-existing-bucket-location";
try {
ossClient.createBucket(bucketName);
String loc = ossClient.getBucketLocation(bucketName);
Assert.assertEquals(OSS_TEST_REGION, loc);
// Try to modify location of existing bucket
CreateBucketRequest request = new CreateBucketRequest(bucketName);
request.setLocationConstraint("oss-ap-southeast-1");
ossClient.createBucket(request);
Assert.fail("Create bucket should not be successful.");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_LOCATION_CONSTRAINT, e.getErrorCode());
Assert.assertTrue(e.getMessage().startsWith(INVALID_LOCATION_CONSTRAINT_ERR));
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithCannedACL.
@Test
public void testPutWithCannedACL() {
final String bucketName = "bucket-with-canned-acl";
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
try {
// Create bucket with default(private) acl
ossClient.createBucket(createBucketRequest);
AccessControlList returnedAcl = ossClient.getBucketAcl(bucketName);
Set<Grant> grants = returnedAcl.getGrants();
Assert.assertEquals(0, grants.size());
Assert.assertEquals(returnedAcl.getCannedACL(), CannedAccessControlList.Private);
// Try to create existing bucket without setting acl
ossClient.createBucket(bucketName);
waitForCacheExpiration(5);
returnedAcl = ossClient.getBucketAcl(bucketName);
grants = returnedAcl.getGrants();
Assert.assertEquals(0, grants.size());
// Create bucket with public-read acl
createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
ossClient.createBucket(createBucketRequest);
waitForCacheExpiration(5);
returnedAcl = ossClient.getBucketAcl(bucketName);
grants = returnedAcl.getGrants();
Assert.assertEquals(1, grants.size());
Grant grant = (Grant) grants.toArray()[0];
Assert.assertEquals(GroupGrantee.AllUsers, grant.getGrantee());
Assert.assertEquals(Permission.Read, grant.getPermission());
Assert.assertEquals(returnedAcl.getCannedACL(), CannedAccessControlList.PublicRead);
// Try to create existing bucket without setting acl
ossClient.createBucket(bucketName);
waitForCacheExpiration(5);
returnedAcl = ossClient.getBucketAcl(bucketName);
grants = returnedAcl.getGrants();
Assert.assertEquals(1, grants.size());
grant = (Grant) grants.toArray()[0];
Assert.assertEquals(GroupGrantee.AllUsers, grant.getGrantee());
Assert.assertEquals(Permission.Read, grant.getPermission());
// Create bucket with public-read-write acl
createBucketRequest.setCannedACL(CannedAccessControlList.PublicReadWrite);
ossClient.createBucket(createBucketRequest);
waitForCacheExpiration(5);
returnedAcl = ossClient.getBucketAcl(bucketName);
grants = returnedAcl.getGrants();
Assert.assertEquals(1, grants.size());
grant = (Grant) grants.toArray()[0];
Assert.assertEquals(GroupGrantee.AllUsers, grant.getGrantee());
Assert.assertEquals(Permission.FullControl, grant.getPermission());
Assert.assertEquals(returnedAcl.getCannedACL(), CannedAccessControlList.PublicReadWrite);
// Try to create existing bucket without setting acl
ossClient.createBucket(bucketName);
waitForCacheExpiration(5);
returnedAcl = ossClient.getBucketAcl(bucketName);
grants = returnedAcl.getGrants();
Assert.assertEquals(1, grants.size());
grant = (Grant) grants.toArray()[0];
Assert.assertEquals(GroupGrantee.AllUsers, grant.getGrantee());
Assert.assertEquals(Permission.FullControl, grant.getPermission());
} catch (Exception ex) {
Assert.fail(ex.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.CreateBucketRequest 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);
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class CreateBucketTest method testPutWithWithStorageTypeUnsupportedLocation.
@Test
public void testPutWithWithStorageTypeUnsupportedLocation() {
final String bucketName = "bucket-with-storage-unsupported-location";
final String unsupportedLocation = "oss-cn-zhengzhou";
CreateBucketRequest request = new CreateBucketRequest(bucketName);
request.setStorageClass(StorageClass.Standard);
request.setLocationConstraint(unsupportedLocation);
try {
ossClient.createBucket(request);
Assert.fail("Create bucket should not be successful.");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_LOCATION_CONSTRAINT, e.getErrorCode());
Assert.assertTrue(e.getMessage().startsWith(INVALID_LOCATION_CONSTRAINT_ERR));
}
}
use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.
the class ArchiveTest method testUnormalOutofRestore.
@Test
public void testUnormalOutofRestore() {
String bucketName = "unnormal-restore-test-bucket";
String key = "unnormal-restore-object.txt";
String filePath = null;
try {
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setStorageClass(StorageClass.Archive);
ossClient.createBucket(createBucketRequest);
filePath = genFixedLengthFile(1024);
ossClient.putObject(bucketName, key, new File(filePath));
try {
ossClient.getObject(bucketName, key);
Assert.fail("Restore object should not be successful");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_OBJECT_STATE, e.getErrorCode());
}
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
removeFile(filePath);
ossClient.deleteObject(bucketName, key);
ossClient.deleteBucket(bucketName);
}
}
Aggregations