use of com.aliyun.oss.model.BucketInfo in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithAll.
@Test
public void testClientBuilderWithAll() {
try {
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setSupportCname(true);
config.setConnectionTimeout(10000);
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET), config);
Assert.assertTrue(ossClient.getClientConfiguration().isSupportCname());
Assert.assertEquals(ossClient.getClientConfiguration().getConnectionTimeout(), 10000);
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(TEST_CONTENT.getBytes().length);
ossClient.putObject(bucketName, TEST_KEY, new ByteArrayInputStream(TEST_CONTENT.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, TEST_KEY);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, TEST_KEY);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.BucketInfo in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderDefault.
@Test
public void testClientBuilderDefault() {
try {
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET);
Assert.assertFalse(ossClient.getClientConfiguration().isSupportCname());
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(TEST_CONTENT.getBytes().length);
ossClient.putObject(bucketName, TEST_KEY, new ByteArrayInputStream(TEST_CONTENT.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, TEST_KEY);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, TEST_KEY);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.BucketInfo in project aliyun-oss-java-sdk by aliyun.
the class BucketInfoTest method testGetBucketInfo.
@SuppressWarnings("deprecation")
@Test
public void testGetBucketInfo() {
try {
ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
Assert.assertEquals(info.getBucket().getLocation(), TestConfig.OSS_TEST_REGION);
Assert.assertNotNull(info.getBucket().getCreationDate());
Assert.assertTrue(info.getBucket().getExtranetEndpoint().length() > 0);
Assert.assertTrue(info.getBucket().getIntranetEndpoint().length() > 0);
Assert.assertTrue(info.getBucket().getOwner().getId().length() > 0);
Assert.assertEquals(CannedAccessControlList.PublicRead, info.getCannedACL());
Assert.assertEquals(info.getBucket().getOwner().getDisplayName(), info.getBucket().getOwner().getId());
Assert.assertEquals(info.getGrants().size(), 1);
Assert.assertEquals(info.getRequestId().length(), REQUEST_ID_LEN);
for (Grant grant : info.getGrants()) {
Assert.assertEquals(grant.getGrantee(), GroupGrantee.AllUsers);
Assert.assertEquals(grant.getPermission(), Permission.Read);
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
Aggregations