package com.qmth.boot.test.core.fss;

import com.qmth.boot.core.fss.store.impl.DiskStore;
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.nio.charset.StandardCharsets;

public class DiskStoreTest {

    @Test
    public void test() throws Exception {
        DiskStore store = new DiskStore("http://server.com", System.getProperty("java.io.tmpdir"),
                System.getProperty("java.io.tmpdir"), null);
        String content = RandomStringUtils.random(128, true, true);
        byte[] data = content.getBytes(StandardCharsets.UTF_8);
        store.write("/1/123.txt", new ByteArrayInputStream(data), ByteArray.md5(data).toBase64());
        Assert.assertTrue(store.exist("1/123.txt"));
        Assert.assertEquals(content, ByteArray.fromInputStream(store.read("1/123.txt")).toString());
    }
}
