feat(测试计划): 计划关联用例

This commit is contained in:
WangXu10 2024-05-11 22:17:15 +08:00 committed by Craftsman
parent 1b00d8cd32
commit 1dae94ad32
15 changed files with 139 additions and 821 deletions

View File

@ -1,55 +1,12 @@
package io.metersphere.plan.controller;
import io.metersphere.plan.constants.TestPlanResourceConfig;
import io.metersphere.plan.dto.request.ResourceSortRequest;
import io.metersphere.plan.dto.request.TestPlanAssociationRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.dto.response.TestPlanResourceSortResponse;
import io.metersphere.plan.service.TestPlanApiCaseService;
import io.metersphere.plan.service.TestPlanManagementService;
import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.security.CheckOwner;
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.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
@Tag(name = "测试计划接口用例")
@RestController
@RequestMapping("/test-plan/api/case")
public class TestPlanApiCaseController {
@Resource
private TestPlanManagementService testPlanManagementService;
@Resource
private TestPlanApiCaseService testPlanApiCaseService;
@PostMapping(value = "/association")
@Operation(summary = "测试计划接口用例-关联接口用例")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public TestPlanAssociationResponse association(@Validated @RequestBody TestPlanAssociationRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_API_CASE));
return testPlanApiCaseService.association(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/association", HttpMethodConstants.POST.name()));
}
@PostMapping(value = "/sort")
@Operation(summary = "测试计划接口用例-关联功能用例")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public TestPlanResourceSortResponse sortNode(@Validated @RequestBody ResourceSortRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_API_CASE));
return testPlanApiCaseService.sortNode(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/sort", HttpMethodConstants.POST.name()));
}
}

View File

@ -1,55 +1,13 @@
package io.metersphere.plan.controller;
import io.metersphere.plan.constants.TestPlanResourceConfig;
import io.metersphere.plan.dto.request.ResourceSortRequest;
import io.metersphere.plan.dto.request.TestPlanAssociationRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.dto.response.TestPlanResourceSortResponse;
import io.metersphere.plan.service.TestPlanApiScenarioService;
import io.metersphere.plan.service.TestPlanManagementService;
import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.security.CheckOwner;
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.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
@Tag(name = "测试计划场景用例")
@RestController
@RequestMapping("/test-plan/api/scenario")
public class TestPlanApiScenarioController {
@Resource
private TestPlanManagementService testPlanManagementService;
@Resource
private TestPlanApiScenarioService testPlanApiScenarioService;
@PostMapping(value = "/association")
@Operation(summary = "测试计划场景用例-关联接口用例")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public TestPlanAssociationResponse association(@Validated @RequestBody TestPlanAssociationRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_API_SCENARIO));
return testPlanApiScenarioService.association(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/scenario/association", HttpMethodConstants.POST.name()));
}
@PostMapping(value = "/sort")
@Operation(summary = "测试计划场景用例-关联功能用例")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public TestPlanResourceSortResponse sortNode(@Validated @RequestBody ResourceSortRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_API_SCENARIO));
return testPlanApiScenarioService.sortNode(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/scenario/sort", HttpMethodConstants.POST.name()));
}
}

View File

@ -158,4 +158,13 @@ public class TestPlanController {
testPlanManagementService.checkModuleIsOpen(request.getProjectId(), TestPlanResourceConfig.CHECK_TYPE_PROJECT, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN));
testPlanService.batchArchived(request, SessionUtils.getUserId());
}
@PostMapping(value = "/association")
@Operation(summary = "测试计划功能用例-关联功能用例")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public void association(@Validated @RequestBody TestPlanAssociationRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE));
testPlanService.association(request);
}
}

View File

@ -5,7 +5,6 @@ import com.github.pagehelper.PageHelper;
import io.metersphere.plan.constants.TestPlanResourceConfig;
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
import io.metersphere.plan.dto.request.ResourceSortRequest;
import io.metersphere.plan.dto.request.TestPlanAssociationRequest;
import io.metersphere.plan.dto.request.TestPlanCaseRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.dto.response.TestPlanCasePageResponse;
@ -41,14 +40,6 @@ public class TestPlanFunctionalCaseController {
@Resource
private TestPlanFunctionalCaseService testPlanFunctionalCaseService;
@PostMapping(value = "/association")
@Operation(summary = "测试计划功能用例-关联功能用例")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public TestPlanAssociationResponse association(@Validated @RequestBody TestPlanAssociationRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE));
return testPlanFunctionalCaseService.association(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/association", HttpMethodConstants.POST.name()));
}
@PostMapping(value = "/sort")
@Operation(summary = "测试计划功能用例-关联功能用例")

View File

@ -1,6 +1,5 @@
package io.metersphere.plan.dto.request;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -12,14 +11,11 @@ import java.util.List;
* @author wx
*/
@Data
public class BaseAssociateCaseRequest extends TableBatchProcessDTO implements Serializable {
public class BaseAssociateCaseRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "模块id")
private List<String> moduleIds;
@Schema(description = "功能用例选中的ids")
private List<String> functionalSelectIds;

View File

@ -3,43 +3,16 @@ package io.metersphere.plan.dto.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.io.Serial;
@Data
public class TestPlanAssociationRequest {
public class TestPlanAssociationRequest extends BaseAssociateCaseRequest {
@Serial
private static final long serialVersionUID = 1L;
@NotBlank(message = "{test_plan.id.not_blank}")
@Schema(description = "测试计划ID")
private String testPlanId;
@Schema(description = "选择的id")
private List<String> selectIds = new ArrayList<>();
@Schema(description = "不处理的ID")
private List<String> excludeIds = new ArrayList<>();
@Schema(description = "选择的模块ID")
private List<String> selectModuleIds = new ArrayList<>();
@Schema(description = "排序字段")
private String orderColumn;
@Schema(description = "是否是正序")
private boolean orderByAsc;
public boolean isEmpty() {
return CollectionUtils.isEmpty(selectIds) && CollectionUtils.isEmpty(selectModuleIds);
}
public String getOrderString() {
if (StringUtils.isNotBlank(orderColumn)) {
if (orderByAsc) {
return orderColumn + " ASC";
} else {
return orderColumn + " DESC";
}
} else {
return null;
}
}
}

View File

@ -1,34 +1,13 @@
package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanApiCase;
import io.metersphere.plan.domain.TestPlanApiCaseExample;
import io.metersphere.plan.dto.AssociationNodeSortDTO;
import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.ResourceSortRequest;
import io.metersphere.plan.dto.request.TestPlanAssociationRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.dto.response.TestPlanResourceSortResponse;
import io.metersphere.plan.mapper.ExtTestPlanApiCaseMapper;
import io.metersphere.plan.mapper.TestPlanApiCaseMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.sdk.constants.ApplicationNumScope;
import io.metersphere.sdk.constants.TestPlanResourceConstants;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator;
import jakarta.annotation.Resource;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
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.List;
@Service
@ -40,10 +19,6 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
@Resource
private TestPlanResourceLogService testPlanResourceLogService;
@Resource
private TestPlanMapper testPlanMapper;
@Override
public int deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -52,78 +27,24 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
return testPlanApiCaseMapper.deleteByExample(example);
}
@Override
public long getNextOrder(String testPlanId) {
Long maxPos = extTestPlanApiCaseMapper.getMaxPosByTestPlanId(testPlanId);
if (maxPos == null) {
return 0;
} else {
return maxPos + DEFAULT_NODE_INTERVAL_POS;
}
}
@Override
public void updatePos(String id, long pos) {
extTestPlanApiCaseMapper.updatePos(id, pos);
// TODO
//extTestPlanApiCaseMapper.updatePos(id, pos);
}
@Override
public void refreshPos(String testPlanId) {
List<String> caseIdList = extTestPlanApiCaseMapper.selectIdByTestPlanIdOrderByPos(testPlanId);
// TODO
/*List<String> caseIdList = extTestPlanApiCaseMapper.selectIdByTestPlanIdOrderByPos(testPlanId);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ExtTestPlanApiCaseMapper batchUpdateMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class);
for (int i = 0; i < caseIdList.size(); i++) {
batchUpdateMapper.updatePos(caseIdList.get(i), i * DEFAULT_NODE_INTERVAL_POS);
}
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);*/
}
public TestPlanAssociationResponse association(TestPlanAssociationRequest request, LogInsertModule logInsertModule) {
return super.association(
TestPlanResourceConstants.RESOURCE_API_CASE,
request,
logInsertModule,
extTestPlanApiCaseMapper::getIdByParam,
this::saveTestPlanResource);
}
private void saveTestPlanResource(@Validated TestPlanResourceAssociationParam associationParam) {
long pox = this.getNextOrder(associationParam.getTestPlanId());
long now = System.currentTimeMillis();
List<TestPlanApiCase> testPlanResourceList = new ArrayList<>();
List<String> associationIdList = associationParam.getResourceIdList();
for (int i = 0; i < associationIdList.size(); i++) {
TestPlanApiCase testPlanResourceCase = new TestPlanApiCase();
testPlanResourceCase.setId(IDGenerator.nextStr());
testPlanResourceCase.setNum(NumGenerator.nextNum(associationParam.getTestPlanNum() + "_" + associationParam.getProjectId(), ApplicationNumScope.TEST_PLAN_API_CASE));
testPlanResourceCase.setTestPlanId(associationParam.getTestPlanId());
testPlanResourceCase.setApiCaseId(associationIdList.get(i));
testPlanResourceCase.setPos(pox + (i + 1) * DEFAULT_NODE_INTERVAL_POS);
testPlanResourceCase.setCreateTime(now);
testPlanResourceCase.setCreateUser(associationParam.getOperator());
testPlanResourceCase.setExecuteUser(associationParam.getOperator());
testPlanResourceList.add(testPlanResourceCase);
}
testPlanApiCaseMapper.batchInsert(testPlanResourceList);
}
public TestPlanResourceSortResponse sortNode(ResourceSortRequest request, LogInsertModule logInsertModule) {
TestPlanResourceSortResponse response = new TestPlanResourceSortResponse();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
TestPlanApiCase dragNode = testPlanApiCaseMapper.selectByPrimaryKey(request.getDragNodeId());
if (dragNode == null) {
throw new MSException("test_plan.drag.node.error");
}
AssociationNodeSortDTO sortDTO = super.getNodeSortDTO(
request,
extTestPlanApiCaseMapper::selectDragInfoById,
extTestPlanApiCaseMapper::selectNodeByPosOperator
);
this.sort(sortDTO);
response.setSortNodeNum(1);
testPlanResourceLogService.saveSortLog(testPlan, request.getDragNodeId(), new ResourceLogInsertModule(TestPlanResourceConstants.RESOURCE_API_CASE, logInsertModule));
return response;
}
}

View File

@ -1,35 +1,13 @@
package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanApiScenario;
import io.metersphere.plan.domain.TestPlanApiScenarioExample;
import io.metersphere.plan.dto.AssociationNodeSortDTO;
import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.ResourceSortRequest;
import io.metersphere.plan.dto.request.TestPlanAssociationRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.dto.response.TestPlanResourceSortResponse;
import io.metersphere.plan.mapper.ExtTestPlanApiCaseMapper;
import io.metersphere.plan.mapper.ExtTestPlanApiScenarioMapper;
import io.metersphere.plan.mapper.TestPlanApiScenarioMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.sdk.constants.ApplicationNumScope;
import io.metersphere.sdk.constants.TestPlanResourceConstants;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator;
import jakarta.annotation.Resource;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
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.List;
@Service
@ -41,10 +19,6 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource
private ExtTestPlanApiScenarioMapper extTestPlanApiScenarioMapper;
@Resource
private TestPlanResourceLogService testPlanResourceLogService;
@Resource
private TestPlanMapper testPlanMapper;
@Override
public int deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -53,77 +27,24 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
return testPlanApiScenarioMapper.deleteByExample(example);
}
@Override
public long getNextOrder(String testPlanId) {
Long maxPos = extTestPlanApiScenarioMapper.getMaxPosByTestPlanId(testPlanId);
if (maxPos == null) {
return 0;
} else {
return maxPos + DEFAULT_NODE_INTERVAL_POS;
}
}
@Override
public void updatePos(String id, long pos) {
extTestPlanApiScenarioMapper.updatePos(id, pos);
// TODO
//extTestPlanApiScenarioMapper.updatePos(id, pos);
}
@Override
public void refreshPos(String testPlanId) {
List<String> caseIdList = extTestPlanApiScenarioMapper.selectIdByTestPlanIdOrderByPos(testPlanId);
// TODO
/* List<String> caseIdList = extTestPlanApiScenarioMapper.selectIdByTestPlanIdOrderByPos(testPlanId);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ExtTestPlanApiCaseMapper batchUpdateMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class);
for (int i = 0; i < caseIdList.size(); i++) {
batchUpdateMapper.updatePos(caseIdList.get(i), i * DEFAULT_NODE_INTERVAL_POS);
}
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);*/
}
public TestPlanAssociationResponse association(TestPlanAssociationRequest request, LogInsertModule logInsertModule) {
return super.association(
TestPlanResourceConstants.RESOURCE_API_CASE,
request,
logInsertModule,
extTestPlanApiScenarioMapper::getIdByParam,
this::saveTestPlanResource);
}
private void saveTestPlanResource(@Validated TestPlanResourceAssociationParam associationParam) {
long pox = this.getNextOrder(associationParam.getTestPlanId());
long now = System.currentTimeMillis();
List<TestPlanApiScenario> testPlanResourceList = new ArrayList<>();
List<String> associationIdList = associationParam.getResourceIdList();
for (int i = 0; i < associationIdList.size(); i++) {
TestPlanApiScenario testPlanResourceCase = new TestPlanApiScenario();
testPlanResourceCase.setId(IDGenerator.nextStr());
testPlanResourceCase.setNum(NumGenerator.nextNum(associationParam.getTestPlanNum() + "_" + associationParam.getProjectId(), ApplicationNumScope.TEST_PLAN_API_SCENARIO));
testPlanResourceCase.setTestPlanId(associationParam.getTestPlanId());
testPlanResourceCase.setApiScenarioId(associationIdList.get(i));
testPlanResourceCase.setPos(pox + (i + 1) * DEFAULT_NODE_INTERVAL_POS);
testPlanResourceCase.setCreateTime(now);
testPlanResourceCase.setCreateUser(associationParam.getOperator());
testPlanResourceCase.setExecuteUser(associationParam.getOperator());
testPlanResourceList.add(testPlanResourceCase);
}
testPlanApiScenarioMapper.batchInsert(testPlanResourceList);
}
public TestPlanResourceSortResponse sortNode(ResourceSortRequest request, LogInsertModule logInsertModule) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
TestPlanApiScenario dragNode = testPlanApiScenarioMapper.selectByPrimaryKey(request.getDragNodeId());
if (dragNode == null) {
throw new MSException("test_plan.drag.node.error");
}
TestPlanResourceSortResponse response = new TestPlanResourceSortResponse();
AssociationNodeSortDTO sortDTO = super.getNodeSortDTO(
request,
extTestPlanApiScenarioMapper::selectDragInfoById,
extTestPlanApiScenarioMapper::selectNodeByPosOperator
);
this.sort(sortDTO);
response.setSortNodeNum(1);
testPlanResourceLogService.saveSortLog(testPlan, request.getDragNodeId(), new ResourceLogInsertModule(TestPlanResourceConstants.RESOURCE_API_CASE, logInsertModule));
return response;
}
}

View File

@ -1,17 +1,25 @@
package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanExample;
import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.BaseAssociateCaseRequest;
import io.metersphere.plan.dto.request.TestPlanAssociationRequest;
import io.metersphere.plan.dto.request.TestPlanBatchProcessRequest;
import io.metersphere.plan.mapper.ExtTestPlanMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.TestPlanConstants;
import io.metersphere.sdk.constants.TestPlanResourceConstants;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.TestPlanModuleExample;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.mapper.TestPlanModuleMapper;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -28,6 +36,10 @@ public class TestPlanBaseUtilsService {
private TestPlanModuleMapper testPlanModuleMapper;
@Resource
private ExtTestPlanMapper extTestPlanMapper;
@Resource
private TestPlanCaseService testPlanCaseService;
@Resource
private TestPlanResourceLogService testPlanResourceLogService;
/**
* 校验模块下重名
@ -76,4 +88,41 @@ public class TestPlanBaseUtilsService {
}
/**
* 关联用例
*
* @param request
* @return
*/
public void association(TestPlanAssociationRequest request) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
handleAssociateCase(request, testPlan);
}
/**
* 处理关联的用例
*
* @param request
* @return
*/
public void handleAssociateCase(BaseAssociateCaseRequest request, TestPlan testPlan) {
//关联的功能用例
handleFunctionalCase(request.getFunctionalSelectIds(), testPlan);
//TODO 关联接口用例/接口场景用例 handleApi(request.getApiSelectIds(),request.getApiCaseSelectIds())
}
/**
* 关联的功能用例
*
* @param functionalSelectIds
*/
private void handleFunctionalCase(List<String> functionalSelectIds, TestPlan testPlan) {
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(SessionUtils.getUserId(), "/test-plan/association", HttpMethodConstants.POST.name())));
}
}
}

View File

@ -68,10 +68,7 @@ public class TestPlanBugService extends TestPlanResourceService {
return bugRelationCases.size();
}
@Override
public long getNextOrder(String testPlanId) {
return 0;
}
@Override
public void updatePos(String id, long pos) {

View File

@ -2,10 +2,10 @@ package io.metersphere.plan.service;
import io.metersphere.bug.dto.CaseRelateBugDTO;
import io.metersphere.bug.mapper.ExtBugRelateCaseMapper;
import io.metersphere.functional.domain.FunctionalCaseModule;
import io.metersphere.functional.dto.FunctionalCaseCustomFieldDTO;
import io.metersphere.functional.dto.FunctionalCaseModuleCountDTO;
import io.metersphere.functional.dto.FunctionalCaseModuleDTO;
import io.metersphere.functional.domain.FunctionalCaseModule;
import io.metersphere.functional.dto.ProjectOptionDTO;
import io.metersphere.functional.service.FunctionalCaseService;
import io.metersphere.plan.domain.TestPlan;
@ -16,7 +16,6 @@ import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
import io.metersphere.plan.dto.request.ResourceSortRequest;
import io.metersphere.plan.dto.request.TestPlanAssociationRequest;
import io.metersphere.plan.dto.request.TestPlanCaseRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.dto.response.TestPlanCasePageResponse;
@ -34,7 +33,6 @@ 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.utils.ServiceUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@ -72,8 +70,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
@Resource
private TestPlanModuleService testPlanModuleService;
@Resource
private TestPlanCaseService testPlanCaseService;
@Resource
private ExtTestPlanModuleMapper extTestPlanModuleMapper;
private static final String CASE_MODULE_COUNT_ALL = "all";
@ -86,16 +82,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
}
@Override
public long getNextOrder(String testPlanId) {
Long maxPos = extTestPlanFunctionalCaseMapper.getMaxPosByTestPlanId(testPlanId);
if (maxPos == null) {
return 0;
} else {
return maxPos + ServiceUtils.POS_STEP;
}
}
@Override
public void updatePos(String id, long pos) {
extTestPlanFunctionalCaseMapper.updatePos(id, pos);
@ -113,15 +99,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
public TestPlanAssociationResponse association(TestPlanAssociationRequest request, LogInsertModule logInsertModule) {
return super.association(
TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE,
request,
logInsertModule,
extTestPlanFunctionalCaseMapper::getIdByParam,
testPlanCaseService::saveTestPlanResource);
}
public void deleteTestPlanResource(@Validated TestPlanResourceAssociationParam associationParam) {
TestPlanFunctionalCaseExample testPlanFunctionalCaseExample = new TestPlanFunctionalCaseExample();

View File

@ -1,13 +1,13 @@
package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanConfig;
import io.metersphere.plan.dto.*;
import io.metersphere.plan.dto.AssociationNode;
import io.metersphere.plan.dto.AssociationNodeSortDTO;
import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
import io.metersphere.plan.dto.request.ResourceSortRequest;
import io.metersphere.plan.dto.request.TestPlanAssociationRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.mapper.TestPlanConfigMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.project.dto.ModuleSortCountResultDTO;
import io.metersphere.project.dto.NodeSortQueryParam;
@ -22,7 +22,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
@ -35,14 +34,10 @@ public abstract class TestPlanResourceService {
@Resource
private TestPlanMapper testPlanMapper;
@Resource
private TestPlanConfigMapper testPlanConfigMapper;
@Resource
private TestPlanResourceLogService testPlanResourceLogService;
protected static final long DEFAULT_NODE_INTERVAL_POS = NodeSortUtils.DEFAULT_NODE_INTERVAL_POS;
public abstract long getNextOrder(String testPlanId);
public abstract void updatePos(String id, long pos);
public abstract void refreshPos(String testPlanId);
@ -53,39 +48,6 @@ public abstract class TestPlanResourceService {
private static final String MOVE_POS_OPERATOR_MORE = "moreThan";
private static final String DRAG_NODE_NOT_EXIST = "drag_node.not.exist";
/**
* 关联资源od
*
* @return
*/
public TestPlanAssociationResponse association(
String resourceType,
TestPlanAssociationRequest request,
@Validated LogInsertModule logInsertModule,
Function<ResourceSelectParam, List<String>> getIdByParam,
Consumer<TestPlanResourceAssociationParam> saveResourceFunc) {
TestPlanAssociationResponse response = new TestPlanAssociationResponse();
if (request.isEmpty()) {
return response;
}
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(request.getTestPlanId());
boolean repeatCase = testPlanConfig.getRepeatCase();
//获取有效ID
List<String> associationIdList =
getIdByParam.apply(
new ResourceSelectParam(request.getTestPlanId(), request.getSelectIds(), request.getSelectModuleIds(), repeatCase, request.getOrderString()));
associationIdList = new ArrayList<>(associationIdList.stream().distinct().toList());
associationIdList.removeAll(request.getExcludeIds());
if (CollectionUtils.isNotEmpty(associationIdList)) {
TestPlanResourceAssociationParam associationParam = new TestPlanResourceAssociationParam(associationIdList, testPlan.getProjectId(), testPlan.getId(), testPlan.getNum(), logInsertModule.getOperator());
saveResourceFunc.accept(associationParam);
response.setAssociationCount(associationIdList.size());
testPlanResourceLogService.saveAddLog(testPlan, new ResourceLogInsertModule(resourceType, logInsertModule));
}
return response;
}
/**
* 取消关联资源od
@ -96,7 +58,7 @@ public abstract class TestPlanResourceService {
String resourceType,
BasePlanCaseBatchRequest request,
@Validated LogInsertModule logInsertModule,
List<String>associationIdList,
List<String> associationIdList,
Consumer<TestPlanResourceAssociationParam> disassociate) {
TestPlanAssociationResponse response = new TestPlanAssociationResponse();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());

View File

@ -1,7 +1,6 @@
package io.metersphere.plan.service;
import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.TestPlanDetailResponse;
import io.metersphere.plan.mapper.*;
@ -104,7 +103,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
testPlanConfig.setTestPlanning(createOrCopyRequest.isTestPlanning());
if (StringUtils.isBlank(id)) {
handleAssociateCase(createOrCopyRequest, createTestPlan);
handleAssociateCase(createOrCopyRequest.getBaseAssociateCaseRequest(), createTestPlan);
} else {
//复制
handleCopy(createTestPlan, id);
@ -115,31 +114,6 @@ public class TestPlanService extends TestPlanBaseUtilsService {
return createTestPlan;
}
/**
* 处理关联的用例
*
* @param request
* @return
*/
private void handleAssociateCase(TestPlanCreateRequest request, TestPlan testPlan) {
//关联的功能用例
handleFunctionalCase(request.getBaseAssociateCaseRequest().getFunctionalSelectIds(), testPlan);
//TODO 关联接口用例/接口场景用例
}
/**
* 关联的功能用例
*
* @param functionalSelectIds
*/
private void handleFunctionalCase(List<String> functionalSelectIds, TestPlan testPlan) {
if (CollectionUtils.isNotEmpty(functionalSelectIds)) {
TestPlanResourceAssociationParam associationParam = new TestPlanResourceAssociationParam(functionalSelectIds, testPlan.getProjectId(), testPlan.getId(), testPlan.getNum(), testPlan.getCreateUser());
testPlanCaseService.saveTestPlanResource(associationParam);
}
}
/**
* 删除测试计划

View File

@ -4,9 +4,11 @@ import io.metersphere.api.domain.ApiScenario;
import io.metersphere.api.domain.ApiTestCase;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.plan.constants.TestPlanResourceConfig;
import io.metersphere.plan.domain.*;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanConfig;
import io.metersphere.plan.domain.TestPlanExample;
import io.metersphere.plan.domain.TestPlanFunctionalCase;
import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.dto.response.TestPlanResourceSortResponse;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.plan.service.TestPlanManagementService;
@ -97,8 +99,6 @@ public class TestPlanTests extends BaseTest {
private static final String URL_POST_MODULE_UPDATE = "/test-plan/module/update";
private static final String URL_POST_MODULE_MOVE = "/test-plan/module/move";
//测试计划url
private static final String URL_GET_TEST_PLAN_COUNT = "/test-plan/getCount/%s";
private static final String URL_GET_TEST_PLAN_DELETE = "/test-plan/delete/%s";
private static final String URL_POST_TEST_PLAN_PAGE = "/test-plan/page";
private static final String URL_POST_TEST_PLAN_MODULE_COUNT = "/test-plan/module/count";
@ -107,17 +107,9 @@ public class TestPlanTests extends BaseTest {
private static final String URL_POST_TEST_PLAN_BATCH_DELETE = "/test-plan/batch-delete";
//测试计划资源-功能用例
private static final String URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION = "/test-plan/functional/case/association";
private static final String URL_POST_RESOURCE_CASE_ASSOCIATION = "/test-plan/association";
private static final String URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT = "/test-plan/functional/case/sort";
//测试计划资源-接口用例
private static final String URL_POST_RESOURCE_API_CASE_ASSOCIATION = "/test-plan/api/case/association";
private static final String URL_POST_RESOURCE_API_CASE_SORT = "/test-plan/api/case/sort";
//测试计划资源-场景用例
private static final String URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION = "/test-plan/api/scenario/association";
private static final String URL_POST_RESOURCE_API_SCENARIO_SORT = "/test-plan/api/scenario/sort";
private static final String URL_TEST_PLAN_EDIT_FOLLOWER = "/test-plan/edit/follower";
private static final String URL_TEST_PLAN_ARCHIVED = "/test-plan/archived/%s";
private static final String URL_TEST_PLAN_COPY = "/test-plan/copy";
@ -985,71 +977,35 @@ public class TestPlanTests extends BaseTest {
//测试不开启用例重复的测试计划多次关联
TestPlanAssociationRequest request = new TestPlanAssociationRequest();
request.setTestPlanId(simpleTestPlan.getId());
request.setSelectIds(FUNCTIONAL_CASES.stream().map(FunctionalCase::getId).collect(Collectors.toList()));
MvcResult result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request);
ResultHolder resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
TestPlanAssociationResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), FUNCTIONAL_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE), FUNCTIONAL_CASES.size());
request.setFunctionalSelectIds(FUNCTIONAL_CASES.stream().map(FunctionalCase::getId).collect(Collectors.toList()));
MvcResult result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_CASE_ASSOCIATION, request);
String returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
//先测试一下没有开启模块时能否使用
testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "caseManagement");
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request).andExpect(status().is5xxServerError());
this.requestPost(URL_POST_RESOURCE_CASE_ASSOCIATION, request).andExpect(status().is5xxServerError());
//恢复
testPlanTestService.resetProjectModule(project, PROJECT_MODULE);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), 0);
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE), FUNCTIONAL_CASES.size());
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_CASE_ASSOCIATION, request);
returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
//测试开启用例重复的测试计划多次关联
request.setTestPlanId(repeatCaseTestPlan.getId());
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), FUNCTIONAL_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE), FUNCTIONAL_CASES.size() * 1);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_CASE_ASSOCIATION, request);
returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), FUNCTIONAL_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE), FUNCTIONAL_CASES.size() * 2);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_CASE_ASSOCIATION, request);
returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
//同时测试名称排序
request.setOrderColumn("name");
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), FUNCTIONAL_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE), FUNCTIONAL_CASES.size() * 3);
request.setOrderByAsc(false);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), FUNCTIONAL_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE), FUNCTIONAL_CASES.size() * 4);
//反例 测试计划ID为空
request.setTestPlanId(null);
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request).andExpect(status().isBadRequest());
//反例 测试计划不存在
request.setTestPlanId(IDGenerator.nextStr());
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request).andExpect(status().is5xxServerError());
//测试权限
request.setTestPlanId(simpleTestPlan.getId());
this.requestPostPermissionTest(PermissionConstants.TEST_PLAN_READ_ASSOCIATION, URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION, request);
LOG_CHECK_LIST.add(
new CheckLogModel(simpleTestPlan.getId(), OperationLogType.ADD, URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION)
);
LOG_CHECK_LIST.add(
new CheckLogModel(repeatCaseTestPlan.getId(), OperationLogType.ADD, URL_POST_RESOURCE_FUNCTIONAL_CASE_ASSOCIATION)
);
}
@Test
@ -1059,11 +1015,10 @@ public class TestPlanTests extends BaseTest {
this.testPlanAssociationFunctionCase();
}
List<TestPlanFunctionalCase> funcList = testPlanTestService.selectTestPlanFunctionalCaseByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertTrue(funcList.size() >= FUNCTIONAL_CASES.size() * 4);
//将第80个移动到第一位之前
//将第30个移动到第一位之前
ResourceSortRequest request = new ResourceSortRequest();
request.setTestPlanId(repeatCaseTestPlan.getId());
request.setDragNodeId(funcList.get(79).getId());
request.setDragNodeId(funcList.get(29).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(-1);
@ -1078,14 +1033,14 @@ public class TestPlanTests extends BaseTest {
TestPlanResourceSortResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class);
Assertions.assertEquals(response.getSortNodeNum(), 1);
funcList = testPlanTestService.selectTestPlanFunctionalCaseByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDropNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDragNodeId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDragNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDropNodeId());
LOG_CHECK_LIST.add(
new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT)
);
//将这时的第80个放到第一位之后
request.setDragNodeId(funcList.get(79).getId());
//将这时的第30个放到第一位之后
request.setDragNodeId(funcList.get(29).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(1);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request);
@ -1100,8 +1055,8 @@ public class TestPlanTests extends BaseTest {
);
//再将这时的第80个放到第一位之后,但是第一个的pos为2检查能否触发ref操作
request.setDragNodeId(funcList.get(79).getId());
//再将这时的第30个放到第一位之后,但是第一个的pos为2检查能否触发ref操作
request.setDragNodeId(funcList.get(29).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(-1);
testPlanTestService.setResourcePos(funcList.get(0).getId(), TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE, 2);
@ -1127,14 +1082,14 @@ public class TestPlanTests extends BaseTest {
request.setDragNodeId(null);
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError());
//反例目标节点不存在
request.setDragNodeId(funcList.get(79).getId());
request.setDragNodeId(funcList.get(29).getId());
request.setDropNodeId(null);
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError());
//反例 节点重复
request.setDropNodeId(request.getDragNodeId());
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError());
//反例 dropPosition取值范围不对
request.setDragNodeId(funcList.get(79).getId());
request.setDragNodeId(funcList.get(29).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(0);
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError());
@ -1146,347 +1101,6 @@ public class TestPlanTests extends BaseTest {
}
@Test
@Order(31)
public void testPlanAssociationApiTestCase() throws Exception {
this.preliminaryTestPlan();
//创建20个功能测试用例
API_TEST_CASES.addAll(testPlanTestService.createApiCases(20, project.getId()));
//测试不开启用例重复的测试计划多次关联
TestPlanAssociationRequest request = new TestPlanAssociationRequest();
request.setTestPlanId(simpleTestPlan.getId());
request.setSelectIds(API_TEST_CASES.stream().map(ApiTestCase::getId).collect(Collectors.toList()));
MvcResult result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_ASSOCIATION, request);
ResultHolder resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
TestPlanAssociationResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_TEST_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_CASE), API_TEST_CASES.size());
//先测试一下没有开启模块时能否使用
testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "apiTest");
this.requestPost(URL_POST_RESOURCE_API_CASE_ASSOCIATION, request).andExpect(status().is5xxServerError());
//恢复
testPlanTestService.resetProjectModule(project, PROJECT_MODULE);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), 0);
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_CASE), API_TEST_CASES.size());
//测试开启用例重复的测试计划多次关联
request.setTestPlanId(repeatCaseTestPlan.getId());
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_TEST_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_CASE), API_TEST_CASES.size() * 1);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_TEST_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_CASE), API_TEST_CASES.size() * 2);
//同时测试名称排序
request.setOrderColumn("name");
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_TEST_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_CASE), API_TEST_CASES.size() * 3);
request.setOrderByAsc(false);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_TEST_CASES.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_CASE), API_TEST_CASES.size() * 4);
//反例 测试计划ID为空
request.setTestPlanId(null);
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().isBadRequest());
//反例 测试计划不存在
request.setTestPlanId(IDGenerator.nextStr());
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError());
//测试权限
request.setTestPlanId(simpleTestPlan.getId());
this.requestPostPermissionTest(PermissionConstants.TEST_PLAN_READ_ASSOCIATION, URL_POST_RESOURCE_API_CASE_ASSOCIATION, request);
LOG_CHECK_LIST.add(
new CheckLogModel(simpleTestPlan.getId(), OperationLogType.ADD, URL_POST_RESOURCE_API_CASE_ASSOCIATION)
);
LOG_CHECK_LIST.add(
new CheckLogModel(repeatCaseTestPlan.getId(), OperationLogType.ADD, URL_POST_RESOURCE_API_CASE_ASSOCIATION)
);
}
@Test
@Order(32)
public void testPlanApiCaseSort() throws Exception {
if (API_TEST_CASES.size() == 0) {
this.testPlanAssociationFunctionCase();
}
List<TestPlanApiCase> funcList = testPlanTestService.selectTestPlanApiCaseByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertTrue(funcList.size() >= API_TEST_CASES.size() * 4);
//将第80个移动到第一位之前
ResourceSortRequest request = new ResourceSortRequest();
request.setTestPlanId(repeatCaseTestPlan.getId());
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(-1);
//先测试一下没有开启模块时能否使用
testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "apiTest");
this.requestPost(URL_POST_RESOURCE_API_CASE_SORT, request).andExpect(status().is5xxServerError());
//恢复
testPlanTestService.resetProjectModule(project, PROJECT_MODULE);
MvcResult result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_SORT, request);
ResultHolder resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
TestPlanResourceSortResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class);
Assertions.assertEquals(response.getSortNodeNum(), 1);
funcList = testPlanTestService.selectTestPlanApiCaseByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDragNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDropNodeId());
LOG_CHECK_LIST.add(
new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_API_CASE_SORT)
);
//将这时的第80个放到第一位之后
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(1);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_SORT, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class);
Assertions.assertEquals(response.getSortNodeNum(), 1);
funcList = testPlanTestService.selectTestPlanApiCaseByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDropNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDragNodeId());
LOG_CHECK_LIST.add(
new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_API_CASE_SORT)
);
//再将这时的第80个放到第一位之前,但是第一个的pos为2检查能否触发ref操作
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(-1);
testPlanTestService.setResourcePos(funcList.get(0).getId(), TestPlanResourceConstants.RESOURCE_API_CASE, 2);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_CASE_SORT, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class);
Assertions.assertEquals(response.getSortNodeNum(), 1);
funcList = testPlanTestService.selectTestPlanApiCaseByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDragNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDropNodeId());
LOG_CHECK_LIST.add(
new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_API_CASE_SORT)
);
//反例测试计划为空
request.setTestPlanId(null);
this.requestPost(URL_POST_RESOURCE_API_CASE_SORT, request).andExpect(status().isBadRequest());
//反例 测试计划不存在
request.setTestPlanId(IDGenerator.nextStr());
this.requestPost(URL_POST_RESOURCE_API_CASE_SORT, request).andExpect(status().is5xxServerError());
//反例拖拽的节点不存在
request.setTestPlanId(repeatCaseTestPlan.getId());
request.setDragNodeId(null);
this.requestPost(URL_POST_RESOURCE_API_CASE_SORT, request).andExpect(status().is5xxServerError());
//反例目标节点不存在
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(null);
this.requestPost(URL_POST_RESOURCE_API_CASE_SORT, request).andExpect(status().is5xxServerError());
//反例 节点重复
request.setDropNodeId(request.getDragNodeId());
this.requestPost(URL_POST_RESOURCE_API_CASE_SORT, request).andExpect(status().is5xxServerError());
//反例 dropPosition取值范围不对
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(0);
this.requestPost(URL_POST_RESOURCE_API_CASE_SORT, request).andExpect(status().is5xxServerError());
//测试权限
request.setDropPosition(1);
this.requestPostPermissionTest(PermissionConstants.TEST_PLAN_READ_UPDATE, URL_POST_RESOURCE_API_CASE_SORT, request);
}
@Test
@Order(41)
public void testPlanAssociationApiScenario() throws Exception {
if (ObjectUtils.anyNull(simpleTestPlan, repeatCaseTestPlan)) {
this.testPlanAddTest();
}
//创建20个功能测试用例
API_SCENARIOS.addAll(testPlanTestService.createApiScenario(20, project.getId()));
//测试不开启用例重复的测试计划多次关联
TestPlanAssociationRequest request = new TestPlanAssociationRequest();
request.setTestPlanId(simpleTestPlan.getId());
request.setSelectIds(API_SCENARIOS.stream().map(ApiScenario::getId).collect(Collectors.toList()));
MvcResult result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request);
ResultHolder resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
TestPlanAssociationResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_SCENARIOS.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_SCENARIO), API_SCENARIOS.size());
//先测试一下没有开启模块时能否使用
testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "apiTest");
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request).andExpect(status().is5xxServerError());
//恢复
testPlanTestService.resetProjectModule(project, PROJECT_MODULE);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), 0);
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_SCENARIO), API_SCENARIOS.size());
//测试开启用例重复的测试计划多次关联
request.setTestPlanId(repeatCaseTestPlan.getId());
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_SCENARIOS.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_SCENARIO), API_SCENARIOS.size() * 1);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_SCENARIOS.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_SCENARIO), API_SCENARIOS.size() * 2);
//同时测试名称排序
request.setOrderColumn("name");
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_SCENARIOS.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_SCENARIO), API_SCENARIOS.size() * 3);
request.setOrderByAsc(false);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanAssociationResponse.class);
Assertions.assertEquals(response.getAssociationCount(), API_SCENARIOS.size());
Assertions.assertEquals(testPlanTestService.countResource(request.getTestPlanId(), TestPlanResourceConstants.RESOURCE_API_SCENARIO), API_SCENARIOS.size() * 4);
//反例 测试计划ID为空
request.setTestPlanId(null);
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request).andExpect(status().isBadRequest());
//反例 测试计划不存在
request.setTestPlanId(IDGenerator.nextStr());
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request).andExpect(status().is5xxServerError());
//测试权限
request.setTestPlanId(simpleTestPlan.getId());
this.requestPostPermissionTest(PermissionConstants.TEST_PLAN_READ_ASSOCIATION, URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION, request);
LOG_CHECK_LIST.add(
new CheckLogModel(simpleTestPlan.getId(), OperationLogType.ADD, URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION)
);
LOG_CHECK_LIST.add(
new CheckLogModel(repeatCaseTestPlan.getId(), OperationLogType.ADD, URL_POST_RESOURCE_API_SCENARIO_ASSOCIATION)
);
}
@Test
@Order(42)
public void testPlanApiScenarioSort() throws Exception {
if (API_SCENARIOS.size() == 0) {
this.testPlanAssociationFunctionCase();
}
List<TestPlanApiScenario> funcList = testPlanTestService.selectTestPlanApiScenarioByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertTrue(funcList.size() >= API_SCENARIOS.size() * 4);
//将第80个移动到第一位之前
ResourceSortRequest request = new ResourceSortRequest();
request.setTestPlanId(repeatCaseTestPlan.getId());
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(-1);
//先测试一下没有开启模块时能否使用
testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "apiTest");
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_SORT, request).andExpect(status().is5xxServerError());
//恢复
testPlanTestService.resetProjectModule(project, PROJECT_MODULE);
MvcResult result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_SORT, request);
ResultHolder resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
TestPlanResourceSortResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class);
Assertions.assertEquals(response.getSortNodeNum(), 1);
funcList = testPlanTestService.selectTestPlanApiScenarioByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDragNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDropNodeId());
LOG_CHECK_LIST.add(
new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_API_SCENARIO_SORT)
);
//将这时的第80个放到第一位之后
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(1);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_SORT, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class);
Assertions.assertEquals(response.getSortNodeNum(), 1);
funcList = testPlanTestService.selectTestPlanApiScenarioByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDropNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDragNodeId());
LOG_CHECK_LIST.add(
new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_API_SCENARIO_SORT)
);
//再将这时的第80个放到第一位之后,但是第一个的pos为2检查能否触发ref操作
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(-1);
testPlanTestService.setResourcePos(funcList.get(0).getId(), TestPlanResourceConstants.RESOURCE_API_SCENARIO, 2);
result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_SORT, request);
resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class);
Assertions.assertEquals(response.getSortNodeNum(), 1);
funcList = testPlanTestService.selectTestPlanApiScenarioByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDragNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDropNodeId());
LOG_CHECK_LIST.add(
new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_API_SCENARIO_SORT)
);
//反例测试计划为空
request.setTestPlanId(null);
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_SORT, request).andExpect(status().isBadRequest());
//反例 测试计划不存在
request.setTestPlanId(IDGenerator.nextStr());
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_SORT, request).andExpect(status().is5xxServerError());
//反例拖拽的节点不存在
request.setTestPlanId(repeatCaseTestPlan.getId());
request.setDragNodeId(null);
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_SORT, request).andExpect(status().is5xxServerError());
//反例目标节点不存在
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(null);
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_SORT, request).andExpect(status().is5xxServerError());
//反例 节点重复
request.setDropNodeId(request.getDragNodeId());
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_SORT, request).andExpect(status().is5xxServerError());
//反例 dropPosition取值范围不对
request.setDragNodeId(funcList.get(79).getId());
request.setDropNodeId(funcList.get(0).getId());
request.setDropPosition(0);
this.requestPost(URL_POST_RESOURCE_API_SCENARIO_SORT, request).andExpect(status().is5xxServerError());
//测试权限
request.setDropPosition(1);
this.requestPostPermissionTest(PermissionConstants.TEST_PLAN_READ_UPDATE, URL_POST_RESOURCE_API_SCENARIO_SORT, request);
}
@Test
@Order(91)
public void moveTest() throws Exception {
@ -1871,7 +1485,7 @@ public class TestPlanTests extends BaseTest {
testPlanModuleService.deleteModule(new ArrayList<>(), project.getId(), null, null, null);
//service层判断测试删除项目
// testPlanModuleService.deleteResources(project.getId());
// testPlanModuleService.deleteResources(project.getId());
//判断权限
this.requestGetPermissionTest(PermissionConstants.TEST_PLAN_MODULE_READ_DELETE, (String.format(URL_GET_MODULE_DELETE, IDGenerator.nextNum())));
@ -2184,8 +1798,8 @@ public class TestPlanTests extends BaseTest {
TestPlanBatchRequest request = new TestPlanBatchRequest();
request.setProjectId("123");
request.setType("ALL");
request.setSelectAll(true);
request.setModuleId("2");
request.setSelectIds(Arrays.asList("wx_test_plan_id_1", "wx_test_plan_id_2"));
this.requestPostWithOkAndReturn(URL_TEST_PLAN_BATCH_COPY, request);
@ -2197,8 +1811,8 @@ public class TestPlanTests extends BaseTest {
TestPlanBatchRequest request = new TestPlanBatchRequest();
request.setProjectId("123");
request.setType("ALL");
request.setSelectAll(true);
request.setModuleId("3");
request.setSelectIds(Arrays.asList("wx_test_plan_id_3","wx_test_plan_id_4"));
this.requestPostWithOkAndReturn(URL_TEST_PLAN_BATCH_MOVE, request);
@ -2217,4 +1831,15 @@ public class TestPlanTests extends BaseTest {
this.requestPostWithOkAndReturn(URL_TEST_PLAN_BATCH_ARCHIVED, request);
}
@Test
@Order(305)
public void testAssociation() throws Exception {
TestPlanAssociationRequest request = new TestPlanAssociationRequest();
request.setTestPlanId("wx_test_plan_id_1");
this.requestPostWithOkAndReturn(URL_POST_RESOURCE_CASE_ASSOCIATION, request);
request.setFunctionalSelectIds(Arrays.asList("my_test_1", "my_test_2", "my_test_3"));
this.requestPostWithOkAndReturn(URL_POST_RESOURCE_CASE_ASSOCIATION, request);
}
}

View File

@ -32,3 +32,11 @@ VALUES
INSERT INTO `test_plan_allocation`(`id`, `test_plan_id`, `run_mode_config`)
VALUES
('1', 'wx_test_plan_id_1', '111');
INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time)
VALUES
('my_test_1', 1, '1', '123', '100001', '1111', 'UN_REVIEWED', NULL, 'TEXT', 55000, 'v3.0.0', 'TEST_FUNCTIONAL_MINDER_CASE_ID_7', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('my_test_2', 2, '1', '123', '100001', '2222', 'UN_REVIEWED', NULL, 'TEXT', 55000, 'v3.0.0', 'TEST_FUNCTIONAL_MINDER_CASE_ID_7', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('my_test_3', 3, 'root', '123', '100001', '3333', 'UN_REVIEWED', NULL, 'TEXT', 55000, 'v3.0.0', 'TEST_FUNCTIONAL_MINDER_CASE_ID_7', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL);