Search in sources :

Example 1 with PutBucketImageRequest

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

the class TestForImg method testForDeleteBucketImage.

public void testForDeleteBucketImage() {
    PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
    clientImg.putBucketImage(request);
    sleepSecond(10);
    clientImg.deleteBucketImage(bucketName);
    // List<Style> styleList = clientImg.listImageStyle(bucketName);
    // System.out.println("Style List:" + styleList.size());
    sleepSecond(10);
    try {
        clientImg.getBucketImage(bucketName);
        Assert.assertTrue(false);
    } catch (Exception e) {
    // e.printStackTrace();
    // Do Nothing
    }
}
Also used : PutBucketImageRequest(com.aliyun.oss.model.PutBucketImageRequest)

Example 2 with PutBucketImageRequest

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

the class TestForImg method testListImageStyle.

public void testListImageStyle() {
    // Clear all image style
    clientImg.deleteBucketImage(bucketName);
    sleepSecond(10);
    PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
    clientImg.putBucketImage(request);
    sleepSecond(10);
    PutImageStyleRequest requestStyle = new PutImageStyleRequest();
    requestStyle.SetBucketName(bucketName);
    // Same length with style
    String[] styleName = { "myStyle", "myStyle1", "myStyle2", "myStyle3", "myStyle4" };
    String[] style = { "200w", "300w", "400w", "500w", "600w" };
    for (int i = 0; i < styleName.length; ++i) {
        requestStyle.SetStyle(style[i]);
        requestStyle.SetStyleName(styleName[i]);
        clientImg.putImageStyle(requestStyle);
    }
    sleepSecond(10);
    List<Style> styleList = clientImg.listImageStyle(bucketName);
    Assert.assertEquals(styleList.size(), styleName.length);
    int i;
    for (Style s : styleList) {
        for (i = 0; i < style.length; i++) {
            if (s.GetStyle().equals(style[i]))
                break;
        }
        Assert.assertTrue(i != style.length);
        for (i = 0; i < styleName.length; i++) {
            if (s.GetStyleName().equals(styleName[i]))
                break;
        }
        Assert.assertTrue(i != styleName.length);
    }
}
Also used : Style(com.aliyun.oss.model.Style) PutBucketImageRequest(com.aliyun.oss.model.PutBucketImageRequest) PutImageStyleRequest(com.aliyun.oss.model.PutImageStyleRequest)

Example 3 with PutBucketImageRequest

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

the class TestForImg method testPutGetDeleteImageStyle.

public void testPutGetDeleteImageStyle() {
    PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
    clientImg.putBucketImage(request);
    sleepSecond(10);
    PutImageStyleRequest requestStyle = new PutImageStyleRequest();
    requestStyle.SetBucketName(bucketName);
    String styleName = "myStyle";
    String style = "200w";
    requestStyle.SetStyle(style);
    requestStyle.SetStyleName(styleName);
    clientImg.putImageStyle(requestStyle);
    sleepSecond(10);
    GetImageStyleResult result = clientImg.getImageStyle(bucketName, styleName);
    Assert.assertEquals(result.GetStyle(), style);
    Assert.assertEquals(result.GetStyleName(), styleName);
    clientImg.deleteImageStyle(bucketName, styleName);
    sleepSecond(20);
    try {
        clientImg.getImageStyle(bucketName, styleName);
        Assert.assertTrue(false);
    } catch (Exception e) {
    // Do Nothing
    }
}
Also used : GetImageStyleResult(com.aliyun.oss.model.GetImageStyleResult) PutBucketImageRequest(com.aliyun.oss.model.PutBucketImageRequest) PutImageStyleRequest(com.aliyun.oss.model.PutImageStyleRequest)

Example 4 with PutBucketImageRequest

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

the class TestForImg method testPutGetBucketImage.

public void testPutGetBucketImage() {
    PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
    clientImg.putBucketImage(request);
    sleepSecond(10);
    GetBucketImageResult result = clientImg.getBucketImage(bucketName);
    Assert.assertEquals(result.GetBucketName(), bucketName);
    Assert.assertEquals(result.GetDefault404Pic(), "");
    Assert.assertFalse(result.GetIsAutoSetContentType());
    Assert.assertFalse(result.GetIsForbidOrigPicAccess());
    Assert.assertFalse(result.GetIsUseSrcFormat());
    Assert.assertFalse(result.GetIsSetAttachName());
    Assert.assertEquals(result.GetStyleDelimiters(), "!");
    Assert.assertEquals(result.GetStatus(), "Enabled");
    request.SetIsForbidOrigPicAccess(true);
    request.SetIsUseStyleOnly(true);
    request.SetIsAutoSetContentType(true);
    request.SetIsUseSrcFormat(true);
    request.SetIsSetAttachName(true);
    String default404Pic = "index.png";
    request.SetDefault404Pic(default404Pic);
    String styleDelimiters = "_";
    request.SetStyleDelimiters(styleDelimiters);
    clientImg.putBucketImage(request);
    sleepSecond(20);
    result = clientImg.getBucketImage(bucketName);
    Assert.assertEquals(result.GetBucketName(), bucketName);
    Assert.assertEquals(result.GetDefault404Pic(), default404Pic);
    Assert.assertFalse(!result.GetIsAutoSetContentType());
    // TODO img's problem
    Assert.assertFalse(!result.GetIsForbidOrigPicAccess());
    Assert.assertFalse(!result.GetIsUseSrcFormat());
    Assert.assertFalse(!result.GetIsSetAttachName());
    Assert.assertEquals(result.GetStyleDelimiters(), styleDelimiters);
    Assert.assertEquals(result.GetStatus(), "Enabled");
}
Also used : PutBucketImageRequest(com.aliyun.oss.model.PutBucketImageRequest) GetBucketImageResult(com.aliyun.oss.model.GetBucketImageResult)

Example 5 with PutBucketImageRequest

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

the class TestForImg method testGenernicRequest.

// 已抓包看了所有请求头
public void testGenernicRequest() {
    PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
    GenericRequest req = new GenericRequest();
    request.addHeader("oss-request-ip", "31.71.68.91");
    request.addHeader("oss-request-agent", "oss-java-sdk");
    request.addHeader("oss-operation", "PutBucketImage");
    try {
        clientImg.putBucketImage(request);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "GetBucketImage");
    try {
        clientImg.getBucketImage(bucketName, req);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "DeleteBucketImage");
    try {
        clientImg.deleteBucketImage(bucketName, req);
    } catch (Exception e) {
    }
    PutImageStyleRequest requestStyle = new PutImageStyleRequest();
    requestStyle.SetBucketName(bucketName);
    String styleName = "style";
    String styleContent = "200w";
    requestStyle.SetStyle(styleName);
    requestStyle.SetStyleName(styleContent);
    requestStyle.addHeader("oss-operation", "PutImageStyle");
    try {
        clientImg.putImageStyle(requestStyle);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "DeleteImageStyle");
    try {
        clientImg.deleteImageStyle(bucketName, styleName, req);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "GetImageStyle");
    try {
        clientImg.getImageStyle(bucketName, styleName, req);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "ListImageStyle");
    try {
        clientImg.listImageStyle(bucketName, req);
    } catch (Exception e) {
    }
}
Also used : PutBucketImageRequest(com.aliyun.oss.model.PutBucketImageRequest) PutImageStyleRequest(com.aliyun.oss.model.PutImageStyleRequest) GenericRequest(com.aliyun.oss.model.GenericRequest)

Aggregations

PutBucketImageRequest (com.aliyun.oss.model.PutBucketImageRequest)5 PutImageStyleRequest (com.aliyun.oss.model.PutImageStyleRequest)3 GenericRequest (com.aliyun.oss.model.GenericRequest)1 GetBucketImageResult (com.aliyun.oss.model.GetBucketImageResult)1 GetImageStyleResult (com.aliyun.oss.model.GetImageStyleResult)1 Style (com.aliyun.oss.model.Style)1