2025-06-11 09:50:36 +08:00

84 lines
3.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cd.casic.server;
import cd.casic.ci.process.dto.req.stage.StageCreateReq;
import cd.casic.ci.process.dto.req.task.TaskUpdateReq;
import cd.casic.ci.process.process.service.stage.StageService;
import cd.casic.ci.process.process.service.task.TaskService;
import com.alibaba.fastjson.JSON;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@SpringBootTest(classes = {OpsServerApplication.class})
@ActiveProfiles("local")
public class TaskTest {
@Resource
StageService stageService;
@Resource
TaskService taskService;
// 添加串行任务
@Test
public void createStageAndTask1(){
// 传入一级stageid 传入task所属二级stageId因为结合sort 创建task
String reqStr = "{\n" +
" \"stageId\": \"716299524129296385\",\n" +
" \"task\": {\n" +
" \"taskType\": \"AFL\",\n" +
" \"taskSort\": 2,\n" +
" \"stageId\": \"716299524129296386\",\n" +
" \"taskName\": \"AFL执行\",\n" +
" \"taskProperties\": {},\n" +
" \"pipelineId\": \"716299522803896320\"\n" +
" }\n" +
"}";
StageCreateReq req = JSON.parseObject(reqStr,StageCreateReq.class);
stageService.createStagesOrTask(req);
}
// 添加并行任务
@Test
public void createStageAndTask2(){
// 因为添加并行任务添加顺序固定而且需要创建二级stage所以不传二级stageid且不传sort
String reqStr = "{\n" +
" \"stageId\": \"716299524129296385\",\n" +
" \"task\": {\n" +
" \"taskType\": \"AFL\",\n" +
" \"taskName\": \"AFL执行\",\n" +
" \"taskProperties\": {},\n" +
" \"pipelineId\": \"716299522803896320\"\n" +
" }\n" +
"}";
StageCreateReq req = JSON.parseObject(reqStr,StageCreateReq.class);
stageService.createStagesOrTask(req);
}
// 添加阶段并添加task
@Test
public void createStageAndTask3(){
// 添加阶段所以一级stageId 不传改为传stageSort因为二级stagetask永远是第一个所以都taskSort和二级stage的stageSort都不需要传
String reqStr = "{\n" +
" \"stageSort\": 4,\n" +
" \"task\": {\n" +
" \"taskType\": \"AFL\",\n" +
" \"taskName\": \"AFL执行\",\n" +
" \"taskProperties\": {},\n" +
" \"pipelineId\": \"716299522803896320\"\n" +
" }\n" +
"}";
StageCreateReq req = JSON.parseObject(reqStr,StageCreateReq.class);
stageService.createStagesOrTask(req);
}
@Test
public void updateTask(){
String reqStr = "{\n" +
" \"id\": \"716299524330622976\",\n" +
" \"taskType\": \"TEST_CASE_GENERATION\",\n" +
" \"taskName\": \"测试用例生成\",\n" +
" \"taskProperties\": {\n" +
" \"buildScript\": \"cd /home/casic/706/yunqi/CaseGenerator\\nPYTHONPATH=$PWD/src python3 ./src/CaseGenerator/main.py --work-dir ./testdata/libpng/libpng/ --binary ./testdata/libpng/libpng/pngfix --output-dir ../case --count 100\"\n" +
" }\n" +
"}";
TaskUpdateReq req = JSON.parseObject(reqStr, TaskUpdateReq.class);
taskService.updateTask(req);
}
}