Search in sources :

Example 1 with PutImageStyleRequest

use of com.aliyun.oss.model.PutImageStyleRequest 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 2 with PutImageStyleRequest

use of com.aliyun.oss.model.PutImageStyleRequest 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 3 with PutImageStyleRequest

use of com.aliyun.oss.model.PutImageStyleRequest 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)3 PutImageStyleRequest (com.aliyun.oss.model.PutImageStyleRequest)3 GenericRequest (com.aliyun.oss.model.GenericRequest)1 GetImageStyleResult (com.aliyun.oss.model.GetImageStyleResult)1 Style (com.aliyun.oss.model.Style)1