refactor(接口测试): 代码格式以及规范调整
This commit is contained in:
parent
3b0a24da8b
commit
06bc78dc29
|
@ -73,10 +73,10 @@ public class ApiDefinitionController {
|
|||
@PostMapping("/page")
|
||||
@Operation(summary = "接口测试-接口管理-接口列表")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
|
||||
public Pager<List<ApiDefinitionDTO>> getListByPage(@Validated @RequestBody ApiDefinitionPageRequest request) {
|
||||
public Pager<List<ApiDefinitionDTO>> getPage(@Validated @RequestBody ApiDefinitionPageRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc");
|
||||
return PageUtils.setPageInfo(page, apiDefinitionService.getApiDefinitionPage(request));
|
||||
return PageUtils.setPageInfo(page, apiDefinitionService.getApiDefinitionPage(request, false));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,18 +10,8 @@ import lombok.EqualsAndHashCode;
|
|||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ApiCaseComputeDTO {
|
||||
|
||||
@Schema(description = "更新人名称")
|
||||
private String updateUserName;
|
||||
|
||||
@Schema(description = "删除人名称")
|
||||
private String deleteUserName;
|
||||
|
||||
@Schema(description = "版本名称")
|
||||
private String versionName;
|
||||
|
||||
@Schema(description = "接口ID")
|
||||
private String apiDefinitionId;
|
||||
|
||||
|
@ -34,10 +24,13 @@ public class ApiCaseComputeDTO {
|
|||
@Schema(description = "用例通过率")
|
||||
private String casePassRate;
|
||||
|
||||
@Schema(description = "用例成功")
|
||||
@Schema(description = "成功用例")
|
||||
private int success;
|
||||
|
||||
@Schema(description = "用例失败")
|
||||
@Schema(description = "失败用例")
|
||||
private int error;
|
||||
|
||||
@Schema(description = "误报用例")
|
||||
private int fakeError;
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||
public interface ExtApiDefinitionMapper {
|
||||
void deleteApiToGc(@Param("ids") List<String> ids, @Param("userId") String userId, @Param("time") long time);
|
||||
|
||||
List<ApiDefinitionDTO> list(@Param("request") ApiDefinitionPageRequest request);
|
||||
List<ApiDefinitionDTO> list(@Param("request") ApiDefinitionPageRequest request, @Param("deleted") boolean deleted);
|
||||
|
||||
List<ApiCaseComputeDTO> selectApiCaseByIdsAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
api_definition.deleted, project_version.name as version_name
|
||||
from api_definition
|
||||
LEFT JOIN project_version ON project_version.id = api_definition.version_id
|
||||
where deleted = #{deleted}
|
||||
<include refid="queryWhereCondition"/>
|
||||
|
||||
</select>
|
||||
|
@ -31,13 +32,14 @@
|
|||
t1.api_definition_id apiDefinitionId,
|
||||
count( t1.id ) caseTotal,
|
||||
SUM( CASE WHEN t2.`status` = 'SUCCESS' THEN 1 ELSE 0 END ) AS `success`,
|
||||
SUM( CASE WHEN t2.`status` IN ( 'ERROR', 'FAKE_ERROR' ) THEN 1 ELSE 0 END ) AS `error`,
|
||||
SUM( CASE WHEN t2.`status` = 'ERROR' THEN 1 ELSE 0 END ) AS `error`,
|
||||
SUM( CASE WHEN t2.`status` = 'FAKE_ERROR' THEN 1 ELSE 0 END ) AS `fakeError`,
|
||||
CONCAT( FORMAT( SUM( IF ( t2.`status` = 'SUCCESS', 1, 0 ))/ COUNT( t1.id )* 100, 2 ), '%' ) casePassRate
|
||||
FROM
|
||||
api_test_case t1
|
||||
LEFT JOIN api_report t2 ON t1.last_report_id = t2.id
|
||||
WHERE
|
||||
t1.project_id = #{projectId} and (t1.`status` is null or t1.`status` != 'Trash')
|
||||
t1.project_id = #{projectId} and t1.deleted = 0
|
||||
|
||||
GROUP BY
|
||||
t1.api_definition_id
|
||||
|
@ -48,7 +50,6 @@
|
|||
</foreach>
|
||||
</select>
|
||||
<sql id="queryWhereCondition">
|
||||
<where>
|
||||
<if test="request.keyword != null and request.keyword != ''">
|
||||
and (
|
||||
api_definition.num like concat('%', #{request.keyword},'%')
|
||||
|
@ -77,7 +78,6 @@
|
|||
<include refid="queryVersionCondition">
|
||||
<property name="versionTable" value="api_definition"/>
|
||||
</include>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<sql id="filters">
|
||||
|
|
|
@ -9,8 +9,6 @@ import io.metersphere.api.dto.request.ApiDefinitionPageRequest;
|
|||
import io.metersphere.api.enums.ApiReportStatus;
|
||||
import io.metersphere.api.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.api.mapper.ExtApiDefinitionMapper;
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.system.mapper.BaseProjectMapper;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
@ -33,8 +31,6 @@ public class ApiDefinitionService {
|
|||
@Resource
|
||||
private ExtApiDefinitionMapper extApiDefinitionMapper;
|
||||
|
||||
@Resource
|
||||
private BaseProjectMapper baseProjectMapper;
|
||||
@Resource
|
||||
private UserLoginService userLoginService;
|
||||
|
||||
|
@ -60,15 +56,15 @@ public class ApiDefinitionService {
|
|||
|
||||
}
|
||||
|
||||
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request){
|
||||
List<ApiDefinitionDTO> list = extApiDefinitionMapper.list(request);
|
||||
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request, Boolean deleted){
|
||||
List<ApiDefinitionDTO> list = extApiDefinitionMapper.list(request, deleted);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
buildConvertInfo(list);
|
||||
convertUserIdToName(list);
|
||||
calculateApiCase(list, request.getProjectId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
private void buildConvertInfo(List<ApiDefinitionDTO> list) {
|
||||
private void convertUserIdToName(List<ApiDefinitionDTO> list) {
|
||||
Set<String> userIds = extractUserIds(list);
|
||||
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
|
||||
|
||||
|
@ -85,14 +81,6 @@ public class ApiDefinitionService {
|
|||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private Map<String, String> fetchProjectNames(List<ApiDefinitionDTO> list) {
|
||||
List<String> projectIds = list.stream()
|
||||
.map(ApiDefinitionDTO::getProjectId)
|
||||
.collect(Collectors.toList());
|
||||
List<Project> projects = baseProjectMapper.selectProjectByIdList(projectIds);
|
||||
return projects.stream().collect(Collectors.toMap(Project::getId, Project::getName));
|
||||
}
|
||||
|
||||
private void calculateApiCase(List<ApiDefinitionDTO> list, String projectId) {
|
||||
List<String> ids = list.stream().map(ApiDefinitionDTO::getId).toList();
|
||||
List<ApiCaseComputeDTO> apiCaseComputeList = extApiDefinitionMapper.selectApiCaseByIdsAndStatusIsNotTrash(ids, projectId);
|
||||
|
@ -103,11 +91,13 @@ public class ApiDefinitionService {
|
|||
if (apiCaseComputeDTO != null) {
|
||||
item.setCaseTotal(apiCaseComputeDTO.getCaseTotal());
|
||||
item.setCasePassRate(apiCaseComputeDTO.getCasePassRate());
|
||||
// 状态优先级 未执行,未通过,通过
|
||||
// 状态优先级 未执行,未通过,误报(FAKE_ERROR),通过
|
||||
if ((apiCaseComputeDTO.getError() + apiCaseComputeDTO.getSuccess()) < apiCaseComputeDTO.getCaseTotal()) {
|
||||
item.setCaseStatus(ApiReportStatus.PENDING.name());
|
||||
} else if (apiCaseComputeDTO.getError() > 0) {
|
||||
item.setCaseStatus(ApiReportStatus.ERROR.name());
|
||||
} else if (apiCaseComputeDTO.getFakeError() > 0) {
|
||||
item.setCaseStatus(ApiReportStatus.FAKE_ERROR.name());
|
||||
} else {
|
||||
item.setCaseStatus(ApiReportStatus.SUCCESS.name());
|
||||
}
|
||||
|
|
|
@ -128,13 +128,14 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(6)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void getListBPage() throws Exception {
|
||||
public void getPage() throws Exception {
|
||||
ApiDefinitionPageRequest request = new ApiDefinitionPageRequest();
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
this.requestPost(URL_DEFINITION_PAGE, request);
|
||||
request.setSort(new HashMap<>() {{
|
||||
put("createTime", "desc");
|
||||
put("createTime", "asc");
|
||||
}});
|
||||
|
||||
// ALL 全部 KEYWORD 关键字 FILTER 筛选 COMBINE 自定义
|
||||
|
|
Loading…
Reference in New Issue