Search in sources :

Example 6 with BucketWebsiteResult

use of com.aliyun.oss.model.BucketWebsiteResult in project aliyun-oss-java-sdk by aliyun.

the class BucketWebsiteTest method testNormalSetBucketWebsite.

@Test
public void testNormalSetBucketWebsite() {
    final String bucketName = "normal-set-bucket-website";
    final String indexDocument = "index.html";
    final String errorDocument = "error.html";
    try {
        ossClient.createBucket(bucketName);
        // Set both index document and error document
        SetBucketWebsiteRequest request = new SetBucketWebsiteRequest(bucketName);
        request.setIndexDocument(indexDocument);
        request.setErrorDocument(errorDocument);
        ossClient.setBucketWebsite(request);
        waitForCacheExpiration(5);
        BucketWebsiteResult result = ossClient.getBucketWebsite(bucketName);
        Assert.assertEquals(indexDocument, result.getIndexDocument());
        Assert.assertEquals(errorDocument, result.getErrorDocument());
        Assert.assertEquals(result.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.deleteBucketWebsite(bucketName);
        // Set index document only
        request = new SetBucketWebsiteRequest(bucketName);
        request.setIndexDocument(indexDocument);
        request.setErrorDocument(null);
        ossClient.setBucketWebsite(request);
        waitForCacheExpiration(5);
        result = ossClient.getBucketWebsite(bucketName);
        Assert.assertEquals(indexDocument, result.getIndexDocument());
        Assert.assertTrue(result.getErrorDocument() == null);
        Assert.assertEquals(result.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.deleteBucketWebsite(bucketName);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    } finally {
        ossClient.deleteBucket(bucketName);
    }
}
Also used : SetBucketWebsiteRequest(com.aliyun.oss.model.SetBucketWebsiteRequest) BucketWebsiteResult(com.aliyun.oss.model.BucketWebsiteResult) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Aggregations

BucketWebsiteResult (com.aliyun.oss.model.BucketWebsiteResult)6 SetBucketWebsiteRequest (com.aliyun.oss.model.SetBucketWebsiteRequest)5 OSSException (com.aliyun.oss.OSSException)4 RoutingRule (com.aliyun.oss.model.RoutingRule)4 Test (org.junit.Test)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