use of com.qcloud.cos.model.CORSRule in project cos-java-sdk-v5 by tencentyun.
the class CORSTest method setBucketCORSTest.
@Test
public void setBucketCORSTest() throws InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
BucketCrossOriginConfiguration bucketCORS = new BucketCrossOriginConfiguration();
List<CORSRule> corsRules = new ArrayList<>();
CORSRule corsRule = new CORSRule();
corsRule.setId("set-bucket-cors-test");
corsRule.setAllowedMethods(AllowedMethods.PUT, AllowedMethods.GET, AllowedMethods.HEAD);
corsRule.setAllowedHeaders("x-cos-grant-full-control");
corsRule.setAllowedOrigins("http://mail.qq.com", "http://www.qq.com", "http://video.qq.com");
corsRule.setExposedHeaders("x-cos-request-id");
corsRule.setMaxAgeSeconds(60);
corsRules.add(corsRule);
bucketCORS.setRules(corsRules);
cosclient.setBucketCrossOriginConfiguration(bucket, bucketCORS);
Thread.sleep(5000L);
BucketCrossOriginConfiguration corsGet = cosclient.getBucketCrossOriginConfiguration(bucket);
assertEquals(1, corsGet.getRules().size());
CORSRule corsRuleGet = corsGet.getRules().get(0);
assertEquals(3, corsRuleGet.getAllowedMethods().size());
assertEquals(1, corsRuleGet.getAllowedHeaders().size());
assertEquals(3, corsRuleGet.getAllowedOrigins().size());
assertEquals(1, corsRuleGet.getExposedHeaders().size());
assertEquals(60, corsRuleGet.getMaxAgeSeconds());
cosclient.deleteBucketCrossOriginConfiguration(bucket);
}
use of com.qcloud.cos.model.CORSRule in project cos-java-sdk-v5 by tencentyun.
the class CORSTest method putAndGetNotExistBucketCORSTest.
@Test
public void putAndGetNotExistBucketCORSTest() {
if (!judgeUserInfoValid()) {
return;
}
String bucketName = "not-exist-" + bucket;
BucketCrossOriginConfiguration bucketCORS = new BucketCrossOriginConfiguration();
List<CORSRule> corsRules = new ArrayList<>();
bucketCORS.setRules(corsRules);
try {
cosclient.setBucketCrossOriginConfiguration(bucketName, bucketCORS);
} catch (CosServiceException cse) {
assertEquals(4, cse.getStatusCode() / 100);
}
try {
cosclient.getBucketCrossOriginConfiguration(bucketName);
} catch (CosServiceException cse) {
assertEquals(404, cse.getStatusCode() / 100);
}
}
Aggregations