refactor(接口测试): 返回执行历史是否删除判断标识
This commit is contained in:
parent
b3ef97eb67
commit
41fac4008c
|
@ -48,6 +48,9 @@ public class ExecuteReportDTO implements Serializable {
|
|||
@Schema(description = "测试计划Num")
|
||||
private String testPlanNum;
|
||||
|
||||
@Schema(description = "结果是否被删除")
|
||||
private Boolean resultDeleted = true;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
|
@ -46,6 +46,8 @@ import io.metersphere.system.utils.ServiceUtils;
|
|||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
@ -111,6 +113,8 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
private ExtApiScenarioMapper extApiScenarioMapper;
|
||||
|
||||
private static final String CASE_TABLE = "api_test_case";
|
||||
@Resource
|
||||
private ApiReportRelateTaskMapper apiReportRelateTaskMapper;
|
||||
|
||||
private void checkProjectExist(String projectId) {
|
||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||
|
@ -578,10 +582,11 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
|
||||
private List<ExecuteReportDTO> handleList(List<ExecHistoryDTO> historyList) {
|
||||
List<ExecuteReportDTO> executeReportDTOList = new ArrayList<>();
|
||||
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(historyList)) {
|
||||
if (CollectionUtils.isNotEmpty(historyList)) {
|
||||
List<String> userIds = historyList.stream().map(ExecHistoryDTO::getCreateUser).toList();
|
||||
Map<String, String> userNameMap = userLoginService.getUserNameMap(userIds);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
Map<String, String> reportMap = getReportMap(historyList);
|
||||
historyList.forEach(item -> {
|
||||
ExecuteReportDTO reportDTO = new ExecuteReportDTO();
|
||||
BeanUtils.copyBean(reportDTO, item);
|
||||
|
@ -591,12 +596,32 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
if (StringUtils.isNotBlank(item.getTestPlanNum())) {
|
||||
reportDTO.setTestPlanNum(StringUtils.join(Translator.get("test_plan"), ": ", item.getTestPlanNum()));
|
||||
}
|
||||
if (BooleanUtils.isTrue(item.getIntegrated()) && reportMap.containsKey(item.getTaskId())) {
|
||||
reportDTO.setResultDeleted(false);
|
||||
}
|
||||
if (BooleanUtils.isFalse(item.getIntegrated()) && reportMap.containsKey(item.getItemId())) {
|
||||
reportDTO.setResultDeleted(false);
|
||||
}
|
||||
executeReportDTOList.add(reportDTO);
|
||||
});
|
||||
}
|
||||
return executeReportDTOList;
|
||||
}
|
||||
|
||||
private Map<String, String> getReportMap(List<ExecHistoryDTO> list) {
|
||||
Map<String, String> reportMap = new HashMap<>();
|
||||
List<String> integratedTaskIds = list.stream().filter(item -> BooleanUtils.isTrue(item.getIntegrated())).map(ExecHistoryDTO::getTaskId).toList();
|
||||
List<String> noIntegratedTaskItemIds = list.stream().filter(item -> BooleanUtils.isFalse(item.getIntegrated())).map(ExecHistoryDTO::getItemId).toList();
|
||||
List<String> resourceIds = ListUtils.union(integratedTaskIds, noIntegratedTaskItemIds);
|
||||
if (CollectionUtils.isNotEmpty(resourceIds)) {
|
||||
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
|
||||
example.createCriteria().andTaskResourceIdIn(resourceIds);
|
||||
List<ApiReportRelateTask> reportRelateTasks = apiReportRelateTaskMapper.selectByExample(example);
|
||||
reportMap = reportRelateTasks.stream().collect(Collectors.toMap(ApiReportRelateTask::getTaskResourceId, ApiReportRelateTask::getReportId));
|
||||
}
|
||||
return reportMap;
|
||||
}
|
||||
|
||||
public List<OperationHistoryDTO> operationHistoryList(OperationHistoryRequest request) {
|
||||
return operationHistoryService.listWidthTable(request, CASE_TABLE);
|
||||
}
|
||||
|
|
|
@ -77,6 +77,8 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.SqlConfig;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultMatcher;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
@ -2704,6 +2706,7 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(10)
|
||||
@Sql(scripts = {"/dml/init_exec_history_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void testExecuteList() throws Exception {
|
||||
ApiScenario first = apiScenarioMapper.selectByExample(new ApiScenarioExample()).getFirst();
|
||||
List<ApiScenarioReport> reports = new ArrayList<>();
|
||||
|
@ -2749,7 +2752,7 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
}
|
||||
apiScenarioReportService.insertApiScenarioReport(reports, records);
|
||||
ExecutePageRequest request = new ExecutePageRequest();
|
||||
request.setId(first.getId());
|
||||
request.setId("1");
|
||||
request.setPageSize(10);
|
||||
request.setCurrent(1);
|
||||
MvcResult mvcResult = responsePost(BASE_PATH + "execute/page", request);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
INSERT INTO `exec_task`(`id`, `num`, `task_name`, `status`, `case_count`, `result`, `task_type`, `trigger_mode`, `project_id`, `organization_id`, `create_time`, `create_user`, `start_time`, `end_time`, `integrated`)
|
||||
VALUES
|
||||
('my_1', 1111, '测试1', 'SUCCESS', 10, 'SUCCESS', 'API_SCENARIO', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639, 1),
|
||||
('my_2', 2222, '测试2', 'SUCCESS', 11, 'SUCCESS', 'API_SCENARIO', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, 0);
|
||||
|
||||
|
||||
INSERT INTO `exec_task_item`(`id`, `task_id`, `resource_id`, `resource_name`, `task_origin`, `status`, `result`, `resource_pool_id`, `resource_pool_node`, `resource_type`, `project_id`, `organization_id`, `thread_id`, `start_time`, `end_time`, `executor`, `case_id`)
|
||||
VALUES
|
||||
('my_1', 'my_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '1'),
|
||||
('my_2', 'my_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '2');
|
||||
|
Loading…
Reference in New Issue