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());
}
}
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());
}
}
Aggregations