fix(接口测试): 修复mock匹配返回值的缺陷
This commit is contained in:
parent
5dc4ebe262
commit
d7d6d298be
|
@ -26,13 +26,13 @@ public class KeyValueInfo {
|
|||
return switch (ParamConditionEnums.valueOf(this.condition)) {
|
||||
case EQUALS -> StringUtils.equals(this.value, value);
|
||||
case NOT_EQUALS -> !StringUtils.equals(this.value, value);
|
||||
case CONTAINS -> StringUtils.contains(this.value, value);
|
||||
case NOT_CONTAINS -> !StringUtils.contains(this.value, value);
|
||||
case CONTAINS -> StringUtils.contains(value, this.value);
|
||||
case NOT_CONTAINS -> !StringUtils.contains(value, this.value);
|
||||
case LENGTH_EQUALS -> this.value.length() == value.length();
|
||||
case LENGTH_NOT_EQUALS -> this.value.length() != value.length();
|
||||
case LENGTH_SHOT -> this.value.length() < value.length();
|
||||
case LENGTH_LARGE -> this.value.length() > value.length();
|
||||
case REGULAR_MATCH -> this.value.matches(Pattern.quote(value));
|
||||
case LENGTH_SHOT -> value.length() < this.value.length();
|
||||
case LENGTH_LARGE -> value.length() > this.value.length();
|
||||
case REGULAR_MATCH -> value.matches(Pattern.quote(this.value));
|
||||
case IS_EMPTY -> StringUtils.isBlank(value);
|
||||
case IS_NOT_EMPTY -> StringUtils.isNotBlank(value);
|
||||
default -> false;
|
||||
|
|
|
@ -75,7 +75,7 @@ public class ApiDebugModuleLogService {
|
|||
|
||||
public void saveDeleteModuleLog(List<BaseTreeNode> deleteModule, String operator, String projectId) {
|
||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||
List<LogDTO> dtos = new ArrayList<>();
|
||||
List<LogDTO> dos = new ArrayList<>();
|
||||
deleteModule.forEach(item -> {
|
||||
LogDTO dto = LogDTOBuilder.builder()
|
||||
.projectId(project.getId())
|
||||
|
@ -88,10 +88,10 @@ public class ApiDebugModuleLogService {
|
|||
.content(item.getName() + " " + Translator.get("log.delete_module"))
|
||||
.createUser(operator)
|
||||
.build().getLogDTO();
|
||||
dtos.add(dto);
|
||||
dos.add(dto);
|
||||
}
|
||||
);
|
||||
operationLogService.batchAdd(dtos);
|
||||
operationLogService.batchAdd(dos);
|
||||
}
|
||||
|
||||
public void saveDeleteDataLog(List<ApiDebug> deleteData, String operator, String projectId) {
|
||||
|
|
|
@ -53,8 +53,6 @@ public class ApiReportService {
|
|||
@Resource
|
||||
private ApiReportLogService apiReportLogService;
|
||||
@Resource
|
||||
private ApiTestCaseRecordMapper apiTestCaseRecordMapper;
|
||||
@Resource
|
||||
private ApiReportLogMapper apiReportLogMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
@ -192,7 +190,7 @@ public class ApiReportService {
|
|||
List<ApiReportLog> apiReportLogs = apiReportLogMapper.selectByExampleWithBLOBs(consoleExample);
|
||||
if (CollectionUtils.isNotEmpty(apiReportLogs)) {
|
||||
//获取所有的console,生成集合
|
||||
List<String> consoleList = apiReportLogs.stream().map(c -> new String (c.getConsole())).toList();
|
||||
List<String> consoleList = apiReportLogs.stream().map(c -> new String(c.getConsole())).toList();
|
||||
apiReportDTO.setConsole(String.join("\n", consoleList));
|
||||
}
|
||||
//查询资源池名称
|
||||
|
@ -230,7 +228,7 @@ public class ApiReportService {
|
|||
apiReportDetails.forEach(apiReportDetail -> {
|
||||
ApiReportDetailDTO apiReportDetailDTO = new ApiReportDetailDTO();
|
||||
BeanUtils.copyBean(apiReportDetailDTO, apiReportDetail);
|
||||
apiReportDetailDTO.setContent(apiReportDetail.getContent() != null ? ApiDataUtils.parseObject(new String(apiReportDetail.getContent()), RequestResult.class): null);
|
||||
apiReportDetailDTO.setContent(apiReportDetail.getContent() != null ? ApiDataUtils.parseObject(new String(apiReportDetail.getContent()), RequestResult.class) : null);
|
||||
results.add(apiReportDetailDTO);
|
||||
});
|
||||
return results;
|
||||
|
@ -248,6 +246,7 @@ public class ApiReportService {
|
|||
|
||||
/**
|
||||
* 更新执行中的用例报告
|
||||
*
|
||||
* @param reportId
|
||||
*/
|
||||
public void updateReportStatus(String reportId, String status) {
|
||||
|
|
|
@ -214,7 +214,8 @@ public class ApiTestCaseBatchRunService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 集成报告,执行前先设置成 RUNNING
|
||||
* 集成报告,执行前先设置成 RUNNING
|
||||
*
|
||||
* @param runModeConfig
|
||||
*/
|
||||
private void setRunningIntegrateReport(ApiRunModeConfigDTO runModeConfig) {
|
||||
|
@ -326,7 +327,7 @@ public class ApiTestCaseBatchRunService {
|
|||
|
||||
TaskRequestDTO taskRequest = getTaskRequestDTO(reportId, apiTestCase, runModeConfig);
|
||||
taskRequest.setQueueId(queue.getQueueId());
|
||||
taskRequest.setRequestCount(1l);
|
||||
taskRequest.setRequestCount(1L);
|
||||
execute(taskRequest, apiTestCase, apiTestCaseBlob, BeanUtils.copyBean(new ApiDefinitionExecuteInfo(), apiDefinition));
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ public class MockServerService {
|
|||
|
||||
// Get and return the response body
|
||||
try {
|
||||
|
||||
return getResponseBody(compareMockConfig, apiDefinition.getId(), apiDefinition.getProjectId());
|
||||
} catch (Exception e) {
|
||||
return requestNotFound();
|
||||
|
@ -127,20 +128,14 @@ public class MockServerService {
|
|||
List<ApiDefinitionMockConfig> mockConfigs = apiDefinitionMockConfigMapper.selectByExampleWithBLOBs(mockConfigExample);
|
||||
// 寻找匹配的 ApiDefinitionMockConfig
|
||||
ApiDefinitionMockConfig apiDefinitionMockConfig = mockConfigs.stream()
|
||||
.filter(mockConfig -> MockServerUtils.matchMockConfig(mockConfig.getMatching(), requestHeaderMap, param))
|
||||
.filter(mockConfig -> MockServerUtils.matchMockConfig(mockConfig.getMatching(), requestHeaderMap, param) && matchBinaryBody(mockConfig, param.getBinaryParamsObj(), apiId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
// 如果是binary类型的body,需要特殊处理
|
||||
if (param.getBinaryParamsObj() != null) {
|
||||
if (apiDefinitionMockConfig != null && !matchBinaryBody(apiDefinitionMockConfig, param.getBinaryParamsObj(), apiDefinitionMockList.getFirst().getProjectId())) {
|
||||
apiDefinitionMockConfig = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (apiDefinitionMockConfig != null) {
|
||||
ApiMockConfigDTO apiMockConfigDTO = new ApiMockConfigDTO();
|
||||
BeanUtils.copyBean(apiMockConfigDTO, apiDefinitionMockConfig);
|
||||
ApiDefinitionMockConfig finalApiDefinitionMockConfig = apiDefinitionMockConfig;
|
||||
apiDefinitionMockList.stream().filter(mock -> StringUtils.equals(mock.getId(), finalApiDefinitionMockConfig.getId()))
|
||||
apiDefinitionMockList.stream().filter(mock -> StringUtils.equals(mock.getId(), apiDefinitionMockConfig.getId()))
|
||||
.findFirst()
|
||||
.ifPresent(mock -> apiMockConfigDTO.setEnable(mock.getEnable()));
|
||||
return apiMockConfigDTO;
|
||||
|
@ -179,7 +174,7 @@ public class MockServerService {
|
|||
return Arrays.equals(bytes, binaryFile);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private ResponseEntity<?> getResponseBody(ApiDefinitionMockConfig config, String apiId, String projectId) {
|
||||
|
|
Loading…
Reference in New Issue