refactor(接口测试): 补充场景相关接口
This commit is contained in:
parent
7d2376b84e
commit
e2d3ab9cfc
|
@ -115,6 +115,15 @@ public class ApiTestCaseController {
|
|||
return apiTestCaseService.update(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@GetMapping(value = "/update-priority/{id}/{priority}")
|
||||
@Operation(summary = "接口测试-接口管理-接口用例-更新等级")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = ApiTestCaseLogService.class)
|
||||
@CheckOwner(resourceId = "#id", resourceType = "api_test_case")
|
||||
public void updatePriority(@PathVariable String id, @PathVariable String priority) {
|
||||
apiTestCaseService.updatePriority(id, priority, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@GetMapping(value = "/update-status/{id}/{status}")
|
||||
@Operation(summary = "接口测试-接口管理-接口用例-更新状态")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE)
|
||||
|
|
|
@ -88,6 +88,7 @@ public class ApiScenarioController {
|
|||
@Operation(summary = "接口测试-接口场景管理-更新场景")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = ApiScenarioLogService.class)
|
||||
@CheckOwner(resourceId = "#request.getId()", resourceType = "api_scenario")
|
||||
public ApiScenario update(@Validated @RequestBody ApiScenarioUpdateRequest request) {
|
||||
return apiScenarioService.update(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -96,6 +97,7 @@ public class ApiScenarioController {
|
|||
@Operation(summary = "接口测试-接口场景管理-删除场景")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_DELETE)
|
||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = ApiScenarioLogService.class)
|
||||
@CheckOwner(resourceId = "#id", resourceType = "api_scenario")
|
||||
public void delete(@PathVariable String id) {
|
||||
apiScenarioService.delete(id);
|
||||
}
|
||||
|
@ -104,6 +106,7 @@ public class ApiScenarioController {
|
|||
@Operation(summary = "接口测试-接口场景管理-删除场景到回收站")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_DELETE)
|
||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = ApiScenarioLogService.class)
|
||||
@CheckOwner(resourceId = "#id", resourceType = "api_scenario")
|
||||
public void deleteToGc(@PathVariable String id) {
|
||||
apiScenarioService.deleteToGc(id);
|
||||
}
|
||||
|
@ -114,4 +117,23 @@ public class ApiScenarioController {
|
|||
public String debug(@RequestBody ApiScenarioDebugRequest request) {
|
||||
return apiScenarioService.debug(request);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/update-status/{id}/{status}")
|
||||
@Operation(summary = "接口测试-接口场景管理-更新状态")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = ApiScenarioLogService.class)
|
||||
@CheckOwner(resourceId = "#id", resourceType = "api_scenario")
|
||||
public void updateStatus(@PathVariable String id, @PathVariable String status) {
|
||||
apiScenarioService.updateStatus(id, status, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@GetMapping(value = "/update-priority/{id}/{priority}")
|
||||
@Operation(summary = "接口测试-接口场景管理-更新等级")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = ApiScenarioLogService.class)
|
||||
@CheckOwner(resourceId = "#id", resourceType = "api_scenario")
|
||||
public void updatePriority(@PathVariable String id, @PathVariable String priority) {
|
||||
apiScenarioService.updatePriority(id, priority, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,12 @@ public class ApiScenarioDTO extends ApiScenario {
|
|||
private String modulePath;
|
||||
@Schema(description = "环境名称")
|
||||
private String environmentName;
|
||||
@Schema(description = "是否有定时任务")
|
||||
private Boolean schedule;
|
||||
@Schema(description = "定时任务状态")
|
||||
private Boolean enable;
|
||||
@Schema(description = "下一次执行时间")
|
||||
private Long scheduleExecuteTime;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -418,7 +418,6 @@ public class ApiTestCaseService {
|
|||
updateCase.setUpdateTime(System.currentTimeMillis());
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ApiTestCaseMapper mapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
||||
|
||||
switch (request.getType()) {
|
||||
case PRIORITY -> batchUpdatePriority(example, updateCase, request.getPriority());
|
||||
case STATUS -> batchUpdateStatus(example, updateCase, request.getStatus());
|
||||
|
@ -426,6 +425,8 @@ public class ApiTestCaseService {
|
|||
case ENVIRONMENT -> batchUpdateEnvironment(example, updateCase, request.getEnvId());
|
||||
default -> throw new MSException(Translator.get("batch_edit_type_error"));
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
List<ApiTestCase> caseInfoByIds = extApiTestCaseMapper.getCaseInfoByIds(ids, false);
|
||||
apiTestCaseLogService.batchEditLog(caseInfoByIds, userId, projectId);
|
||||
}
|
||||
|
@ -577,4 +578,14 @@ public class ApiTestCaseService {
|
|||
|
||||
return operationHistoryList;
|
||||
}
|
||||
|
||||
public void updatePriority(String id, String priority, String userId) {
|
||||
checkResourceExist(id);
|
||||
ApiTestCase update = new ApiTestCase();
|
||||
update.setId(id);
|
||||
update.setPriority(priority);
|
||||
update.setUpdateUser(userId);
|
||||
update.setUpdateTime(System.currentTimeMillis());
|
||||
apiTestCaseMapper.updateByPrimaryKeySelective(update);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,6 +131,22 @@ public class ApiScenarioLogService {
|
|||
return dto;
|
||||
}
|
||||
|
||||
public LogDTO updateLog(String id) {
|
||||
ApiScenario apiScenario = apiScenarioMapper.selectByPrimaryKey(id);
|
||||
// todo 记录完整的场景信息
|
||||
LogDTO dto = new LogDTO(
|
||||
null,
|
||||
null,
|
||||
apiScenario.getId(),
|
||||
null,
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.API_SCENARIO,
|
||||
apiScenario.getName());
|
||||
dto.setHistory(true);
|
||||
dto.setOriginalValue(JSON.toJSONBytes(apiScenario));
|
||||
return dto;
|
||||
}
|
||||
|
||||
public LogDTO deleteLog(String id) {
|
||||
ApiScenario apiScenario = apiScenarioMapper.selectByPrimaryKey(id);
|
||||
LogDTO dto = new LogDTO(
|
||||
|
|
|
@ -178,6 +178,8 @@ public class ApiScenarioService {
|
|||
case ENVIRONMENT -> batchUpdateEnvironment(example, updateScenario, request);
|
||||
default -> throw new MSException(Translator.get("batch_edit_type_error"));
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
List<ApiScenario> scenarioInfoByIds = extApiScenarioMapper.getInfoByIds(ids, false);
|
||||
apiScenarioLogService.batchEditLog(scenarioInfoByIds, userId, projectId);
|
||||
}
|
||||
|
@ -506,7 +508,7 @@ public class ApiScenarioService {
|
|||
* @return
|
||||
*/
|
||||
private List<ApiScenarioStep> getApiScenarioSteps(ApiScenarioStepRequest parent,
|
||||
List<ApiScenarioStepRequest> steps) {
|
||||
List<ApiScenarioStepRequest> steps) {
|
||||
|
||||
if (CollectionUtils.isEmpty(steps)) {
|
||||
return Collections.emptyList();
|
||||
|
@ -737,6 +739,7 @@ public class ApiScenarioService {
|
|||
|
||||
/**
|
||||
* 设置部分引用的步骤的启用状态
|
||||
*
|
||||
* @param step
|
||||
* @param stepDetailMap
|
||||
*/
|
||||
|
@ -751,6 +754,7 @@ public class ApiScenarioService {
|
|||
|
||||
/**
|
||||
* 设置部分引用的步骤的启用状态
|
||||
*
|
||||
* @param steps
|
||||
* @param enableStepIds
|
||||
* @param stepDetailMap
|
||||
|
@ -868,4 +872,24 @@ public class ApiScenarioService {
|
|||
}
|
||||
return scenarioConfig;
|
||||
}
|
||||
|
||||
public void updateStatus(String id, String status, String userId) {
|
||||
checkResourceExist(id);
|
||||
ApiScenario update = new ApiScenario();
|
||||
update.setId(id);
|
||||
update.setStatus(status);
|
||||
update.setUpdateUser(userId);
|
||||
update.setUpdateTime(System.currentTimeMillis());
|
||||
apiScenarioMapper.updateByPrimaryKeySelective(update);
|
||||
}
|
||||
|
||||
public void updatePriority(String id, String priority, String userId) {
|
||||
checkResourceExist(id);
|
||||
ApiScenario update = new ApiScenario();
|
||||
update.setId(id);
|
||||
update.setPriority(priority);
|
||||
update.setUpdateUser(userId);
|
||||
update.setUpdateTime(System.currentTimeMillis());
|
||||
apiScenarioMapper.updateByPrimaryKeySelective(update);
|
||||
}
|
||||
}
|
|
@ -63,6 +63,8 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
protected static final String UPLOAD_TEMP_FILE = "upload/temp/file";
|
||||
protected static final String DELETE_TO_GC = "delete-to-gc/{0}";
|
||||
protected static final String DEBUG = "debug";
|
||||
private static final String UPDATE_STATUS = "update-status";
|
||||
private static final String UPDATE_PRIORITY = "update-priority";
|
||||
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
@Resource
|
||||
|
@ -609,6 +611,34 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
assertErrorCode(this.requestGet(FOLLOW + "111"), NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
public void updateStatus() throws Exception {
|
||||
List<ApiScenario> apiScenarioList = apiScenarioMapper.selectByExample(new ApiScenarioExample());
|
||||
String scenarioId = apiScenarioList.getFirst().getId();
|
||||
// @@请求成功
|
||||
this.requestGetWithOk(UPDATE_STATUS + "/" + scenarioId + "/Underway");
|
||||
ApiScenario apiScenario = apiScenarioMapper.selectByPrimaryKey(scenarioId);
|
||||
Assertions.assertEquals(apiScenario.getStatus(), "Underway");
|
||||
// @@校验日志
|
||||
checkLog(scenarioId, OperationLogType.UPDATE);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_UPDATE, UPDATE_STATUS + "/" + scenarioId + "/Underway");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
public void updatePriority() throws Exception {
|
||||
// @@请求成功
|
||||
this.requestGetWithOk(UPDATE_PRIORITY + "/" + "api-scenario-id1" + "/P1");
|
||||
ApiScenario apiScenario = apiScenarioMapper.selectByPrimaryKey("api-scenario-id1");
|
||||
Assertions.assertEquals(apiScenario.getPriority(), "P1");
|
||||
// @@校验日志
|
||||
checkLog("api-scenario-id1", OperationLogType.UPDATE);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_UPDATE, UPDATE_PRIORITY + "/" + "api-scenario-id1" + "/P1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
public void batchEdit() throws Exception {
|
||||
|
|
|
@ -77,6 +77,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
private static final String PAGE = BASE_PATH + "page";
|
||||
private static final String TRASH_PAGE = BASE_PATH + "trash/page";
|
||||
private static final String UPDATE_STATUS = BASE_PATH + "update-status";
|
||||
private static final String UPDATE_PRIORITY = BASE_PATH + "update-priority";
|
||||
private static final String BATCH_EDIT = BASE_PATH + "batch/edit";
|
||||
private static final String BATCH_DELETE = BASE_PATH + "batch/delete";
|
||||
private static final String BATCH_MOVE_GC = BASE_PATH + "batch/move-gc";
|
||||
|
@ -696,6 +697,20 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE, UPDATE_STATUS + "/" + apiTestCase.getId() + "/Underway");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
public void updatePriority() throws Exception {
|
||||
// @@请求成功
|
||||
this.requestGetWithOk(UPDATE_PRIORITY + "/" + apiTestCase.getId() + "/P1");
|
||||
ApiTestCase apiCase = apiTestCaseMapper.selectByPrimaryKey(apiTestCase.getId());
|
||||
Assertions.assertEquals(apiCase.getPriority(), "P1");
|
||||
// @@校验日志
|
||||
checkLog(apiTestCase.getId(), OperationLogType.UPDATE);
|
||||
this.requestGet(UPDATE_PRIORITY + "/" + "11111" + "/P1").andExpect(ERROR_REQUEST_MATCHER);
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE, UPDATE_PRIORITY + "/" + apiTestCase.getId() + "/P1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
public void batchEdit() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue