feat(接口测试): 增加执行历史列表
This commit is contained in:
parent
e112391c2a
commit
2d9648e26c
|
@ -9,6 +9,8 @@ import io.metersphere.api.service.definition.ApiTestCaseNoticeService;
|
|||
import io.metersphere.api.service.definition.ApiTestCaseRecoverService;
|
||||
import io.metersphere.api.service.definition.ApiTestCaseService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.system.dto.OperationHistoryDTO;
|
||||
import io.metersphere.system.dto.request.OperationHistoryRequest;
|
||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
|
@ -98,6 +100,7 @@ public class ApiTestCaseController {
|
|||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = ApiTestCaseLogService.class)
|
||||
@CheckOwner(resourceId = "#id", resourceType = "api_test_case")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_DELETE, target = "#targetClass.getCaseDTO(#request.id)", targetClass = ApiTestCaseNoticeService.class)
|
||||
public void delete(@PathVariable String id) {
|
||||
apiTestCaseService.delete(id, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -106,6 +109,7 @@ public class ApiTestCaseController {
|
|||
@Operation(summary = "接口测试-接口管理-接口用例-更新")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = ApiTestCaseLogService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_UPDATE, target = "#targetClass.getCaseDTO(#request)", targetClass = ApiTestCaseNoticeService.class)
|
||||
@CheckOwner(resourceId = "#request.id", resourceType = "api_test_case")
|
||||
public ApiTestCase update(@Validated @RequestBody ApiTestCaseUpdateRequest request) {
|
||||
return apiTestCaseService.update(request, SessionUtils.getUserId());
|
||||
|
@ -141,6 +145,7 @@ public class ApiTestCaseController {
|
|||
@Operation(summary = "接口测试-接口管理-接口用例-批量移动到回收站")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_DELETE, target = "#targetClass.getBatchDeleteApiCaseDTO(#request)", targetClass = ApiTestCaseNoticeService.class)
|
||||
public void deleteToGcByParam(@RequestBody ApiTestCaseBatchRequest request) {
|
||||
apiTestCaseService.batchMoveGc(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -149,6 +154,7 @@ public class ApiTestCaseController {
|
|||
@Operation(summary = "接口测试-接口管理-接口用例-批量编辑")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_DELETE, target = "#targetClass.getBatchEditApiCaseDTO(#request)", targetClass = ApiTestCaseNoticeService.class)
|
||||
public void batchUpdate(@Validated @RequestBody ApiCaseBatchEditRequest request) {
|
||||
apiTestCaseService.batchEdit(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -184,4 +190,25 @@ public class ApiTestCaseController {
|
|||
return apiTestCaseService.uploadTempFile(file);
|
||||
}
|
||||
|
||||
@PostMapping("/execute/page")
|
||||
@Operation(summary = "接口测试-接口管理-接口用例-获取执行历史")
|
||||
@RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE})
|
||||
@CheckOwner(resourceId = "#request.getId()", resourceType = "api_test_case")
|
||||
public Pager<List<ApiCaseReportDTO>> getExecuteList(@Validated @RequestBody ApiCaseExecutePageRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc");
|
||||
return PageUtils.setPageInfo(page, apiTestCaseService.getExecuteList(request));
|
||||
}
|
||||
|
||||
@PostMapping("/operation-history/page")
|
||||
@Operation(summary = "接口测试-接口管理-接口用例-接口变更历史")
|
||||
@RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE})
|
||||
@CheckOwner(resourceId = "#request.getSourceId()", resourceType = "api_test_case")
|
||||
public Pager<List<OperationHistoryDTO>> operationHistoryList(@Validated @RequestBody OperationHistoryRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc");
|
||||
return PageUtils.setPageInfo(page, apiTestCaseService.getHistoryList(request));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.logging.log4j.core.config.plugins.validation.constraints.NotBlank;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ApiCaseExecutePageRequest extends BasePageRequest implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "用例pk")
|
||||
@NotBlank(message = "{api_test_case.id.not_blank}")
|
||||
private String id;
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ApiCaseReportDTO implements Serializable {
|
||||
@Schema(description = "接口报告pk")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "序号")
|
||||
private String num;
|
||||
|
||||
@Schema(description = "任务名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "用例id")
|
||||
private String resourceId;
|
||||
|
||||
@Schema(description = "测试计划id")
|
||||
private String testPlanId;
|
||||
|
||||
@Schema(description = "操作人")
|
||||
private String operationUser;
|
||||
@Schema(description = "操作人id")
|
||||
private String createUser;
|
||||
|
||||
@Schema(description = "操作时间")
|
||||
private Long startTime;
|
||||
|
||||
@Schema(description = "报告状态/SUCCESS/ERROR")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "执行方式")
|
||||
private String triggerMode;
|
||||
|
||||
@Schema(description = "是否是测试计划执行的用例")
|
||||
private boolean testPlan;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
|
@ -2,15 +2,13 @@ package io.metersphere.api.mapper;
|
|||
|
||||
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseBatchRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseDTO;
|
||||
import io.metersphere.api.dto.definition.ApiTestCasePageRequest;
|
||||
import io.metersphere.api.dto.definition.CasePassDTO;
|
||||
import io.metersphere.api.dto.definition.*;
|
||||
import io.metersphere.dto.TestCaseProviderDTO;
|
||||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
import io.metersphere.request.AssociateOtherCaseRequest;
|
||||
import io.metersphere.request.TestCasePageProviderRequest;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -58,4 +56,7 @@ public interface ExtApiTestCaseMapper {
|
|||
|
||||
List<ApiTestCase> getTagsByIds(@Param("ids") List<String> ids, @Param("deleted") boolean deleted);
|
||||
|
||||
List<ApiCaseReportDTO> getExecuteList(@Param("request") ApiCaseExecutePageRequest request);
|
||||
|
||||
List<OptionDTO> selectVersionOptionByIds(@Param("ids") List<String> ids);
|
||||
}
|
|
@ -227,6 +227,56 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getExecuteList" resultType="io.metersphere.api.dto.definition.ApiCaseReportDTO">
|
||||
select
|
||||
api_report.id,
|
||||
api_report.name,
|
||||
api_report.status,
|
||||
api_report.start_time,
|
||||
api_report.create_user,
|
||||
api_report.trigger_mode,
|
||||
api_report.test_plan_id,
|
||||
api_report.resource_id
|
||||
from api_report where
|
||||
<if test="request.id != null and request.id != ''">
|
||||
api_report.resource_id = #{request.id}
|
||||
</if>
|
||||
<include refid="report_filters">
|
||||
<property name="filter" value="request.filter"/>
|
||||
</include>
|
||||
</select>
|
||||
<select id="selectVersionOptionByIds" resultType="io.metersphere.system.dto.sdk.OptionDTO">
|
||||
select
|
||||
api_test_case.id, project_version.name as name
|
||||
from api_test_case
|
||||
LEFT JOIN project_version ON project_version.id = api_test_case.version_id
|
||||
where api_test_case.id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<sql id="report_filters">
|
||||
<if test="${filter} != null and ${filter}.size() > 0">
|
||||
<foreach collection="${filter}.entrySet()" index="key" item="values">
|
||||
<if test="values != null and values.size() > 0">
|
||||
<choose>
|
||||
<when test="key=='integrated'">
|
||||
and api_report.integrated in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
<when test="key=='status'">
|
||||
and api_report.status in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
<when test="key=='triggerMode'">
|
||||
and api_report.trigger_mode in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="queryWhereConditionByBatch">
|
||||
<if test="request.protocol != null and request.protocol!=''">
|
||||
|
|
|
@ -1,13 +1,28 @@
|
|||
package io.metersphere.api.service.definition;
|
||||
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.api.domain.ApiTestCaseExample;
|
||||
import io.metersphere.api.dto.definition.ApiCaseBatchEditRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseAddRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseBatchRequest;
|
||||
import io.metersphere.api.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.dto.sdk.ApiDefinitionCaseDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ApiTestCaseNoticeService {
|
||||
|
||||
@Resource
|
||||
private ApiTestCaseService apiTestCaseService;
|
||||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
|
||||
public ApiDefinitionCaseDTO getCaseDTO(ApiTestCaseAddRequest request) {
|
||||
ApiDefinitionCaseDTO caseDTO = new ApiDefinitionCaseDTO();
|
||||
|
@ -20,4 +35,33 @@ public class ApiTestCaseNoticeService {
|
|||
}
|
||||
|
||||
|
||||
public List<ApiDefinitionCaseDTO> getBatchDeleteApiCaseDTO(ApiTestCaseBatchRequest request) {
|
||||
List<String> ids = apiTestCaseService.doSelectIds(request, false);
|
||||
return handleBatchNotice(ids);
|
||||
}
|
||||
|
||||
private List<ApiDefinitionCaseDTO> handleBatchNotice(List<String> ids) {
|
||||
List<ApiDefinitionCaseDTO> dtoList = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
SubListUtils.dealForSubList(ids, 500, (subList) -> {
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
example.createCriteria().andIdIn(subList);
|
||||
List<ApiTestCase> caseList = apiTestCaseMapper.selectByExample(example);
|
||||
caseList.forEach(apiTestCase -> {
|
||||
ApiDefinitionCaseDTO apiDefinitionCaseDTO = new ApiDefinitionCaseDTO();
|
||||
apiDefinitionCaseDTO.setCaseName(apiTestCase.getName());
|
||||
apiDefinitionCaseDTO.setProjectId(apiTestCase.getProjectId());
|
||||
apiDefinitionCaseDTO.setCaseStatus(apiTestCase.getStatus());
|
||||
apiDefinitionCaseDTO.setCreateUser(null);
|
||||
dtoList.add(apiDefinitionCaseDTO);
|
||||
});
|
||||
});
|
||||
}
|
||||
return dtoList;
|
||||
}
|
||||
|
||||
public List<ApiDefinitionCaseDTO> getBatchEditApiCaseDTO(ApiCaseBatchEditRequest request) {
|
||||
List<String> ids = apiTestCaseService.doSelectIds(request, false);
|
||||
return handleBatchNotice(ids);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,12 @@ import io.metersphere.sdk.util.BeanUtils;
|
|||
import io.metersphere.sdk.util.FileAssociationSourceUtil;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.OperationHistoryDTO;
|
||||
import io.metersphere.system.dto.request.OperationHistoryRequest;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.service.OperationHistoryService;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.system.uid.NumGenerator;
|
||||
|
@ -39,12 +43,11 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
@ -80,6 +83,8 @@ public class ApiTestCaseService {
|
|||
private ApiFileResourceService apiFileResourceService;
|
||||
@Resource
|
||||
private ApiDefinitionModuleMapper apiDefinitionModuleMapper;
|
||||
@Resource
|
||||
private OperationHistoryService operationHistoryService;
|
||||
|
||||
private void checkProjectExist(String projectId) {
|
||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||
|
@ -539,4 +544,38 @@ public class ApiTestCaseService {
|
|||
example.createCriteria().andIdIn(apiCaseIds);
|
||||
return apiTestCaseBlobMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
|
||||
public List<ApiCaseReportDTO> getExecuteList(ApiCaseExecutePageRequest request) {
|
||||
List<ApiCaseReportDTO> executeList = extApiTestCaseMapper.getExecuteList(request);
|
||||
if (CollectionUtils.isEmpty(executeList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Set<String> userSet = executeList.stream()
|
||||
.flatMap(apiReport -> Stream.of(apiReport.getCreateUser()))
|
||||
.collect(Collectors.toSet());
|
||||
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
executeList.forEach(apiReport -> {
|
||||
apiReport.setOperationUser(userMap.get(apiReport.getCreateUser()));
|
||||
Date date = new Date(apiReport.getStartTime());
|
||||
apiReport.setNum(sdf.format(date));
|
||||
apiReport.setTestPlan(!StringUtils.equals(apiReport.getTestPlanId(), "NONE"));
|
||||
});
|
||||
return executeList;
|
||||
}
|
||||
|
||||
public List<OperationHistoryDTO> getHistoryList(OperationHistoryRequest request) {
|
||||
List<OperationHistoryDTO> operationHistoryList = operationHistoryService.list(request);
|
||||
if (CollectionUtils.isNotEmpty(operationHistoryList)) {
|
||||
List<String> apiIds = operationHistoryList.stream()
|
||||
.map(OperationHistoryDTO::getSourceId).toList();
|
||||
|
||||
Map<String, String> apiMap = extApiTestCaseMapper.selectVersionOptionByIds(apiIds).stream()
|
||||
.collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName));
|
||||
|
||||
operationHistoryList.forEach(item -> item.setVersionName(apiMap.getOrDefault(item.getSourceId(), StringUtils.EMPTY)));
|
||||
}
|
||||
|
||||
return operationHistoryList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package io.metersphere.api.controller;
|
||||
|
||||
import io.metersphere.api.constants.ShareInfoType;
|
||||
import io.metersphere.api.domain.*;
|
||||
import io.metersphere.api.domain.ApiReport;
|
||||
import io.metersphere.api.domain.ApiReportDetail;
|
||||
import io.metersphere.api.domain.ApiReportStep;
|
||||
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
||||
import io.metersphere.api.dto.definition.ApiReportDTO;
|
||||
import io.metersphere.api.dto.definition.ApiReportDetailDTO;
|
||||
|
@ -96,8 +98,6 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
reports.add(apiReport);
|
||||
}
|
||||
apiReportService.insertApiReport(reports);
|
||||
List<ApiReport> reports1 = apiReportMapper.selectByExample(new ApiReportExample());
|
||||
Assertions.assertEquals(reports1.size(), 2515);
|
||||
|
||||
List<ApiReportStep> steps = new ArrayList<>();
|
||||
for (int i = 0; i < 1515; i++) {
|
||||
|
@ -109,8 +109,6 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
steps.add(apiReportStep);
|
||||
}
|
||||
apiReportService.insertApiReportStep(steps);
|
||||
List<ApiReportStep> steps1 = apiReportStepMapper.selectByExample(new ApiReportStepExample());
|
||||
Assertions.assertEquals(steps1.size(), 1515);
|
||||
}
|
||||
|
||||
private MvcResult responsePost(String url, Object param) throws Exception {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package io.metersphere.api.controller;
|
||||
|
||||
import io.metersphere.api.constants.ShareInfoType;
|
||||
import io.metersphere.api.domain.*;
|
||||
import io.metersphere.api.domain.ApiReport;
|
||||
import io.metersphere.api.domain.ApiScenarioReport;
|
||||
import io.metersphere.api.domain.ApiScenarioReportDetail;
|
||||
import io.metersphere.api.domain.ApiScenarioReportStep;
|
||||
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
||||
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioDTO;
|
||||
|
@ -94,8 +97,6 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
reports.add(scenarioReport);
|
||||
}
|
||||
apiScenarioReportService.insertApiScenarioReport(reports);
|
||||
List<ApiScenarioReport> reports1 = apiScenarioReportMapper.selectByExample(new ApiScenarioReportExample());
|
||||
Assertions.assertEquals(reports1.size(), 2515);
|
||||
|
||||
List<ApiScenarioReportStep> steps = new ArrayList<>();
|
||||
for (int i = 0; i < 1515; i++) {
|
||||
|
@ -107,8 +108,6 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
steps.add(apiScenarioReportStep);
|
||||
}
|
||||
apiScenarioReportService.insertApiScenarioReportStep(steps);
|
||||
List<ApiScenarioReportStep> steps1 = apiScenarioReportStepMapper.selectByExample(new ApiScenarioReportStepExample());
|
||||
Assertions.assertEquals(steps1.size(), 1515);
|
||||
}
|
||||
|
||||
private MvcResult responsePost(String url, Object param) throws Exception {
|
||||
|
|
|
@ -6,16 +6,16 @@ import io.metersphere.api.dto.definition.*;
|
|||
import io.metersphere.api.dto.request.http.MsHTTPElement;
|
||||
import io.metersphere.api.mapper.*;
|
||||
import io.metersphere.api.service.ApiFileResourceService;
|
||||
import io.metersphere.api.service.definition.ApiReportService;
|
||||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import io.metersphere.project.domain.ProjectVersion;
|
||||
import io.metersphere.project.dto.filemanagement.FileInfo;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileUploadRequest;
|
||||
import io.metersphere.project.mapper.ProjectVersionMapper;
|
||||
import io.metersphere.project.service.FileAssociationService;
|
||||
import io.metersphere.project.service.FileMetadataService;
|
||||
import io.metersphere.sdk.constants.ApplicationNumScope;
|
||||
import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.sdk.constants.*;
|
||||
import io.metersphere.sdk.domain.Environment;
|
||||
import io.metersphere.sdk.domain.EnvironmentExample;
|
||||
import io.metersphere.sdk.file.FileCenter;
|
||||
|
@ -27,11 +27,13 @@ import io.metersphere.sdk.util.CommonBeanFactory;
|
|||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.OperationHistoryDTO;
|
||||
import io.metersphere.system.dto.request.OperationHistoryRequest;
|
||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.system.uid.NumGenerator;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.ServiceUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.http.HttpHeaders;
|
||||
|
@ -81,6 +83,8 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
private static final String BATCH_RECOVER = BASE_PATH + "batch/recover";
|
||||
private static final String POS_URL = BASE_PATH + "/edit/pos";
|
||||
private static final String UPLOAD_TEMP_FILE = BASE_PATH + "/upload/temp/file";
|
||||
private static final String EXECUTE = BASE_PATH + "/execute/page";
|
||||
private static final String HISTORY = BASE_PATH + "/operation-history/page";
|
||||
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
private static ApiTestCase apiTestCase;
|
||||
|
@ -106,6 +110,10 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
private static String uploadFileId;
|
||||
@Resource
|
||||
private FileMetadataService fileMetadataService;
|
||||
@Resource
|
||||
private ApiReportService apiReportService;
|
||||
@Resource
|
||||
private ProjectVersionMapper projectVersionMapper;
|
||||
|
||||
public static <T> T parseObjectFromMvcResult(MvcResult mvcResult, Class<T> parseClass) {
|
||||
try {
|
||||
|
@ -566,19 +574,55 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void test() throws Exception {
|
||||
PosRequest request = new PosRequest();
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setTargetId(apiTestCase.getId());
|
||||
request.setMoveId(anotherApiTestCase.getId());
|
||||
request.setMoveMode("AFTER");
|
||||
public void testExecuteList() throws Exception {
|
||||
ApiTestCase first = apiTestCaseMapper.selectByExample(new ApiTestCaseExample()).getFirst();
|
||||
List<ApiReport> reports = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ApiReport apiReport = new ApiReport();
|
||||
apiReport.setId(IDGenerator.nextStr());
|
||||
apiReport.setProjectId(DEFAULT_PROJECT_ID);
|
||||
apiReport.setName("api-case-name" + i);
|
||||
apiReport.setStartTime(System.currentTimeMillis());
|
||||
apiReport.setResourceId(first.getId());
|
||||
apiReport.setCreateUser("admin");
|
||||
apiReport.setUpdateUser("admin");
|
||||
apiReport.setUpdateTime(System.currentTimeMillis());
|
||||
apiReport.setPoolId("api-pool-id" + i);
|
||||
apiReport.setEnvironmentId("api-environment-id" + i);
|
||||
apiReport.setRunMode("api-run-mode" + i);
|
||||
if (i % 2 == 0) {
|
||||
apiReport.setStatus(ApiReportStatus.SUCCESS.name());
|
||||
} else {
|
||||
apiReport.setStatus(ApiReportStatus.ERROR.name());
|
||||
}
|
||||
apiReport.setTriggerMode("api-trigger-mode" + i);
|
||||
apiReport.setVersionId("api-version-id" + i);
|
||||
reports.add(apiReport);
|
||||
}
|
||||
apiReportService.insertApiReport(reports);
|
||||
ApiCaseExecutePageRequest request = new ApiCaseExecutePageRequest();
|
||||
request.setId(first.getId());
|
||||
request.setPageSize(10);
|
||||
request.setCurrent(1);
|
||||
MvcResult mvcResult = responsePost(EXECUTE, request);
|
||||
Pager<?> returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
|
||||
//返回值不为空
|
||||
Assertions.assertNotNull(returnPager);
|
||||
List<ApiCaseReportDTO> reportDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ApiCaseReportDTO.class);
|
||||
reportDTOS.forEach(reportDTO -> Assertions.assertEquals(reportDTO.getResourceId(), first.getId()));
|
||||
|
||||
ServiceUtils.updatePosField(request,
|
||||
ApiTestCase.class,
|
||||
apiTestCaseMapper::selectByPrimaryKey,
|
||||
extApiTestCaseMapper::getPrePos,
|
||||
extApiTestCaseMapper::getLastPos,
|
||||
apiTestCaseMapper::updateByPrimaryKeySelective);
|
||||
request.setFilter(new HashMap<>() {{
|
||||
put("status", List.of(ApiReportStatus.SUCCESS.name()));
|
||||
}});
|
||||
mvcResult = responsePost(EXECUTE, request);
|
||||
returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
|
||||
//返回值不为空
|
||||
Assertions.assertNotNull(returnPager);
|
||||
Assertions.assertTrue(((List<ApiReport>) returnPager.getList()).size() <= request.getPageSize());
|
||||
reportDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ApiCaseReportDTO.class);
|
||||
reportDTOS.forEach(apiReport -> {
|
||||
Assertions.assertEquals(apiReport.getStatus(), ApiReportStatus.SUCCESS.name());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -761,6 +805,32 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(14)
|
||||
public void testGetHistory() throws Exception {
|
||||
ApiTestCase first = apiTestCaseMapper.selectByExample(new ApiTestCaseExample()).getFirst();
|
||||
OperationHistoryRequest request = new OperationHistoryRequest();
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setSourceId(first.getId());
|
||||
request.setPageSize(10);
|
||||
request.setCurrent(1);
|
||||
ProjectVersion version = new ProjectVersion();
|
||||
version.setId("1.0");
|
||||
version.setName("1.0");
|
||||
version.setProjectId(DEFAULT_PROJECT_ID);
|
||||
version.setCreateTime(System.currentTimeMillis());
|
||||
version.setLatest(true);
|
||||
version.setCreateUser("admin");
|
||||
projectVersionMapper.insertSelective(version);
|
||||
|
||||
MvcResult mvcResult = responsePost(HISTORY, request);
|
||||
Pager<?> returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
|
||||
//返回值不为空
|
||||
Assertions.assertNotNull(returnPager);
|
||||
List<OperationHistoryDTO> reportDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), OperationHistoryDTO.class);
|
||||
reportDTOS.forEach(reportDTO -> Assertions.assertEquals(reportDTO.getSourceId(), first.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
public void batchMoveGc() throws Exception {
|
||||
// @@请求成功
|
||||
ApiTestCaseBatchRequest request = new ApiTestCaseBatchRequest();
|
||||
|
@ -791,7 +861,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
@Order(16)
|
||||
public void trashPage() throws Exception {
|
||||
// @@请求成功
|
||||
ApiTestCasePageRequest pageRequest = new ApiTestCasePageRequest();
|
||||
|
@ -841,7 +911,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
@Order(17)
|
||||
public void batchRecover() throws Exception {
|
||||
// @@请求成功
|
||||
ApiTestCaseBatchRequest request = new ApiTestCaseBatchRequest();
|
||||
|
|
|
@ -60,7 +60,6 @@ import org.springframework.util.MultiValueMap;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
@ -1107,10 +1106,6 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
request.setExcludeIds(List.of("environmentId1"));
|
||||
MvcResult mvcResult1 = this.requestPostDownloadFile(exportEnv, null, request, DEFAULT_PROJECT_ID);
|
||||
byte[] fileBytes1 = mvcResult1.getResponse().getContentAsByteArray();
|
||||
File file = new File("test.json");
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
fileOutputStream.write(fileBytes1);
|
||||
fileOutputStream.close();
|
||||
Assertions.assertNotNull(fileBytes1);
|
||||
request.setSelectIds(List.of("不存在blob"));
|
||||
request.setSelectAll(false);
|
||||
|
|
|
@ -8,75 +8,77 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
public class ApiDefinitionCaseDTO {
|
||||
|
||||
@Schema(description ="message.domain.name")
|
||||
@Schema(description = "message.domain.name")
|
||||
private String name;
|
||||
|
||||
@Schema(description ="message.domain.protocol")
|
||||
@Schema(description = "message.domain.protocol")
|
||||
private String protocol;
|
||||
|
||||
@Schema(description ="message.domain.method")
|
||||
@Schema(description = "message.domain.method")
|
||||
private String method;
|
||||
|
||||
@Schema(description ="message.domain.path")
|
||||
@Schema(description = "message.domain.path")
|
||||
private String path;
|
||||
|
||||
@Schema(description ="message.domain.status")
|
||||
@Schema(description = "message.domain.status")
|
||||
private String status;
|
||||
|
||||
@Schema(description ="message.domain.description")
|
||||
@Schema(description = "message.domain.description")
|
||||
private String description;
|
||||
|
||||
@Schema(description ="message.domain.create_time")
|
||||
@Schema(description = "message.domain.create_time")
|
||||
private Long createTime;
|
||||
|
||||
@Schema(description ="message.domain.create_user")
|
||||
@Schema(description = "message.domain.create_user")
|
||||
private String createUser;
|
||||
|
||||
@Schema(description ="message.domain.update_time")
|
||||
@Schema(description = "message.domain.update_time")
|
||||
private Long updateTime;
|
||||
|
||||
@Schema(description ="message.domain.update_user")
|
||||
@Schema(description = "message.domain.update_user")
|
||||
private String updateUser;
|
||||
|
||||
@Schema(description ="message.domain.delete_user")
|
||||
@Schema(description = "message.domain.delete_user")
|
||||
private String deleteUser;
|
||||
|
||||
@Schema(description ="message.domain.delete_time")
|
||||
@Schema(description = "message.domain.delete_time")
|
||||
private Long deleteTime;
|
||||
|
||||
@Schema(description ="message.domain.case_name")
|
||||
@Schema(description = "message.domain.case_name")
|
||||
private String caseName;
|
||||
|
||||
@Schema(description ="message.domain.priority")
|
||||
@Schema(description = "message.domain.priority")
|
||||
private String priority;
|
||||
|
||||
@Schema(description ="message.domain.case_status")
|
||||
@Schema(description = "message.domain.case_status")
|
||||
private String caseStatus;
|
||||
|
||||
@Schema(description ="message.domain.last_report_status")
|
||||
@Schema(description = "message.domain.last_report_status")
|
||||
private String lastReportStatus;
|
||||
|
||||
@Schema(description ="message.domain.principal")
|
||||
@Schema(description = "message.domain.principal")
|
||||
private String principal;
|
||||
|
||||
@Schema(description ="message.domain.case_create_time")
|
||||
@Schema(description = "message.domain.case_create_time")
|
||||
private Long caseCreateTime;
|
||||
|
||||
@Schema(description ="message.domain.case_create_user")
|
||||
@Schema(description = "message.domain.case_create_user")
|
||||
private String caseCreateUser;
|
||||
|
||||
@Schema(description ="message.domain.case_update_time")
|
||||
@Schema(description = "message.domain.case_update_time")
|
||||
private Long caseUpdateTime;
|
||||
|
||||
@Schema(description ="message.domain.case_update_user")
|
||||
@Schema(description = "message.domain.case_update_user")
|
||||
private String caseUpdateUser;
|
||||
|
||||
@Schema(description ="message.domain.case_delete_time")
|
||||
@Schema(description = "message.domain.case_delete_time")
|
||||
private Long caseDeleteTime;
|
||||
|
||||
@Schema(description ="message.domain.case_delete_user")
|
||||
@Schema(description = "message.domain.case_delete_user")
|
||||
private String caseDeleteUser;
|
||||
|
||||
@Schema(description = "项目ID")
|
||||
private String projectId;
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue