diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java index 617e3a4373..ab9c7e94b4 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java @@ -1,7 +1,6 @@ package io.metersphere.track.controller; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.datacount.request.ScheduleInfoRequest; @@ -19,7 +18,7 @@ import io.metersphere.track.dto.*; import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testplan.AddTestPlanRequest; -import io.metersphere.track.request.testplan.TestplanRunRequest; +import io.metersphere.track.request.testplan.TestPlanRunRequest; import io.metersphere.track.request.testplancase.TestCaseRelevanceRequest; import io.metersphere.track.service.TestPlanProjectService; import io.metersphere.track.service.TestPlanService; @@ -207,18 +206,18 @@ public class TestPlanController { @PostMapping("/edit/runModeConfig") - public void updateRunModeConfig(@RequestBody TestplanRunRequest testplanRunRequest) { - testPlanService.updateRunModeConfig(testplanRunRequest); + public void updateRunModeConfig(@RequestBody TestPlanRunRequest testplanRunRequest) { + testPlanService.updateRunModeConfig(testplanRunRequest); } @PostMapping("/run") - public String run(@RequestBody TestplanRunRequest testplanRunRequest) { + public String run(@RequestBody TestPlanRunRequest testplanRunRequest) { return testPlanService.runPlan(testplanRunRequest); } @PostMapping(value = "/run/batch") - @MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.ids)", msClass = TestPlanService.class) - public void runBatch(@RequestBody TestplanRunRequest request) { + @MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.testPlanIds)", msClass = TestPlanService.class) + public void runBatch(@RequestBody TestPlanRunRequest request) { request.setTriggerMode(TriggerMode.BATCH.name()); testPlanService.runBatch(request); } diff --git a/backend/src/main/java/io/metersphere/track/request/testplan/TestplanRunRequest.java b/backend/src/main/java/io/metersphere/track/request/testplan/TestPlanRunRequest.java similarity index 85% rename from backend/src/main/java/io/metersphere/track/request/testplan/TestplanRunRequest.java rename to backend/src/main/java/io/metersphere/track/request/testplan/TestPlanRunRequest.java index 1096b6598c..141802f6be 100644 --- a/backend/src/main/java/io/metersphere/track/request/testplan/TestplanRunRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testplan/TestPlanRunRequest.java @@ -9,15 +9,15 @@ import java.util.Map; @Getter @Setter -public class TestplanRunRequest { +public class TestPlanRunRequest { private String testPlanId; private String projectId; private String userId; private String triggerMode;//触发方式 private String mode;//运行模式 private String reportType;//报告展示方式 - private String onSampleError;//是否失败停止 - private String runWithinResourcePool;//是否选择资源池 + private boolean onSampleError;//是否失败停止 + private boolean runWithinResourcePool;//是否选择资源池 private String resourcePoolId;//资源池Id private Map envMap; private String environmentType; diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index c5bb9eb498..39d18c0f63 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -30,7 +30,8 @@ import io.metersphere.track.request.report.QueryTestPlanReportRequest; import io.metersphere.track.request.report.TestPlanReportSaveRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testplan.LoadCaseRequest; -import io.metersphere.track.request.testplan.TestplanRunRequest; +import io.metersphere.track.request.testplan.TestPlanRunRequest; +import io.metersphere.track.service.utils.TestPlanRequestUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -584,7 +585,8 @@ public class TestPlanReportService { TestPlanExecutionQueue testPlanExecutionQueue = planExecutionQueueList.get(0); TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(testPlanExecutionQueue.getTestPlanId()); JSONObject jsonObject = JSONObject.parseObject(testPlan.getRunModeConfig()); - TestplanRunRequest runRequest = JSON.toJavaObject(jsonObject, TestplanRunRequest.class); + TestPlanRequestUtil.changeStringToBoolean(jsonObject); + TestPlanRunRequest runRequest = JSON.toJavaObject(jsonObject, TestPlanRunRequest.class); runRequest.setReportId(testPlanExecutionQueue.getReportId()); testPlanService.runPlan(runRequest); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index d221f1819d..1c8c4eddbf 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -44,8 +44,9 @@ import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testplan.AddTestPlanRequest; import io.metersphere.track.request.testplan.LoadCaseReportRequest; import io.metersphere.track.request.testplan.LoadCaseRequest; -import io.metersphere.track.request.testplan.TestplanRunRequest; +import io.metersphere.track.request.testplan.TestPlanRunRequest; import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest; +import io.metersphere.track.service.utils.TestPlanRequestUtil; import io.metersphere.utils.LoggerUtil; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections.CollectionUtils; @@ -974,11 +975,27 @@ public class TestPlanService { LogUtil.error(e); } if (runModeConfig == null) { - runModeConfig = new RunModeConfigDTO(); - runModeConfig.setMode(RunModeConstants.SERIAL.name()); - runModeConfig.setReportType("iddReport"); - runModeConfig.setEnvMap(new HashMap<>()); - runModeConfig.setOnSampleError(false); + TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanID); + if (StringUtils.isNotEmpty(testPlanWithBLOBs.getRunModeConfig())) { + JSONObject json = JSONObject.parseObject(testPlanWithBLOBs.getRunModeConfig()); + TestPlanRequestUtil.changeStringToBoolean(json); + TestPlanRunRequest testPlanRunRequest = JSON.toJavaObject(json, TestPlanRunRequest.class); + if (StringUtils.equals("GROUP", testPlanRunRequest.getEnvironmentType()) && StringUtils.isBlank(testPlanRunRequest.getEnvironmentGroupId())) { + runModeConfig = buildRunModeConfigDTO(); + } else { + runModeConfig = new RunModeConfigDTO(); + runModeConfig.setMode(testPlanRunRequest.getMode()); + runModeConfig.setReportType(testPlanRunRequest.getReportType()); + if (testPlanRunRequest.getEnvMap() == null) { + runModeConfig.setEnvMap(new HashMap<>()); + } else { + runModeConfig.setEnvMap(testPlanRunRequest.getEnvMap()); + } + runModeConfig.setOnSampleError(testPlanRunRequest.isOnSampleError()); + } + } else { + runModeConfig = buildRunModeConfigDTO(); + } } else { if (runModeConfig.getEnvMap() == null) { runModeConfig.setEnvMap(new HashMap<>()); @@ -1029,6 +1046,15 @@ public class TestPlanService { return planReportId; } + private RunModeConfigDTO buildRunModeConfigDTO() { + RunModeConfigDTO runModeConfig = new RunModeConfigDTO(); + runModeConfig.setMode(RunModeConstants.SERIAL.name()); + runModeConfig.setReportType("iddReport"); + runModeConfig.setEnvMap(new HashMap<>()); + runModeConfig.setOnSampleError(false); + return runModeConfig; + } + private Map executeApiTestCase(String triggerMode, String planReportId, String userId, List planCaseIds, RunModeConfigDTO runModeConfig) { BatchRunDefinitionRequest request = new BatchRunDefinitionRequest(); request.setTriggerMode(triggerMode); @@ -1118,6 +1144,24 @@ public class TestPlanService { return returnMap; } + public String getLogDetails(List ids) { + if (CollectionUtils.isNotEmpty(ids)) { + TestPlanExample testPlanExample = new TestPlanExample(); + testPlanExample.createCriteria().andIdIn(ids); + List planList = testPlanMapper.selectByExample(testPlanExample); + if (CollectionUtils.isNotEmpty(planList)) { + List detailsList = new ArrayList<>(); + for (TestPlan plan : planList) { + List columns = ReflexObjectUtil.getColumns(planList.get(0), TestPlanReference.testPlanColumns); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(plan.getId()), plan.getProjectId(), plan.getName(), plan.getCreator(), columns); + detailsList.add(details); + } + return JSON.toJSONString(detailsList); + } + } + return null; + } + public String getLogDetails(String id) { TestPlan plan = testPlanMapper.selectByPrimaryKey(id); if (plan != null) { @@ -2074,7 +2118,7 @@ public class TestPlanService { return envMap; } - public String runPlan(TestplanRunRequest testplanRunRequest) { + public String runPlan(TestPlanRunRequest testplanRunRequest) { //检查测试计划下有没有可以执行的用例; if (!haveExecCase(testplanRunRequest.getTestPlanId()) && !haveUiCase(testplanRunRequest.getTestPlanId())) { MSException.throwException(Translator.get("plan_warning")); @@ -2091,7 +2135,7 @@ public class TestPlanService { } - private RunModeConfigDTO getRunModeConfigDTO(TestplanRunRequest testplanRunRequest, String envType, Map envMap, String environmentGroupId, String testPlanId) { + private RunModeConfigDTO getRunModeConfigDTO(TestPlanRunRequest testplanRunRequest, String envType, Map envMap, String environmentGroupId, String testPlanId) { RunModeConfigDTO runModeConfig = new RunModeConfigDTO(); runModeConfig.setEnvironmentType(testplanRunRequest.getEnvironmentType()); if (StringUtils.equals(envType, EnvironmentType.JSON.name()) && !envMap.isEmpty()) { @@ -2103,7 +2147,7 @@ public class TestPlanService { } runModeConfig.setMode(testplanRunRequest.getMode()); runModeConfig.setResourcePoolId(testplanRunRequest.getResourcePoolId()); - runModeConfig.setOnSampleError(Boolean.parseBoolean(testplanRunRequest.getOnSampleError())); + runModeConfig.setOnSampleError(testplanRunRequest.isOnSampleError()); if (StringUtils.isBlank(testplanRunRequest.getReportType())) { runModeConfig.setReportType("iddReport"); } else { @@ -2116,7 +2160,7 @@ public class TestPlanService { return runModeConfig; } - private void updatePlan(TestplanRunRequest testplanRunRequest, String testPlanId) { + private void updatePlan(TestPlanRunRequest testplanRunRequest, String testPlanId) { String request = JSON.toJSONString(testplanRunRequest); TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanId); if (testPlanWithBLOBs.getRunModeConfig() == null || !(StringUtils.equals(request, testPlanWithBLOBs.getRunModeConfig()))) { @@ -2293,7 +2337,7 @@ public class TestPlanService { return extTestPlanMapper.list(request); } - public void runBatch(TestplanRunRequest request) { + public void runBatch(TestPlanRunRequest request) { List ids = request.getTestPlanIds(); if (CollectionUtils.isEmpty(ids) && !request.getIsAll()) { return; @@ -2360,7 +2404,7 @@ public class TestPlanService { } - private List getTestPlanExecutionQueues(TestplanRunRequest request, Map executeQueue) { + private List getTestPlanExecutionQueues(TestPlanRunRequest request, Map executeQueue) { List planExecutionQueues = new ArrayList<>(); String resourceId = UUID.randomUUID().toString(); final int[] nextNum = {testPlanExecutionQueueService.getNextNum(resourceId)}; @@ -2379,7 +2423,7 @@ public class TestPlanService { return planExecutionQueues; } - private void runByMode(TestplanRunRequest request, Map testPlanMap, List planExecutionQueues) { + private void runByMode(TestPlanRunRequest request, Map testPlanMap, List planExecutionQueues) { if (CollectionUtils.isNotEmpty(planExecutionQueues)) { Thread thread = new Thread(new Runnable() { @Override @@ -2389,14 +2433,16 @@ public class TestPlanService { TestPlanExecutionQueue planExecutionQueue = planExecutionQueues.get(0); TestPlanWithBLOBs testPlan = testPlanMap.get(planExecutionQueue.getTestPlanId()); JSONObject jsonObject = JSONObject.parseObject(testPlan.getRunModeConfig()); - TestplanRunRequest runRequest = JSON.toJavaObject(jsonObject, TestplanRunRequest.class); + TestPlanRequestUtil.changeStringToBoolean(jsonObject); + TestPlanRunRequest runRequest = JSON.toJavaObject(jsonObject, TestPlanRunRequest.class); runRequest.setReportId(planExecutionQueue.getReportId()); runPlan(runRequest); } else { for (TestPlanExecutionQueue planExecutionQueue : planExecutionQueues) { TestPlanWithBLOBs testPlan = testPlanMap.get(planExecutionQueue.getTestPlanId()); JSONObject jsonObject = JSONObject.parseObject(testPlan.getRunModeConfig()); - TestplanRunRequest runRequest = JSON.toJavaObject(jsonObject, TestplanRunRequest.class); + TestPlanRequestUtil.changeStringToBoolean(jsonObject); + TestPlanRunRequest runRequest = JSON.toJavaObject(jsonObject, TestPlanRunRequest.class); runRequest.setReportId(planExecutionQueue.getReportId()); runPlan(runRequest); } @@ -2407,7 +2453,7 @@ public class TestPlanService { } } - public void updateRunModeConfig(TestplanRunRequest testplanRunRequest) { + public void updateRunModeConfig(TestPlanRunRequest testplanRunRequest) { String testPlanId = testplanRunRequest.getTestPlanId(); updatePlan(testplanRunRequest, testPlanId); } diff --git a/backend/src/main/java/io/metersphere/track/service/utils/TestPlanRequestUtil.java b/backend/src/main/java/io/metersphere/track/service/utils/TestPlanRequestUtil.java new file mode 100644 index 0000000000..aa01e3d061 --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/service/utils/TestPlanRequestUtil.java @@ -0,0 +1,24 @@ +package io.metersphere.track.service.utils; + +import com.alibaba.fastjson.JSONObject; + +public class TestPlanRequestUtil { + + private static final String ON_SAMPLE_ERROR = "onSampleError"; + private static final String RUN_WITHIN_RESOURCE_POOL = "runWithinResourcePool"; + + public static void changeStringToBoolean(JSONObject runModeConfig) { + if (runModeConfig != null) { + if (runModeConfig.get(ON_SAMPLE_ERROR).equals("true") || runModeConfig.get(ON_SAMPLE_ERROR).equals(true)) { + runModeConfig.put(ON_SAMPLE_ERROR, true); + } else { + runModeConfig.put(ON_SAMPLE_ERROR, false); + } + if (runModeConfig.get(RUN_WITHIN_RESOURCE_POOL).equals("true") || runModeConfig.get(RUN_WITHIN_RESOURCE_POOL).equals(true)) { + runModeConfig.put(RUN_WITHIN_RESOURCE_POOL, true); + } else { + runModeConfig.put(RUN_WITHIN_RESOURCE_POOL, false); + } + } + } +} diff --git a/frontend/src/business/components/track/plan/common/PlanRunModeWithEnv.vue b/frontend/src/business/components/track/plan/common/PlanRunModeWithEnv.vue index 432560729e..fe5d380489 100644 --- a/frontend/src/business/components/track/plan/common/PlanRunModeWithEnv.vue +++ b/frontend/src/business/components/track/plan/common/PlanRunModeWithEnv.vue @@ -125,7 +125,7 @@
{{ $t("run_mode.retry_message") }}
- +
{{ $t("run_mode.retry") }} @@ -145,8 +145,9 @@
{{ - $t("api_test.fail_to_stop") - }} + $t("api_test.fail_to_stop") + }} +
@@ -163,20 +164,23 @@ {{ $t("commons.cancel") }} - {{ $t("load_test.save_and_run") + {{ + $t("load_test.save_and_run") }} {{ - $t("load_test.save_and_run") - }} + $t("load_test.save_and_run") + }} + {{ - $t("commons.save") - }} + $t("commons.save") + }} +
- + @@ -184,13 +188,12 @@