Search in sources :

Example 1 with SetBucketTaggingRequest

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

the class BucketTaggingTest method testSetBucketTagging.

@Test
public void testSetBucketTagging() {
    try {
        SetBucketTaggingRequest request = new SetBucketTaggingRequest(bucketName);
        request.setTag("tk1", "tv1");
        request.setTag("tk2", "tv2");
        ossClient.setBucketTagging(request);
        TagSet tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
        Assert.assertEquals(tagSet.getRequestId().length(), REQUEST_ID_LEN);
        Map<String, String> tags = tagSet.getAllTags();
        Assert.assertEquals(2, tags.size());
        Assert.assertTrue(tags.containsKey("tk1"));
        Assert.assertTrue(tags.containsKey("tk2"));
        ossClient.deleteBucketTagging(new GenericRequest(bucketName));
        waitForCacheExpiration(5);
        tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
        Assert.assertEquals(tagSet.getRequestId().length(), REQUEST_ID_LEN);
        tags = tagSet.getAllTags();
        Assert.assertTrue(tags.isEmpty());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : SetBucketTaggingRequest(com.aliyun.oss.model.SetBucketTaggingRequest) TagSet(com.aliyun.oss.model.TagSet) GenericRequest(com.aliyun.oss.model.GenericRequest) Test(org.junit.Test)

Aggregations

GenericRequest (com.aliyun.oss.model.GenericRequest)1 SetBucketTaggingRequest (com.aliyun.oss.model.SetBucketTaggingRequest)1 TagSet (com.aliyun.oss.model.TagSet)1 Test (org.junit.Test)1