diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/debug/ApiDebugModuleController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/debug/ApiDebugModuleController.java index c864199338..dcdad9b0e2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/debug/ApiDebugModuleController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/debug/ApiDebugModuleController.java @@ -26,11 +26,11 @@ public class ApiDebugModuleController { @Resource private ApiDebugModuleService apiDebugModuleService; - @GetMapping("/tree/{protocol}") + @GetMapping("/tree") @Operation(summary = "接口测试-接口调试-模块-查找模块") @RequiresPermissions(PermissionConstants.PROJECT_API_DEBUG_READ) - public List getTree(@PathVariable String protocol) { - return apiDebugModuleService.getTree(protocol, SessionUtils.getUserId()); + public List getTree() { + return apiDebugModuleService.getTree(SessionUtils.getUserId()); } @PostMapping("/add") diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/debug/ApiDebugRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/debug/ApiDebugRequest.java index bef52476f7..df8a741971 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/debug/ApiDebugRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/debug/ApiDebugRequest.java @@ -1,9 +1,7 @@ package io.metersphere.api.dto.debug; -import io.metersphere.sdk.constants.ModuleConstants; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; import lombok.Data; import java.util.List; @@ -13,11 +11,6 @@ public class ApiDebugRequest { @Schema(description = "模块ID(根据模块树查询时要把当前节点以及子节点都放在这里。)") private List<@NotBlank String> moduleIds; - @Schema(description = "协议", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{api_debug_module.protocol.not_blank}") - @Size(min = 1, max = 20, message = "{api_debug.protocol.length_range}") - private String protocol = ModuleConstants.NODE_PROTOCOL_HTTP; - @Schema(description = "关键字") private String keyword; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDebugModuleMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDebugModuleMapper.java index f0f332f038..930f57c26c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDebugModuleMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDebugModuleMapper.java @@ -11,9 +11,9 @@ import org.apache.ibatis.annotations.Param; import java.util.List; public interface ExtApiDebugModuleMapper { - List selectBaseByProtocolAndUser(String protocol, String userId); + List selectBaseByProtocolAndUser(String userId); - List selectIdAndParentIdByProtocolAndUserId(String protocol, String userId); + List selectIdAndParentIdByProtocolAndUserId(String userId); List selectChildrenIdsByParentIds(@Param("ids") List deleteIds); @@ -29,7 +29,7 @@ public interface ExtApiDebugModuleMapper { BaseModule selectModuleByParentIdAndPosOperator(NodeSortQueryParam nodeSortQueryParam); - List selectApiDebugByProtocolAndUser(String protocol, String userId); + List selectApiDebugByProtocolAndUser(String userId); List countModuleIdByKeywordAndProtocol(@Param("request") ApiDebugRequest request, @Param("userId") String userId); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDebugModuleMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDebugModuleMapper.xml index fcb1d49696..95bbbe7326 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDebugModuleMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDebugModuleMapper.xml @@ -110,9 +110,6 @@ #{item} - - AND f.protocol = #{request.protocol} - diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/body/DocumentAssertionConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/body/DocumentAssertionConverter.java index 153d555847..17ccbff5bb 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/body/DocumentAssertionConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/body/DocumentAssertionConverter.java @@ -56,10 +56,15 @@ public class DocumentAssertionConverter extends ResponseBodyTypeAssertionConvert private void conditions(List dataList, Map conditionMap) { dataList.forEach(item -> { - ElementCondition elementCondition = new ElementCondition(item.getInclude(), item.getTypeVerification(), item.getArrayVerification(), new LinkedList() {{ - this.add(new Condition(item.getCondition(), item.getExpectedResult())); - }}); - elementCondition.setType(item.getType()); + ElementCondition elementCondition = + ElementCondition.builder() + .include(item.getInclude()) + .typeVerification(item.getTypeVerification()) + .arrayVerification(item.getArrayVerification()) + .type(item.getType()) + .conditions(new LinkedList() {{ + this.add(new Condition(item.getCondition(), item.getExpectedResult())); + }}).build(); conditionMap.put(item.getId(), elementCondition); if (CollectionUtils.isNotEmpty(item.getChildren())) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugModuleService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugModuleService.java index 28571234ad..17995215e3 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugModuleService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugModuleService.java @@ -59,10 +59,10 @@ public class ApiDebugModuleService extends ModuleTreeService { @Resource private ApiFileResourceService apiFileResourceService; - public List getTree(String protocol, String userId) { - List fileModuleList = extApiDebugModuleMapper.selectBaseByProtocolAndUser(protocol, userId); + public List getTree(String userId) { + List fileModuleList = extApiDebugModuleMapper.selectBaseByProtocolAndUser(userId); List baseTreeNodes = super.buildTreeAndCountResource(fileModuleList, true, Translator.get(UNPLANNED)); - List apiTreeNodeList = extApiDebugModuleMapper.selectApiDebugByProtocolAndUser(protocol, userId); + List apiTreeNodeList = extApiDebugModuleMapper.selectApiDebugByProtocolAndUser(userId); return getBaseTreeNodes(apiTreeNodeList, baseTreeNodes); } @@ -79,6 +79,7 @@ public class ApiDebugModuleService extends ModuleTreeService { baseTreeNode.setType(apiTreeNode.getType()); if (StringUtils.equals(apiTreeNode.getProtocol(), ModuleConstants.NODE_PROTOCOL_HTTP)) { baseTreeNode.putAttachInfo(METHOD, apiTreeNode.getMethod()); + baseTreeNode.putAttachInfo(PROTOCOL, apiTreeNode.getProtocol()); } else { baseTreeNode.putAttachInfo(PROTOCOL, apiTreeNode.getProtocol()); } @@ -103,9 +104,9 @@ public class ApiDebugModuleService extends ModuleTreeService { return baseTreeNodes; } - public List getTreeOnlyIdsAndResourceCount(String protocol, String userId, List moduleCountDTOList) { + public List getTreeOnlyIdsAndResourceCount(String userId, List moduleCountDTOList) { //节点内容只有Id和parentId - List fileModuleList = extApiDebugModuleMapper.selectIdAndParentIdByProtocolAndUserId(protocol, userId); + List fileModuleList = extApiDebugModuleMapper.selectIdAndParentIdByProtocolAndUserId(userId); return super.buildTreeAndCountResource(fileModuleList, moduleCountDTOList, true, Translator.get(UNPLANNED)); } @@ -160,15 +161,6 @@ public class ApiDebugModuleService extends ModuleTreeService { example.clear(); } - private String getRootNodeId(ApiDebugModule module) { - if (StringUtils.equals(module.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) { - return module.getId(); - } else { - ApiDebugModule parentModule = apiDebugModuleMapper.selectByPrimaryKey(module.getParentId()); - return this.getRootNodeId(parentModule); - } - } - public void update(ModuleUpdateRequest request, String userId, String projectId) { ApiDebugModule module = checkModuleExist(request.getId()); ApiDebugModule updateModule = new ApiDebugModule(); @@ -258,9 +250,9 @@ public class ApiDebugModuleService extends ModuleTreeService { /** * 查找当前项目下模块每个节点对应的资源统计 */ - public Map getModuleCountMap(String protocol, String userId, List moduleCountDTOList) { + public Map getModuleCountMap(String userId, List moduleCountDTOList) { //构建模块树,并计算每个节点下的所有数量(包含子节点) - List treeNodeList = this.getTreeOnlyIdsAndResourceCount(protocol, userId, moduleCountDTOList); + List treeNodeList = this.getTreeOnlyIdsAndResourceCount(userId, moduleCountDTOList); return super.getIdCountMapByBreadth(treeNodeList); } @@ -294,7 +286,7 @@ public class ApiDebugModuleService extends ModuleTreeService { request.setModuleIds(null); List moduleCountDTOList = extApiDebugModuleMapper.countModuleIdByKeywordAndProtocol(request, operator); long allCount = getAllCount(moduleCountDTOList); - Map moduleCountMap = getModuleCountMap(request.getProtocol(), operator, moduleCountDTOList); + Map moduleCountMap = getModuleCountMap(operator, moduleCountDTOList); moduleCountMap.put(DEBUG_MODULE_COUNT_ALL, allCount); return moduleCountMap; } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugModuleControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugModuleControllerTests.java index 8a3576c888..d32e96a4ca 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugModuleControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugModuleControllerTests.java @@ -48,7 +48,7 @@ public class ApiDebugModuleControllerTests extends BaseTest { private static final String URL_MODULE_ADD = "/api/debug/module/add"; private static final String URL_MODULE_UPDATE = "/api/debug/module/update"; private static final String URL_MODULE_DELETE = "/api/debug/module/delete/%s"; - private static final String URL_MODULE_TREE = "/api/debug/module/tree/%s"; + private static final String URL_MODULE_TREE = "/api/debug/module/tree"; private static final String URL_MODULE_MOVE = "/api/debug/module/move"; private static final String URL_FILE_MODULE_COUNT = "/api/debug/module/count"; private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest(); @@ -748,9 +748,7 @@ public class ApiDebugModuleControllerTests extends BaseTest { @Order(8) public void TestModuleCountSuccess() throws Exception { this.preliminaryData(); - ApiDebugRequest request = new ApiDebugRequest() {{ - this.setProtocol(ApiConstants.HTTP_PROTOCOL); - }}; + ApiDebugRequest request = new ApiDebugRequest(); MvcResult moduleCountMvcResult = this.requestPostWithOkAndReturn(URL_FILE_MODULE_COUNT, request); Map moduleCountResult = JSON.parseObject(JSON.toJSONString( JSON.parseObject(moduleCountMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), @@ -760,15 +758,6 @@ public class ApiDebugModuleControllerTests extends BaseTest { } - @Test - @Order(8) - public void TestModuleCountError() throws Exception { - ApiDebugRequest request = new ApiDebugRequest(); - request.setProtocol(null); - this.requestPost(URL_FILE_MODULE_COUNT, request).andExpect(BAD_REQUEST_MATCHER); - - } - @Test @Order(10) public void deleteModuleTestSuccess() throws Exception { @@ -801,10 +790,10 @@ public class ApiDebugModuleControllerTests extends BaseTest { } private List getDebugModuleTreeNode() throws Exception { - MvcResult result = this.requestGetWithOkAndReturn(String.format(URL_MODULE_TREE, ModuleConstants.NODE_PROTOCOL_HTTP)); + MvcResult result = this.requestGetWithOkAndReturn(URL_MODULE_TREE); String returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); - this.requestGetWithOkAndReturn(String.format(URL_MODULE_TREE, "TCP")); + this.requestGetWithOkAndReturn(URL_MODULE_TREE); return JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class); } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionModuleControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionModuleControllerTests.java index 73903c5725..31496daa91 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionModuleControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionModuleControllerTests.java @@ -2,7 +2,6 @@ package io.metersphere.api.controller; import io.metersphere.api.constants.ApiConstants; import io.metersphere.api.domain.*; -import io.metersphere.api.dto.debug.ApiDebugRequest; import io.metersphere.api.dto.debug.ModuleCreateRequest; import io.metersphere.api.dto.debug.ModuleUpdateRequest; import io.metersphere.api.dto.definition.ApiModuleDTO; @@ -825,15 +824,6 @@ public class ApiDefinitionModuleControllerTests extends BaseTest { } - @Test - @Order(9) - public void TestModuleCountError() throws Exception { - ApiDebugRequest request = new ApiDebugRequest(); - request.setProtocol(null); - this.requestPost(URL_FILE_MODULE_COUNT, request).andExpect(BAD_REQUEST_MATCHER); - - } - @Test @Order(10) public void deleteModuleTestSuccess() throws Exception { diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/Condition.java b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/Condition.java index ccbe364fec..cc3ef841d6 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/Condition.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/Condition.java @@ -1,18 +1,13 @@ package io.metersphere.project.api.assertion.body; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@NoArgsConstructor +@AllArgsConstructor public class Condition { private String key; private Object value; - - public Condition() { - - } - - public Condition(String key, Object value) { - this.key = key; - this.value = value; - } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/ElementCondition.java b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/ElementCondition.java index 0ee97e7b89..72bc99a6ac 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/ElementCondition.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/ElementCondition.java @@ -1,10 +1,12 @@ package io.metersphere.project.api.assertion.body; +import lombok.Builder; import lombok.Data; import java.util.List; @Data +@Builder public class ElementCondition { private boolean include; private boolean typeVerification; @@ -12,11 +14,4 @@ public class ElementCondition { private String type; List conditions; - - public ElementCondition(boolean include, boolean typeVerification, boolean arrayVerification, List conditions) { - this.include = include; - this.typeVerification = typeVerification; - this.arrayVerification = arrayVerification; - this.conditions = conditions; - } }