Search in sources :

Example 11 with CreateBucketRequest

use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.

the class CreateBucketTest method testPutWithStorageType.

@Ignore
public void testPutWithStorageType() {
    final String bucketName = "bucket-with-storage-type";
    CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
    createBucketRequest.setStorageClass(StorageClass.IA);
    try {
        ossClient.createBucket(createBucketRequest);
        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);
    }
}
Also used : AccessControlList(com.aliyun.oss.model.AccessControlList) CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) Grant(com.aliyun.oss.model.Grant) CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) BucketList(com.aliyun.oss.model.BucketList) OSSException(com.aliyun.oss.OSSException) Ignore(org.junit.Ignore)

Example 12 with CreateBucketRequest

use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.

the class CreateBucketTest method testPutWithInconsistentLocation.

@Test
public void testPutWithInconsistentLocation() {
    final String bucketName = "bucket-with-inconsistent-location";
    CreateBucketRequest request = new CreateBucketRequest(bucketName);
    // Make location constraint inconsistent with endpoint
    request.setLocationConstraint("oss-ap-southeast-1");
    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));
    }
}
Also used : CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 13 with CreateBucketRequest

use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.

the class CreateBucketTest method testPutWithStorageTypeModify.

@Ignore
public void testPutWithStorageTypeModify() {
    final String bucketName = "bucket-with-storage-type-modify";
    CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
    try {
        ossClient.createBucket(createBucketRequest);
        BucketList buckets = ossClient.listBuckets(bucketName, "", 100);
        Assert.assertEquals(1, buckets.getBucketList().size());
        Assert.assertEquals(StorageClass.Standard, buckets.getBucketList().get(0).getStorageClass());
        try {
            createBucketRequest.setStorageClass(StorageClass.IA);
            ossClient.createBucket(createBucketRequest);
            Assert.fail("Create bucket should not be successful.");
        } catch (OSSException oe) {
            Assert.assertEquals(OSSErrorCode.BUCKET_ALREADY_EXISTS, oe.getErrorCode());
            Assert.assertTrue(oe.getMessage().startsWith(MODIFY_STORAGE_TYPE_ERR));
        }
    } catch (Exception ex) {
        Assert.fail(ex.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) OSSException(com.aliyun.oss.OSSException) BucketList(com.aliyun.oss.model.BucketList) OSSException(com.aliyun.oss.OSSException) Ignore(org.junit.Ignore)

Example 14 with CreateBucketRequest

use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.

the class CreateBucketTest method testPutWithUnsupportedLocation.

@Test
public void testPutWithUnsupportedLocation() {
    final String bucketName = "bucket-with-unsupported-location";
    final String unsupportedLocation = "oss-cn-zhengzhou";
    CreateBucketRequest request = new CreateBucketRequest(bucketName);
    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));
    }
}
Also used : CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 15 with CreateBucketRequest

use of com.aliyun.oss.model.CreateBucketRequest in project aliyun-oss-java-sdk by aliyun.

the class ArchiveTest method testNormalRestoreObject.

@Ignore
public void testNormalRestoreObject() {
    String bucketName = "restore-object-test-bucket";
    String key = "normal-restore-object.txt";
    String filePath = null;
    try {
        // create archive bucket
        CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
        createBucketRequest.setStorageClass(StorageClass.Archive);
        ossClient.createBucket(createBucketRequest);
        // put archive object
        filePath = genFixedLengthFile(1024);
        ossClient.putObject(bucketName, key, new File(filePath));
        ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, key);
        // check whether the object is archive class
        StorageClass storageClass = objectMetadata.getObjectStorageClass();
        if (storageClass == StorageClass.Archive) {
            // restore object
            ossClient.restoreObject(bucketName, key);
            // wait for restore completed
            do {
                Thread.sleep(1000);
                objectMetadata = ossClient.getObjectMetadata(bucketName, key);
                System.out.println("x-oss-restore:" + objectMetadata.getObjectRawRestore());
            } while (!objectMetadata.isRestoreCompleted());
        }
        // get restored object
        OSSObject ossObject = ossClient.getObject(bucketName, key);
        ossObject.getObjectContent().close();
        // restore repeatedly
        ossClient.restoreObject(bucketName, key);
        // delete object
        ossClient.deleteObject(bucketName, key);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    } finally {
        removeFile(filePath);
        ossClient.deleteBucket(bucketName);
    }
}
Also used : OSSObject(com.aliyun.oss.model.OSSObject) CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) StorageClass(com.aliyun.oss.model.StorageClass) TestUtils.genFixedLengthFile(com.aliyun.oss.integrationtests.TestUtils.genFixedLengthFile) TestUtils.removeFile(com.aliyun.oss.integrationtests.TestUtils.removeFile) File(java.io.File) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) OSSException(com.aliyun.oss.OSSException) Ignore(org.junit.Ignore)

Aggregations

CreateBucketRequest (com.aliyun.oss.model.CreateBucketRequest)17 OSSException (com.aliyun.oss.OSSException)15 Test (org.junit.Test)11 BucketList (com.aliyun.oss.model.BucketList)6 AccessControlList (com.aliyun.oss.model.AccessControlList)4 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)4 Grant (com.aliyun.oss.model.Grant)4 Ignore (org.junit.Ignore)4 TestUtils.genFixedLengthFile (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthFile)3 TestUtils.removeFile (com.aliyun.oss.integrationtests.TestUtils.removeFile)3 File (java.io.File)3 OSS (com.aliyun.oss.OSS)2 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)2 OSSObject (com.aliyun.oss.model.OSSObject)2 PutObjectRequest (com.aliyun.oss.model.PutObjectRequest)2 ClientException (com.aliyun.oss.ClientException)1 Bucket (com.aliyun.oss.model.Bucket)1 ListBucketsRequest (com.aliyun.oss.model.ListBucketsRequest)1 OSSObjectSummary (com.aliyun.oss.model.OSSObjectSummary)1 ObjectAcl (com.aliyun.oss.model.ObjectAcl)1