feat(测试计划): 接口用例批量取消关联用例
This commit is contained in:
parent
65a2d5570d
commit
8406e85963
|
@ -2,7 +2,7 @@ package io.metersphere.plan.controller;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
||||||
|
@ -75,19 +75,31 @@ public class TestPlanApiCaseController {
|
||||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
|
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
|
||||||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||||
public TestPlanAssociationResponse disassociate(@Validated @RequestBody TestPlanDisassociationRequest request) {
|
public TestPlanAssociationResponse disassociate(@Validated @RequestBody TestPlanDisassociationRequest request) {
|
||||||
BasePlanCaseBatchRequest batchRequest = new BasePlanCaseBatchRequest();
|
TestPlanApiCaseBatchRequest batchRequest = new TestPlanApiCaseBatchRequest();
|
||||||
batchRequest.setTestPlanId(request.getTestPlanId());
|
batchRequest.setTestPlanId(request.getTestPlanId());
|
||||||
batchRequest.setSelectIds(List.of(request.getId()));
|
batchRequest.setSelectIds(List.of(request.getId()));
|
||||||
TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/association", HttpMethodConstants.POST.name()));
|
TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/disassociate", HttpMethodConstants.POST.name()));
|
||||||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/batch/disassociate")
|
||||||
|
@Operation(summary = "测试计划-计划详情-列表-批量取消关联用例")
|
||||||
|
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION)
|
||||||
|
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||||
|
public TestPlanAssociationResponse batchDisassociate(@Validated @RequestBody TestPlanApiCaseBatchRequest request) {
|
||||||
|
TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/batch/disassociate", HttpMethodConstants.POST.name()));
|
||||||
|
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/batch/update/executor")
|
@PostMapping("/batch/update/executor")
|
||||||
@Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人")
|
@Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人")
|
||||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
|
||||||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||||
@Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanApiCaseLogService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanApiCaseLogService.class)
|
||||||
public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiCaseUpdateRequest request) {
|
public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiCaseUpdateRequest request) {
|
||||||
testPlanApiCaseService.batchUpdateExecutor(request);
|
testPlanApiCaseService.batchUpdateExecutor(request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class TestPlanFunctionalCaseController {
|
||||||
BasePlanCaseBatchRequest batchRequest = new BasePlanCaseBatchRequest();
|
BasePlanCaseBatchRequest batchRequest = new BasePlanCaseBatchRequest();
|
||||||
batchRequest.setTestPlanId(request.getTestPlanId());
|
batchRequest.setTestPlanId(request.getTestPlanId());
|
||||||
batchRequest.setSelectIds(List.of(request.getId()));
|
batchRequest.setSelectIds(List.of(request.getId()));
|
||||||
TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/association", HttpMethodConstants.POST.name()));
|
TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/disassociate", HttpMethodConstants.POST.name()));
|
||||||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public class TestPlanFunctionalCaseController {
|
||||||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||||
public TestPlanAssociationResponse batchDisassociate(@Validated @RequestBody BasePlanCaseBatchRequest request) {
|
public TestPlanAssociationResponse batchDisassociate(@Validated @RequestBody BasePlanCaseBatchRequest request) {
|
||||||
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE));
|
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE));
|
||||||
TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/association", HttpMethodConstants.POST.name()));
|
TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/batch/disassociate", HttpMethodConstants.POST.name()));
|
||||||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package io.metersphere.plan.dto.request;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wx
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TestPlanApiCaseBatchRequest extends BasePlanCaseBatchRequest {
|
||||||
|
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "{api_definition.protocol.not_blank}")
|
||||||
|
private List<String> protocols;
|
||||||
|
}
|
|
@ -2,23 +2,18 @@ package io.metersphere.plan.dto.request;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wx
|
* @author wx
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class TestPlanApiCaseUpdateRequest extends BasePlanCaseBatchRequest {
|
public class TestPlanApiCaseUpdateRequest extends TestPlanApiCaseBatchRequest {
|
||||||
|
|
||||||
@Schema(description = "执行人id", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "执行人id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotBlank(message = "{test_plan.user_id.not_blank}")
|
@NotBlank(message = "{test_plan.user_id.not_blank}")
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
|
|
||||||
@NotEmpty(message = "{api_definition.protocol.not_blank}")
|
|
||||||
private List<String> protocols;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import io.metersphere.plan.domain.TestPlanApiCase;
|
||||||
import io.metersphere.plan.dto.ApiCaseModuleDTO;
|
import io.metersphere.plan.dto.ApiCaseModuleDTO;
|
||||||
import io.metersphere.plan.dto.ResourceSelectParam;
|
import io.metersphere.plan.dto.ResourceSelectParam;
|
||||||
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
||||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiRequest;
|
||||||
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
||||||
|
@ -49,7 +49,7 @@ public interface ExtTestPlanApiCaseMapper {
|
||||||
|
|
||||||
List<ApiCaseModuleDTO> selectBaseByProjectIdAndTestPlanId(@Param("testPlanId") String testPlanId);
|
List<ApiCaseModuleDTO> selectBaseByProjectIdAndTestPlanId(@Param("testPlanId") String testPlanId);
|
||||||
|
|
||||||
List<String> getIds(@Param("request") BasePlanCaseBatchRequest request, @Param("deleted") boolean deleted, @Param("protocols") List<String> protocols);
|
List<String> getIds(@Param("request") TestPlanApiCaseBatchRequest request, @Param("deleted") boolean deleted);
|
||||||
|
|
||||||
void batchUpdateExecutor(@Param("ids") List<String> ids, @Param("userId") String userId);
|
void batchUpdateExecutor(@Param("ids") List<String> ids, @Param("userId") String userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -599,9 +599,9 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<sql id="queryWhereConditionByBatchQueryRequest">
|
<sql id="queryWhereConditionByBatchQueryRequest">
|
||||||
<if test="protocols != null and protocols.size() > 0">
|
<if test="request.protocols != null and request.protocols.size() > 0">
|
||||||
and a.protocol in
|
and a.protocol in
|
||||||
<foreach collection="protocols" item="protocol" separator="," open="(" close=")">
|
<foreach collection="request.protocols" item="protocol" separator="," open="(" close=")">
|
||||||
#{protocol}
|
#{protocol}
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class TestPlanApiCaseLogService {
|
||||||
private ApiTestCaseMapper apiTestCaseMapper;
|
private ApiTestCaseMapper apiTestCaseMapper;
|
||||||
|
|
||||||
public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) {
|
public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) {
|
||||||
List<String> ids = testPlanApiCaseService.doSelectIds(request, request.getProtocols());
|
List<String> ids = testPlanApiCaseService.doSelectIds(request);
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||||
example.createCriteria().andIdIn(ids);
|
example.createCriteria().andIdIn(ids);
|
||||||
|
|
|
@ -12,10 +12,7 @@ import io.metersphere.plan.domain.TestPlanApiCaseExample;
|
||||||
import io.metersphere.plan.dto.ApiCaseModuleDTO;
|
import io.metersphere.plan.dto.ApiCaseModuleDTO;
|
||||||
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
|
||||||
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
|
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
|
||||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
import io.metersphere.plan.dto.request.*;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiRequest;
|
|
||||||
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
|
||||||
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
||||||
import io.metersphere.plan.mapper.ExtTestPlanApiCaseMapper;
|
import io.metersphere.plan.mapper.ExtTestPlanApiCaseMapper;
|
||||||
|
@ -324,12 +321,13 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
* @param logInsertModule
|
* @param logInsertModule
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TestPlanAssociationResponse disassociate(BasePlanCaseBatchRequest request, LogInsertModule logInsertModule) {
|
public TestPlanAssociationResponse disassociate(TestPlanApiCaseBatchRequest request, LogInsertModule logInsertModule) {
|
||||||
|
List<String> selectIds = doSelectIds(request);
|
||||||
return super.disassociate(
|
return super.disassociate(
|
||||||
TestPlanResourceConstants.RESOURCE_API_CASE,
|
TestPlanResourceConstants.RESOURCE_API_CASE,
|
||||||
request,
|
request,
|
||||||
logInsertModule,
|
logInsertModule,
|
||||||
request.getSelectIds(),
|
selectIds,
|
||||||
this::deleteTestPlanResource);
|
this::deleteTestPlanResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,9 +339,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> doSelectIds(BasePlanCaseBatchRequest request, List<String> protocols) {
|
public List<String> doSelectIds(TestPlanApiCaseBatchRequest request) {
|
||||||
if (request.isSelectAll()) {
|
if (request.isSelectAll()) {
|
||||||
List<String> ids = extTestPlanApiCaseMapper.getIds(request, false, protocols);
|
List<String> ids = extTestPlanApiCaseMapper.getIds(request, false);
|
||||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||||
ids.removeAll(request.getExcludeIds());
|
ids.removeAll(request.getExcludeIds());
|
||||||
}
|
}
|
||||||
|
@ -360,7 +358,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
* @param request
|
* @param request
|
||||||
*/
|
*/
|
||||||
public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) {
|
public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) {
|
||||||
List<String> ids = doSelectIds(request, request.getProtocols());
|
List<String> ids = doSelectIds(request);
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
extTestPlanApiCaseMapper.batchUpdateExecutor(ids, request.getUserId());
|
extTestPlanApiCaseMapper.batchUpdateExecutor(ids, request.getUserId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.plan.controller;
|
package io.metersphere.plan.controller;
|
||||||
|
|
||||||
|
import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest;
|
||||||
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
import io.metersphere.plan.dto.request.TestPlanDisassociationRequest;
|
||||||
|
@ -26,6 +27,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
|
||||||
public static final String API_CASE_TREE_COUNT = "/test-plan/api/case/module/count";
|
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_TREE_MODULE_TREE = "/test-plan/api/case/tree/";
|
||||||
public static final String API_CASE_DISASSOCIATE = "/test-plan/api/case/disassociate";
|
public static final String API_CASE_DISASSOCIATE = "/test-plan/api/case/disassociate";
|
||||||
|
public static final String API_CASE_BATCH_DISASSOCIATE = "/test-plan/api/case/batch/disassociate";
|
||||||
public static final String API_CASE_BATCH_UPDATE_EXECUTOR_URL = "/test-plan/api/case/batch/update/executor";
|
public static final String API_CASE_BATCH_UPDATE_EXECUTOR_URL = "/test-plan/api/case/batch/update/executor";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -104,4 +106,19 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
|
||||||
request.setSelectIds(List.of("wxxx_1"));
|
request.setSelectIds(List.of("wxxx_1"));
|
||||||
this.requestPostWithOk(API_CASE_BATCH_UPDATE_EXECUTOR_URL, request);
|
this.requestPostWithOk(API_CASE_BATCH_UPDATE_EXECUTOR_URL, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(6)
|
||||||
|
public void testApiCaseBatchDisassociate() throws Exception {
|
||||||
|
TestPlanApiCaseBatchRequest request = new TestPlanApiCaseBatchRequest();
|
||||||
|
request.setTestPlanId("wxxx_2");
|
||||||
|
request.setProtocols(List.of("HTTP"));
|
||||||
|
request.setSelectAll(true);
|
||||||
|
MvcResult mvcResult = this.requestPostWithOkAndReturn(API_CASE_BATCH_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