use of com.aliyun.oss.model.PutObjectResult in project aliyun-oss-java-sdk by aliyun.
the class HeadObjectTest method testHeadObject.
@Test
public void testHeadObject() {
final String key = "head-object";
final long inputStreanLength = 1024;
try {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, genFixedLengthInputStream(inputStreanLength), null);
PutObjectResult putObjectResult = ossClient.putObject(putObjectRequest);
Assert.assertEquals(putObjectResult.getRequestId().length(), REQUEST_ID_LEN);
HeadObjectRequest headObjectRequest = new HeadObjectRequest(bucketName, key);
List<String> matchingETags = new LinkedList<String>();
matchingETags.add(putObjectResult.getETag());
headObjectRequest.setMatchingETagConstraints(matchingETags);
ObjectMetadata o = ossClient.headObject(headObjectRequest);
Assert.assertEquals(o.getETag(), putObjectResult.getETag());
headObjectRequest = new HeadObjectRequest(bucketName, key);
List<String> nonmatchingEtags = new LinkedList<String>();
nonmatchingEtags.add("nonmatching");
headObjectRequest.setNonmatchingETagConstraints(nonmatchingEtags);
o = ossClient.headObject(headObjectRequest);
Assert.assertEquals(o.getETag(), putObjectResult.getETag());
headObjectRequest = new HeadObjectRequest(bucketName, key);
headObjectRequest.setModifiedSinceConstraint(new Date(System.currentTimeMillis() - 3600 * 1000));
o = ossClient.headObject(headObjectRequest);
Assert.assertEquals(o.getETag(), putObjectResult.getETag());
headObjectRequest = new HeadObjectRequest(bucketName, key);
headObjectRequest.setUnmodifiedSinceConstraint(new Date(System.currentTimeMillis() + 3600 * 1000));
o = ossClient.headObject(headObjectRequest);
Assert.assertEquals(o.getETag(), putObjectResult.getETag());
o = ossClient.headObject(bucketName, key);
Assert.assertEquals(o.getETag(), putObjectResult.getETag());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.PutObjectResult in project aliyun-oss-java-sdk by aliyun.
the class ObjectVersionTest method testPutObject.
@Test
public void testPutObject() {
String key = "version-test-put-object";
long inputStreamLength = 1024;
try {
InputStream instream = genFixedLengthInputStream(inputStreamLength);
ObjectMetadata metadata = new ObjectMetadata();
PutObjectResult putResult = ossClient.putObject(bucketName, key, instream, metadata);
Assert.assertNotNull(putResult.getVersionId());
Assert.assertEquals(64, putResult.getVersionId().length());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.PutObjectResult in project aliyun-oss-java-sdk by aliyun.
the class ObjectVersionTest method testGetObjectMetadata.
@Test
public void testGetObjectMetadata() {
String key = "version-test-get-object-metadata";
long inputStreamLength1 = 512;
long inputStreamLength2 = 1024;
try {
// Put object verison1
InputStream instream = genFixedLengthInputStream(inputStreamLength1);
ObjectMetadata metadata = new ObjectMetadata();
PutObjectResult putResult = ossClient.putObject(bucketName, key, instream, metadata);
Assert.assertNotNull(putResult.getVersionId());
Assert.assertEquals(64, putResult.getVersionId().length());
String versionId1 = putResult.getVersionId();
// Put object version2
instream = genFixedLengthInputStream(inputStreamLength2);
putResult = ossClient.putObject(bucketName, key, instream);
Assert.assertNotNull(putResult.getVersionId());
Assert.assertEquals(64, putResult.getVersionId().length());
String versionId2 = putResult.getVersionId();
// Test getObjectMetadata
GenericRequest getObjectMetadataRequest = new GenericRequest(bucketName, key, versionId1);
ObjectMetadata objectMetadata = ossClient.getObjectMetadata(getObjectMetadataRequest);
Assert.assertNotNull(objectMetadata.getVersionId());
Assert.assertEquals(64, objectMetadata.getVersionId().length());
Assert.assertEquals(objectMetadata.getContentLength(), inputStreamLength1);
// Test headObject
HeadObjectRequest HeadObjectRequest = new HeadObjectRequest(bucketName, key, versionId1);
objectMetadata = ossClient.headObject(HeadObjectRequest);
Assert.assertNotNull(objectMetadata.getVersionId());
Assert.assertEquals(64, objectMetadata.getVersionId().length());
Assert.assertEquals(objectMetadata.getContentLength(), inputStreamLength1);
// Test getSimplifiedObjectMeta
GenericRequest getSimplifiedObjectMetaRequest = new GenericRequest(bucketName, key, versionId1);
SimplifiedObjectMeta simplifiedObjectMeta = ossClient.getSimplifiedObjectMeta(getSimplifiedObjectMetaRequest);
Assert.assertNotNull(simplifiedObjectMeta.getVersionId());
Assert.assertEquals(64, simplifiedObjectMeta.getVersionId().length());
Assert.assertEquals(simplifiedObjectMeta.getVersionId(), versionId1);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.PutObjectResult in project aliyun-oss-java-sdk by aliyun.
the class ObjectVersionTest method testObjectAcl.
@Test
public void testObjectAcl() {
String key = "version-test-set-object-acl";
long inputStreamLength = 1024;
try {
InputStream instream = genFixedLengthInputStream(inputStreamLength);
ObjectMetadata metadata = new ObjectMetadata();
PutObjectResult putResult = ossClient.putObject(bucketName, key, instream, metadata);
Assert.assertNotNull(putResult.getVersionId());
String versionId1 = putResult.getVersionId();
instream = genFixedLengthInputStream(inputStreamLength);
putResult = ossClient.putObject(bucketName, key, instream, metadata);
Assert.assertNotNull(putResult.getVersionId());
String versionId2 = putResult.getVersionId();
// Set version1 'PublicRead'
SetObjectAclRequest setObjectAclRequest = new SetObjectAclRequest(bucketName, key, versionId1, CannedAccessControlList.PublicRead);
ossClient.setObjectAcl(setObjectAclRequest);
// Set version2 'Private'
setObjectAclRequest = new SetObjectAclRequest(bucketName, key, versionId2).withCannedACL(CannedAccessControlList.Private);
ossClient.setObjectAcl(setObjectAclRequest);
// Check acl of object version1
GenericRequest genericRequest = new GenericRequest(bucketName, key, versionId1);
ObjectAcl objectAcl = ossClient.getObjectAcl(genericRequest);
Assert.assertEquals(ObjectPermission.PublicRead, objectAcl.getPermission());
Assert.assertNotNull(objectAcl.getVersionId());
Assert.assertEquals(64, objectAcl.getVersionId().length());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.PutObjectResult 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