package cd.casic.server;

import cd.casic.ci.process.engine.manager.RunContextManager;
import cd.casic.ci.process.engine.runContext.PipelineRunContext;
import cd.casic.ci.process.engine.runContext.SecondStageRunContext;
import cd.casic.ci.process.engine.runContext.TaskRunContext;
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
import cd.casic.ci.process.process.dataObject.stage.PipStage;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import cd.casic.ci.process.process.service.pipeline.PipelineService;
import cd.casic.ci.process.process.service.stage.StageService;
import cd.casic.ci.process.process.service.task.TaskService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.util.HashMap;

@SpringBootTest(classes = {OpsServerApplication.class})
@ActiveProfiles("local")
public class RunContextManagerTest {
    @Resource
    RunContextManager contextManager;
    @Resource
    PipelineService pipelineService;
    @Resource
    StageService stageService;
    @Resource
    TaskService taskService;
    @Test
    public void test01(){
        // 所使用的 pipeline 、stage、task 必须有父子集关系
        PipPipeline pipeline = pipelineService.getById("719208124933869568");
        PipelineRunContext pipelineRunContext = new PipelineRunContext(pipeline, 11);
        PipStage childStage = stageService.getById("719208126888415232");
        SecondStageRunContext secondStageRunContext = new SecondStageRunContext(childStage,11,pipelineRunContext,new HashMap<>());
        PipTask task = taskService.getById("719208127425286144");
        TaskRunContext taskRunContext = new TaskRunContext(task, secondStageRunContext, new HashMap<>());
        contextManager.contextRegister(pipelineRunContext);
        contextManager.contextRegister(secondStageRunContext);
        contextManager.contextRegister(taskRunContext);
    }
}
