package com.friday.tooldriver.service.rpa.driverimpl;

import com.friday.base.common.response.DubboResult;
import com.friday.operation.api.tooldriver.dto.common.DriverBase;
import com.friday.operation.api.tooldriver.dto.rpa.*;
import com.friday.tooldriver.ServiceUTBase;
import org.assertj.core.util.Lists;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class INFODATORDriverServiceImplTest extends ServiceUTBase {

    @Autowired
    private INFODATORDriverServiceImpl infodatorDriverService;

    @Test
    public void createTenant() {
    }

    @Test
    public void queryTenants() {
    }

    @Test
    public void queryTenantByKey() {
    }

    @Test
    public void deleteTenantByKey() {
    }

    @Test
    public void updateTenantByKey() {
    }

    @Test
    public void activateTenantByKey() {
    }

    @Test
    public void createGroup() {
        GroupDto group = new GroupDto();
        group.setName("groupName2");
        group.setDescription("测试组");
        DubboResult result = infodatorDriverService.createGroup(getDriverBase(), group);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryGroups() {
        GroupFilter filter = new GroupFilter();
        DubboResult result = infodatorDriverService.queryGroups(getDriverBase(), filter);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryGroupByKey() {
        DubboResult result = infodatorDriverService.queryGroupByKey(getDriverBase(), "18");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void deleteGroupByKey() {
        DubboResult result = infodatorDriverService.deleteGroupByKey(getDriverBase(), "17");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void uploadPackage() {
        CodePackageDto pkg = CodePackageDto.builder()
                .key("18")
                .processKey(null)
                .name("测试流程")
                .fileName("DE0118-金控开户审核流程maker审核-v10.1214-无业务操作.ibt")
                .filePath("C:\\Users\\K0051588\\Desktop\\DE0118-金控开户审核流程maker审核-v10.1214-无业务操作.ibt")
                .fileType("ibt")
                .version(null)
                .versionType(null)
                .build();
        DubboResult result = infodatorDriverService.uploadPackage(getDriverBase(), pkg);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void deletePackageByKey() {
        DubboResult result = infodatorDriverService.deletePackageByKey(getDriverBase(), "367");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryPackages() {
        CodePackageFilter filter = new CodePackageFilter();
        DubboResult result = infodatorDriverService.queryPackages(getDriverBase(), filter);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryPackageByKey() {
        DubboResult result = infodatorDriverService.queryPackageByKey(getDriverBase(), "440");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void downloadPackageByKey() {
        DubboResult result = infodatorDriverService.downloadPackageByKey(getDriverBase(), "196028", "test.ibt");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void releaseProcess() {
        ReleaseDto release = new ReleaseDto();
        release.setKey("368");
        release.setProcessVersion("1.0.3143");
//        release.setProcessVersion("1.1.8168");
        DubboResult result = infodatorDriverService.releaseProcess(getDriverBase(), release);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void deleteProcessReleaseByKey() {
        DubboResult result = infodatorDriverService.deleteProcessReleaseByKey(getDriverBase(), "363");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryProcessReleases() {
        ReleaseFilter filter = new ReleaseFilter();
        filter.setName("测试");
        DubboResult result = infodatorDriverService.queryProcessReleases(getDriverBase(), filter);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryProcessReleaseByKey() {
        DubboResult result = infodatorDriverService.queryProcessReleaseByKey(getDriverBase(), "368");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void createRobot() {
        RobotDto robot = new RobotDto();
        robot.setName("GW_ROBOT");
        robot.setKey(null);
        DubboResult result = infodatorDriverService.createRobot(getDriverBase(), robot);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void deleteRobotByKey() {
        DubboResult result = infodatorDriverService.deleteRobotByKey(getDriverBase(), "63");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryRobots() {
        RobotFilter filter = new RobotFilter();
        filter.setName("00");
        filter.setState("0");
        DubboResult result = infodatorDriverService.queryRobots(getDriverBase(), filter);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryRobotByKey() {
        DubboResult result = infodatorDriverService.queryRobotByKey(getDriverBase(), "52");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void assignRobotToGroup() {
        DubboResult result = infodatorDriverService.assignRobotToGroup(getDriverBase(), "52", "19");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void enableLicense() {
        LicenseDto license = new LicenseDto();
        license.setRobotKey("52");
        license.setLicenseKey(null);
        DubboResult result = infodatorDriverService.enableLicense(getDriverBase(), license);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void disableLicense() {
        LicenseDto license = new LicenseDto();
        license.setRobotKey("52");
        license.setLicenseKey(null);

        DubboResult result = infodatorDriverService.disableLicense(getDriverBase(), license);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void startJob() {
        StartJobDto start = new StartJobDto();
        start.setRobotKey("52");
        start.setProcessReleaseKey("369");
        start.setInputArguments(null);
        DubboResult result = infodatorDriverService.startJob(getDriverBase(), start);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void restartJob() {
        DubboResult result = infodatorDriverService.restartJob(getDriverBase(), "29848");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void pauseJob() {
        DubboResult result = infodatorDriverService.pauseJob(getDriverBase(), "29855");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void resumeJob() {
        DubboResult result = infodatorDriverService.resumeJob(getDriverBase(), "29855");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void stopJob() {
        DubboResult result = infodatorDriverService.stopJob(getDriverBase(), "29855");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void stopJobs() {
        List<String> jobIdList = Lists.newArrayList("29848");
        DubboResult result = infodatorDriverService.stopJobs(getDriverBase(), jobIdList);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryJobs() {
        JobFilter filter = new JobFilter();
        DubboResult result = infodatorDriverService.queryJobs(getDriverBase(), filter);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryJobByKey() {
        DubboResult result = infodatorDriverService.queryJobByKey(getDriverBase(), "29848");
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    private DriverBase getDriverBase(){
        return DriverBase.builder()
                .tenantKey("default")
                .groupKey(null)
                .build();
    }
}