import cn.reghao.oss.storeapi.constant.ObjectScope;
import cn.reghao.oss.storeapi.constant.UploadChannel;
import cn.reghao.oss.console.OssConsoleApplication;
import cn.reghao.oss.console.account.service.AccountService;
import cn.reghao.oss.console.app.model.dto.UploadChannelDto;
import cn.reghao.oss.console.app.service.UploadChannelService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @author reghao
 * @date 2022-08-17 15:53:04
 */
@Slf4j
@ActiveProfiles("dev")
@SpringBootTest(classes = OssConsoleApplication.class)
@RunWith(SpringRunner.class)
public class OssConsoleTest {
    @Autowired
    AccountService accountService;

    @Test
    public void createUserAccount() {
    }

    @Autowired
    UploadChannelService uploadChannelService;
    @Test
    public void initChannel() {
        int nodeId = 1;
        for (UploadChannel uploadChannel : UploadChannel.values()) {
            String name = uploadChannel.name();
            if (name.equals("disk")) {
                continue;
            }

            long maxSize = uploadChannel.getMaxSize();
            String prefix = uploadChannel.getPrefix();
            int fileType = uploadChannel.getFileType();

            UploadChannelDto uploadChannelDto = new UploadChannelDto();
            uploadChannelDto.setChannelPrefix(prefix);
            uploadChannelDto.setMaxSize(maxSize);
            uploadChannelDto.setName(name);
            uploadChannelDto.setFileType(fileType);
            uploadChannelDto.setScope(ObjectScope.PRIVATE.getCode());
            uploadChannelDto.setNodeId(nodeId);
            uploadChannelService.add(uploadChannelDto);
        }
    }
}
