package com.tax.file.test;

import com.tax.file.constants.CommonConstants;
import com.yxcheng.tax.fs.minio.service.MinioTemplate;
import io.minio.ObjectStat;
import org.junit.Before;
import org.junit.Test;

import java.io.FileInputStream;

public class TestMinio {
    MinioTemplate template = null;

    @Before
    public void getTemplate(){
        String url ="http://file.taxservices.cn";
        String downUrl ="http://file.taxservices.cn";
        String accessKey ="JHJG2Y3HVTM48YUU2ZYW";
        String secretKey ="TAe9uLLOj+frn0s3xXr+3gPozqmJDHIWfBqXSOEq";

//        String url ="http://localhost:9000";
//        String accessKey ="admin";
//        String secretKey ="admin123";
        template = new MinioTemplate(url,downUrl,accessKey,secretKey);
        try {
            template.afterPropertiesSet();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    @Test
    public void upload(){
        String path = "/Users/wenhao/timg.jpeg";
        String fileKey = "1234225.zip";
        System.out.println(fileKey);
        try {
            template.putObject(CommonConstants.BUCKET_NAME, fileKey, new FileInputStream(path));
            String fileSysUrl = template.getObjectURL(CommonConstants.BUCKET_NAME, fileKey, CommonConstants.EXPIRES);
            System.out.println(fileSysUrl);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Test
    public void stat(){
        String fileKey = "/2021/10/22//bwgf-limit/9137000072495538X6/1/10/20211016/40280fca7ca6f2ea017ca6fa6cb30063.zip";
        System.out.println(fileKey);
        try {

            ObjectStat fileSysUrl = template.getObjectInfo(CommonConstants.BUCKET_NAME + "b", fileKey);
            System.out.println(fileSysUrl);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("==========");
        }

    }
    @Test
    public void remove(){
        String fileKey = "/2021/04/8ad1a3c87916826c0179235dc24b527c1.zip";
        System.out.println(fileKey);
        try {
            template.removeObject(CommonConstants.BUCKET_NAME + "b", fileKey);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
