Search in sources :

Example 6 with BucketInfo

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());
    }
}
Also used : ClientBuilderConfiguration(com.aliyun.oss.ClientBuilderConfiguration) OSSObject(com.aliyun.oss.model.OSSObject) ByteArrayInputStream(java.io.ByteArrayInputStream) OSSClient(com.aliyun.oss.OSSClient) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultCredentialProvider(com.aliyun.oss.common.auth.DefaultCredentialProvider) BucketInfo(com.aliyun.oss.model.BucketInfo) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) Test(org.junit.Test)

Example 7 with BucketInfo

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());
    }
}
Also used : OSSObject(com.aliyun.oss.model.OSSObject) ByteArrayInputStream(java.io.ByteArrayInputStream) OSSClient(com.aliyun.oss.OSSClient) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BucketInfo(com.aliyun.oss.model.BucketInfo) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) Test(org.junit.Test)

Example 8 with BucketInfo

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());
    }
}
Also used : Grant(com.aliyun.oss.model.Grant) BucketInfo(com.aliyun.oss.model.BucketInfo) Test(org.junit.Test)

Aggregations

BucketInfo (com.aliyun.oss.model.BucketInfo)8 OSSObject (com.aliyun.oss.model.OSSObject)6 OSSClient (com.aliyun.oss.OSSClient)5 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)5 ObjectMetadata (com.aliyun.oss.model.ObjectMetadata)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 Test (org.junit.Test)5 ClientBuilderConfiguration (com.aliyun.oss.ClientBuilderConfiguration)3 DefaultCredentialProvider (com.aliyun.oss.common.auth.DefaultCredentialProvider)3 ClientException (com.aliyun.oss.ClientException)1 OSS (com.aliyun.oss.OSS)1 OSSException (com.aliyun.oss.OSSException)1 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 Bucket (com.aliyun.oss.model.Bucket)1 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)1 Grant (com.aliyun.oss.model.Grant)1 OSSObjectSummary (com.aliyun.oss.model.OSSObjectSummary)1 ObjectListing (com.aliyun.oss.model.ObjectListing)1 Owner (com.aliyun.oss.model.Owner)1