use of com.aliyun.oss.model.RoutingRule in project aliyun-oss-java-sdk by aliyun.
the class BucketWebsiteTest method testUnormalSetBucketWebsiteWithMirror.
@Test
public void testUnormalSetBucketWebsiteWithMirror() {
final String bucketName = "unormal-set-bucket-website-mirror";
final String indexDocument = "index.html";
try {
ossClient.createBucket(bucketName);
SetBucketWebsiteRequest request = new SetBucketWebsiteRequest(bucketName);
RoutingRule rule = new RoutingRule();
rule.setNumber(-1);
rule.getCondition().setHttpErrorCodeReturnedEquals(404);
rule.getRedirect().setRedirectType(RoutingRule.RedirectType.Mirror);
rule.getRedirect().setMirrorURL("http://oss-test.aliyun-inc.com/mirror-test-source/");
request.setIndexDocument(indexDocument);
// rule Number invalid
try {
request.AddRoutingRule(rule);
Assert.fail("Add routing rule should not be successful");
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
}
request = new SetBucketWebsiteRequest(bucketName);
rule = new RoutingRule();
rule.setNumber(1);
rule.getCondition().setHttpErrorCodeReturnedEquals(404);
rule.getRedirect().setRedirectType(RoutingRule.RedirectType.Mirror);
request.setIndexDocument(indexDocument);
// rule MirrorURL invalid
try {
request.AddRoutingRule(rule);
Assert.fail("Add routing rule should not be successful");
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
}
// rule MirrorURL invalid
request = new SetBucketWebsiteRequest(bucketName);
rule = new RoutingRule();
rule.setNumber(1);
rule.getCondition().setHttpErrorCodeReturnedEquals(404);
rule.getRedirect().setRedirectType(RoutingRule.RedirectType.Mirror);
rule.getRedirect().setMirrorURL("oss-test.aliyun-inc.com/mirror-test-source/");
request.setIndexDocument(indexDocument);
try {
request.AddRoutingRule(rule);
Assert.fail("Add routing rule should not be successful");
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
}
// rule http error code invalid
request = new SetBucketWebsiteRequest(bucketName);
rule = new RoutingRule();
rule.setNumber(1);
rule.getCondition().setHttpErrorCodeReturnedEquals(403);
rule.getRedirect().setRedirectType(RoutingRule.RedirectType.Mirror);
rule.getRedirect().setMirrorURL("http://oss-test.aliyun-inc.com/mirror-test-source/");
request.setIndexDocument(indexDocument);
request.AddRoutingRule(rule);
try {
ossClient.setBucketWebsite(request);
Assert.fail("Set bucket website should not be successful");
} catch (OSSException e) {
Assert.assertEquals(OSSErrorCode.INVALID_ARGUMENT, e.getErrorCode());
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
Aggregations