feat(测试计划): 取消关联接口用例
This commit is contained in:
parent
8a307bb87d
commit
c14b6399ec
|
@ -92,6 +92,8 @@ log.delete.test_plan_group=Test plan group deleted
|
|||
log.test_plan.add=Association resources
|
||||
log.test_plan.remove=Remove resource
|
||||
log.test_plan.move=Move resources
|
||||
log.test_plan.disassociate=Disassociate resources
|
||||
log.test_plan.associate=Associate resources
|
||||
log.test_plan.move.test_plan=Move test plan
|
||||
log.test_plan.update=Update resources
|
||||
log.test_plan.functional_case=Functional case
|
||||
|
|
|
@ -92,6 +92,8 @@ log.delete.test_plan_group=删除测试计划组
|
|||
log.test_plan.add=关联了资源
|
||||
log.test_plan.remove=移除了资源
|
||||
log.test_plan.move=移动了资源
|
||||
log.test_plan.disassociate=取消关联了资源
|
||||
log.test_plan.associate=关联了资源
|
||||
log.test_plan.move.test_plan=移动了测试计划
|
||||
log.test_plan.update=修改了资源
|
||||
log.test_plan.functional_case=功能用例
|
||||
|
|
|
@ -91,6 +91,8 @@ log.delete.test_plan_group=刪除測試計劃組
|
|||
log.test_plan.add=關聯了資源
|
||||
log.test_plan.remove=移除了資源
|
||||
log.test_plan.move=移動了資源
|
||||
log.test_plan.disassociate=取消關聯了資源
|
||||
log.test_plan.associate=關聯了賳源
|
||||
log.test_plan.move.test_plan=移動了測試計劃
|
||||
log.test_plan.update=修改了資源
|
||||
log.test_plan.functional_case=功能用例
|
||||
|
|
|
@ -2,14 +2,21 @@ package io.metersphere.plan.controller;
|
|||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
||||
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
||||
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
||||
import io.metersphere.plan.service.TestPlanApiCaseService;
|
||||
import io.metersphere.plan.service.TestPlanService;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.system.dto.LogInsertModule;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
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;
|
||||
|
@ -28,6 +35,8 @@ public class TestPlanApiCaseController {
|
|||
|
||||
@Resource
|
||||
private TestPlanApiCaseService testPlanApiCaseService;
|
||||
@Resource
|
||||
private TestPlanService testPlanService;
|
||||
|
||||
|
||||
@PostMapping("/page")
|
||||
|
@ -57,5 +66,19 @@ public class TestPlanApiCaseController {
|
|||
return testPlanApiCaseService.getTree(testPlanId);
|
||||
}
|
||||
|
||||
@PostMapping("/disassociate")
|
||||
@Operation(summary = "测试计划-计划详情-接口用例列表-取消关联用例")
|
||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
|
||||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||
public TestPlanAssociationResponse disassociate(@Validated @RequestBody TestPlanDisassociationRequest request) {
|
||||
BasePlanCaseBatchRequest batchRequest = new BasePlanCaseBatchRequest();
|
||||
batchRequest.setTestPlanId(request.getTestPlanId());
|
||||
batchRequest.setSelectIds(List.of(request.getId()));
|
||||
TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/association", HttpMethodConstants.POST.name()));
|
||||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
//TODO 计划集 type
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.metersphere.plan.domain.TestPlanApiCase;
|
|||
import io.metersphere.plan.dto.ApiCaseModuleDTO;
|
||||
import io.metersphere.plan.dto.ResourceSelectParam;
|
||||
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiRequest;
|
||||
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
||||
|
@ -47,4 +48,6 @@ public interface ExtTestPlanApiCaseMapper {
|
|||
List<ProjectOptionDTO> selectRootIdByTestPlanId(@Param("testPlanId") String testPlanId);
|
||||
|
||||
List<ApiCaseModuleDTO> selectBaseByProjectIdAndTestPlanId(@Param("testPlanId") String testPlanId);
|
||||
|
||||
List<String> getIds(@Param("request") BasePlanCaseBatchRequest request, @Param("deleted") boolean deleted);
|
||||
}
|
||||
|
|
|
@ -584,4 +584,49 @@
|
|||
ORDER BY pos
|
||||
</select>
|
||||
|
||||
<select id="getIds" resultType="java.lang.String">
|
||||
SELECT
|
||||
t.id as id
|
||||
FROM
|
||||
test_plan_api_case t
|
||||
INNER JOIN api_test_case atc ON t.api_case_id = atc.id
|
||||
INNER JOIN api_definition a ON atc.api_definition_id = a.id
|
||||
WHERE
|
||||
t.test_plan_id = #{request.testPlanId}
|
||||
AND atc.deleted = #{deleted}
|
||||
<include refid="queryWhereConditionByBatchQueryRequest"/>
|
||||
</select>
|
||||
|
||||
<sql id="queryWhereConditionByBatchQueryRequest">
|
||||
<if test="request.protocol != null and request.protocol!=''">
|
||||
and a.protocol = #{request.protocol}
|
||||
</if>
|
||||
<if test="request.apiDefinitionId != null and request.apiDefinitionId!=''">
|
||||
and atc.api_definition_id = #{request.apiDefinitionId}
|
||||
</if>
|
||||
<if test="request.condition.keyword != null and request.condition.keyword !=''">
|
||||
and (
|
||||
atc.name like concat('%', #{request.condition.keyword},'%')
|
||||
or atc.num like concat('%', #{request.condition.keyword},'%')
|
||||
or a.path like concat('%', #{request.condition.keyword},'%')
|
||||
or atc.tags like concat('%', #{request.condition.keyword},'%')
|
||||
)
|
||||
</if>
|
||||
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||
and a.module_id in
|
||||
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||
#{nodeId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.collectionIds != null and request.collectionIds.size() > 0">
|
||||
and t.test_plan_collection_id in
|
||||
<foreach collection="request.collectionIds" item="collectionId" separator="," open="(" close=")">
|
||||
#{collectionId}
|
||||
</foreach>
|
||||
</if>
|
||||
<include refid="filters">
|
||||
<property name="filter" value="request.condition.filter"/>
|
||||
</include>
|
||||
</sql>
|
||||
|
||||
</mapper>
|
|
@ -11,9 +11,12 @@ import io.metersphere.plan.domain.TestPlanApiCase;
|
|||
import io.metersphere.plan.domain.TestPlanApiCaseExample;
|
||||
import io.metersphere.plan.dto.ApiCaseModuleDTO;
|
||||
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
||||
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
|
||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanApiRequest;
|
||||
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
||||
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
||||
import io.metersphere.plan.mapper.ExtTestPlanApiCaseMapper;
|
||||
import io.metersphere.plan.mapper.TestPlanApiCaseMapper;
|
||||
import io.metersphere.project.domain.Project;
|
||||
|
@ -21,11 +24,13 @@ import io.metersphere.project.domain.ProjectExample;
|
|||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.constants.TestPlanResourceConstants;
|
||||
import io.metersphere.sdk.domain.Environment;
|
||||
import io.metersphere.sdk.domain.EnvironmentExample;
|
||||
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.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
|
@ -39,6 +44,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
|
|||
import org.mybatis.spring.SqlSessionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -68,6 +74,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
|||
private static final String CASE_MODULE_COUNT_ALL = "all";
|
||||
@Resource
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
@Override
|
||||
public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
|
@ -307,4 +314,42 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
|||
});
|
||||
return returnList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消关联
|
||||
*
|
||||
* @param request
|
||||
* @param logInsertModule
|
||||
* @return
|
||||
*/
|
||||
public TestPlanAssociationResponse disassociate(BasePlanCaseBatchRequest request, LogInsertModule logInsertModule) {
|
||||
List<String> selectIds = doSelectIds(request);
|
||||
return super.disassociate(
|
||||
TestPlanResourceConstants.RESOURCE_API_CASE,
|
||||
request,
|
||||
logInsertModule,
|
||||
selectIds,
|
||||
this::deleteTestPlanResource);
|
||||
}
|
||||
|
||||
|
||||
public void deleteTestPlanResource(@Validated TestPlanResourceAssociationParam associationParam) {
|
||||
TestPlanApiCaseExample testPlanApiCaseExample = new TestPlanApiCaseExample();
|
||||
testPlanApiCaseExample.createCriteria().andIdIn(associationParam.getResourceIdList());
|
||||
testPlanApiCaseMapper.deleteByExample(testPlanApiCaseExample);
|
||||
}
|
||||
|
||||
|
||||
public List<String> doSelectIds(BasePlanCaseBatchRequest request) {
|
||||
if (request.isSelectAll()) {
|
||||
List<String> ids = extTestPlanApiCaseMapper.getIds(request, false);
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
ids.removeAll(request.getExcludeIds());
|
||||
}
|
||||
return ids;
|
||||
} else {
|
||||
return request.getSelectIds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ public class TestPlanBaseUtilsService {
|
|||
if (CollectionUtils.isNotEmpty(functionalSelectIds)) {
|
||||
TestPlanResourceAssociationParam associationParam = new TestPlanResourceAssociationParam(functionalSelectIds, testPlan.getProjectId(), testPlan.getId(), testPlan.getNum(), testPlan.getCreateUser());
|
||||
testPlanCaseService.saveTestPlanResource(associationParam);
|
||||
testPlanResourceLogService.saveAddLog(testPlan, new ResourceLogInsertModule(TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE, new LogInsertModule(operator, "/test-plan/association", HttpMethodConstants.POST.name())));
|
||||
testPlanResourceLogService.saveAssociateLog(testPlan, new ResourceLogInsertModule(TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE, new LogInsertModule(operator, "/test-plan/association", HttpMethodConstants.POST.name())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,4 +86,38 @@ public class TestPlanResourceLogService {
|
|||
.build().getLogDTO();
|
||||
operationLogService.add(dto);
|
||||
}
|
||||
|
||||
|
||||
public void saveDisassociateLog(TestPlan module, @Validated ResourceLogInsertModule logInsertModule) {
|
||||
Project project = projectMapper.selectByPrimaryKey(module.getProjectId());
|
||||
LogDTO dto = LogDTOBuilder.builder()
|
||||
.projectId(module.getProjectId())
|
||||
.organizationId(project.getOrganizationId())
|
||||
.type(OperationLogType.DISASSOCIATE.name())
|
||||
.module(logModule)
|
||||
.method(logInsertModule.getRequestMethod())
|
||||
.path(logInsertModule.getRequestUrl())
|
||||
.sourceId(module.getId())
|
||||
.content(generateContent(module.getName(), logInsertModule.getResourceType(), "disassociate"))
|
||||
.createUser(logInsertModule.getOperator())
|
||||
.build().getLogDTO();
|
||||
operationLogService.add(dto);
|
||||
}
|
||||
|
||||
|
||||
public void saveAssociateLog(TestPlan module, @Validated ResourceLogInsertModule logInsertModule) {
|
||||
Project project = projectMapper.selectByPrimaryKey(module.getProjectId());
|
||||
LogDTO dto = LogDTOBuilder.builder()
|
||||
.projectId(module.getProjectId())
|
||||
.organizationId(project.getOrganizationId())
|
||||
.type(OperationLogType.ASSOCIATE.name())
|
||||
.module(logModule)
|
||||
.method(logInsertModule.getRequestMethod())
|
||||
.path(logInsertModule.getRequestUrl())
|
||||
.sourceId(module.getId())
|
||||
.content(generateContent(module.getName(), logInsertModule.getResourceType(), "associate"))
|
||||
.createUser(logInsertModule.getOperator())
|
||||
.build().getLogDTO();
|
||||
operationLogService.add(dto);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
|
|||
TestPlanResourceAssociationParam associationParam = new TestPlanResourceAssociationParam(associationIdList, testPlan.getProjectId(), testPlan.getId(), testPlan.getNum(), logInsertModule.getOperator());
|
||||
disassociate.accept(associationParam);
|
||||
response.setAssociationCount(associationIdList.size());
|
||||
testPlanResourceLogService.saveDeleteLog(testPlan, new ResourceLogInsertModule(resourceType, logInsertModule));
|
||||
testPlanResourceLogService.saveDisassociateLog(testPlan, new ResourceLogInsertModule(resourceType, logInsertModule));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.plan.controller;
|
||||
|
||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
|
@ -22,6 +23,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
|
|||
public static final String API_CASE_PAGE = "/test-plan/api/case/page";
|
||||
public static final String API_CASE_TREE_COUNT = "/test-plan/api/case/module/count";
|
||||
public static final String API_CASE_TREE_MODULE_TREE = "/test-plan/api/case/tree/";
|
||||
public static final String API_CASE_DISASSOCIATE = "/test-plan/api/case/disassociate";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
|
@ -70,4 +72,18 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
|
|||
this.requestGetWithOkAndReturn(API_CASE_TREE_MODULE_TREE + "wxxx_2");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testApiCaseDisassociate() throws Exception {
|
||||
TestPlanDisassociationRequest request = new TestPlanDisassociationRequest();
|
||||
request.setTestPlanId("wxxx_2");
|
||||
request.setId("wxxx_3");
|
||||
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(API_CASE_DISASSOCIATE, request);
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue