Search in sources :

Example 6 with RoutingRule

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

Aggregations

RoutingRule (com.aliyun.oss.model.RoutingRule)6 OSSException (com.aliyun.oss.OSSException)5 SetBucketWebsiteRequest (com.aliyun.oss.model.SetBucketWebsiteRequest)5 Test (org.junit.Test)5 BucketWebsiteResult (com.aliyun.oss.model.BucketWebsiteResult)4 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 ParseException (java.text.ParseException)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1