MainTest.java 3.01 KB
package com.viontech.fanxing.task;

import com.alibaba.fastjson.JSON;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.task.model.TaskData;
import com.viontech.fanxing.task.model.runtime.DailyRuntimeConfig;
import com.viontech.fanxing.commons.model.main.VaServerInfo;
import com.viontech.fanxing.task.service.OpsClientService;
import com.viontech.fanxing.task.service.TaskDataService;
import com.viontech.fanxing.task.service.VAServerHttpService;
import com.viontech.fanxing.task.service.VAServerService;
import com.viontech.fanxing.task.service.impl.TaskServiceImpl;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Date;

/**
 * .
 *
 * @author 谢明辉
 * @date 2021/7/21
 */

@SpringBootTest
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
public class MainTest {

    @Resource
    private OpsClientService opsClientService;
    @Resource
    private TaskServiceImpl taskService;
    @Resource
    private TaskDataService taskDataService;
    @Resource
    private VAServerService vaServerService;
    @Resource
    private VAServerHttpService vaServerHttpService;

    @Test
    public void opsClientTest() {

        DictCode nvs3000 = opsClientService.getDictCodeByUnid("460b359f-0bc6-11ec-a74d-0242ac11001d");
        Channel channel = opsClientService.getChannelByChannelUnid("2200001201000D01");
        String defaultConfig = opsClientService.getContentByName("defaultConfig");

        System.out.println(JSON.toJSONString(nvs3000));
        System.out.println(JSON.toJSONString(channel));
        System.out.println(JSON.toJSONString(defaultConfig));

    }

    @Test
    public void dailyRuntimeConfigTest() {
        DailyRuntimeConfig dailyRuntimeConfig = new DailyRuntimeConfig("{\"config\":[{\"start\":\"08:00:00\",\"end\":\"10:00:00\"}]}");
        ImmutablePair<Long, Long> n = dailyRuntimeConfig.getNextTimeOfExecutionAndTerminal();
        System.out.println(new Date(n.left));
        System.out.println(new Date(n.right));
    }

    @Test
    public void nextTimeTest() {
        TaskData taskData = taskDataService.getRepository().getTaskDataByUnid("612f56aa-3c6c-11ec-a7e6-0242ac110007");
        ImmutablePair<Long, Long> next = taskData.getRuntimeConfig().getNextTimeOfExecutionAndTerminal();
        System.out.println(next);
//        assert next.left == 1635906774000L;
//        assert next.right == 1635953574000L;
    }

    @Test
    public void stopTask() {
        String taskUnid = "090677cc-3c6c-11ec-a7e6-0242ac110007";
        VaServerInfo vaServerInfo = taskDataService.taskRunOn(taskUnid);
        vaServerHttpService.rmTask(taskUnid, vaServerInfo);

    }

    @Test
    public void LogTest() {
        opsClientService.addLog("task test test test");
    }
}