diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/mockserver/KeyValueInfo.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/mockserver/KeyValueInfo.java index cbe4d8e2b0..b9f5592999 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/mockserver/KeyValueInfo.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/mockserver/KeyValueInfo.java @@ -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; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugModuleLogService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugModuleLogService.java index b02bc17805..3311675da1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugModuleLogService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugModuleLogService.java @@ -75,7 +75,7 @@ public class ApiDebugModuleLogService { public void saveDeleteModuleLog(List deleteModule, String operator, String projectId) { Project project = projectMapper.selectByPrimaryKey(projectId); - List dtos = new ArrayList<>(); + List 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 deleteData, String operator, String projectId) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java index 96b7226c40..a53030eb13 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java @@ -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 apiReportLogs = apiReportLogMapper.selectByExampleWithBLOBs(consoleExample); if (CollectionUtils.isNotEmpty(apiReportLogs)) { //获取所有的console,生成集合 - List consoleList = apiReportLogs.stream().map(c -> new String (c.getConsole())).toList(); + List 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) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java index 78d3ce23c9..3b559ea18d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java @@ -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)); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/mockserver/MockServerService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/mockserver/MockServerService.java index ce25438d98..b14f00f39d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/mockserver/MockServerService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/mockserver/MockServerService.java @@ -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 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) {