refactor(接口测试): 场景增加导入系统请求
This commit is contained in:
parent
8e2f4ba7cc
commit
2359bea50a
|
@ -121,11 +121,11 @@ public class ApiScenarioController {
|
||||||
return apiScenarioService.get(scenarioId);
|
return apiScenarioService.get(scenarioId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/step/get/{stepId}")
|
@PostMapping("/step/get")
|
||||||
@Operation(summary = "接口测试-接口场景管理-获取场景步骤详情")
|
@Operation(summary = "接口测试-接口场景管理-获取场景步骤详情")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ)
|
||||||
public Object getStepDetail(@PathVariable String stepId) {
|
public Object getStepDetail(@Validated @RequestBody StepRequest request) {
|
||||||
return apiScenarioService.getStepDetail(stepId);
|
return apiScenarioService.getStepDetail(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -192,4 +192,13 @@ public class ApiScenarioController {
|
||||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "resource_num desc");
|
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "resource_num desc");
|
||||||
return PageUtils.setPageInfo(page, apiScenarioService.getAssociationPage(request));
|
return PageUtils.setPageInfo(page, apiScenarioService.getAssociationPage(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/get/system-request")
|
||||||
|
@Operation(summary = "接口测试-接口场景管理-获取系统请求")
|
||||||
|
@RequiresPermissions(value = {PermissionConstants.PROJECT_API_SCENARIO_READ, PermissionConstants.PROJECT_API_SCENARIO_ADD, PermissionConstants.PROJECT_API_SCENARIO_UPDATE}, logical = Logical.OR)
|
||||||
|
public List<ApiScenarioStepDTO> getSystemRequest(@Validated @RequestBody ApiScenarioSystemRequest request) {
|
||||||
|
return apiScenarioService.getSystemRequest(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package io.metersphere.api.dto.scenario;
|
||||||
|
|
||||||
|
import io.metersphere.api.constants.ApiScenarioStepRefType;
|
||||||
|
import io.metersphere.system.valid.EnumValue;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class ApiScenarioSystemRequest {
|
||||||
|
@Schema(description = "接口的参数")
|
||||||
|
private ScenarioSystemRequest apiRequest;
|
||||||
|
@Schema(description = "用例的参数")
|
||||||
|
private ScenarioSystemRequest caseRequest;
|
||||||
|
@Schema(description = "场景的参数")
|
||||||
|
private ScenarioSystemRequest scenarioRequest;
|
||||||
|
@Schema(description = "关联类型 COPY:复制 REF:引用")
|
||||||
|
@EnumValue(enumClass = ApiScenarioStepRefType.class)
|
||||||
|
@NotBlank
|
||||||
|
private String refType;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package io.metersphere.api.dto.scenario;
|
||||||
|
|
||||||
|
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 lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class ScenarioSystemRequest {
|
||||||
|
@Schema(description = "模块id集合")
|
||||||
|
private List<@NotBlank String> moduleIds = new ArrayList<>();
|
||||||
|
@Schema(description = "选中的id集合")
|
||||||
|
private List<@NotBlank String> selectedIds = new ArrayList<>();
|
||||||
|
@Schema(description = "未选中的id集合")
|
||||||
|
private List<@NotBlank String> unselectedIds = new ArrayList<>();
|
||||||
|
@Schema(description = "项目id")
|
||||||
|
@NotBlank(message = "{api_scenario.project_id.not_blank}")
|
||||||
|
@Size(min = 1, max = 50, message = "{api_scenario.project_id.length_range}")
|
||||||
|
private String projectId;
|
||||||
|
@Schema(description = "协议 接口和用例的时候 是必传的", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotBlank
|
||||||
|
private String protocol = ModuleConstants.NODE_PROTOCOL_HTTP;
|
||||||
|
@Schema(description = "版本id")
|
||||||
|
private String versionId;
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package io.metersphere.api.dto.scenario;
|
||||||
|
|
||||||
|
import io.metersphere.api.constants.ApiScenarioStepType;
|
||||||
|
import io.metersphere.system.valid.EnumValue;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class StepRequest {
|
||||||
|
@Schema(description = "步骤id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@Size(max = 50, message = "{api_scenario_step.id.length_range}")
|
||||||
|
@NotBlank
|
||||||
|
private String stepId;
|
||||||
|
@Schema(description = "资源id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@Size(max = 50, message = "{api_scenario_step.resource_id.length_range}")
|
||||||
|
@NotBlank
|
||||||
|
private String resourceId;
|
||||||
|
@Schema(description = "步骤类型 API:接口 API_CASE:用例 API_SCENARIO:场景", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotBlank
|
||||||
|
@EnumValue(enumClass = ApiScenarioStepType.class)
|
||||||
|
private String stepType;
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.api.domain.ApiDefinition;
|
||||||
import io.metersphere.api.domain.ApiDefinitionCustomField;
|
import io.metersphere.api.domain.ApiDefinitionCustomField;
|
||||||
import io.metersphere.api.dto.converter.ApiDefinitionImportDetail;
|
import io.metersphere.api.dto.converter.ApiDefinitionImportDetail;
|
||||||
import io.metersphere.api.dto.definition.*;
|
import io.metersphere.api.dto.definition.*;
|
||||||
|
import io.metersphere.api.dto.scenario.ScenarioSystemRequest;
|
||||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
@ -54,4 +55,6 @@ public interface ExtApiDefinitionMapper {
|
||||||
ApiDefinition selectApiDefinitionByVersion(@Param("refId") String refId, @Param("versionId") String versionId);
|
ApiDefinition selectApiDefinitionByVersion(@Param("refId") String refId, @Param("versionId") String versionId);
|
||||||
|
|
||||||
List<ApiDefinitionCustomField> getCustomFieldByCaseIds(@Param("ids") List<String> ids);
|
List<ApiDefinitionCustomField> getCustomFieldByCaseIds(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
List<String> getIdsByModules(@Param("request") ScenarioSystemRequest request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,4 +501,27 @@
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getIdsByModules" resultType="java.lang.String">
|
||||||
|
select id from api_definition
|
||||||
|
where deleted = false
|
||||||
|
<if test="request.projectId != null and request.projectId != ''">
|
||||||
|
and api_definition.project_id = #{request.projectId}
|
||||||
|
</if>
|
||||||
|
<if test="request.protocol != null and request.protocol != ''">
|
||||||
|
AND api_definition.protocol = #{request.protocol}
|
||||||
|
</if>
|
||||||
|
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||||
|
and api_definition.module_id in
|
||||||
|
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||||
|
#{nodeId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="request.versionId != null and request.versionId != ''">
|
||||||
|
and api_definition.version_id = #{request.versionId}
|
||||||
|
</if>
|
||||||
|
<if test="request.versionId = null">
|
||||||
|
and api_definition.latest = 1
|
||||||
|
</if>
|
||||||
|
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -35,4 +35,6 @@ public interface ExtApiScenarioMapper {
|
||||||
List<TaskCenterDTO> taskCenterlist(@Param("request") TaskCenterPageRequest request, @Param("projectIds") List<String> projectIds);
|
List<TaskCenterDTO> taskCenterlist(@Param("request") TaskCenterPageRequest request, @Param("projectIds") List<String> projectIds);
|
||||||
|
|
||||||
List<ApiScenarioAssociationDTO> getAssociationPage(@Param("request") ApiScenarioAssociationPageRequest request);
|
List<ApiScenarioAssociationDTO> getAssociationPage(@Param("request") ApiScenarioAssociationPageRequest request);
|
||||||
|
|
||||||
|
List<String> getIdsByModules(@Param("request") ScenarioSystemRequest scenarioRequest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -439,6 +439,26 @@
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
<select id="getIdsByModules" resultType="java.lang.String">
|
||||||
|
select id from api_scenario
|
||||||
|
where deleted = false
|
||||||
|
<if test="request.projectId != null and request.projectId != ''">
|
||||||
|
and api_scenario.project_id = #{request.projectId}
|
||||||
|
</if>
|
||||||
|
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||||
|
and api_scenario.module_id in
|
||||||
|
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||||
|
#{nodeId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="request.versionId != null and request.versionId != ''">
|
||||||
|
and api_scenario.version_id = #{request.versionId}
|
||||||
|
</if>
|
||||||
|
<if test="request.versionId = null">
|
||||||
|
and api_scenario.latest = 1
|
||||||
|
</if>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<sql id="taskCenterFilters">
|
<sql id="taskCenterFilters">
|
||||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.api.mapper;
|
||||||
|
|
||||||
import io.metersphere.api.domain.ApiTestCase;
|
import io.metersphere.api.domain.ApiTestCase;
|
||||||
import io.metersphere.api.dto.definition.*;
|
import io.metersphere.api.dto.definition.*;
|
||||||
|
import io.metersphere.api.dto.scenario.ScenarioSystemRequest;
|
||||||
import io.metersphere.dto.TestCaseProviderDTO;
|
import io.metersphere.dto.TestCaseProviderDTO;
|
||||||
import io.metersphere.project.dto.ModuleCountDTO;
|
import io.metersphere.project.dto.ModuleCountDTO;
|
||||||
import io.metersphere.request.AssociateOtherCaseRequest;
|
import io.metersphere.request.AssociateOtherCaseRequest;
|
||||||
|
@ -59,4 +60,6 @@ public interface ExtApiTestCaseMapper {
|
||||||
List<ApiCaseReportDTO> getExecuteList(@Param("request") ApiCaseExecutePageRequest request);
|
List<ApiCaseReportDTO> getExecuteList(@Param("request") ApiCaseExecutePageRequest request);
|
||||||
|
|
||||||
List<OptionDTO> selectVersionOptionByIds(@Param("ids") List<String> ids);
|
List<OptionDTO> selectVersionOptionByIds(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
List<String> getIdsByModules(@Param("request") ScenarioSystemRequest caseRequest);
|
||||||
}
|
}
|
|
@ -254,6 +254,25 @@
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getIdsByModules" resultType="java.lang.String">
|
||||||
|
select api_test_case.id from api_test_case left join api_definition on api_definition.id = api_test_case.api_definition_id
|
||||||
|
where api_test_case.deleted = false
|
||||||
|
<if test="request.projectId != null and request.projectId != ''">
|
||||||
|
and api_test_case.project_id = #{request.projectId}
|
||||||
|
</if>
|
||||||
|
<if test="request.protocol != null and request.protocol != ''">
|
||||||
|
AND api_definition.protocol = #{request.protocol}
|
||||||
|
</if>
|
||||||
|
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||||
|
and api_definition.module_id in
|
||||||
|
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||||
|
#{nodeId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="request.versionId != null and request.versionId != ''">
|
||||||
|
and api_test_case.version_id = #{request.versionId}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
<sql id="report_filters">
|
<sql id="report_filters">
|
||||||
<if test="${filter} != null and ${filter}.size() > 0">
|
<if test="${filter} != null and ${filter}.size() > 0">
|
||||||
<foreach collection="${filter}.entrySet()" index="key" item="values">
|
<foreach collection="${filter}.entrySet()" index="key" item="values">
|
||||||
|
|
|
@ -56,11 +56,13 @@ import io.metersphere.system.uid.IDGenerator;
|
||||||
import io.metersphere.system.uid.NumGenerator;
|
import io.metersphere.system.uid.NumGenerator;
|
||||||
import io.metersphere.system.utils.ServiceUtils;
|
import io.metersphere.system.utils.ServiceUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.collections4.ListUtils;
|
import org.apache.commons.collections4.ListUtils;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
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;
|
||||||
|
@ -146,6 +148,14 @@ public class ApiScenarioService {
|
||||||
private ApiPluginService apiPluginService;
|
private ApiPluginService apiPluginService;
|
||||||
@Resource
|
@Resource
|
||||||
private ProjectMapper projectMapper;
|
private ProjectMapper projectMapper;
|
||||||
|
@Resource
|
||||||
|
private ExtApiDefinitionMapper extApiDefinitionMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiDefinitionMapper apiDefinitionMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiTestCaseMapper apiTestCaseMapper;
|
||||||
|
@Resource
|
||||||
|
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
||||||
|
|
||||||
public static final String PRIORITY = "Priority";
|
public static final String PRIORITY = "Priority";
|
||||||
public static final String STATUS = "Status";
|
public static final String STATUS = "Status";
|
||||||
|
@ -1380,13 +1390,15 @@ public class ApiScenarioService {
|
||||||
List<ApiScenarioStepDTO> allSteps = getAllStepsByScenarioIds(List.of(scenarioId));
|
List<ApiScenarioStepDTO> allSteps = getAllStepsByScenarioIds(List.of(scenarioId));
|
||||||
//获取所有步骤的csv的关联关系
|
//获取所有步骤的csv的关联关系
|
||||||
List<String> stepIds = allSteps.stream().map(ApiScenarioStepDTO::getId).toList();
|
List<String> stepIds = allSteps.stream().map(ApiScenarioStepDTO::getId).toList();
|
||||||
List<ApiScenarioCsvStep> csvSteps = extApiScenarioStepMapper.getCsvStepByStepIds(stepIds);
|
if (CollectionUtils.isNotEmpty(stepIds)) {
|
||||||
// 构造 map,key 为步骤ID,value 为csv文件ID列表
|
List<ApiScenarioCsvStep> csvSteps = extApiScenarioStepMapper.getCsvStepByStepIds(stepIds);
|
||||||
Map<String, List<String>> stepsCsvMap = csvSteps.stream()
|
// 构造 map,key 为步骤ID,value 为csv文件ID列表
|
||||||
.collect(Collectors.groupingBy(ApiScenarioCsvStep::getStepId, Collectors.mapping(ApiScenarioCsvStep::getFileId, Collectors.toList())));
|
Map<String, List<String>> stepsCsvMap = csvSteps.stream()
|
||||||
//将stepsCsvMap根据步骤id放入到allSteps中
|
.collect(Collectors.groupingBy(ApiScenarioCsvStep::getStepId, Collectors.mapping(ApiScenarioCsvStep::getFileId, Collectors.toList())));
|
||||||
if (CollectionUtils.isNotEmpty(allSteps)) {
|
//将stepsCsvMap根据步骤id放入到allSteps中
|
||||||
allSteps.forEach(step -> step.setCsvFileIds(stepsCsvMap.get(step.getId())));
|
if (CollectionUtils.isNotEmpty(allSteps)) {
|
||||||
|
allSteps.forEach(step -> step.setCsvFileIds(stepsCsvMap.get(step.getId())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造 map,key 为场景ID,value 为步骤列表
|
// 构造 map,key 为场景ID,value 为步骤列表
|
||||||
|
@ -1397,6 +1409,9 @@ public class ApiScenarioService {
|
||||||
Map<String, String> stepDetailMap = getStepDetailMap(allSteps);
|
Map<String, String> stepDetailMap = getStepDetailMap(allSteps);
|
||||||
|
|
||||||
// key 为父步骤ID,value 为子步骤列表
|
// key 为父步骤ID,value 为子步骤列表
|
||||||
|
if (MapUtils.isEmpty(scenarioStepMap)) {
|
||||||
|
return apiScenarioDetail;
|
||||||
|
}
|
||||||
Map<String, List<ApiScenarioStepDTO>> parentStepMap = scenarioStepMap.get(scenarioId)
|
Map<String, List<ApiScenarioStepDTO>> parentStepMap = scenarioStepMap.get(scenarioId)
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.groupingBy(step -> Optional.ofNullable(step.getParentId()).orElse(StringUtils.EMPTY)));
|
.collect(Collectors.groupingBy(step -> Optional.ofNullable(step.getParentId()).orElse(StringUtils.EMPTY)));
|
||||||
|
@ -1525,16 +1540,18 @@ public class ApiScenarioService {
|
||||||
return extApiScenarioStepMapper.getStepDTOByScenarioIds(scenarioIds);
|
return extApiScenarioStepMapper.getStepDTOByScenarioIds(scenarioIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getStepDetail(String stepId) {
|
public Object getStepDetail(StepRequest request) {
|
||||||
ApiScenarioStep step = checkStepExist(stepId);
|
ApiScenarioStep step = apiScenarioStepMapper.selectByPrimaryKey(request.getStepId());
|
||||||
|
if (step == null) {
|
||||||
|
step = new ApiScenarioStep();
|
||||||
|
step.setStepType(request.getStepType());
|
||||||
|
step.setResourceId(request.getResourceId());
|
||||||
|
step.setRefType(ApiScenarioStepRefType.REF.name());
|
||||||
|
}
|
||||||
StepParser stepParser = StepParserFactory.getStepParser(step.getStepType());
|
StepParser stepParser = StepParserFactory.getStepParser(step.getStepType());
|
||||||
return stepParser.parseDetail(step);
|
return stepParser.parseDetail(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiScenarioStep checkStepExist(String id) {
|
|
||||||
return ServiceUtils.checkResourceExist(apiScenarioStepMapper.selectByPrimaryKey(id), "permission.api_step.name");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkTargetModule(String targetModuleId, String projectId) {
|
private void checkTargetModule(String targetModuleId, String projectId) {
|
||||||
if (!StringUtils.equals(targetModuleId, ModuleConstants.DEFAULT_NODE_ID)) {
|
if (!StringUtils.equals(targetModuleId, ModuleConstants.DEFAULT_NODE_ID)) {
|
||||||
ApiScenarioModule module = apiScenarioModuleMapper.selectByPrimaryKey(targetModuleId);
|
ApiScenarioModule module = apiScenarioModuleMapper.selectByPrimaryKey(targetModuleId);
|
||||||
|
@ -1858,4 +1875,80 @@ public class ApiScenarioService {
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ApiScenarioStepDTO> getSystemRequest(ApiScenarioSystemRequest request) {
|
||||||
|
//分批处理 如果是api的处理api的 构造步骤数据
|
||||||
|
List<ApiScenarioStepDTO> steps = new ArrayList<>();
|
||||||
|
ScenarioSystemRequest apiRequest = request.getApiRequest();
|
||||||
|
ScenarioSystemRequest caseRequest = request.getCaseRequest();
|
||||||
|
ScenarioSystemRequest scenarioRequest = request.getScenarioRequest();
|
||||||
|
|
||||||
|
if (ObjectUtils.isNotEmpty(apiRequest)) {
|
||||||
|
if (CollectionUtils.isNotEmpty(apiRequest.getModuleIds())) {
|
||||||
|
apiRequest.getSelectedIds().addAll(extApiDefinitionMapper.getIdsByModules(apiRequest));
|
||||||
|
}
|
||||||
|
apiRequest.getSelectedIds().removeAll(apiRequest.getUnselectedIds());
|
||||||
|
List<@NotBlank String> allApiIds = apiRequest.getSelectedIds().stream().distinct().toList();
|
||||||
|
SubListUtils.dealForSubList(allApiIds, 100, sublist -> {
|
||||||
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
|
example.createCriteria().andIdIn(sublist);
|
||||||
|
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||||
|
apiDefinitions.forEach(item -> {
|
||||||
|
ApiScenarioStepDTO step = new ApiScenarioStepDTO();
|
||||||
|
step.setStepType(ApiScenarioStepType.API.name());
|
||||||
|
step.setName(item.getName());
|
||||||
|
step.setResourceId(item.getId());
|
||||||
|
step.setRefType(request.getRefType());
|
||||||
|
step.setProjectId(item.getProjectId());
|
||||||
|
step.setResourceNum(item.getNum().toString());
|
||||||
|
step.setVersionId(item.getVersionId());
|
||||||
|
steps.add(step);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (ObjectUtils.isNotEmpty(caseRequest)) {
|
||||||
|
if (CollectionUtils.isNotEmpty(caseRequest.getModuleIds())) {
|
||||||
|
caseRequest.getSelectedIds().addAll(extApiTestCaseMapper.getIdsByModules(caseRequest));
|
||||||
|
}
|
||||||
|
caseRequest.getSelectedIds().removeAll(caseRequest.getUnselectedIds());
|
||||||
|
List<@NotBlank String> allCaseIds = caseRequest.getSelectedIds().stream().distinct().toList();
|
||||||
|
SubListUtils.dealForSubList(allCaseIds, 100, sublist -> {
|
||||||
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
|
example.createCriteria().andIdIn(sublist);
|
||||||
|
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
||||||
|
apiTestCases.forEach(item -> {
|
||||||
|
ApiScenarioStepDTO step = new ApiScenarioStepDTO();
|
||||||
|
step.setStepType(ApiScenarioStepType.API_CASE.name());
|
||||||
|
step.setName(item.getName());
|
||||||
|
step.setResourceId(item.getId());
|
||||||
|
step.setRefType(request.getRefType());
|
||||||
|
step.setProjectId(item.getProjectId());
|
||||||
|
step.setResourceNum(item.getNum().toString());
|
||||||
|
step.setVersionId(item.getVersionId());
|
||||||
|
steps.add(step);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (ObjectUtils.isNotEmpty(scenarioRequest)) {
|
||||||
|
if (CollectionUtils.isNotEmpty(scenarioRequest.getModuleIds())) {
|
||||||
|
scenarioRequest.getSelectedIds().addAll(extApiScenarioMapper.getIdsByModules(scenarioRequest));
|
||||||
|
}
|
||||||
|
scenarioRequest.getSelectedIds().removeAll(scenarioRequest.getUnselectedIds());
|
||||||
|
List<@NotBlank String> allScenario = scenarioRequest.getSelectedIds().stream().distinct().toList();
|
||||||
|
allScenario.forEach(item -> {
|
||||||
|
ApiScenarioDetail apiScenarioDetail = get(item);
|
||||||
|
ApiScenarioStepDTO step = new ApiScenarioStepDTO();
|
||||||
|
step.setStepType(ApiScenarioStepType.API_SCENARIO.name());
|
||||||
|
step.setName(apiScenarioDetail.getName());
|
||||||
|
step.setResourceId(apiScenarioDetail.getId());
|
||||||
|
step.setRefType(request.getRefType());
|
||||||
|
step.setProjectId(apiScenarioDetail.getProjectId());
|
||||||
|
step.setResourceNum(apiScenarioDetail.getNum().toString());
|
||||||
|
step.setVersionId(apiScenarioDetail.getVersionId());
|
||||||
|
step.setChildren(apiScenarioDetail.getSteps());
|
||||||
|
steps.add(step);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,10 +5,9 @@ import io.metersphere.api.constants.ApiScenarioStatus;
|
||||||
import io.metersphere.api.constants.ApiScenarioStepRefType;
|
import io.metersphere.api.constants.ApiScenarioStepRefType;
|
||||||
import io.metersphere.api.constants.ApiScenarioStepType;
|
import io.metersphere.api.constants.ApiScenarioStepType;
|
||||||
import io.metersphere.api.domain.*;
|
import io.metersphere.api.domain.*;
|
||||||
|
import io.metersphere.api.dto.assertion.MsAssertionConfig;
|
||||||
import io.metersphere.api.dto.definition.ApiDefinitionAddRequest;
|
import io.metersphere.api.dto.definition.ApiDefinitionAddRequest;
|
||||||
import io.metersphere.api.dto.definition.ApiTestCaseAddRequest;
|
import io.metersphere.api.dto.definition.ApiTestCaseAddRequest;
|
||||||
import io.metersphere.api.dto.assertion.MsAssertionConfig;
|
|
||||||
import io.metersphere.project.api.assertion.MsScriptAssertion;
|
|
||||||
import io.metersphere.api.dto.request.http.MsHTTPElement;
|
import io.metersphere.api.dto.request.http.MsHTTPElement;
|
||||||
import io.metersphere.api.dto.response.ApiScenarioBatchOperationResponse;
|
import io.metersphere.api.dto.response.ApiScenarioBatchOperationResponse;
|
||||||
import io.metersphere.api.dto.response.OperationDataInfo;
|
import io.metersphere.api.dto.response.OperationDataInfo;
|
||||||
|
@ -25,6 +24,7 @@ import io.metersphere.api.utils.JmeterElementConverterRegister;
|
||||||
import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter;
|
import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter;
|
||||||
import io.metersphere.plugin.api.spi.JmeterElementConverter;
|
import io.metersphere.plugin.api.spi.JmeterElementConverter;
|
||||||
import io.metersphere.plugin.api.spi.MsTestElement;
|
import io.metersphere.plugin.api.spi.MsTestElement;
|
||||||
|
import io.metersphere.project.api.assertion.MsScriptAssertion;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentGroupProjectDTO;
|
import io.metersphere.project.dto.environment.EnvironmentGroupProjectDTO;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentGroupRequest;
|
import io.metersphere.project.dto.environment.EnvironmentGroupRequest;
|
||||||
|
@ -90,7 +90,7 @@ public class ApiScenarioControllerTests extends BaseTest {
|
||||||
private static final String FOLLOW = "follow/";
|
private static final String FOLLOW = "follow/";
|
||||||
protected static final String UPLOAD_TEMP_FILE = "upload/temp/file";
|
protected static final String UPLOAD_TEMP_FILE = "upload/temp/file";
|
||||||
protected static final String DELETE_TO_GC = "delete-to-gc/{0}";
|
protected static final String DELETE_TO_GC = "delete-to-gc/{0}";
|
||||||
protected static final String STEP_GET = "step/get/{0}";
|
protected static final String STEP_GET = "step/get";
|
||||||
protected static final String DEBUG = "debug";
|
protected static final String DEBUG = "debug";
|
||||||
private static final String UPDATE_STATUS = "update-status";
|
private static final String UPDATE_STATUS = "update-status";
|
||||||
private static final String UPDATE_PRIORITY = "update-priority";
|
private static final String UPDATE_PRIORITY = "update-priority";
|
||||||
|
@ -145,6 +145,10 @@ public class ApiScenarioControllerTests extends BaseTest {
|
||||||
private PluginService pluginService;
|
private PluginService pluginService;
|
||||||
@Resource
|
@Resource
|
||||||
private PluginLoadService pluginLoadService;
|
private PluginLoadService pluginLoadService;
|
||||||
|
@Resource
|
||||||
|
private ApiDefinitionMapper apiDefinitionMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiTestCaseMapper apiTestCaseMapper;
|
||||||
private static String fileMetadataId;
|
private static String fileMetadataId;
|
||||||
private static String localFileId;
|
private static String localFileId;
|
||||||
private static ApiScenario addApiScenario;
|
private static ApiScenario addApiScenario;
|
||||||
|
@ -725,8 +729,12 @@ public class ApiScenarioControllerTests extends BaseTest {
|
||||||
steps = apiScenarioDetail.getSteps();
|
steps = apiScenarioDetail.getSteps();
|
||||||
requestGetStepDetail(steps);
|
requestGetStepDetail(steps);
|
||||||
|
|
||||||
|
StepRequest stepRequest = new StepRequest();
|
||||||
|
stepRequest.setStepId(addApiScenario.getId());
|
||||||
|
stepRequest.setStepType("API_SCENARIO");
|
||||||
|
stepRequest.setResourceId(addApiScenario.getId());
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, STEP_GET, addApiScenario.getId());
|
requestPostPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, STEP_GET, stepRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestGetStepDetail(List<? extends ApiScenarioStepCommonDTO> steps) throws Exception {
|
private void requestGetStepDetail(List<? extends ApiScenarioStepCommonDTO> steps) throws Exception {
|
||||||
|
@ -734,7 +742,11 @@ public class ApiScenarioControllerTests extends BaseTest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (ApiScenarioStepCommonDTO step : steps) {
|
for (ApiScenarioStepCommonDTO step : steps) {
|
||||||
this.requestGetWithOk(STEP_GET, step.getId());
|
StepRequest stepRequest = new StepRequest();
|
||||||
|
stepRequest.setStepId(step.getId());
|
||||||
|
stepRequest.setStepType(step.getStepType());
|
||||||
|
stepRequest.setResourceId(step.getResourceId());
|
||||||
|
this.requestPost(STEP_GET, stepRequest);
|
||||||
List<? extends ApiScenarioStepCommonDTO> children = step.getChildren();
|
List<? extends ApiScenarioStepCommonDTO> children = step.getChildren();
|
||||||
requestGetStepDetail(children);
|
requestGetStepDetail(children);
|
||||||
}
|
}
|
||||||
|
@ -1995,4 +2007,110 @@ public class ApiScenarioControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(35)
|
||||||
|
public void testGetSystemRequest() throws Exception {
|
||||||
|
//需要造假数据, 接口 用例 场景
|
||||||
|
//接口
|
||||||
|
List<ApiDefinition> apiDefinitions = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
ApiDefinition apiDefinition = new ApiDefinition();
|
||||||
|
if (i == 0) {
|
||||||
|
apiDefinition.setId("system-api-id");
|
||||||
|
} else {
|
||||||
|
apiDefinition.setId(IDGenerator.nextStr());
|
||||||
|
}
|
||||||
|
apiDefinition.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
|
apiDefinition.setName("接口" + i);
|
||||||
|
apiDefinition.setNum(NumGenerator.nextNum(DEFAULT_PROJECT_ID, ApplicationNumScope.API_DEFINITION));
|
||||||
|
apiDefinition.setCreateTime(System.currentTimeMillis());
|
||||||
|
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||||
|
apiDefinition.setCreateUser("admin");
|
||||||
|
apiDefinition.setUpdateUser("admin");
|
||||||
|
apiDefinition.setPath("/test/" + i);
|
||||||
|
apiDefinition.setModuleId("test-default");
|
||||||
|
apiDefinition.setStatus("未规划");
|
||||||
|
apiDefinition.setDeleted(false);
|
||||||
|
apiDefinition.setLatest(true);
|
||||||
|
apiDefinition.setProtocol("HTTP");
|
||||||
|
apiDefinition.setMethod("GET");
|
||||||
|
apiDefinition.setVersionId("1.0");
|
||||||
|
apiDefinition.setRefId(apiDefinition.getId());
|
||||||
|
apiDefinition.setPos(i * 64L);
|
||||||
|
apiDefinitions.add(apiDefinition);
|
||||||
|
}
|
||||||
|
apiDefinitionMapper.batchInsert(apiDefinitions);
|
||||||
|
|
||||||
|
//用例
|
||||||
|
List<ApiTestCase> apiTestCases = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
ApiTestCase apiTestCase = new ApiTestCase();
|
||||||
|
apiTestCase.setId(IDGenerator.nextStr());
|
||||||
|
apiTestCase.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
|
apiTestCase.setName("用例" + i);
|
||||||
|
apiTestCase.setNum(NumGenerator.nextNum(DEFAULT_PROJECT_ID, ApplicationNumScope.API_DEFINITION));
|
||||||
|
apiTestCase.setCreateTime(System.currentTimeMillis());
|
||||||
|
apiTestCase.setUpdateTime(System.currentTimeMillis());
|
||||||
|
apiTestCase.setCreateUser("admin");
|
||||||
|
apiTestCase.setUpdateUser("admin");
|
||||||
|
apiTestCase.setStatus("未规划");
|
||||||
|
apiTestCase.setDeleted(false);
|
||||||
|
apiTestCase.setPriority("P0");
|
||||||
|
apiTestCase.setPos(i * 64L);
|
||||||
|
apiTestCase.setApiDefinitionId("system-api-id");
|
||||||
|
apiTestCase.setVersionId("1.0");
|
||||||
|
apiTestCases.add(apiTestCase);
|
||||||
|
}
|
||||||
|
apiTestCaseMapper.batchInsert(apiTestCases);
|
||||||
|
|
||||||
|
List<ApiScenario> apiScenarios = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
ApiScenario apiScenario = new ApiScenario();
|
||||||
|
apiScenario.setId("system-scenario-id" + i);
|
||||||
|
apiScenario.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
|
apiScenario.setName("场景" + i);
|
||||||
|
apiScenario.setNum(NumGenerator.nextNum(DEFAULT_PROJECT_ID, ApplicationNumScope.API_SCENARIO));
|
||||||
|
apiScenario.setCreateTime(System.currentTimeMillis());
|
||||||
|
apiScenario.setUpdateTime(System.currentTimeMillis());
|
||||||
|
apiScenario.setCreateUser("admin");
|
||||||
|
apiScenario.setUpdateUser("admin");
|
||||||
|
apiScenario.setStatus("未规划");
|
||||||
|
apiScenario.setDeleted(false);
|
||||||
|
apiScenario.setPriority("P0");
|
||||||
|
apiScenario.setStepTotal(0);
|
||||||
|
apiScenario.setPos(i * 64L);
|
||||||
|
apiScenario.setModuleId("test-default");
|
||||||
|
apiScenario.setVersionId("1.0");
|
||||||
|
apiScenario.setRequestPassRate(String.valueOf(0));
|
||||||
|
apiScenario.setRefId(apiScenario.getId());
|
||||||
|
apiScenario.setLatest(true);
|
||||||
|
apiScenario.setLastReportStatus("未执行");
|
||||||
|
apiScenarios.add(apiScenario);
|
||||||
|
}
|
||||||
|
apiScenarioMapper.batchInsert(apiScenarios);
|
||||||
|
|
||||||
|
|
||||||
|
ScenarioSystemRequest scenarioSystemRequest = new ScenarioSystemRequest();
|
||||||
|
scenarioSystemRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
|
scenarioSystemRequest.setProtocol("HTTP");
|
||||||
|
scenarioSystemRequest.setModuleIds(List.of("test-default"));
|
||||||
|
ApiScenarioSystemRequest apiScenarioSystemRequest = new ApiScenarioSystemRequest();
|
||||||
|
apiScenarioSystemRequest.setApiRequest(scenarioSystemRequest);
|
||||||
|
apiScenarioSystemRequest.setCaseRequest(scenarioSystemRequest);
|
||||||
|
apiScenarioSystemRequest.setScenarioRequest(scenarioSystemRequest);
|
||||||
|
apiScenarioSystemRequest.setRefType(ApiScenarioStepRefType.COPY.name());
|
||||||
|
this.requestPostWithOkAndReturn("/get/system-request", apiScenarioSystemRequest);
|
||||||
|
|
||||||
|
StepRequest stepRequest = new StepRequest();
|
||||||
|
stepRequest.setStepId("system-scenario-id1");
|
||||||
|
stepRequest.setStepType(ApiScenarioStepType.API_SCENARIO.name());
|
||||||
|
stepRequest.setResourceId("system-scenario-id1");
|
||||||
|
|
||||||
|
mockMvc.perform(getPostRequestBuilder(STEP_GET, stepRequest))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
public class TableBatchProcessDTO {
|
public class TableBatchProcessDTO {
|
||||||
@Schema(description = "不处理的ID")
|
@Schema(description = "不处理的ID")
|
||||||
List<String> excludeIds;
|
List<String> excludeIds = new ArrayList<>();
|
||||||
|
|
||||||
@Schema(description = "选择的ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "选择的ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@Valid
|
@Valid
|
||||||
|
|
Loading…
Reference in New Issue