Skip to content

Commit

Permalink
fix: 定时任务ESB接口,返回的expression字段不对 TencentBlueKing#2724
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliaozhong committed Jan 11, 2024
1 parent b93f9e2 commit 89a9573
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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<EsbPlanBasicInfoV3DTO> 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<EsbResp<EsbPageDataV3<EsbPlanBasicInfoV3DTO>>>() {
})
.getData();
List<EsbPlanBasicInfoV3DTO> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -201,6 +218,9 @@ void testUpdateCronStatus() {
@DisplayName("测试更新定时任务")
void testUpdateCron() {
EsbCronInfoV3DTO createdCron = Operations.createCron();
if (createdCron == null) {
return;
}
createdCronList.add(createdCron);

EsbSaveCronV3Request req = new EsbSaveCronV3Request();
Expand Down
1 change: 0 additions & 1 deletion tests/openapi/src/test/resources/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 89a9573

Please sign in to comment.