feat(接口测试): 场景增加查询引用列表
This commit is contained in:
parent
f1e566062a
commit
82df20db05
|
@ -182,4 +182,14 @@ public class ApiScenarioController {
|
||||||
apiValidateService.validateApiMenuInProject(request.getScenarioId(), ApiResource.API_SCENARIO.name());
|
apiValidateService.validateApiMenuInProject(request.getScenarioId(), ApiResource.API_SCENARIO.name());
|
||||||
return apiScenarioService.scheduleConfig(request, SessionUtils.getUserId());
|
return apiScenarioService.scheduleConfig(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/association/page")
|
||||||
|
@Operation(summary = "接口测试-接口场景管理-场景引用关系列表")
|
||||||
|
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ)
|
||||||
|
@CheckOwner(resourceId = "#request.id", resourceType = "api_scenario")
|
||||||
|
public Pager<List<ApiScenarioAssociationDTO>> getAssociationPage(@Validated @RequestBody ApiScenarioAssociationPageRequest request) {
|
||||||
|
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
|
||||||
|
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "resource_num desc");
|
||||||
|
return PageUtils.setPageInfo(page, apiScenarioService.getAssociationPage(request));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package io.metersphere.api.dto.scenario;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class ApiScenarioAssociationDTO {
|
||||||
|
@Schema(description = "编号")
|
||||||
|
private String resourceNum;
|
||||||
|
@Schema(description = "资源id")
|
||||||
|
private String resourceId;
|
||||||
|
@Schema(description = "资源名称")
|
||||||
|
private String name;
|
||||||
|
@Schema(description = "资源类型 ")
|
||||||
|
private String stepType;
|
||||||
|
@Schema(description = "引用类型 COPY:复制,REF:引用")
|
||||||
|
private String refType;
|
||||||
|
@Schema(description = "项目名称")
|
||||||
|
private String projectName;
|
||||||
|
@Schema(description = "项目id")
|
||||||
|
private String projectId;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package io.metersphere.api.dto.scenario;
|
||||||
|
|
||||||
|
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class ApiScenarioAssociationPageRequest extends BasePageRequest {
|
||||||
|
|
||||||
|
@Schema(description = "场景pk")
|
||||||
|
@Size(min = 1, max = 50, message = "{api_scenario_step.scenario_id.length_range}")
|
||||||
|
private String id;
|
||||||
|
}
|
|
@ -1,16 +1,14 @@
|
||||||
package io.metersphere.api.mapper;
|
package io.metersphere.api.mapper;
|
||||||
|
|
||||||
import io.metersphere.api.domain.ApiScenario;
|
import io.metersphere.api.domain.ApiScenario;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioBatchRequest;
|
import io.metersphere.api.dto.scenario.*;
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioDTO;
|
|
||||||
import io.metersphere.api.dto.scenario.ApiScenarioPageRequest;
|
|
||||||
import io.metersphere.system.dto.taskcenter.TaskCenterDTO;
|
|
||||||
import io.metersphere.system.dto.taskcenter.request.TaskCenterPageRequest;
|
|
||||||
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;
|
||||||
import io.metersphere.request.TestCasePageProviderRequest;
|
import io.metersphere.request.TestCasePageProviderRequest;
|
||||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||||
|
import io.metersphere.system.dto.taskcenter.TaskCenterDTO;
|
||||||
|
import io.metersphere.system.dto.taskcenter.request.TaskCenterPageRequest;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -35,4 +33,6 @@ public interface ExtApiScenarioMapper {
|
||||||
Long getLastPos(@Param("projectId") String projectId);
|
Long getLastPos(@Param("projectId") String projectId);
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,6 +417,29 @@
|
||||||
<property name="filter" value="request.filter"/>
|
<property name="filter" value="request.filter"/>
|
||||||
</include>
|
</include>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getAssociationPage" resultType="io.metersphere.api.dto.scenario.ApiScenarioAssociationDTO">
|
||||||
|
SELECT
|
||||||
|
distinct a.ref_type, a.scenario_id,
|
||||||
|
s.name AS name,
|
||||||
|
a.resource_id AS resourceId,
|
||||||
|
a.resource_num AS resourceNum,
|
||||||
|
a.step_type AS stepType,
|
||||||
|
a.project_id AS projectId
|
||||||
|
FROM
|
||||||
|
api_scenario_step a
|
||||||
|
INNER JOIN
|
||||||
|
api_scenario s ON a.scenario_id = s.id
|
||||||
|
WHERE
|
||||||
|
a.parent_id = 'NONE'
|
||||||
|
AND a.resource_id = #{request.id}
|
||||||
|
<if test="request.keyword != null and request.keyword != ''">
|
||||||
|
and (
|
||||||
|
a.name like concat('%', #{request.keyword},'%')
|
||||||
|
or a.num like concat('%', #{request.keyword},'%')
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
<sql id="taskCenterFilters">
|
<sql id="taskCenterFilters">
|
||||||
<if test="${filter} != null and ${filter}.size() > 0">
|
<if test="${filter} != null and ${filter}.size() > 0">
|
||||||
|
|
|
@ -23,8 +23,11 @@ import io.metersphere.api.service.definition.ApiTestCaseService;
|
||||||
import io.metersphere.api.utils.ApiScenarioBatchOperationUtils;
|
import io.metersphere.api.utils.ApiScenarioBatchOperationUtils;
|
||||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||||
import io.metersphere.project.domain.FileMetadata;
|
import io.metersphere.project.domain.FileMetadata;
|
||||||
|
import io.metersphere.project.domain.Project;
|
||||||
|
import io.metersphere.project.domain.ProjectExample;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentInfoDTO;
|
import io.metersphere.project.dto.environment.EnvironmentInfoDTO;
|
||||||
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
|
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
|
||||||
|
import io.metersphere.project.mapper.ProjectMapper;
|
||||||
import io.metersphere.project.service.*;
|
import io.metersphere.project.service.*;
|
||||||
import io.metersphere.sdk.constants.*;
|
import io.metersphere.sdk.constants.*;
|
||||||
import io.metersphere.sdk.domain.Environment;
|
import io.metersphere.sdk.domain.Environment;
|
||||||
|
@ -141,6 +144,8 @@ public class ApiScenarioService {
|
||||||
private EnvironmentGroupService environmentGroupService;
|
private EnvironmentGroupService environmentGroupService;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiPluginService apiPluginService;
|
private ApiPluginService apiPluginService;
|
||||||
|
@Resource
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
public static final String PRIORITY = "Priority";
|
public static final String PRIORITY = "Priority";
|
||||||
public static final String STATUS = "Status";
|
public static final String STATUS = "Status";
|
||||||
|
@ -1186,6 +1191,7 @@ public class ApiScenarioService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 scenarioParseEnvInfo 获取对应环境组的 projectEnvMap
|
* 从 scenarioParseEnvInfo 获取对应环境组的 projectEnvMap
|
||||||
|
*
|
||||||
* @param scenarioParseEnvInfo
|
* @param scenarioParseEnvInfo
|
||||||
* @param environmentId
|
* @param environmentId
|
||||||
* @return
|
* @return
|
||||||
|
@ -1834,4 +1840,21 @@ public class ApiScenarioService {
|
||||||
ApiScenarioScheduleJob.class,
|
ApiScenarioScheduleJob.class,
|
||||||
operator);
|
operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ApiScenarioAssociationDTO> getAssociationPage(ApiScenarioAssociationPageRequest request) {
|
||||||
|
List<ApiScenarioAssociationDTO> list = extApiScenarioMapper.getAssociationPage(request);
|
||||||
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
|
//获取所有的项目ID
|
||||||
|
List<String> projectIds = list.stream().map(ApiScenarioAssociationDTO::getProjectId).distinct().toList();
|
||||||
|
ProjectExample example = new ProjectExample();
|
||||||
|
example.createCriteria().andIdIn(projectIds);
|
||||||
|
List<Project> projects = projectMapper.selectByExample(example);
|
||||||
|
Map<String, Project> projectMap = projects.stream().collect(Collectors.toMap(Project::getId, Function.identity()));
|
||||||
|
list.forEach(apiScenarioAssociationDTO -> {
|
||||||
|
apiScenarioAssociationDTO.setProjectName(projectMap.get(apiScenarioAssociationDTO.getProjectId()).getName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -878,6 +878,57 @@ public class ApiScenarioControllerTests extends BaseTest {
|
||||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, DEFAULT_PAGE, pageRequest);
|
requestPostPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, DEFAULT_PAGE, pageRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(11)
|
||||||
|
public void testGetAssociatedCase() throws Exception {
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
ApiScenario apiScenario = new ApiScenario();
|
||||||
|
apiScenario.setId("test-api-scenario-id" + i);
|
||||||
|
apiScenario.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
|
apiScenario.setNum(NumGenerator.nextNum(DEFAULT_PROJECT_ID, ApplicationNumScope.API_SCENARIO));
|
||||||
|
apiScenario.setName(StringUtils.join("建国批量测试接口场景-", apiScenario.getId()));
|
||||||
|
apiScenario.setModuleId("test-associated");
|
||||||
|
apiScenario.setStatus("未规划");
|
||||||
|
apiScenario.setPos(1L);
|
||||||
|
apiScenario.setPriority("P0");
|
||||||
|
apiScenario.setLatest(true);
|
||||||
|
apiScenario.setVersionId("1.0");
|
||||||
|
apiScenario.setRefId(apiScenario.getId());
|
||||||
|
apiScenario.setCreateTime(System.currentTimeMillis());
|
||||||
|
apiScenario.setUpdateTime(System.currentTimeMillis());
|
||||||
|
apiScenario.setCreateUser("admin");
|
||||||
|
apiScenario.setUpdateUser("admin");
|
||||||
|
apiScenarioMapper.insertSelective(apiScenario);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
ApiScenarioStep step1 = new ApiScenarioStep();
|
||||||
|
step1.setId(IDGenerator.nextStr());
|
||||||
|
step1.setScenarioId("test-api-scenario-id1");
|
||||||
|
step1.setName("test" + "_" + IDGenerator.nextStr());
|
||||||
|
step1.setSort(0L);
|
||||||
|
step1.setEnable(true);
|
||||||
|
step1.setResourceId("test-api-scenario-id0");
|
||||||
|
step1.setResourceNum("test-resource-num");
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
step1.setRefType("COPY");
|
||||||
|
} else {
|
||||||
|
step1.setRefType("REF");
|
||||||
|
}
|
||||||
|
step1.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
|
apiScenarioStepMapper.insertSelective(step1);
|
||||||
|
}
|
||||||
|
ApiScenarioAssociationPageRequest request = new ApiScenarioAssociationPageRequest();
|
||||||
|
request.setPageSize(10);
|
||||||
|
request.setCurrent(1);
|
||||||
|
this.requestPost("/association/page", request, status().is4xxClientError());
|
||||||
|
request.setId("test-api-scenario-id1");
|
||||||
|
this.requestPostAndReturn("/association/page", request);
|
||||||
|
request.setId("test-api-scenario-id0");
|
||||||
|
this.requestPostAndReturn("association/page", request);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(12)
|
@Order(12)
|
||||||
public void follow() throws Exception {
|
public void follow() throws Exception {
|
||||||
|
@ -1943,4 +1994,5 @@ public class ApiScenarioControllerTests extends BaseTest {
|
||||||
BATCH_OPERATION_SCENARIO_ID.add(apiScenario.getId());
|
BATCH_OPERATION_SCENARIO_ID.add(apiScenario.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -966,8 +966,9 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
@Order(23)
|
@Order(23)
|
||||||
public void testGetOptions() throws Exception {
|
public void testGetOptions() throws Exception {
|
||||||
ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
|
ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
|
||||||
projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest"));
|
|
||||||
projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||||
|
this.requestPost(getPoolOptions, projectPoolRequest, BAD_REQUEST_MATCHER);
|
||||||
|
projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest"));
|
||||||
this.responsePost(getPoolOptions, projectPoolRequest);
|
this.responsePost(getPoolOptions, projectPoolRequest);
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
requestPostPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getPoolOptions, projectPoolRequest);
|
requestPostPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getPoolOptions, projectPoolRequest);
|
||||||
|
|
|
@ -1097,8 +1097,8 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
@Order(22)
|
@Order(22)
|
||||||
public void testGetOptions() throws Exception {
|
public void testGetOptions() throws Exception {
|
||||||
ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
|
ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
|
||||||
|
this.requestPost(getPoolOptions, projectPoolRequest, BAD_REQUEST_MATCHER);
|
||||||
projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest"));
|
projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest"));
|
||||||
this.responsePost(getPoolOptions, projectPoolRequest);
|
|
||||||
projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||||
this.responsePost(getPoolOptions, projectPoolRequest);
|
this.responsePost(getPoolOptions, projectPoolRequest);
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
|
|
Loading…
Reference in New Issue