Search in sources :

Example 1 with SetObjectTaggingRequest

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

the class ObjectTaggingTest method testNormalSetObjectAcl.

@Test
public void testNormalSetObjectAcl() {
    String key = "normal-set-tagging-acl";
    try {
        InputStream instream = genFixedLengthInputStream(1024);
        ossClient.putObject(bucketName, key, instream);
        Map<String, String> tags = new HashMap<String, String>(1);
        tags.put("tag1", "balabala");
        tags.put("tag2", "haha");
        ossClient.setObjectTagging(bucketName, key, tags);
        TagSet tagSet = ossClient.getObjectTagging(bucketName, key);
        Assert.assertEquals(tagSet.getAllTags().size(), 2);
        ossClient.deleteObjectTagging(bucketName, key);
        tagSet = ossClient.getObjectTagging(bucketName, key);
        Assert.assertEquals(tagSet.getAllTags().size(), 0);
        tagSet = new TagSet();
        tagSet.setTag("tag1", "balabala");
        SetObjectTaggingRequest request = new SetObjectTaggingRequest(bucketName, key).withTagSet(tagSet);
        Assert.assertEquals("balabala", request.getTag("tag1"));
        ossClient.setObjectTagging(request);
        tagSet = ossClient.getObjectTagging(bucketName, key);
        Assert.assertEquals(tagSet.getAllTags().size(), 1);
        ossClient.deleteObjectTagging(bucketName, key);
        tagSet = ossClient.getObjectTagging(bucketName, key);
        Assert.assertEquals(tagSet.getAllTags().size(), 0);
        tagSet = new TagSet();
        tagSet.setTag("tag1", "balabala");
        tagSet.setTag("tag2", "ala");
        // request = new SetObjectTaggingRequest(bucketName, key, tagSet);
        ossClient.setObjectTagging(bucketName, key, tagSet);
        tagSet = ossClient.getObjectTagging(bucketName, key);
        Assert.assertEquals(tagSet.getAllTags().size(), 2);
        ossClient.deleteObject(bucketName, key);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) TestUtils.genFixedLengthInputStream(com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream) InputStream(java.io.InputStream) TagSet(com.aliyun.oss.model.TagSet) SetObjectTaggingRequest(com.aliyun.oss.model.SetObjectTaggingRequest) Test(org.junit.Test)

Example 2 with SetObjectTaggingRequest

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

the class ObjectVersionTest method testObjectTagging.

@Test
public void testObjectTagging() {
    String key = "version-test-object-tagging";
    try {
        InputStream instream = genFixedLengthInputStream(1024);
        PutObjectResult putObjectResult = ossClient.putObject(bucketName, key, instream);
        String versionId = putObjectResult.getVersionId();
        Map<String, String> tags = new HashMap<String, String>(1);
        tags.put("tag1", "balabala");
        tags.put("tag2", "haha");
        SetObjectTaggingRequest setObjectTaggingRequest = new SetObjectTaggingRequest(bucketName, key, tags);
        setObjectTaggingRequest.setVersionId(versionId);
        ossClient.setObjectTagging(setObjectTaggingRequest);
        GenericRequest genericRequest = new GenericRequest(bucketName, key, versionId);
        TagSet tagSet = ossClient.getObjectTagging(genericRequest);
        Assert.assertEquals(tagSet.getAllTags().size(), 2);
        ossClient.deleteObjectTagging(genericRequest);
        tagSet = ossClient.getObjectTagging(genericRequest);
        Assert.assertEquals(tagSet.getAllTags().size(), 0);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : PutObjectResult(com.aliyun.oss.model.PutObjectResult) HashMap(java.util.HashMap) InputStream(java.io.InputStream) TagSet(com.aliyun.oss.model.TagSet) SetObjectTaggingRequest(com.aliyun.oss.model.SetObjectTaggingRequest) GenericRequest(com.aliyun.oss.model.GenericRequest) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Aggregations

SetObjectTaggingRequest (com.aliyun.oss.model.SetObjectTaggingRequest)2 TagSet (com.aliyun.oss.model.TagSet)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 OSSException (com.aliyun.oss.OSSException)1 TestUtils.genFixedLengthInputStream (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream)1 GenericRequest (com.aliyun.oss.model.GenericRequest)1 PutObjectResult (com.aliyun.oss.model.PutObjectResult)1