refactor(接口测试): 优化环境获取接口模块树的参数

This commit is contained in:
wxg0103 2024-02-05 20:58:19 +08:00 committed by Craftsman
parent 174d2f00d2
commit d6c1b9f55a
5 changed files with 28 additions and 26 deletions

View File

@ -1,14 +1,11 @@
package io.metersphere.api.dto.definition;
import io.metersphere.project.dto.environment.http.SelectModule;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class ApiModuleDTO {
@Schema(description = "模块ID")
private String id;
@Schema(description = "id的状态 None:手动选 Current:选中当前 All:全选中")
private String status;
public class ApiModuleDTO extends SelectModule {
@Schema(description = "是否禁用")
private Boolean disabled = false;
}

View File

@ -1,7 +1,6 @@
package io.metersphere.api.service.definition;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.constants.ModuleStatus;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.debug.ApiTreeNode;
import io.metersphere.api.dto.debug.ModuleCreateRequest;
@ -23,6 +22,7 @@ import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -307,7 +307,7 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
List<ApiModuleDTO> currentModules = new ArrayList<>();
if (CollectionUtils.isNotEmpty(selectedModules)) {
//将选中的模块id转换为Map 方便后面的查询 key为id
Map<String, ApiModuleDTO> selectedModuleMap = selectedModules.stream().collect(Collectors.toMap(ApiModuleDTO::getId, apiModuleDTO -> apiModuleDTO));
Map<String, ApiModuleDTO> selectedModuleMap = selectedModules.stream().collect(Collectors.toMap(ApiModuleDTO::getModuleId, apiModuleDTO -> apiModuleDTO));
getAllModuleIds(baseTreeNodes, currentModules, selectedModuleMap);
}
envApiTreeDTO.setSelectedModules(currentModules);
@ -318,7 +318,7 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
baseTreeNodes.forEach(baseTreeNode -> {
if (selectedModuleMap.containsKey(baseTreeNode.getId())) {
ApiModuleDTO apiModuleDTO = selectedModuleMap.get(baseTreeNode.getId());
if (StringUtils.equals(apiModuleDTO.getStatus(), ModuleStatus.All.name())) {
if (BooleanUtils.isTrue(apiModuleDTO.getContainChildModule())) {
currentModules.add(apiModuleDTO);
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
setChildren(baseTreeNode.getChildren(), currentModules);
@ -336,8 +336,8 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
public void setChildren(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules) {
baseTreeNodes.forEach(baseTreeNode -> {
ApiModuleDTO children = new ApiModuleDTO();
children.setId(baseTreeNode.getId());
children.setStatus(ModuleStatus.All.name());
children.setModuleId(baseTreeNode.getId());
children.setContainChildModule(true);
children.setDisabled(true);
currentModules.add(children);
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {

View File

@ -916,26 +916,26 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
BaseTreeNode a1a1Node = getNodeByName(baseTreeNodes, "500-test-root-20");
assert a1a1Node != null;
ApiModuleDTO apiModuleDTO = new ApiModuleDTO();
apiModuleDTO.setId(a1a1Node.getId());
apiModuleDTO.setStatus("None");
apiModuleDTO.setModuleId(a1a1Node.getId());
apiModuleDTO.setContainChildModule(false);
apiModuleDTOS.add(apiModuleDTO);
BaseTreeNode a40Node = getNodeByName(baseTreeNodes, "500-test-root-40");
assert a40Node != null;
apiModuleDTO = new ApiModuleDTO();
apiModuleDTO.setId(a40Node.getId());
apiModuleDTO.setStatus("All");
apiModuleDTO.setModuleId(a40Node.getId());
apiModuleDTO.setContainChildModule(true);
apiModuleDTOS.add(apiModuleDTO);
BaseTreeNode a50Node = getNodeByName(baseTreeNodes, "500-test-root-50");
assert a50Node != null;
apiModuleDTO = new ApiModuleDTO();
apiModuleDTO.setId(a50Node.getId());
apiModuleDTO.setStatus("Current");
apiModuleDTO.setModuleId(a50Node.getId());
apiModuleDTO.setContainChildModule(false);
apiModuleDTOS.add(apiModuleDTO);
BaseTreeNode a100Node = getNodeByName(baseTreeNodes, "500-test-root-100");
assert a100Node != null;
apiModuleDTO = new ApiModuleDTO();
apiModuleDTO.setId(a100Node.getId());
apiModuleDTO.setStatus("All");
apiModuleDTO.setModuleId(a100Node.getId());
apiModuleDTO.setContainChildModule(true);
apiModuleDTOS.add(apiModuleDTO);
result = this.requestPostWithOkAndReturn("/api/definition/module/env/tree", new EnvApiModuleRequest() {{
this.setProjectId(project.getId());

View File

@ -22,11 +22,4 @@ public class HttpConfigModuleMatchRule implements Serializable {
@Valid
private List<SelectModule> modules = new ArrayList<>(0);
@Data
public class SelectModule {
@Schema(description = "模块ID")
private String moduleId;
@Schema(description = "是否包含新增子模块")
private Boolean containChildModule = false;
}
}

View File

@ -0,0 +1,12 @@
package io.metersphere.project.dto.environment.http;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class SelectModule {
@Schema(description = "模块ID")
private String moduleId;
@Schema(description = "是否包含新增子模块")
private Boolean containChildModule = false;
}