diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java index 582a18aef3..d8061743a0 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java @@ -785,7 +785,6 @@ public class TestPlanApiCaseService extends TestPlanResourceService { if (StringUtils.isEmpty(taskItem.getReportId())) { taskInfo.setRealTime(false); - taskItem.setReportId(IDGenerator.nextStr()); } else { // 如果传了报告ID,则实时获取结果 taskInfo.setRealTime(true); @@ -794,6 +793,30 @@ public class TestPlanApiCaseService extends TestPlanResourceService { return apiExecuteService.execute(taskRequest); } + public void runRun(ExecTask execTask, ExecTaskItem execTaskItem, String userId) { + String id = execTaskItem.getResourceId(); + TestPlanApiCase testPlanApiCase = checkResourceExist(id); + TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); + testPlanService.setActualStartTime(testPlanApiCase.getTestPlanId()); + ApiTestCase apiTestCase = apiTestCaseService.checkResourceExist(testPlanApiCase.getApiCaseId()); + ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(testPlanApiCase.getTestPlanCollectionId()); + runModeConfig.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanApiCase.getEnvironmentId())); + runModeConfig.setRunMode(ApiBatchRunMode.PARALLEL.name()); + TaskRequestDTO taskRequest = getTaskRequest(null, id, apiTestCase.getProjectId(), ApiExecuteRunMode.RUN.name()); + + TaskInfo taskInfo = taskRequest.getTaskInfo(); + TaskItem taskItem = taskRequest.getTaskItem(); + taskInfo.setTaskId(execTask.getId()); + taskInfo.setRunModeConfig(runModeConfig); + taskInfo.setSaveResult(true); + taskInfo.setRealTime(true); + taskInfo.setUserId(userId); + taskItem.setId(execTaskItem.getId()); + taskInfo.setRealTime(false); + + apiExecuteService.execute(taskRequest); + } + public TestPlanApiCase checkResourceExist(String id) { return ServiceUtils.checkResourceExist(testPlanApiCaseMapper.selectByPrimaryKey(id), "api_test_case_not_exist"); } @@ -1008,4 +1031,5 @@ public class TestPlanApiCaseService extends TestPlanResourceService { list.add(bugRelationCase); }); } + } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java index 3dd7030b4c..ee4a4e0594 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java @@ -387,6 +387,29 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { return apiExecuteService.execute(taskRequest); } + public void runRun(ExecTask execTask, ExecTaskItem execTaskItem, String userId) { + TestPlanApiScenario testPlanApiScenario = checkResourceExist(execTaskItem.getResourceId()); + TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); + testPlanService.setActualStartTime(testPlanApiScenario.getTestPlanId()); + ApiScenario apiScenario = apiScenarioService.checkResourceExist(testPlanApiScenario.getApiScenarioId()); + ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(testPlanApiScenario.getTestPlanCollectionId()); + runModeConfig.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanApiScenario.getEnvironmentId())); + TaskRequestDTO taskRequest = getTaskRequest(null, execTaskItem.getResourceId(), apiScenario.getProjectId(), ApiExecuteRunMode.RUN.name()); + + TaskInfo taskInfo = taskRequest.getTaskInfo(); + taskInfo.setTaskId(execTask.getId()); + taskInfo.setRunModeConfig(runModeConfig); + taskInfo.setSaveResult(true); + taskInfo.setRealTime(true); + taskInfo.setUserId(userId); + taskInfo.setRealTime(false); + + TaskItem taskItem = taskRequest.getTaskItem(); + taskItem.setId(execTaskItem.getId()); + + apiExecuteService.execute(taskRequest); + } + /** * 预生成用例的执行报告 * diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiCaseRerunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiCaseRerunService.java new file mode 100644 index 0000000000..9dff766217 --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiCaseRerunService.java @@ -0,0 +1,37 @@ +package io.metersphere.plan.service.rerun; + +import io.metersphere.plan.service.TestPlanApiCaseService; +import io.metersphere.sdk.constants.ExecTaskType; +import io.metersphere.system.domain.ExecTask; +import io.metersphere.system.domain.ExecTaskItem; +import io.metersphere.system.invoker.TaskRerunServiceInvoker; +import io.metersphere.system.mapper.ExecTaskItemMapper; +import io.metersphere.system.service.TaskRerunService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * @Author: jianxing + * @CreateTime: 2024-02-06 20:47 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class TestPlanApiCaseRerunService implements TaskRerunService { + @Resource + private TestPlanApiCaseService testPlanApiCaseService; + @Resource + private ExecTaskItemMapper execTaskItemMapper; + + public TestPlanApiCaseRerunService() { + TaskRerunServiceInvoker.register(ExecTaskType.TEST_PLAN_API_CASE, this); + } + + @Override + public void rerun(ExecTask execTask, List taskItemIds, String userId) { + ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(taskItemIds.getFirst()); + testPlanApiCaseService.runRun(execTask, execTaskItem, userId); + } +} diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiScenarioRerunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiScenarioRerunService.java new file mode 100644 index 0000000000..42494d3041 --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiScenarioRerunService.java @@ -0,0 +1,37 @@ +package io.metersphere.plan.service.rerun; + +import io.metersphere.plan.service.TestPlanApiScenarioService; +import io.metersphere.sdk.constants.ExecTaskType; +import io.metersphere.system.domain.ExecTask; +import io.metersphere.system.domain.ExecTaskItem; +import io.metersphere.system.invoker.TaskRerunServiceInvoker; +import io.metersphere.system.mapper.ExecTaskItemMapper; +import io.metersphere.system.service.TaskRerunService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * @Author: jianxing + * @CreateTime: 2024-02-06 20:47 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class TestPlanApiScenarioRerunService implements TaskRerunService { + @Resource + private TestPlanApiScenarioService testPlanApiScenarioService; + @Resource + private ExecTaskItemMapper execTaskItemMapper; + + public TestPlanApiScenarioRerunService() { + TaskRerunServiceInvoker.register(ExecTaskType.TEST_PLAN_API_SCENARIO, this); + } + + @Override + public void rerun(ExecTask execTask, List taskItemIds, String userId) { + ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(taskItemIds.getFirst()); + testPlanApiScenarioService.runRun(execTask, execTaskItem, userId); + } +}