fix(测试计划): 补充关联日志

This commit is contained in:
WangXu10 2024-06-14 16:44:43 +08:00 committed by Craftsman
parent 572b527b96
commit 7703a79d03
12 changed files with 158 additions and 47 deletions

View File

@ -165,7 +165,7 @@ public class CaseReviewLogService {
caseReview.getProjectId(),
null,
caseReview.getId(),
caseReview.getCreateUser(),
null,
OperationLogType.ASSOCIATE.name(),
OperationLogModule.CASE_REVIEW_DETAIL,
functionalCase.getName());

View File

@ -44,8 +44,7 @@ public class TestPlanCollectionMinderController {
}, logical = Logical.OR)
@CheckOwner(resourceId = "#request.planId", resourceType = "test_plan")
public void editMindTestPlanCase(@Validated @RequestBody TestPlanCollectionMinderEditRequest request) {
String userId = SessionUtils.getUserId();
testPlanCollectionMinderService.editMindTestPlanCase(request, userId);
testPlanCollectionMinderService.editMindTestPlanCase(request, SessionUtils.getUser());
}

View File

@ -684,8 +684,10 @@
<select id="selectApiCaseByDefinitionIds" resultType="io.metersphere.api.domain.ApiTestCase">
SELECT
api_test_case.id,
api_test_case.name,
api_test_case.api_definition_id,
api_test_case.environment_id
api_test_case.environment_id,
api_test_case.create_user
FROM
api_test_case
WHERE

View File

@ -36,6 +36,11 @@ 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.dto.sdk.SessionUser;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.service.UserLoginService;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.ServiceUtils;
@ -99,7 +104,8 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
private TestPlanConfigService testPlanConfigService;
@Resource
private ApiReportMapper apiReportMapper;
@Resource
private OperationLogService operationLogService;
@Override
public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -493,17 +499,20 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
}
@Override
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, String userId) {
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
List<TestPlanApiCase> testPlanApiCaseList = new ArrayList<>();
List<LogDTO> logDTOS = new ArrayList<>();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
//处理数据
handleApiData(collectionAssociates.get(AssociateCaseType.API), userId, testPlanApiCaseList, planId);
handleApiCaseData(collectionAssociates.get(AssociateCaseType.API_CASE), userId, testPlanApiCaseList, planId);
handleApiData(collectionAssociates.get(AssociateCaseType.API), user, testPlanApiCaseList, testPlan, logDTOS);
handleApiCaseData(collectionAssociates.get(AssociateCaseType.API_CASE), user, testPlanApiCaseList, testPlan, logDTOS);
if (CollectionUtils.isNotEmpty(testPlanApiCaseList)) {
testPlanApiCaseMapper.batchInsert(testPlanApiCaseList);
operationLogService.batchAdd(logDTOS);
}
}
private void handleApiCaseData(List<BaseCollectionAssociateRequest> apiCaseList, String userId, List<TestPlanApiCase> testPlanApiCaseList, String planId) {
private void handleApiCaseData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan, List<LogDTO> logDTOS) {
if (CollectionUtils.isNotEmpty(apiCaseList)) {
List<String> ids = apiCaseList.stream().flatMap(item -> item.getIds().stream()).toList();
ApiTestCaseExample example = new ApiTestCaseExample();
@ -513,22 +522,22 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
List<String> apiCaseIds = apiCase.getIds();
if (CollectionUtils.isNotEmpty(apiCaseIds)) {
List<ApiTestCase> apiTestCases = apiTestCaseList.stream().filter(item -> apiCaseIds.contains(item.getId())).collect(Collectors.toList());
buildTestPlanApiCase(planId, apiTestCases, apiCase.getCollectionId(), userId, testPlanApiCaseList);
buildTestPlanApiCase(testPlan, apiTestCases, apiCase.getCollectionId(), user, testPlanApiCaseList, logDTOS);
}
});
}
}
private void handleApiData(List<BaseCollectionAssociateRequest> apiCaseList, String userId, List<TestPlanApiCase> testPlanApiCaseList, String planId) {
private void handleApiData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan, List<LogDTO> logDTOS) {
if (CollectionUtils.isNotEmpty(apiCaseList)) {
List<String> ids = apiCaseList.stream().flatMap(item -> item.getIds().stream()).toList();
boolean isRepeat = testPlanConfigService.isRepeatCase(planId);
boolean isRepeat = testPlanConfigService.isRepeatCase(testPlan.getId());
List<ApiTestCase> apiTestCaseList = extTestPlanApiCaseMapper.selectApiCaseByDefinitionIds(ids, isRepeat);
apiCaseList.forEach(apiCase -> {
List<String> apiCaseIds = apiCase.getIds();
if (CollectionUtils.isNotEmpty(apiCaseIds)) {
List<ApiTestCase> apiTestCases = apiTestCaseList.stream().filter(item -> apiCaseIds.contains(item.getApiDefinitionId())).collect(Collectors.toList());
buildTestPlanApiCase(planId, apiTestCases, apiCase.getCollectionId(), userId, testPlanApiCaseList);
buildTestPlanApiCase(testPlan, apiTestCases, apiCase.getCollectionId(), user, testPlanApiCaseList, logDTOS);
}
});
}
@ -537,27 +546,44 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
/**
* 构建测试计划接口用例对象
*
* @param planId
* @param testPlan
* @param apiTestCases
* @param collectionId
* @param userId
* @param user
* @param testPlanApiCaseList
*/
private void buildTestPlanApiCase(String planId, List<ApiTestCase> apiTestCases, String collectionId, String userId, List<TestPlanApiCase> testPlanApiCaseList) {
private void buildTestPlanApiCase(TestPlan testPlan, List<ApiTestCase> apiTestCases, String collectionId, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, List<LogDTO> logDTOS) {
apiTestCases.forEach(apiTestCase -> {
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
testPlanApiCase.setId(IDGenerator.nextStr());
testPlanApiCase.setTestPlanCollectionId(collectionId);
testPlanApiCase.setTestPlanId(planId);
testPlanApiCase.setTestPlanId(testPlan.getId());
testPlanApiCase.setApiCaseId(apiTestCase.getId());
testPlanApiCase.setEnvironmentId(apiTestCase.getEnvironmentId());
testPlanApiCase.setCreateTime(System.currentTimeMillis());
testPlanApiCase.setCreateUser(userId);
testPlanApiCase.setCreateUser(user.getId());
testPlanApiCase.setPos(getNextOrder(collectionId));
testPlanApiCase.setExecuteUser(apiTestCase.getCreateUser());
testPlanApiCaseList.add(testPlanApiCase);
buildLog(logDTOS, testPlan, user, apiTestCase);
});
}
private void buildLog(List<LogDTO> logDTOS, TestPlan testPlan, SessionUser user, ApiTestCase apiTestCase) {
LogDTO dto = new LogDTO(
testPlan.getProjectId(),
user.getLastOrganizationId(),
testPlan.getId(),
user.getId(),
OperationLogType.ASSOCIATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("log.test_plan.api_case") + ":" + apiTestCase.getName());
dto.setHistory(true);
dto.setPath("/test-plan/mind/data/edit");
dto.setMethod(HttpMethodConstants.POST.name());
logDTOS.add(dto);
}
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.API_CASE.getKey())

View File

@ -37,6 +37,10 @@ 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.dto.sdk.SessionUser;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.service.UserLoginService;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.ServiceUtils;
@ -161,15 +165,17 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
}
@Override
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, String userId) {
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
List<TestPlanApiScenario> testPlanApiScenarioList = new ArrayList<>();
handleApiScenarioData(collectionAssociates.get(AssociateCaseType.API_SCENARIO), userId, testPlanApiScenarioList, planId);
List<LogDTO> logDTOS = new ArrayList<>();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
handleApiScenarioData(collectionAssociates.get(AssociateCaseType.API_SCENARIO), user, testPlanApiScenarioList, testPlan, logDTOS);
if (CollectionUtils.isNotEmpty(testPlanApiScenarioList)) {
testPlanApiScenarioMapper.batchInsert(testPlanApiScenarioList);
}
}
private void handleApiScenarioData(List<BaseCollectionAssociateRequest> apiScenarioList, String userId, List<TestPlanApiScenario> testPlanApiScenarioList, String planId) {
private void handleApiScenarioData(List<BaseCollectionAssociateRequest> apiScenarioList, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList, TestPlan testPlan, List<LogDTO> logDTOS) {
if (CollectionUtils.isNotEmpty(apiScenarioList)) {
List<String> ids = apiScenarioList.stream().flatMap(item -> item.getIds().stream()).toList();
ApiScenarioExample scenarioExample = new ApiScenarioExample();
@ -179,7 +185,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
List<String> apiScenarioIds = apiScenario.getIds();
if (CollectionUtils.isNotEmpty(apiScenarioIds)) {
List<ApiScenario> scenarios = apiScenarios.stream().filter(item -> apiScenarioIds.contains(item.getId())).collect(Collectors.toList());
buildTestPlanApiScenario(planId, scenarios, apiScenario.getCollectionId(), userId, testPlanApiScenarioList);
buildTestPlanApiScenario(testPlan, scenarios, apiScenario.getCollectionId(), user, testPlanApiScenarioList, logDTOS);
}
});
}
@ -188,28 +194,45 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
/**
* 构建测试计划场景用例对象
*
* @param planId
* @param testPlan
* @param scenarios
* @param collectionId
* @param userId
* @param user
* @param testPlanApiScenarioList
*/
private void buildTestPlanApiScenario(String planId, List<ApiScenario> scenarios, String collectionId, String userId, List<TestPlanApiScenario> testPlanApiScenarioList) {
private void buildTestPlanApiScenario(TestPlan testPlan, List<ApiScenario> scenarios, String collectionId, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList, List<LogDTO> logDTOS) {
scenarios.forEach(scenario -> {
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
testPlanApiScenario.setId(IDGenerator.nextStr());
testPlanApiScenario.setTestPlanId(planId);
testPlanApiScenario.setTestPlanId(testPlan.getId());
testPlanApiScenario.setApiScenarioId(scenario.getId());
testPlanApiScenario.setTestPlanCollectionId(collectionId);
testPlanApiScenario.setGrouped(scenario.getGrouped());
testPlanApiScenario.setEnvironmentId(scenario.getEnvironmentId());
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
testPlanApiScenario.setCreateUser(userId);
testPlanApiScenario.setCreateUser(user.getId());
testPlanApiScenario.setPos(getNextOrder(collectionId));
testPlanApiScenario.setExecuteUser(scenario.getCreateUser());
testPlanApiScenarioList.add(testPlanApiScenario);
buildLog(logDTOS, testPlan, user, scenario);
});
}
private void buildLog(List<LogDTO> logDTOS, TestPlan testPlan, SessionUser user, ApiScenario scenario) {
LogDTO dto = new LogDTO(
testPlan.getProjectId(),
user.getLastOrganizationId(),
testPlan.getId(),
user.getId(),
OperationLogType.ASSOCIATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("log.test_plan.api_scenario") + ":" + scenario.getName());
dto.setHistory(true);
dto.setPath("/test-plan/mind/data/edit");
dto.setMethod(HttpMethodConstants.POST.name());
logDTOS.add(dto);
}
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.SCENARIO_CASE.getKey())

View File

@ -11,6 +11,7 @@ import io.metersphere.plan.dto.response.TestPlanBugPageResponse;
import io.metersphere.plan.mapper.ExtTestPlanBugMapper;
import io.metersphere.plugin.platform.dto.SelectOption;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.mapper.BaseUserMapper;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
@ -119,7 +120,7 @@ public class TestPlanBugService extends TestPlanResourceService {
}
@Override
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates,String userId) {
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
// TODO: 暂不支持缺陷关联测试集
}

View File

@ -11,6 +11,7 @@ import io.metersphere.sdk.constants.CommonConstants;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
@ -240,14 +241,14 @@ public class TestPlanCollectionMinderService {
}
public void editMindTestPlanCase(TestPlanCollectionMinderEditRequest request, String userId) {
public void editMindTestPlanCase(TestPlanCollectionMinderEditRequest request, SessionUser user) {
Map<String, List<BaseCollectionAssociateRequest>> associateMap = new HashMap<>();
//处理新增与更新
dealEditList(request, userId, associateMap);
dealEditList(request, user.getId(), associateMap);
//处理关联关系
Map<String, TestPlanResourceService> beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class);
beansOfType.forEach((k, v) -> {
v.associateCollection(request.getPlanId(), associateMap, userId);
v.associateCollection(request.getPlanId(), associateMap, user);
});
}

View File

@ -11,6 +11,7 @@ import io.metersphere.bug.service.BugStatusService;
import io.metersphere.dto.BugProviderDTO;
import io.metersphere.functional.constants.CaseFileSourceType;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseExample;
import io.metersphere.functional.domain.FunctionalCaseModule;
import io.metersphere.functional.dto.*;
import io.metersphere.functional.mapper.FunctionalCaseMapper;
@ -42,11 +43,13 @@ import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.log.aspect.OperationLogAspect;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.ExtUserMapper;
import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.service.UserLoginService;
@ -114,6 +117,10 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
@Resource
private ExtUserMapper extUserMapper;
private static final String CASE_MODULE_COUNT_ALL = "all";
@Resource
private FunctionalCaseMapper functionalCaseMapper;
@Resource
private OperationLogService operationLogService;
@Override
public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) {
@ -727,42 +734,68 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
}
@Override
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, String userId) {
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
List<TestPlanFunctionalCase> testPlanFunctionalCaseList = new ArrayList<>();
List<BaseCollectionAssociateRequest> functionalList = collectionAssociates.get(AssociateCaseType.FUNCTIONAL);
List<LogDTO> logDTOS = new ArrayList<>();
if (CollectionUtils.isNotEmpty(functionalList)) {
functionalList.forEach(functional -> buildTestPlanFunctionalCase(planId, functional, userId, testPlanFunctionalCaseList));
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
functionalList.forEach(functional -> buildTestPlanFunctionalCase(testPlan, functional, user, testPlanFunctionalCaseList, logDTOS));
}
if (CollectionUtils.isNotEmpty(testPlanFunctionalCaseList)) {
testPlanFunctionalCaseMapper.batchInsert(testPlanFunctionalCaseList);
operationLogService.batchAdd(logDTOS);
}
}
/**
* 构建测试计划功能用例对象
*
* @param planId
* @param testPlan
* @param functional
* @param userId
* @param user
* @param testPlanFunctionalCaseList
*/
private void buildTestPlanFunctionalCase(String planId, BaseCollectionAssociateRequest functional, String userId, List<TestPlanFunctionalCase> testPlanFunctionalCaseList) {
private void buildTestPlanFunctionalCase(TestPlan testPlan, BaseCollectionAssociateRequest functional, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList, List<LogDTO> logDTOS) {
List<String> functionalIds = functional.getIds();
if (CollectionUtils.isNotEmpty(functionalIds)) {
FunctionalCaseExample example = new FunctionalCaseExample();
example.createCriteria().andIdIn(functionalIds);
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(example);
Map<String, FunctionalCase> collect = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, functionalCase -> functionalCase));
functionalIds.forEach(functionalId -> {
FunctionalCase functionalCase = collect.get(functionalId);
TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase();
testPlanFunctionalCase.setId(IDGenerator.nextStr());
testPlanFunctionalCase.setTestPlanCollectionId(functional.getCollectionId());
testPlanFunctionalCase.setTestPlanId(planId);
testPlanFunctionalCase.setTestPlanId(testPlan.getId());
testPlanFunctionalCase.setFunctionalCaseId(functionalId);
testPlanFunctionalCase.setCreateUser(userId);
testPlanFunctionalCase.setCreateUser(user.getId());
testPlanFunctionalCase.setCreateTime(System.currentTimeMillis());
testPlanFunctionalCase.setPos(getNextOrder(functional.getCollectionId()));
testPlanFunctionalCase.setExecuteUser(functionalCase.getCreateUser());
testPlanFunctionalCase.setLastExecResult(ExecStatus.PENDING.name());
testPlanFunctionalCaseList.add(testPlanFunctionalCase);
buildLog(logDTOS, testPlan, user, functionalCase);
});
}
}
private void buildLog(List<LogDTO> logDTOS, TestPlan testPlan, SessionUser user, FunctionalCase functionalCase) {
LogDTO dto = new LogDTO(
testPlan.getProjectId(),
user.getLastOrganizationId(),
testPlan.getId(),
user.getId(),
OperationLogType.ASSOCIATE.name(),
OperationLogModule.TEST_PLAN,
Translator.get("log.test_plan.functional_case") + ":" + functionalCase.getName());
dto.setHistory(true);
dto.setPath("/test-plan/mind/data/edit");
dto.setMethod(HttpMethodConstants.POST.name());
logDTOS.add(dto);
}
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.FUNCTIONAL_CASE.getKey())

View File

@ -9,6 +9,7 @@ import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.dto.sdk.SessionUser;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.transaction.annotation.Transactional;
@ -62,7 +63,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
* @param planId 计划ID
* @param collectionAssociates 测试集关联用例参数
*/
public abstract void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, String userId);
public abstract void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user);
/**
* 初始化旧的关联资源到默认测试集

View File

@ -26,18 +26,19 @@ import io.metersphere.plan.dto.response.TestPlanOperationResponse;
import io.metersphere.plan.mapper.TestPlanApiCaseMapper;
import io.metersphere.plan.service.TestPlanApiCaseService;
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.sdk.constants.ApiBatchRunMode;
import io.metersphere.sdk.constants.ApiExecuteResourceType;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.ReportStatus;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.dto.api.task.GetRunScriptRequest;
import io.metersphere.sdk.dto.api.task.TaskItem;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.dto.sdk.enums.MoveTypeEnum;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@ -50,6 +51,7 @@ import org.springframework.test.web.servlet.MvcResult;
import java.nio.charset.StandardCharsets;
import java.util.*;
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -254,7 +256,13 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
baseCollectionAssociateRequest.setIds(List.of("wxxx_api_1"));
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
collectionAssociates.put(AssociateCaseType.API, baseCollectionAssociateRequests);
testPlanApiCaseService.associateCollection("wxxx_2", collectionAssociates, "wx");
UserDTO userDTO = new UserDTO();
userDTO.setId(sessionId);
userDTO.setName("admin");
userDTO.setLastOrganizationId("wxx_1234");
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
testPlanApiCaseService.associateCollection("wxxx_2", collectionAssociates, user);
//api case
Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates1 = new HashMap<>();
@ -264,7 +272,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
baseCollectionAssociateRequest1.setIds(List.of("wxxx_api_case_1"));
baseCollectionAssociateRequests1.add(baseCollectionAssociateRequest1);
collectionAssociates1.put(AssociateCaseType.API_CASE, baseCollectionAssociateRequests1);
testPlanApiCaseService.associateCollection("wxxx_2", collectionAssociates1, "wx");
testPlanApiCaseService.associateCollection("wxxx_2", collectionAssociates1, user);
apiTestCase = initApiData();
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();

View File

@ -37,8 +37,11 @@ import io.metersphere.sdk.dto.api.task.TaskItem;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.dto.sdk.enums.MoveTypeEnum;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@ -269,7 +272,13 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
baseCollectionAssociateRequest.setIds(List.of("wxxx_api_scenario_1"));
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
collectionAssociates.put(AssociateCaseType.API_SCENARIO, baseCollectionAssociateRequests);
testPlanApiScenarioService.associateCollection("wxxx_plan_2", collectionAssociates, "wx");
UserDTO userDTO = new UserDTO();
userDTO.setId(sessionId);
userDTO.setName("admin");
userDTO.setLastOrganizationId("wxx_1234");
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
testPlanApiScenarioService.associateCollection("wxxx_plan_2", collectionAssociates, user);
}
@Test

View File

@ -23,6 +23,9 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.junit.jupiter.api.*;
@ -363,7 +366,12 @@ public class TestPlanCaseControllerTests extends BaseTest {
baseCollectionAssociateRequest.setIds(List.of("fc_1"));
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
collectionAssociates.put(AssociateCaseType.FUNCTIONAL, baseCollectionAssociateRequests);
testPlanFunctionalCaseService.associateCollection("plan_1", collectionAssociates, "wx");
UserDTO userDTO = new UserDTO();
userDTO.setId(sessionId);
userDTO.setName("admin");
userDTO.setLastOrganizationId("wxx_1234");
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
testPlanFunctionalCaseService.associateCollection("plan_1", collectionAssociates, user);
}
@Test