diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java index 18fc78db7a..bfd1d0517c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteService.java @@ -220,6 +220,24 @@ public class ApiExecuteService { return null; } + /** + * 测试计划资源,发送执行任务 + * + * @param taskRequest 执行参数 + */ + public TaskRequestDTO executePlanResource(TaskRequestDTO taskRequest) { + try { + return execute(taskRequest); + } catch (MSException e) { + if (e.getErrorCode() == ApiResultCode.EXECUTE_RESOURCE_POOL_NOT_CONFIG) { + // 提示没有可用资源池 + throw new MSException(ApiResultCode.TASK_ERROR_MESSAGE_INVALID_RESOURCE_POOL); + } else { + throw e; + } + } + } + /** * 发送执行任务 * @@ -804,6 +822,7 @@ public class ApiExecuteService { if (testResourcePool == null || // 资源池禁用 !testResourcePool.getEnable() || + testResourcePool.getDeleted() || // 项目没有资源池权限 !commonProjectService.validateProjectResourcePool(testResourcePool, projectId)) { throw new MSException(ApiResultCode.EXECUTE_RESOURCE_POOL_NOT_CONFIG); 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 8b968fe1f7..d7cc81f011 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 @@ -801,7 +801,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService { taskInfo.setRealTime(true); } - return apiExecuteService.execute(taskRequest); + return apiExecuteService.executePlanResource(taskRequest); } public void runRun(ExecTask execTask, ExecTaskItem execTaskItem, String userId) { 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 956dcda8ec..5608c1c768 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 @@ -395,7 +395,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { apiScenarioRunService.initApiScenarioReport(taskItem.getId(), apiScenario, scenarioReport); } - return apiExecuteService.execute(taskRequest); + return apiExecuteService.executePlanResource(taskRequest); } public void runRun(ExecTask execTask, ExecTaskItem execTaskItem, String userId) { diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java index c98adb6e2b..822f94f954 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java @@ -366,7 +366,8 @@ public class TestPlanApiCaseControllerTests extends BaseTest { public static void assertRun(MvcResult mvcResult) throws UnsupportedEncodingException { Map resultData = JSON.parseMap(mvcResult.getResponse().getContentAsString()); Integer code = (Integer) resultData.get("code"); - if (code != ApiResultCode.RESOURCE_POOL_EXECUTE_ERROR.getCode() && code != ApiResultCode.EXECUTE_RESOURCE_POOL_NOT_CONFIG.getCode()) { + if (code != ApiResultCode.RESOURCE_POOL_EXECUTE_ERROR.getCode() && code != ApiResultCode.EXECUTE_RESOURCE_POOL_NOT_CONFIG.getCode() + && code != ApiResultCode.TASK_ERROR_MESSAGE_INVALID_RESOURCE_POOL.getCode()) { Assertions.assertTrue(false); } }