refactor(接口测试): 优化环境获取接口模块树的参数
This commit is contained in:
parent
174d2f00d2
commit
d6c1b9f55a
|
@ -1,14 +1,11 @@
|
||||||
package io.metersphere.api.dto.definition;
|
package io.metersphere.api.dto.definition;
|
||||||
|
|
||||||
|
import io.metersphere.project.dto.environment.http.SelectModule;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ApiModuleDTO {
|
public class ApiModuleDTO extends SelectModule {
|
||||||
@Schema(description = "模块ID")
|
|
||||||
private String id;
|
|
||||||
@Schema(description = "id的状态 None:手动选 Current:选中当前 All:全选中")
|
|
||||||
private String status;
|
|
||||||
@Schema(description = "是否禁用")
|
@Schema(description = "是否禁用")
|
||||||
private Boolean disabled = false;
|
private Boolean disabled = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package io.metersphere.api.service.definition;
|
package io.metersphere.api.service.definition;
|
||||||
|
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.api.constants.ModuleStatus;
|
|
||||||
import io.metersphere.api.domain.*;
|
import io.metersphere.api.domain.*;
|
||||||
import io.metersphere.api.dto.debug.ApiTreeNode;
|
import io.metersphere.api.dto.debug.ApiTreeNode;
|
||||||
import io.metersphere.api.dto.debug.ModuleCreateRequest;
|
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 io.metersphere.system.uid.IDGenerator;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.ibatis.session.ExecutorType;
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
@ -307,7 +307,7 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||||
List<ApiModuleDTO> currentModules = new ArrayList<>();
|
List<ApiModuleDTO> currentModules = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(selectedModules)) {
|
if (CollectionUtils.isNotEmpty(selectedModules)) {
|
||||||
//将选中的模块id转换为Map 方便后面的查询 key为id
|
//将选中的模块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);
|
getAllModuleIds(baseTreeNodes, currentModules, selectedModuleMap);
|
||||||
}
|
}
|
||||||
envApiTreeDTO.setSelectedModules(currentModules);
|
envApiTreeDTO.setSelectedModules(currentModules);
|
||||||
|
@ -318,7 +318,7 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||||
baseTreeNodes.forEach(baseTreeNode -> {
|
baseTreeNodes.forEach(baseTreeNode -> {
|
||||||
if (selectedModuleMap.containsKey(baseTreeNode.getId())) {
|
if (selectedModuleMap.containsKey(baseTreeNode.getId())) {
|
||||||
ApiModuleDTO apiModuleDTO = selectedModuleMap.get(baseTreeNode.getId());
|
ApiModuleDTO apiModuleDTO = selectedModuleMap.get(baseTreeNode.getId());
|
||||||
if (StringUtils.equals(apiModuleDTO.getStatus(), ModuleStatus.All.name())) {
|
if (BooleanUtils.isTrue(apiModuleDTO.getContainChildModule())) {
|
||||||
currentModules.add(apiModuleDTO);
|
currentModules.add(apiModuleDTO);
|
||||||
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
||||||
setChildren(baseTreeNode.getChildren(), currentModules);
|
setChildren(baseTreeNode.getChildren(), currentModules);
|
||||||
|
@ -336,8 +336,8 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||||
public void setChildren(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules) {
|
public void setChildren(List<BaseTreeNode> baseTreeNodes, List<ApiModuleDTO> currentModules) {
|
||||||
baseTreeNodes.forEach(baseTreeNode -> {
|
baseTreeNodes.forEach(baseTreeNode -> {
|
||||||
ApiModuleDTO children = new ApiModuleDTO();
|
ApiModuleDTO children = new ApiModuleDTO();
|
||||||
children.setId(baseTreeNode.getId());
|
children.setModuleId(baseTreeNode.getId());
|
||||||
children.setStatus(ModuleStatus.All.name());
|
children.setContainChildModule(true);
|
||||||
children.setDisabled(true);
|
children.setDisabled(true);
|
||||||
currentModules.add(children);
|
currentModules.add(children);
|
||||||
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) {
|
||||||
|
|
|
@ -916,26 +916,26 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
|
||||||
BaseTreeNode a1a1Node = getNodeByName(baseTreeNodes, "500-test-root-20");
|
BaseTreeNode a1a1Node = getNodeByName(baseTreeNodes, "500-test-root-20");
|
||||||
assert a1a1Node != null;
|
assert a1a1Node != null;
|
||||||
ApiModuleDTO apiModuleDTO = new ApiModuleDTO();
|
ApiModuleDTO apiModuleDTO = new ApiModuleDTO();
|
||||||
apiModuleDTO.setId(a1a1Node.getId());
|
apiModuleDTO.setModuleId(a1a1Node.getId());
|
||||||
apiModuleDTO.setStatus("None");
|
apiModuleDTO.setContainChildModule(false);
|
||||||
apiModuleDTOS.add(apiModuleDTO);
|
apiModuleDTOS.add(apiModuleDTO);
|
||||||
BaseTreeNode a40Node = getNodeByName(baseTreeNodes, "500-test-root-40");
|
BaseTreeNode a40Node = getNodeByName(baseTreeNodes, "500-test-root-40");
|
||||||
assert a40Node != null;
|
assert a40Node != null;
|
||||||
apiModuleDTO = new ApiModuleDTO();
|
apiModuleDTO = new ApiModuleDTO();
|
||||||
apiModuleDTO.setId(a40Node.getId());
|
apiModuleDTO.setModuleId(a40Node.getId());
|
||||||
apiModuleDTO.setStatus("All");
|
apiModuleDTO.setContainChildModule(true);
|
||||||
apiModuleDTOS.add(apiModuleDTO);
|
apiModuleDTOS.add(apiModuleDTO);
|
||||||
BaseTreeNode a50Node = getNodeByName(baseTreeNodes, "500-test-root-50");
|
BaseTreeNode a50Node = getNodeByName(baseTreeNodes, "500-test-root-50");
|
||||||
assert a50Node != null;
|
assert a50Node != null;
|
||||||
apiModuleDTO = new ApiModuleDTO();
|
apiModuleDTO = new ApiModuleDTO();
|
||||||
apiModuleDTO.setId(a50Node.getId());
|
apiModuleDTO.setModuleId(a50Node.getId());
|
||||||
apiModuleDTO.setStatus("Current");
|
apiModuleDTO.setContainChildModule(false);
|
||||||
apiModuleDTOS.add(apiModuleDTO);
|
apiModuleDTOS.add(apiModuleDTO);
|
||||||
BaseTreeNode a100Node = getNodeByName(baseTreeNodes, "500-test-root-100");
|
BaseTreeNode a100Node = getNodeByName(baseTreeNodes, "500-test-root-100");
|
||||||
assert a100Node != null;
|
assert a100Node != null;
|
||||||
apiModuleDTO = new ApiModuleDTO();
|
apiModuleDTO = new ApiModuleDTO();
|
||||||
apiModuleDTO.setId(a100Node.getId());
|
apiModuleDTO.setModuleId(a100Node.getId());
|
||||||
apiModuleDTO.setStatus("All");
|
apiModuleDTO.setContainChildModule(true);
|
||||||
apiModuleDTOS.add(apiModuleDTO);
|
apiModuleDTOS.add(apiModuleDTO);
|
||||||
result = this.requestPostWithOkAndReturn("/api/definition/module/env/tree", new EnvApiModuleRequest() {{
|
result = this.requestPostWithOkAndReturn("/api/definition/module/env/tree", new EnvApiModuleRequest() {{
|
||||||
this.setProjectId(project.getId());
|
this.setProjectId(project.getId());
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
||||||
* @CreateTime: 2024-02-05 18:53
|
* @CreateTime: 2024-02-05 18:53
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class HttpConfigModuleMatchRule implements Serializable {
|
public class HttpConfigModuleMatchRule implements Serializable {
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ -22,11 +22,4 @@ public class HttpConfigModuleMatchRule implements Serializable {
|
||||||
@Valid
|
@Valid
|
||||||
private List<SelectModule> modules = new ArrayList<>(0);
|
private List<SelectModule> modules = new ArrayList<>(0);
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SelectModule {
|
|
||||||
@Schema(description = "模块ID")
|
|
||||||
private String moduleId;
|
|
||||||
@Schema(description = "是否包含新增子模块")
|
|
||||||
private Boolean containChildModule = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue