feat(测试计划): 已关联场景列表接口
This commit is contained in:
parent
bcb92cb79e
commit
85a5863d4d
|
@ -1,15 +1,26 @@
|
|||
package io.metersphere.plan.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiScenarioRequest;
|
||||
import io.metersphere.plan.dto.response.TestPlanApiScenarioPageResponse;
|
||||
import io.metersphere.plan.service.TestPlanApiScenarioService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
|
||||
import io.metersphere.system.security.CheckOwner;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "测试计划场景用例")
|
||||
@RestController
|
||||
@RequestMapping("/test-plan/api/scenario")
|
||||
|
@ -25,4 +36,15 @@ public class TestPlanApiScenarioController {
|
|||
public TaskRequestDTO run(@PathVariable String id, @RequestParam(required = false) String reportId) {
|
||||
return testPlanApiScenarioService.run(id, reportId, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/page")
|
||||
@Operation(summary = "测试计划-已关联场景用例列表分页查询")
|
||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ)
|
||||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||
public Pager<List<TestPlanApiScenarioPageResponse>> page(@Validated @RequestBody TestPlanApiScenarioRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString("id")) ? request.getSortString("id") : "create_time desc");
|
||||
return PageUtils.setPageInfo(page, testPlanApiScenarioService.hasRelateApiScenarioList(request, false));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,4 +15,7 @@ public class TestPlanApiScenarioRequest extends ApiScenarioPageRequest {
|
|||
@NotBlank(message = "{test_plan.id.not_blank}")
|
||||
private String testPlanId;
|
||||
|
||||
@Schema(description = "计划集id")
|
||||
private String collectionId;
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package io.metersphere.plan.dto.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author wx
|
||||
*/
|
||||
@Data
|
||||
public class TestPlanApiScenarioPageResponse implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "ID")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "业务ID")
|
||||
private Long num;
|
||||
|
||||
@Schema(description = "场景名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "场景等级")
|
||||
private String priority;
|
||||
|
||||
@Schema(description = "项目id")
|
||||
private String projectId;
|
||||
|
||||
@Schema(description = "项目名称")
|
||||
private String projectName;
|
||||
|
||||
@Schema(description = "模块ID")
|
||||
private String moduleId;
|
||||
|
||||
@Schema(description = "环境fk")
|
||||
private String environmentId;
|
||||
|
||||
@Schema(description = "环境名称")
|
||||
private String environmentName;
|
||||
|
||||
@Schema(description = "执行结果")
|
||||
private String lastExecResult;
|
||||
|
||||
@Schema(description = "执行人")
|
||||
private String executeUser;
|
||||
|
||||
@Schema(description = "执行人名称")
|
||||
private String executeUserName;
|
||||
|
||||
@Schema(description = "最后执行时间")
|
||||
private Long lastExecTime;
|
||||
|
||||
@Schema(description = "创建人id")
|
||||
private String createUser;
|
||||
|
||||
@Schema(description = "创建人名称")
|
||||
private String createUserName;
|
||||
|
||||
@Schema(description = "测试集id")
|
||||
private String testPlanCollectionId;
|
||||
|
||||
@Schema(description = "报告id")
|
||||
private String lastExecReportId;
|
||||
}
|
|
@ -3,6 +3,8 @@ package io.metersphere.plan.mapper;
|
|||
import io.metersphere.plan.domain.TestPlanApiScenario;
|
||||
import io.metersphere.plan.dto.ResourceSelectParam;
|
||||
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiScenarioRequest;
|
||||
import io.metersphere.plan.dto.response.TestPlanApiScenarioPageResponse;
|
||||
import io.metersphere.project.dto.DropNode;
|
||||
import io.metersphere.project.dto.NodeSortQueryParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
@ -26,4 +28,6 @@ public interface ExtTestPlanApiScenarioMapper {
|
|||
List<TestPlanCaseRunResultCount> selectCaseExecResultCount(String testPlanId);
|
||||
|
||||
List<TestPlanApiScenario> selectByTestPlanIdAndNotDeleted(String testPlanId);
|
||||
|
||||
List<TestPlanApiScenarioPageResponse> relateApiScenarioList(@Param("request") TestPlanApiScenarioRequest request, @Param("deleted") boolean deleted);
|
||||
}
|
||||
|
|
|
@ -82,4 +82,232 @@
|
|||
WHERE t.test_plan_id = #{0}
|
||||
AND a.deleted = false
|
||||
</select>
|
||||
|
||||
<select id="relateApiScenarioList" resultType="io.metersphere.plan.dto.response.TestPlanApiScenarioPageResponse">
|
||||
SELECT
|
||||
test_plan_api_scenario.id,
|
||||
test_plan_api_scenario.test_plan_collection_id,
|
||||
api_scenario.num,
|
||||
api_scenario.name,
|
||||
api_scenario.priority,
|
||||
api_scenario.project_id,
|
||||
api_scenario.create_user,
|
||||
test_plan_api_scenario.create_time,
|
||||
test_plan_api_scenario.environment_id,
|
||||
api_scenario.module_id,
|
||||
test_plan_api_scenario.last_exec_result,
|
||||
test_plan_api_scenario.execute_user,
|
||||
test_plan_api_scenario.last_exec_time,
|
||||
test_plan_api_scenario.last_exec_report_id
|
||||
FROM
|
||||
test_plan_api_scenario
|
||||
inner join api_scenario on api_scenario.id = test_plan_api_scenario.api_scenario_id
|
||||
WHERE api_scenario.deleted =#{deleted}
|
||||
and test_plan_api_scenario.test_plan_id = #{request.testPlanId}
|
||||
<include refid="queryApiScenarioWhereCondition"/>
|
||||
</select>
|
||||
|
||||
<sql id="queryApiScenarioWhereCondition">
|
||||
<if test="request.keyword != null and request.keyword != ''">
|
||||
and (
|
||||
api_scenario.num like concat('%', #{request.keyword},'%')
|
||||
or api_scenario.name like concat('%', #{request.keyword},'%')
|
||||
or api_scenario.tags like concat('%', #{request.keyword},'%')
|
||||
)
|
||||
</if>
|
||||
<if test="request.scenarioId != null and request.scenarioId != ''">
|
||||
and api_scenario.id = #{request.scenarioId}
|
||||
</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.collectionId != null and request.collectionId != ''">
|
||||
and t.test_plan_collection_id = #{request.collectionId}
|
||||
</if>
|
||||
<include refid="filters">
|
||||
<property name="filter" value="request.filter"/>
|
||||
</include>
|
||||
|
||||
<if test="request.combine != null and request.combine != ''">
|
||||
<include refid="combine">
|
||||
<property name="condition" value="request.combine"/>
|
||||
<property name="name" value="request.name"/>
|
||||
<property name="ObjectTags" value="request.combine.tags"/>
|
||||
</include>
|
||||
</if>
|
||||
|
||||
<include refid="queryVersionCondition">
|
||||
<property name="versionTable" value="api_scenario"/>
|
||||
</include>
|
||||
</sql>
|
||||
|
||||
<sql id="filters">
|
||||
<if test="${filter} != null and ${filter}.size() > 0">
|
||||
<foreach collection="${filter}.entrySet()" index="key" item="values">
|
||||
<if test="values != null and values.size() > 0">
|
||||
<choose>
|
||||
<when test="key=='lastReportStatus' and values.size() != 7 ">
|
||||
<!-- 取值范围在7个状态(成功、失败、误报、停止、执行中、重跑中、排队中)内选。如果全部全选,则不用拼接这条语句-->
|
||||
<if test="values.contains('PENDING')">
|
||||
and (
|
||||
(api_scenario.last_report_status is null or api_scenario.last_report_status = '')
|
||||
or api_scenario.last_report_status in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
)
|
||||
</if>
|
||||
<if test="!values.contains('PENDING')">
|
||||
and api_scenario.last_report_status in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</if>
|
||||
</when>
|
||||
<when test="key=='status'">
|
||||
and api_scenario.status in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
<when test="key=='createUser'">
|
||||
and api_scenario.create_user in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
<when test="key=='updateUser'">
|
||||
and api_scenario.update_user in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
<when test="key=='deleteUser'">
|
||||
and api_scenario.delete_user in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
<when test="key=='versionId'">
|
||||
and api_scenario.version_id in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
<when test="key=='priority'">
|
||||
and api_scenario.priority in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
</when>
|
||||
<when test="key.startsWith('custom_single')">
|
||||
and api_scenario.id in (
|
||||
select api_id from api_definition_custom_field where concat('custom_single_', field_id) =
|
||||
#{key}
|
||||
and trim(both '"' from `value`) in
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
|
||||
)
|
||||
</when>
|
||||
<when test="key.startsWith('custom_multiple')">
|
||||
and api_scenario.id in (
|
||||
select api_id from api_definition_custom_field where concat('custom_multiple_', field_id) =
|
||||
#{key}
|
||||
and
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.filterMultipleWrapper"/>
|
||||
)
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="combine">
|
||||
<if test='${condition}.name != null and (${name} == null or ${name} == "")'>
|
||||
and api_scenario.name
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="${condition}.name"/>
|
||||
</include>
|
||||
</if>
|
||||
|
||||
<if test='${condition}.id != null'>
|
||||
and api_scenario.num
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="${condition}.id"/>
|
||||
</include>
|
||||
</if>
|
||||
|
||||
<if test="${condition}.updateTime != null">
|
||||
and api_scenario.update_time
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="${condition}.updateTime"/>
|
||||
</include>
|
||||
</if>
|
||||
|
||||
<if test="${condition}.createTime != null">
|
||||
and api_scenario.create_time
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="${condition}.createTime"/>
|
||||
</include>
|
||||
</if>
|
||||
|
||||
<if test="${condition}.status != null">
|
||||
and api_scenario.status
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="${condition}.status"/>
|
||||
</include>
|
||||
</if>
|
||||
|
||||
<if test='${condition}.tags != null and ${ObjectTags}.operator == "not like"'>
|
||||
and (api_scenario.tags is null or api_scenario.tags
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="${condition}.tags"/>
|
||||
</include>
|
||||
)
|
||||
</if>
|
||||
|
||||
<if test='${condition}.tags != null and ${ObjectTags}.operator == "like"'>
|
||||
and api_scenario.tags
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="${condition}.tags"/>
|
||||
</include>
|
||||
</if>
|
||||
|
||||
<if test="${condition}.customs != null and ${condition}.customs.size() > 0">
|
||||
<foreach collection="${condition}.customs" item="custom" separator="" open="" close="">
|
||||
<if test="custom.value != ''">
|
||||
<if test='custom.operator == "not like" or custom.operator == "not in"'>
|
||||
and api_scenario.id not in (
|
||||
</if>
|
||||
<if test='custom.operator != "not like" and custom.operator != "not in"'>
|
||||
and api_scenario.id in (
|
||||
</if>
|
||||
select api_id from api_definition_custom_field where field_id = #{custom.id}
|
||||
<choose>
|
||||
<when test="custom.type == 'TEXTAREA' or custom.operator == 'current user'">
|
||||
and `value`
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="custom"/>
|
||||
</include>
|
||||
</when>
|
||||
<when test="custom.type == 'MULTIPLE_MEMBER' or custom.type == 'CHECKBOX' or custom.type == 'MULTIPLE_SELECT'">
|
||||
and ${custom.value}
|
||||
</when>
|
||||
<when test="custom.type == 'DATE' or custom.type == 'DATETIME'">
|
||||
and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13)
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="custom"/>
|
||||
</include>
|
||||
</when>
|
||||
<otherwise>
|
||||
and trim(both '"' from `value`)
|
||||
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
|
||||
<property name="object" value="custom"/>
|
||||
</include>
|
||||
</otherwise>
|
||||
</choose>
|
||||
)
|
||||
</if>
|
||||
</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="queryVersionCondition">
|
||||
<if test="request.versionId != null and request.versionId != ''">
|
||||
and ${versionTable}.version_id = #{request.versionId}
|
||||
</if>
|
||||
<if test="request.refId != null and request.refId != ''">
|
||||
and ${versionTable}.ref_id = #{request.refId}
|
||||
</if>
|
||||
<if test="request.versionId == null and request.refId == null and request.scenarioId == null">
|
||||
AND ${versionTable}.latest = 1
|
||||
</if>
|
||||
</sql>
|
||||
</mapper>
|
|
@ -15,21 +15,31 @@ import io.metersphere.plan.domain.TestPlanApiScenarioExample;
|
|||
import io.metersphere.plan.dto.ResourceLogInsertModule;
|
||||
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
||||
import io.metersphere.plan.dto.TestPlanCollectionDTO;
|
||||
import io.metersphere.plan.dto.TestPlanCollectionEnvDTO;
|
||||
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
|
||||
import io.metersphere.plan.dto.request.ResourceSortRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiScenarioRequest;
|
||||
import io.metersphere.plan.dto.response.TestPlanApiScenarioPageResponse;
|
||||
import io.metersphere.plan.dto.response.TestPlanOperationResponse;
|
||||
import io.metersphere.plan.mapper.*;
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.domain.ProjectExample;
|
||||
import io.metersphere.project.dto.MoveNodeSortDTO;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.*;
|
||||
import io.metersphere.sdk.domain.Environment;
|
||||
import io.metersphere.sdk.domain.EnvironmentExample;
|
||||
import io.metersphere.sdk.dto.api.task.*;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.LogInsertModule;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.system.utils.ServiceUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
@ -62,6 +72,14 @@ public class TestPlanApiScenarioService extends TestPlanResourceService implemen
|
|||
private ApiScenarioRunService apiScenarioRunService;
|
||||
@Resource
|
||||
private ApiExecuteService apiExecuteService;
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
@Resource
|
||||
private UserLoginService userLoginService;
|
||||
@Resource
|
||||
private ExtTestPlanCollectionMapper extTestPlanCollectionMapper;
|
||||
@Resource
|
||||
private EnvironmentMapper environmentMapper;
|
||||
|
||||
public TestPlanApiScenarioService() {
|
||||
GetRunScriptServiceRegister.register(ApiExecuteResourceType.TEST_PLAN_API_SCENARIO, this);
|
||||
|
@ -161,6 +179,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService implemen
|
|||
List<ApiScenarioDTO> scenarioPage = apiScenarioService.getScenarioPage(request, isRepeat, request.getTestPlanId());
|
||||
return scenarioPage;
|
||||
}
|
||||
|
||||
public TestPlanOperationResponse sortNode(ResourceSortRequest request, LogInsertModule logInsertModule) {
|
||||
TestPlanApiScenario dragNode = testPlanApiScenarioMapper.selectByPrimaryKey(request.getMoveId());
|
||||
if (dragNode == null) {
|
||||
|
@ -234,4 +253,85 @@ public class TestPlanApiScenarioService extends TestPlanResourceService implemen
|
|||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(taskItem.getResourceId());
|
||||
return apiScenarioRunService.getRunScript(request, testPlanApiScenario.getApiScenarioId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 已关联接口场景列表
|
||||
*
|
||||
* @param request
|
||||
* @param deleted
|
||||
* @return
|
||||
*/
|
||||
public List<TestPlanApiScenarioPageResponse> hasRelateApiScenarioList(TestPlanApiScenarioRequest request, boolean deleted) {
|
||||
List<TestPlanApiScenarioPageResponse> list = extTestPlanApiScenarioMapper.relateApiScenarioList(request, deleted);
|
||||
buildApiScenarioResponse(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void buildApiScenarioResponse(List<TestPlanApiScenarioPageResponse> apiScenarioList) {
|
||||
if (CollectionUtils.isNotEmpty(apiScenarioList)) {
|
||||
Map<String, String> projectMap = getProject(apiScenarioList);
|
||||
Map<String, String> userMap = getUserMap(apiScenarioList);
|
||||
handleScenarioAndEnv(apiScenarioList, projectMap, userMap);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleScenarioAndEnv(List<TestPlanApiScenarioPageResponse> apiScenarioList, Map<String, String> projectMap, Map<String, String> userMap) {
|
||||
//获取二级节点环境
|
||||
List<TestPlanCollectionEnvDTO> secondEnv = extTestPlanCollectionMapper.selectSecondCollectionEnv(CaseType.SCENARIO_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID);
|
||||
Map<String, TestPlanCollectionEnvDTO> secondEnvMap = secondEnv.stream().collect(Collectors.toMap(TestPlanCollectionEnvDTO::getId, item -> item));
|
||||
//当前用例环境
|
||||
List<String> caseEnvIds = apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getEnvironmentId).toList();
|
||||
EnvironmentExample environmentExample = new EnvironmentExample();
|
||||
environmentExample.createCriteria().andIdIn(caseEnvIds);
|
||||
List<Environment> caseEnv = environmentMapper.selectByExample(environmentExample);
|
||||
Map<String, String> caseEnvMap = caseEnv.stream().collect(Collectors.toMap(Environment::getId, Environment::getName));
|
||||
apiScenarioList.forEach(item -> {
|
||||
item.setProjectName(projectMap.get(item.getProjectId()));
|
||||
item.setCreateUserName(userMap.get(item.getCreateUser()));
|
||||
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
|
||||
if (StringUtils.equalsIgnoreCase(collectEnv.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
|
||||
//计划集 == 默认环境 处理默认环境
|
||||
doHandleDefaultEnv(item, caseEnvMap);
|
||||
} else {
|
||||
//计划集 != 默认环境
|
||||
doHandleEnv(item, collectEnv);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doHandleEnv(TestPlanApiScenarioPageResponse item, TestPlanCollectionEnvDTO collectEnv) {
|
||||
if (StringUtils.isNotBlank(collectEnv.getEnvironmentName())) {
|
||||
item.setEnvironmentId(collectEnv.getEnvironmentId());
|
||||
item.setEnvironmentName(collectEnv.getEnvironmentName());
|
||||
} else {
|
||||
item.setEnvironmentId(null);
|
||||
item.setEnvironmentName(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void doHandleDefaultEnv(TestPlanApiScenarioPageResponse item, Map<String, String> caseEnvMap) {
|
||||
if (caseEnvMap.containsKey(item.getEnvironmentId())) {
|
||||
item.setEnvironmentName(caseEnvMap.get(item.getEnvironmentId()));
|
||||
} else {
|
||||
item.setEnvironmentId(null);
|
||||
item.setEnvironmentName(null);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getUserMap(List<TestPlanApiScenarioPageResponse> apiScenarioList) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
userIds.addAll(apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getCreateUser).toList());
|
||||
userIds.addAll(apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getExecuteUser).toList());
|
||||
return userLoginService.getUserNameMap(userIds.stream().filter(StringUtils::isNotBlank).distinct().toList());
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> getProject(List<TestPlanApiScenarioPageResponse> apiScenarioList) {
|
||||
List<String> projectIds = apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getProjectId).toList();
|
||||
ProjectExample projectExample = new ProjectExample();
|
||||
projectExample.createCriteria().andIdIn(projectIds);
|
||||
List<Project> projectList = projectMapper.selectByExample(projectExample);
|
||||
return projectList.stream().collect(Collectors.toMap(Project::getId, Project::getName));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import io.metersphere.api.dto.scenario.ScenarioOtherConfig;
|
|||
import io.metersphere.api.service.scenario.ApiScenarioService;
|
||||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
import io.metersphere.plan.domain.TestPlanApiScenario;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiScenarioRequest;
|
||||
import io.metersphere.plan.mapper.TestPlanApiScenarioMapper;
|
||||
import io.metersphere.plan.service.TestPlanApiScenarioService;
|
||||
import io.metersphere.project.api.assertion.MsResponseCodeAssertion;
|
||||
|
@ -26,15 +28,17 @@ import io.metersphere.sdk.dto.api.task.GetRunScriptRequest;
|
|||
import io.metersphere.sdk.dto.api.task.TaskItem;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.SqlConfig;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -50,6 +54,7 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
|
|||
private static final String BASE_PATH = "/test-plan/api/scenario/";
|
||||
public static final String RUN = "run/{0}";
|
||||
public static final String RUN_WITH_REPORT_ID = "run/{0}?reportId={1}";
|
||||
public static final String API_SCENARIO_PAGE = "page";
|
||||
|
||||
@Resource
|
||||
private TestPlanApiScenarioService testPlanApiScenarioService;
|
||||
|
@ -172,4 +177,25 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
|
|||
private Object getMsHttpElementStr(MsHTTPElement msHTTPElement) {
|
||||
return JSON.parseObject(ApiDataUtils.toJSONString(msHTTPElement));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
@Sql(scripts = {"/dml/init_test_plan_api_scenario.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void testApiCasePageList() throws Exception {
|
||||
TestPlanApiScenarioRequest request = new TestPlanApiScenarioRequest();
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
request.setTestPlanId("wxxx_plan_1");
|
||||
request.setProjectId("wxx_project_1234");
|
||||
this.requestPost(API_SCENARIO_PAGE, request);
|
||||
request.setSort(new HashMap<>() {{
|
||||
put("createTime", "desc");
|
||||
}});
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(API_SCENARIO_PAGE, request);
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
INSERT INTO `test_plan`(`id`, `num`, `project_id`, `group_id`, `module_id`, `name`, `status`, `type`, `tags`, `create_time`, `create_user`, `update_time`, `update_user`, `planned_start_time`, `planned_end_time`, `actual_start_time`, `actual_end_time`, `description`)
|
||||
VALUES
|
||||
('wxxx_plan_1', 5000, 'wxx_1234', 'NONE', '1', 'qwe', 'PREPARED', 'TEST_PLAN', NULL, 1714980158000, 'WX', 1714980158000, 'WX', 1714980158000, 1714980158000, 1714980158000, 1714980158000, '11'),
|
||||
('wxxx_plan_2', 10000, 'wxx_1234', 'NONE', '1', 'eeew', 'PREPARED', 'TEST_PLAN', NULL, 1714980158000, 'WX', 1714980158000, 'WX', 1714980158000, 1714980158000, 1714980158000, 1714980158000, '11');
|
||||
|
||||
|
||||
INSERT INTO `test_plan_config`(`test_plan_id`, `automatic_status_update`, `repeat_case`, `pass_threshold`,
|
||||
`case_run_mode`)
|
||||
VALUES ('wxxx_plan_1', b'0', b'0', 100, 'PARALLEL'),
|
||||
('wxxx_plan_2', b'0', b'0', 100, 'PARALLEL');
|
||||
|
||||
|
||||
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, module_setting)
|
||||
VALUES
|
||||
('wxx_project_1234', 5, 1, 'wx', 'wx', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,'["bugManagement","caseManagement","apiTest","testPlan"]');
|
||||
|
||||
|
||||
INSERT INTO `test_plan_api_scenario`(`id`, `test_plan_id`, `api_scenario_id`, `environment_id`, `execute_user`, `last_exec_result`, `last_exec_report_id`, `create_time`, `create_user`, `pos`, `test_plan_collection_id`, `grouped`, `last_exec_time`)
|
||||
VALUES
|
||||
('wxxx_plan_scenario_1', 'wxxx_plan_1', 'wxxx_api_scenario_1', '1', 'admin', '', NULL, 1716370415311, 'admin', 64, 'wxxx_collection_2', b'0', 1716370415311),
|
||||
('wxxx_plan_scenario_2', 'wxxx_plan_1', 'wxxx_api_scenario_2', '123', 'admin', '', NULL, 1716370415311, 'admin', 64, 'wxxx_collection_3', b'0', 1716370415311);
|
||||
|
||||
INSERT INTO `api_scenario`(`id`, `name`, `priority`, `status`, `step_total`, `request_pass_rate`, `last_report_status`, `last_report_id`, `num`, `deleted`, `pos`, `version_id`, `ref_id`, `latest`, `project_id`, `module_id`, `description`, `tags`, `grouped`, `environment_id`, `create_user`, `create_time`, `delete_time`, `delete_user`, `update_user`, `update_time`)
|
||||
VALUES
|
||||
('wxxx_api_scenario_1', 'axx', 'P0', 'UNDERWAY', 3, '0.46', 'ERROR', '971160841641984', 100027, b'0', 5568, '718273150722066', '1023696881426432', b'1', 'wxx_project_1234', 'root', '', '[]', b'0', 'wx_env_123', '714940256100352', 1717489987182, NULL, NULL, '714940256100352', 1717557159805),
|
||||
('wxxx_api_scenario_2', 'xww', 'P0', 'UNDERWAY', 3, '0.46', 'ERROR', '971160841641984', 100027, b'0', 5568, '718273150722066', '1023696881426432', b'1', 'wxx_project_1234', 'root', '', '[]', b'0', 'wx_env_123', '714940256100352', 1717489987182, NULL, NULL, '714940256100352', 1717557159805);
|
||||
|
||||
|
||||
|
||||
INSERT INTO `test_plan_collection`(`id`, `test_plan_id`, `name`, `type`, `environment_id`, `test_resource_pool_id`, `pos`, `create_user`, `create_time`, `parent_id`)
|
||||
VALUES
|
||||
('wxxx_collection_1', 'wxxx_plan_1', 'wxxx_wx_1', 'SCENARIO', 'NONE', 'NONE', 1, 'admin', 1716370415311, 'NONE'),
|
||||
('wxxx_collection_2', 'wxxx_plan_1', 'wxxx_wx_2', 'SCENARIO', 'wx_env_123', 'NONE', 2, 'admin', 1716370415311, 'wxxx_collection_1'),
|
||||
('wxxx_collection_3', 'wxxx_plan_2', 'wxxx_wx_3', 'SCENARIO', 'NONE', 'NONE', 3, 'admin', 1716370415311, 'wxxx_collection_1');
|
||||
|
||||
|
||||
|
||||
INSERT INTO `environment`(`id`, `name`, `project_id`, `create_user`, `update_user`, `create_time`, `update_time`, `mock`, `description`, `pos`)
|
||||
VALUES
|
||||
('wx_env_123', 'Mock环境', 'wxx_project_1234', 'admin', 'admin', 1716175907000, 1716175907000, b'1', NULL, 64),
|
||||
('wx_env_223', '测试环境', 'wxx_project_1234', 'admin', 'admin', 1716175907000, 1716175907000, b'1', NULL, 128);
|
||||
|
||||
|
Loading…
Reference in New Issue