diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/props/TestProps.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/props/TestProps.java index 66ddd2b94e..0552cc2372 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/props/TestProps.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/props/TestProps.java @@ -93,9 +93,6 @@ private static void load() { // 用于测试的默认系统账号别名 public static final String DEFAULT_OS_ACCOUNT_ALIAS = getPropString("os.account.alias.default"); - // 定义默认的执行方案ID - public static final Long TASK_PLAN_DEFAULT_ID = getPropLong("task.plan.default.id"); - public static Integer getPropInteger(String key) { String value = props.getProperty(key); diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java index 528a549bd1..4606b48476 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java @@ -11,6 +11,8 @@ import com.tencent.bk.job.api.v3.model.EsbDangerousRuleV3DTO; import com.tencent.bk.job.api.v3.model.EsbFileSourceV3DTO; import com.tencent.bk.job.api.v3.model.EsbJobExecuteV3DTO; +import com.tencent.bk.job.api.v3.model.EsbPageDataV3; +import com.tencent.bk.job.api.v3.model.EsbPlanBasicInfoV3DTO; import com.tencent.bk.job.api.v3.model.EsbScriptVersionDetailV3DTO; import com.tencent.bk.job.api.v3.model.EsbServerV3DTO; import com.tencent.bk.job.api.v3.model.HostDTO; @@ -24,6 +26,7 @@ import com.tencent.bk.job.api.v3.model.request.EsbExecuteJobV3Request; import com.tencent.bk.job.api.v3.model.request.EsbFastExecuteScriptV3Request; import com.tencent.bk.job.api.v3.model.request.EsbFastTransferFileV3Request; +import com.tencent.bk.job.api.v3.model.request.EsbGetPlanListV3Request; import com.tencent.bk.job.api.v3.model.request.EsbManageDangerousRuleV3Req; import com.tencent.bk.job.api.v3.model.request.EsbSaveCronV3Request; import io.restassured.common.mapper.TypeRef; @@ -305,13 +308,16 @@ public static EsbJobExecuteV3DTO executePlanTask() { } public static EsbCronInfoV3DTO createCron() { + Long planId = getTaskPlanId(); + if (planId == null) { + return null; + } EsbSaveCronV3Request req = new EsbSaveCronV3Request(); req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); req.setName(TestValueGenerator.generateUniqueStrValue("cron_task", 50)); req.setCronExpression("* * * * *"); - req.setPlanId(TestProps.TASK_PLAN_DEFAULT_ID); - + req.setPlanId(planId); return given() .spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) .body(JsonUtil.toJson(req)) @@ -325,6 +331,30 @@ public static EsbCronInfoV3DTO createCron() { .getData(); } + public static Long getTaskPlanId() { + EsbGetPlanListV3Request req = new EsbGetPlanListV3Request(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setLength(1); + EsbPageDataV3 data = given() + .spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.GET_JOB_PLAN_LIST) + .then() + .statusCode(200) + .extract() + .body() + .as(new TypeRef>>() { + }) + .getData(); + List planList = data.getData(); + if (planList != null && planList.size() > 0) { + EsbPlanBasicInfoV3DTO planBasicInfoV3DTO = planList.get(0); + return planBasicInfoV3DTO.getId(); + } + return null; + } + private static String buildJobName() { return "api.test." + DateUtils.formatLocalDateTime(LocalDateTime.now(), "yyyyMMddhhmmssSSS"); } diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java index cc093fbac3..4b2ebcd41b 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java @@ -69,4 +69,6 @@ public interface APIV3Urls { String GET_CRON_LIST = "/api/job/v3/job-crontab/get_cron_list"; String UPDATE_CRON_STATUS = "/api/job/v3/job-crontab/update_cron_status"; String GET_CRON_DETAIL = "/api/job/v3/job-crontab/get_cron_detail"; + + String GET_JOB_PLAN_LIST = "/api/job/v3/job-manage/get_job_plan_list"; } diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbBaseListRequest.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbBaseListRequest.java index 8bc4ee0731..fa9cf532a4 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbBaseListRequest.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbBaseListRequest.java @@ -1,13 +1,13 @@ package com.tencent.bk.job.api.v3.model.request; import com.fasterxml.jackson.annotation.JsonProperty; -import com.tencent.bk.job.api.model.BaseEsbReq; +import com.tencent.bk.job.api.model.EsbAppScopeReq; import lombok.Data; import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = true) -public class EsbBaseListRequest extends BaseEsbReq { +public class EsbBaseListRequest extends EsbAppScopeReq { /** * 业务 ID diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CronResourceAPITest.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CronResourceAPITest.java index 94b4e8c799..ed0721fcd1 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CronResourceAPITest.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CronResourceAPITest.java @@ -47,12 +47,16 @@ class CronCreateTest { @Test @DisplayName("测试定时作业正常创建") void testCreateCron() { + Long planId = Operations.getTaskPlanId(); + if (planId == null) { + return; + } EsbSaveCronV3Request req = new EsbSaveCronV3Request(); req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); req.setName(TestValueGenerator.generateUniqueStrValue("cron_task", 50)); req.setCronExpression("3 * * * 3"); - req.setPlanId(TestProps.TASK_PLAN_DEFAULT_ID); + req.setPlanId(planId); EsbCronInfoV3DTO createdCron = given() @@ -84,13 +88,17 @@ void testCreateCron() { @Test @DisplayName("创建定时作业异常场景测试") void givenInvalidCreateCronThenFail() { + Long planId = Operations.getTaskPlanId(); + if (planId == null) { + return; + } EsbSaveCronV3Request req = new EsbSaveCronV3Request(); req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); req.setName(TestValueGenerator.generateUniqueStrValue("cron_task", 50)); // 不是Unix格式的表达式 req.setCronExpression("* 0/5 * * * * *"); - req.setPlanId(TestProps.TASK_PLAN_DEFAULT_ID); + req.setPlanId(planId); given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) .body(JsonUtil.toJson(req)) .post(APIV3Urls.SAVE_CRON) @@ -107,7 +115,7 @@ void givenInvalidCreateCronThenFail() { // 定时作业名称为null req.setName(null); - req.setPlanId(TestProps.TASK_PLAN_DEFAULT_ID); + req.setPlanId(planId); given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) .body(JsonUtil.toJson(req)) .post(APIV3Urls.SAVE_CRON) @@ -122,6 +130,9 @@ class CronGetTest { @DisplayName("测试获取定时作业列表") void testGetCronList() { EsbCronInfoV3DTO createdCron = Operations.createCron(); + if (createdCron == null) { + return; + } createdCronList.add(createdCron); EsbGetCronListV3Request req = new EsbGetCronListV3Request(); req.setScopeId(createdCron.getScopeId()); @@ -139,6 +150,9 @@ void testGetCronList() { @DisplayName("测试获取定时作业详情") void testGetCronDetail() { EsbCronInfoV3DTO createdCron = Operations.createCron(); + if (createdCron == null) { + return; + } createdCronList.add(createdCron); EsbGetCronDetailV3Request req = new EsbGetCronDetailV3Request(); req.setScopeId(createdCron.getScopeId()); @@ -170,6 +184,9 @@ class CronUpdateTest { @DisplayName("测试更新定时任务状态") void testUpdateCronStatus() { EsbCronInfoV3DTO createdCron = Operations.createCron(); + if (createdCron == null) { + return; + } createdCronList.add(createdCron); EsbUpdateCronStatusV3Request req = new EsbUpdateCronStatusV3Request(); req.setScopeId(createdCron.getScopeId()); @@ -201,6 +218,9 @@ void testUpdateCronStatus() { @DisplayName("测试更新定时任务") void testUpdateCron() { EsbCronInfoV3DTO createdCron = Operations.createCron(); + if (createdCron == null) { + return; + } createdCronList.add(createdCron); EsbSaveCronV3Request req = new EsbSaveCronV3Request(); diff --git a/tests/openapi/src/test/resources/test.properties b/tests/openapi/src/test/resources/test.properties index cfe1fa66cf..c59481655c 100644 --- a/tests/openapi/src/test/resources/test.properties +++ b/tests/openapi/src/test/resources/test.properties @@ -20,4 +20,3 @@ biz.2.id=3 biz_set.default.id=9991001 test.user.default=admin os.account.alias.default=root -task.plan.default.id=1