Search in sources :

Example 11 with BucketVersioningConfiguration

use of com.qcloud.cos.model.BucketVersioningConfiguration in project cos-java-sdk-v5 by tencentyun.

the class BucketVersioningTest method testBucketVersioningEnabled.

@Test
public void testBucketVersioningEnabled() {
    if (!judgeUserInfoValid()) {
        return;
    }
    BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
    cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
    try {
        Thread.sleep(5000L);
    } catch (InterruptedException e) {
        fail(e.toString());
    }
    BucketVersioningConfiguration bucketVersioningRet = cosclient.getBucketVersioningConfiguration(bucket);
    assertEquals(BucketVersioningConfiguration.ENABLED, bucketVersioningRet.getStatus());
}
Also used : SetBucketVersioningConfigurationRequest(com.qcloud.cos.model.SetBucketVersioningConfigurationRequest) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) Test(org.junit.Test)

Example 12 with BucketVersioningConfiguration

use of com.qcloud.cos.model.BucketVersioningConfiguration in project cos-java-sdk-v5 by tencentyun.

the class CreateDeleteHeadBucketTest method testCreateDeleteBucketPrivate.

@Test
public void testCreateDeleteBucketPrivate() throws Exception {
    if (!judgeUserInfoValid()) {
        return;
    }
    try {
        String bucketName = String.format("java-pri-%s", appid);
        CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
        createBucketRequest.setCannedAcl(CannedAccessControlList.Private);
        Bucket bucket = cosclient.createBucket(createBucketRequest);
        assertEquals(bucketName, bucket.getName());
        assertTrue(cosclient.doesBucketExist(bucketName));
        BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(bucketName);
        assertEquals(BucketVersioningConfiguration.OFF, bucketVersioningConfiguration.getStatus());
        cosclient.deleteBucket(bucketName);
        // 删除bucket后, 由于server端有缓存 需要稍后查询, 这里sleep 5 秒
        Thread.sleep(5000L);
        assertFalse(cosclient.doesBucketExist(bucketName));
    } catch (CosServiceException cse) {
        fail(cse.toString());
    }
}
Also used : CosServiceException(com.qcloud.cos.exception.CosServiceException) Bucket(com.qcloud.cos.model.Bucket) CreateBucketRequest(com.qcloud.cos.model.CreateBucketRequest) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) Test(org.junit.Test)

Example 13 with BucketVersioningConfiguration

use of com.qcloud.cos.model.BucketVersioningConfiguration in project cos-java-sdk-v5 by tencentyun.

the class BucketVersioningTest method testBucketVersioningSuspended.

@Test
public void testBucketVersioningSuspended() {
    if (!judgeUserInfoValid()) {
        return;
    }
    BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.SUSPENDED);
    cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
    try {
        Thread.sleep(5000L);
    } catch (InterruptedException e) {
        fail(e.toString());
    }
    BucketVersioningConfiguration bucketVersioningRet = cosclient.getBucketVersioningConfiguration(bucket);
    assertEquals(BucketVersioningConfiguration.SUSPENDED, bucketVersioningRet.getStatus());
}
Also used : SetBucketVersioningConfigurationRequest(com.qcloud.cos.model.SetBucketVersioningConfigurationRequest) BucketVersioningConfiguration(com.qcloud.cos.model.BucketVersioningConfiguration) Test(org.junit.Test)

Aggregations

BucketVersioningConfiguration (com.qcloud.cos.model.BucketVersioningConfiguration)13 Test (org.junit.Test)10 SetBucketVersioningConfigurationRequest (com.qcloud.cos.model.SetBucketVersioningConfigurationRequest)9 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 Bucket (com.qcloud.cos.model.Bucket)3 CreateBucketRequest (com.qcloud.cos.model.CreateBucketRequest)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 COSVersionSummary (com.qcloud.cos.model.COSVersionSummary)2 DeleteObjectsRequest (com.qcloud.cos.model.DeleteObjectsRequest)2 KeyVersion (com.qcloud.cos.model.DeleteObjectsRequest.KeyVersion)2 DeleteObjectsResult (com.qcloud.cos.model.DeleteObjectsResult)2 ListVersionsRequest (com.qcloud.cos.model.ListVersionsRequest)2 PutObjectResult (com.qcloud.cos.model.PutObjectResult)2 VersionListing (com.qcloud.cos.model.VersionListing)2 COSClient (com.qcloud.cos.COSClient)1 ClientConfig (com.qcloud.cos.ClientConfig)1 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)1 COSCredentials (com.qcloud.cos.auth.COSCredentials)1 CosClientException (com.qcloud.cos.exception.CosClientException)1