refactor(接口测试): 根据代码规范优化枚举变量名称

根据代码规范优化枚举变量名称
This commit is contained in:
song-tianyang 2022-06-10 13:17:27 +08:00 committed by TIanyang
parent 2b7e047e6a
commit d7e5cf0495
14 changed files with 60 additions and 51 deletions

View File

@ -442,7 +442,7 @@ public class ApiDefinitionExecResultService {
saveResult.setId(reportId);
//对响应内容进行进一步解析如果有附加信息比如误报库信息则根据附加信息内的数据进行其他判读
RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item);
String status = item.isSuccess() ? ExecuteResult.success.name() : ExecuteResult.error.name();
String status = item.isSuccess() ? ExecuteResult.API_SUCCESS.toString() : ExecuteResult.API_ERROR.toString();
if (MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())) {
if (StringUtils.isNotEmpty(expandDTO.getStatus())) {
status = expandDTO.getStatus();

View File

@ -174,7 +174,7 @@ public class ApiExecutionQueueService {
if (StringUtils.contains(dto.getRunMode(), ApiRunMode.SCENARIO.name())) {
if (StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
ApiScenarioReportResultExample example = new ApiScenarioReportResultExample();
example.createCriteria().andReportIdEqualTo(dto.getReportId()).andStatusEqualTo(ExecuteResult.Error.name());
example.createCriteria().andReportIdEqualTo(dto.getReportId()).andStatusEqualTo(ExecuteResult.SCENARIO_ERROR.toString());
long error = apiScenarioReportResultMapper.countByExample(example);
isError = error > 0;
} else {

View File

@ -122,11 +122,11 @@ public class ApiScenarioReportResultService {
ApiScenarioReportResultWithBLOBs report = newScenarioReportResult(reportId, resourceId);
report.setTotalAssertions(Long.parseLong(result.getTotalAssertions() + ""));
report.setPassAssertions(Long.parseLong(result.getPassAssertions() + ""));
String status = result.getError() == 0 ? ExecuteResult.Success.name() : ExecuteResult.Error.name();
String status = result.getError() == 0 ? ExecuteResult.SCENARIO_SUCCESS.toString() : ExecuteResult.SCENARIO_ERROR.toString();
if (CollectionUtils.isNotEmpty(errorCodeDTO.getErrorCodeList())) {
report.setErrorCode(errorCodeDTO.getErrorCodeStr());
}
if (StringUtils.equalsIgnoreCase(errorCodeDTO.getRequestStatus(), ExecuteResult.errorReportResult.name())) {
if (StringUtils.equalsIgnoreCase(errorCodeDTO.getRequestStatus(), ExecuteResult.ERROR_REPORT_RESULT.toString())) {
status = errorCodeDTO.getRequestStatus();
}
report.setStatus(status);

View File

@ -374,13 +374,13 @@ public class ApiScenarioReportService {
hasUnExecute = true;
}else {
for (String status : reportStatus) {
if (StringUtils.equalsIgnoreCase(status, ExecuteResult.Error.name())) {
if (StringUtils.equalsIgnoreCase(status, ExecuteResult.SCENARIO_ERROR.toString())) {
hasError = true;
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.errorReportResult.name())) {
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.ERROR_REPORT_RESULT.toString())) {
hasErrorReport = true;
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.STOP.name())) {
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.STOP.toString())) {
hasStop = true;
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.unexecute.name())) {
} else if (StringUtils.equalsIgnoreCase(status, ExecuteResult.UN_EXECUTE.toString())) {
hasUnExecute = true;
} else {
hasOtherStatus = true;
@ -394,9 +394,9 @@ public class ApiScenarioReportService {
}
return hasError ? ScenarioStatus.Error.name() :
hasErrorReport ? ExecuteResult.errorReportResult.name() :
hasStop ? ExecuteResult.STOP.name() :
hasUnExecute ? ExecuteResult.unexecute.name() : ScenarioStatus.Success.name();
hasErrorReport ? ExecuteResult.ERROR_REPORT_RESULT.toString() :
hasStop ? ExecuteResult.STOP.toString() :
hasUnExecute ? ExecuteResult.UN_EXECUTE.toString() : ScenarioStatus.Success.name();
}
public void margeReport(String reportId, String runMode, String console) {
@ -441,7 +441,7 @@ public class ApiScenarioReportService {
scenario = apiScenarioMapper.selectByPrimaryKey(report.getScenarioId());
}
if (scenario != null) {
if (StringUtils.equalsAnyIgnoreCase(status, ExecuteResult.errorReportResult.name())) {
if (StringUtils.equalsAnyIgnoreCase(status, ExecuteResult.ERROR_REPORT_RESULT.toString())) {
scenario.setLastResult(status);
} else {
scenario.setLastResult(errorSize > 0 ? "Fail" : ScenarioStatus.Success.name());
@ -482,7 +482,7 @@ public class ApiScenarioReportService {
scenario = uiScenarioMapper.selectByPrimaryKey(report.getScenarioId());
}
if (scenario != null) {
if (StringUtils.equalsAnyIgnoreCase(status, ExecuteResult.errorReportResult.name())) {
if (StringUtils.equalsAnyIgnoreCase(status, ExecuteResult.ERROR_REPORT_RESULT.toString())) {
scenario.setLastResult(status);
} else {
scenario.setLastResult(errorSize > 0 ? "Fail" : ScenarioStatus.Success.name());
@ -896,7 +896,7 @@ public class ApiScenarioReportService {
for (ApiScenarioReportResult result : requestResults) {
if (StringUtils.equalsIgnoreCase(result.getStatus(), ScenarioStatus.Error.name())) {
errorSize++;
} else if (StringUtils.equalsIgnoreCase(result.getStatus(), ExecuteResult.errorReportResult.name())) {
} else if (StringUtils.equalsIgnoreCase(result.getStatus(), ExecuteResult.ERROR_REPORT_RESULT.toString())) {
errorReportResultSize++;
}
}
@ -904,9 +904,9 @@ public class ApiScenarioReportService {
if (errorSize > 0) {
status = ScenarioStatus.Error.name();
} else if (errorReportResultSize > 0) {
status = ExecuteResult.errorReportResult.name();
status = ExecuteResult.ERROR_REPORT_RESULT.toString();
} else {
status = requestResults.isEmpty() ? ExecuteResult.unexecute.name() : ScenarioStatus.Success.name();
status = requestResults.isEmpty() ? ExecuteResult.UN_EXECUTE.toString() : ScenarioStatus.Success.name();
}
if (dto != null && dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("TIMEOUT") && (Boolean) dto.getArbitraryData().get("TIMEOUT")) {

View File

@ -194,7 +194,7 @@ public class ApiScenarioReportStructureService {
totalScenario.set(totalScenario.longValue() + 1);
if (StringUtils.equalsIgnoreCase(step.getTotalStatus(), "fail")) {
scenarioError.set(scenarioError.longValue() + 1);
} else if (StringUtils.equalsAnyIgnoreCase(step.getTotalStatus(), "errorCode", ExecuteResult.errorReportResult.name())) {
} else if (StringUtils.equalsAnyIgnoreCase(step.getTotalStatus(), "errorCode", ExecuteResult.ERROR_REPORT_RESULT.toString())) {
errorReport.set(errorReport.longValue() + 1);
} else if (!StringUtils.equalsIgnoreCase(step.getTotalStatus(), "success")) {
unExecute.set(unExecute.longValue() + 1);
@ -346,7 +346,7 @@ public class ApiScenarioReportStructureService {
//当有多个子步骤结果时如果当前步骤不是场景失败>误报>未执行>成功>未执行 如果是场景误报>失败>成功>未执行
if (failCount == 0 && errorReportCount == 0 && successCount == 0) {
dto.setTotalStatus(ExecuteResult.unexecute.name());
dto.setTotalStatus(ExecuteResult.UN_EXECUTE.toString());
} else if (successCount == dto.getChildren().size() || (successCount > 0 && errorReportCount == 0 && failCount == 0)) {
dto.setTotalStatus("success");
} else {
@ -370,7 +370,7 @@ public class ApiScenarioReportStructureService {
}
}
if (StringUtils.isEmpty(dto.getTotalStatus())) {
dto.setTotalStatus(ExecuteResult.unexecute.name());
dto.setTotalStatus(ExecuteResult.UN_EXECUTE.toString());
} else if (StringUtils.equalsAnyIgnoreCase(dto.getTotalStatus(), "error")) {
dto.setTotalStatus("fail");
}
@ -393,8 +393,8 @@ public class ApiScenarioReportStructureService {
}
// 非正常执行结束的请求结果
List<StepTreeDTO> unList = dtoList.stream().filter(e -> e.getValue() != null
&& ((StringUtils.equalsIgnoreCase(e.getType(), "DubboSampler") && e.getValue().getStartTime() == 0)
|| StringUtils.equalsIgnoreCase(e.getTotalStatus(), ExecuteResult.unexecute.name())))
&& ((StringUtils.equalsIgnoreCase(e.getType(), "DubboSampler") && e.getValue().getStartTime() == 0)
|| StringUtils.equalsIgnoreCase(e.getTotalStatus(), ExecuteResult.UN_EXECUTE.toString())))
.collect(Collectors.toList());
// 有效数据按照时间排序
@ -461,7 +461,7 @@ public class ApiScenarioReportStructureService {
}
if (vo.getRequestResult() == null) {
RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO();
requestResultExpandDTO.setStatus(ExecuteResult.unexecute.name());
requestResultExpandDTO.setStatus(ExecuteResult.UN_EXECUTE.toString());
requestResultExpandDTO.setName(item.getName());
vo.setRequestResult(requestResultExpandDTO);
}
@ -498,7 +498,7 @@ public class ApiScenarioReportStructureService {
if (CollectionUtils.isNotEmpty(reportResults)) {
reportDTO.setTotal(reportResults.size());
reportDTO.setError(reportResults.stream().filter(e -> StringUtils.equalsAnyIgnoreCase(e.getStatus(), "Error")).collect(Collectors.toList()).size());
reportDTO.setUnExecute(reportResults.stream().filter(e -> StringUtils.equalsAnyIgnoreCase(e.getStatus(), "STOP", ExecuteResult.unexecute.name())).collect(Collectors.toList()).size());
reportDTO.setUnExecute(reportResults.stream().filter(e -> StringUtils.equalsAnyIgnoreCase(e.getStatus(), "STOP", ExecuteResult.UN_EXECUTE.toString())).collect(Collectors.toList()).size());
reportDTO.setErrorCode(reportResults.stream().filter(e -> StringUtils.equalsAnyIgnoreCase(e.getStatus(), "errorReportResult")).collect(Collectors.toList()).size());
reportDTO.setPassAssertions(reportResults.stream().mapToLong(ApiDefinitionExecResultVo::getPassAssertions).sum());
reportDTO.setTotalAssertions(reportResults.stream().mapToLong(ApiDefinitionExecResultVo::getTotalAssertions).sum());
@ -576,7 +576,7 @@ public class ApiScenarioReportStructureService {
reportDTO.setTotal(reportResults.size());
reportDTO.setError(reportResults.stream().filter(e -> StringUtils.equals(e.getStatus(), "Error")).collect(Collectors.toList()).size());
reportDTO.setErrorCode(reportResults.stream().filter(e -> StringUtils.equals(e.getStatus(), ExecuteResult.errorReportResult.name())).collect(Collectors.toList()).size());
reportDTO.setErrorCode(reportResults.stream().filter(e -> StringUtils.equals(e.getStatus(), ExecuteResult.ERROR_REPORT_RESULT.toString())).collect(Collectors.toList()).size());
reportDTO.setPassAssertions(reportResults.stream().mapToLong(ApiScenarioReportResult::getPassAssertions).sum());
reportDTO.setTotalAssertions(reportResults.stream().mapToLong(ApiScenarioReportResult::getTotalAssertions).sum());
@ -662,7 +662,7 @@ public class ApiScenarioReportStructureService {
for (StepTreeDTO step : stepList) {
if (step.getValue() != null) {
if (step.getValue() instanceof RequestResultExpandDTO
&& StringUtils.equalsIgnoreCase(((RequestResultExpandDTO) step.getValue()).getStatus(), ExecuteResult.unexecute.name())) {
&& StringUtils.equalsIgnoreCase(((RequestResultExpandDTO) step.getValue()).getStatus(), ExecuteResult.UN_EXECUTE.toString())) {
allUnExecute.set(allUnExecute.longValue() + 1);
}
}

View File

@ -2,17 +2,26 @@ package io.metersphere.commons.constants;
public enum ExecuteResult {
//误报状态
errorReportResult,
ERROR_REPORT_RESULT("errorReportResult"),
//停止状态
STOP("STOP"),
//接口执行状态(兼容旧数据)
success, error, STOP,
API_SUCCESS("success"), API_ERROR("error"),
//未执行状态
unexecute,
UN_EXECUTE("unexecute"),
//场景执行状态(兼容旧数据)
Success, Error,
SCENARIO_SUCCESS("Success"), SCENARIO_ERROR("Error"),
//测试计划执行状态(兼容旧数据)
PREPARE, RUNNING, SUCCESS, FAILD
TEST_PLAN_PREPARE("PREPARE"), TEST_PLAN_RUNNING("RUNNING");
private String value;
ExecuteResult(String value) {
this.value = value;
}
@Override
public String toString() {
return this.value;
}
}

View File

@ -147,12 +147,12 @@ public class ErrorReportLibraryUtil {
if(MapUtils.isNotEmpty(errorReportAssertionMap)){
if (MapUtils.isNotEmpty(errorAssertionMap)) {
if(higherThanError){
result.requestStatus = ExecuteResult.errorReportResult.name();
result.requestStatus = ExecuteResult.ERROR_REPORT_RESULT.toString();
}
}else if(higherThanSuccess){
result.requestStatus = ExecuteResult.errorReportResult.name();
result.requestStatus = ExecuteResult.ERROR_REPORT_RESULT.toString();
}else if(MapUtils.isEmpty(successAssertionMap)){
result.requestStatus = ExecuteResult.errorReportResult.name();
result.requestStatus = ExecuteResult.ERROR_REPORT_RESULT.toString();
}
}
}

View File

@ -24,13 +24,13 @@ public class ResponseUtil {
if (CollectionUtils.isNotEmpty(errorCodeDTO.getErrorCodeList())) {
Map<String, String> expandMap = new HashMap<>();
expandMap.put(ExecuteResult.errorReportResult.name(), errorCodeDTO.getErrorCodeStr());
if (StringUtils.equalsIgnoreCase(errorCodeDTO.getRequestStatus(), ExecuteResult.errorReportResult.name())) {
expandMap.put("status", ExecuteResult.errorReportResult.name());
expandMap.put(ExecuteResult.ERROR_REPORT_RESULT.toString(), errorCodeDTO.getErrorCodeStr());
if (StringUtils.equalsIgnoreCase(errorCodeDTO.getRequestStatus(), ExecuteResult.ERROR_REPORT_RESULT.toString())) {
expandMap.put("status", ExecuteResult.ERROR_REPORT_RESULT.toString());
}
expandDTO.setAttachInfoMap(expandMap);
}
if (StringUtils.equalsIgnoreCase(errorCodeDTO.getRequestStatus(), ExecuteResult.errorReportResult.name())) {
if (StringUtils.equalsIgnoreCase(errorCodeDTO.getRequestStatus(), ExecuteResult.ERROR_REPORT_RESULT.toString())) {
expandDTO.setStatus(errorCodeDTO.getRequestStatus());
}
return expandDTO;

View File

@ -53,7 +53,7 @@ public class TestPlanUtils {
addToReportStatusResultList(resultMap, statusResult, "SUCCESS");
addToReportStatusResultList(resultMap, statusResult, "STOP");
addToReportStatusResultList(resultMap, statusResult, TestPlanTestCaseStatus.Prepare.name());
addToReportStatusResultList(resultMap, statusResult, ExecuteResult.errorReportResult.name());
addToReportStatusResultList(resultMap, statusResult, ExecuteResult.ERROR_REPORT_RESULT.toString());
}
/**

View File

@ -456,7 +456,7 @@ public class TestPlanApiCaseService {
}
public List<TestPlanFailureApiDTO> getErrorReportCases(String planId) {
List<TestPlanFailureApiDTO> apiTestCases = extTestPlanApiCaseMapper.getFailureList(planId, ExecuteResult.errorReportResult.name());
List<TestPlanFailureApiDTO> apiTestCases = extTestPlanApiCaseMapper.getFailureList(planId, ExecuteResult.ERROR_REPORT_RESULT.toString());
return buildCases(apiTestCases);
}

View File

@ -441,7 +441,7 @@ public class TestPlanReportService {
}
if (testPlanReport != null) {
boolean isSendMessage = false;
if(StringUtils.equalsIgnoreCase(testPlanReport.getStatus(),ExecuteResult.RUNNING.name())){
if(StringUtils.equalsIgnoreCase(testPlanReport.getStatus(),ExecuteResult.TEST_PLAN_RUNNING.toString())){
isSendMessage = true;
}
//初始化测试计划包含组件信息
@ -689,7 +689,7 @@ public class TestPlanReportService {
if (sendMessage && testPlan != null && StringUtils.equalsAny(report.getTriggerMode(),
ReportTriggerMode.MANUAL.name(),
ReportTriggerMode.API.name(),
ReportTriggerMode.SCHEDULE.name()) && !StringUtils.equalsIgnoreCase(report.getStatus(), ExecuteResult.RUNNING.name())
ReportTriggerMode.SCHEDULE.name()) && !StringUtils.equalsIgnoreCase(report.getStatus(), ExecuteResult.TEST_PLAN_RUNNING.toString())
) {
//发送通知
testPlanMessageService.sendMessage(testPlan, report, testPlan.getProjectId());

View File

@ -478,7 +478,7 @@ public class TestPlanScenarioCaseService {
List<TestCaseReportStatusResultDTO> stepResult = new ArrayList<>();
getScenarioCaseReportStatusResultDTO(TestPlanTestCaseStatus.Failure.name(), stepCount.getScenarioStepError(), stepResult);
getScenarioCaseReportStatusResultDTO(TestPlanTestCaseStatus.Pass.name(), stepCount.getScenarioStepSuccess(), stepResult);
getScenarioCaseReportStatusResultDTO(ExecuteResult.errorReportResult.name(), stepCount.getScenarioStepErrorReport(), stepResult);
getScenarioCaseReportStatusResultDTO(ExecuteResult.ERROR_REPORT_RESULT.toString(), stepCount.getScenarioStepErrorReport(), stepResult);
getScenarioCaseReportStatusResultDTO(TestPlanTestCaseStatus.Underway.name(),
stepCount.getScenarioStepTotal() - stepCount.getScenarioStepSuccess() - stepCount.getScenarioStepError() - stepCount.getScenarioStepErrorReport() + underwayStepsCounts, stepResult);
apiResult.setApiScenarioData(statusResult);
@ -604,7 +604,7 @@ public class TestPlanScenarioCaseService {
public List<TestPlanFailureScenarioDTO> getErrorReportCases(String planId) {
List<TestPlanFailureScenarioDTO> apiTestCases =
extTestPlanScenarioCaseMapper.getFailureList(planId, ExecuteResult.errorReportResult.name());
extTestPlanScenarioCaseMapper.getFailureList(planId, ExecuteResult.ERROR_REPORT_RESULT.toString());
return buildCases(apiTestCases);
}

View File

@ -1617,7 +1617,7 @@ public class TestPlanService {
for (TestPlanFailureScenarioDTO scenario : scenarios) {
if (StringUtils.equalsAnyIgnoreCase(scenario.getLastResult(), "Fail", "Error")) {
failureScenarios.add(scenario);
} else if (StringUtils.equalsIgnoreCase(scenario.getLastResult(), ExecuteResult.errorReportResult.name())) {
} else if (StringUtils.equalsIgnoreCase(scenario.getLastResult(), ExecuteResult.ERROR_REPORT_RESULT.toString())) {
errorReportScenarios.add(scenario);
} else if (StringUtils.equalsAnyIgnoreCase(scenario.getLastResult(), "stop", "unexecute")) {
unExecuteScenarios.add(scenario);
@ -1643,7 +1643,7 @@ public class TestPlanService {
for (TestPlanFailureApiDTO apiDTO : apiAllCases) {
if (StringUtils.equalsIgnoreCase(apiDTO.getExecResult(), "error")) {
apiFailureCases.add(apiDTO);
} else if (StringUtils.equalsIgnoreCase(apiDTO.getExecResult(), ExecuteResult.errorReportResult.name())) {
} else if (StringUtils.equalsIgnoreCase(apiDTO.getExecResult(), ExecuteResult.ERROR_REPORT_RESULT.toString())) {
apiErrorReportCases.add(apiDTO);
} else if (StringUtils.equalsAnyIgnoreCase(apiDTO.getExecResult(), "stop", "unexecute")) {
apiUnExecuteCases.add(apiDTO);

View File

@ -125,7 +125,7 @@
</span>
<span v-else-if="item.executionStatus && item.executionStatus.toLowerCase() === 'unexecute'"
class="ms-task-stopped">
unexecute
Unexecuted
</span>
<span v-else-if="item.executionStatus && item.executionStatus.toLowerCase() === 'errorreportresult'"
class="ms-task-error-report-status">
@ -205,7 +205,7 @@ export default {
{id: 'success', label: 'Success'},
{id: 'waiting', label: 'Waiting'},
{id: 'fail', label: 'Fail'},
{id: 'unexecute', label: 'unexecute'},
{id: 'unexecute', label: 'Unexecuted'},
{id: 'stop', label: 'Stopped'}
],
condition: {triggerMode: "", executionStatus: ""},