|
@@ -5,6 +5,7 @@ import com.qmth.boot.core.fss.utils.OssConfig;
|
|
|
import com.qmth.boot.tools.models.ByteArray;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.junit.Assert;
|
|
|
+import org.junit.Test;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.time.Duration;
|
|
@@ -19,17 +20,24 @@ public class OssStoreTest {
|
|
|
|
|
|
private String config_local = "oss://key:secret@test.oss-api.qmth.com.cn";
|
|
|
|
|
|
- //@Test
|
|
|
+ @Test
|
|
|
public void test() throws Exception {
|
|
|
OssStore store = new OssStore(new OssConfig(config_cloud, server_cloud), System.getProperty("java.io.tmpdir"));
|
|
|
String content = RandomStringUtils.random(128, true, true);
|
|
|
ByteArray data = ByteArray.fromString(content);
|
|
|
- store.write("/test/1.txt", new ByteArrayInputStream(data.value()), ByteArray.md5(data.value()).toHexString());
|
|
|
- Assert.assertTrue(store.exist("test/1.txt"));
|
|
|
- Assert.assertEquals(content, ByteArray.fromInputStream(store.read("test/1.txt")).toString());
|
|
|
- String url = store.getServerUrl("/test/1.txt", Duration.ofMinutes(5));
|
|
|
+ store.write("/test/randome", new ByteArrayInputStream(data.value()), ByteArray.md5(data.value()).toHexString());
|
|
|
+ Assert.assertTrue(store.exist("test/randome"));
|
|
|
+ Assert.assertEquals(content, ByteArray.fromInputStream(store.read("test/randome")).toString());
|
|
|
+ String url = store.getServerUrl("/test/randome", Duration.ofMinutes(5));
|
|
|
//System.out.println(url);
|
|
|
Assert.assertEquals(content, ByteArray.fromUrl(url).toString());
|
|
|
+
|
|
|
+ // data = ByteArray.fromFile(new File("/Users/luoshi/Downloads/test.pdf"));
|
|
|
+ // store.write("/test/test.pdf", new ByteArrayInputStream(data.value()),
|
|
|
+ // ByteArray.md5(data.value()).toHexString());
|
|
|
+ // data = ByteArray.fromFile(new File("/Users/luoshi/Downloads/test.json"));
|
|
|
+ // store.write("/test/test.json", new ByteArrayInputStream(data.value()),
|
|
|
+ // ByteArray.md5(data.value()).toHexString());
|
|
|
store.close();
|
|
|
}
|
|
|
|