From be9c06a76d854b37b7ac2d43b1d8cb47a999d128 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Thu, 24 Oct 2024 16:19:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):?= =?UTF-8?q?=20=E5=90=8E=E5=8F=B0=E4=BB=BB=E5=8A=A1=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92&?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sdk/constants/ScheduleResourceType.java | 1 + .../plan/service/TestPlanScheduleService.java | 76 +++++++++---------- .../plan/controller/TestPlanTests.java | 3 - 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ScheduleResourceType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ScheduleResourceType.java index a440a4b021..9e43383331 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ScheduleResourceType.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ScheduleResourceType.java @@ -4,6 +4,7 @@ public enum ScheduleResourceType { API_IMPORT, API_SCENARIO, TEST_PLAN, + TEST_PLAN_GROUP, CLEAN_REPORT, DEMAND_SYNC, BUG_SYNC diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanScheduleService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanScheduleService.java index bbcd1ca6ad..6f571cecb6 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanScheduleService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanScheduleService.java @@ -23,45 +23,45 @@ import java.util.List; @Transactional(rollbackFor = Exception.class) public class TestPlanScheduleService { - @Resource - private TestPlanMapper testPlanMapper; - @Resource - private ScheduleService scheduleService; + @Resource + private TestPlanMapper testPlanMapper; + @Resource + private ScheduleService scheduleService; - public String scheduleConfig(BaseScheduleConfigRequest request, String operator) { - TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getResourceId()); - if (testPlan == null) { - throw new MSException(Translator.get("test_plan.not.exist")); - } - ScheduleConfig scheduleConfig = ScheduleConfig.builder() - .resourceId(testPlan.getId()) - .key(testPlan.getId()) - .projectId(testPlan.getProjectId()) - .name(testPlan.getName()) - .enable(request.isEnable()) - .cron(request.getCron()) - .resourceType(ScheduleResourceType.TEST_PLAN.name()) - .config(JSON.toJSONString(request.getRunConfig())) - .build(); + public String scheduleConfig(BaseScheduleConfigRequest request, String operator) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getResourceId()); + if (testPlan == null) { + throw new MSException(Translator.get("test_plan.not.exist")); + } + ScheduleConfig scheduleConfig = ScheduleConfig.builder() + .resourceId(testPlan.getId()) + .key(testPlan.getId()) + .projectId(testPlan.getProjectId()) + .name(testPlan.getName()) + .enable(request.isEnable()) + .cron(request.getCron()) + .resourceType(testPlan.getType() == TestPlanConstants.TEST_PLAN_TYPE_PLAN ? ScheduleResourceType.TEST_PLAN.name() : ScheduleResourceType.TEST_PLAN_GROUP.name()) + .config(JSON.toJSONString(request.getRunConfig())) + .build(); - if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { - //配置开启的测试计划组定时任务,要将组下的所有测试计划定时任务都关闭掉 - TestPlanExample example = new TestPlanExample(); - example.createCriteria().andGroupIdEqualTo(testPlan.getId()).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); - example.setOrderByClause("pos asc"); - List children = testPlanMapper.selectByExample(example); - for (TestPlan child : children) { - scheduleService.updateIfExist(child.getId(), false, TestPlanScheduleJob.getJobKey(testPlan.getId()), - TestPlanScheduleJob.getTriggerKey(testPlan.getId()), - TestPlanScheduleJob.class, operator); - } - } + if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { + //配置开启的测试计划组定时任务,要将组下的所有测试计划定时任务都关闭掉 + TestPlanExample example = new TestPlanExample(); + example.createCriteria().andGroupIdEqualTo(testPlan.getId()).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); + example.setOrderByClause("pos asc"); + List children = testPlanMapper.selectByExample(example); + for (TestPlan child : children) { + scheduleService.updateIfExist(child.getId(), false, TestPlanScheduleJob.getJobKey(testPlan.getId()), + TestPlanScheduleJob.getTriggerKey(testPlan.getId()), + TestPlanScheduleJob.class, operator); + } + } - return scheduleService.scheduleConfig( - scheduleConfig, - TestPlanScheduleJob.getJobKey(testPlan.getId()), - TestPlanScheduleJob.getTriggerKey(testPlan.getId()), - TestPlanScheduleJob.class, - operator); - } + return scheduleService.scheduleConfig( + scheduleConfig, + TestPlanScheduleJob.getJobKey(testPlan.getId()), + TestPlanScheduleJob.getTriggerKey(testPlan.getId()), + TestPlanScheduleJob.class, + operator); + } } diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index 8645cda783..2d2e2de417 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -1507,8 +1507,6 @@ public class TestPlanTests extends BaseTest { .getResponse().getContentAsString(), ResultHolder.class).getData()), TestPlanStatisticsResponse.class); Assertions.assertTrue(statisticsResponses.size() > 1); - Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() > 0); - Assertions.assertTrue(statisticsResponses.getFirst().getScheduleConfig().isEnable()); //增加日志检查 @@ -1533,7 +1531,6 @@ public class TestPlanTests extends BaseTest { TestPlanStatisticsResponse.class); Assertions.assertTrue(statisticsResponses.size() > 1); Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() == null); - Assertions.assertFalse(statisticsResponses.getFirst().getScheduleConfig().isEnable()); //测试各种corn表达式用于校验正则的准确性