Search in sources :

Example 1 with CreateSymlinkRequest

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

the class SymlinkTest method testNormalCreateSymlink.

@Test
public void testNormalCreateSymlink() {
    final String symLink = "normal-create-sym-link";
    try {
        ossClient.putObject(bucketName, targetObject, new ByteArrayInputStream(content.getBytes()));
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentType("text/plain");
        metadata.addUserMetadata("property", "property-value");
        CreateSymlinkRequest createSymlinkRequest = new CreateSymlinkRequest(bucketName, symLink, targetObject);
        createSymlinkRequest.setMetadata(metadata);
        ossClient.createSymlink(createSymlinkRequest);
        OSSSymlink symbolicLink = ossClient.getSymlink(bucketName, symLink);
        Assert.assertEquals(symbolicLink.getSymlink(), symLink);
        Assert.assertEquals(symbolicLink.getTarget(), targetObject);
        Assert.assertEquals(symbolicLink.getMetadata().getContentType(), "text/plain");
        Assert.assertEquals(symbolicLink.getMetadata().getUserMetadata().get("property"), "property-value");
        Assert.assertEquals(symbolicLink.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.deleteObject(bucketName, symLink);
        ossClient.deleteObject(bucketName, targetObject);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CreateSymlinkRequest(com.aliyun.oss.model.CreateSymlinkRequest) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) OSSException(com.aliyun.oss.OSSException) OSSSymlink(com.aliyun.oss.model.OSSSymlink) Test(org.junit.Test)

Aggregations

OSSException (com.aliyun.oss.OSSException)1 CreateSymlinkRequest (com.aliyun.oss.model.CreateSymlinkRequest)1 OSSSymlink (com.aliyun.oss.model.OSSSymlink)1 ObjectMetadata (com.aliyun.oss.model.ObjectMetadata)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.Test)1