feat(接口测试): 添加场景查询跨项目信息接口

This commit is contained in:
AgAngle 2024-03-29 15:20:49 +08:00 committed by 刘瑞斌
parent 04c02be0d0
commit b8364cc042
5 changed files with 85 additions and 8 deletions

View File

@ -14,6 +14,7 @@ import io.metersphere.api.service.ApiValidateService;
import io.metersphere.api.service.scenario.ApiScenarioLogService;
import io.metersphere.api.service.scenario.ApiScenarioNoticeService;
import io.metersphere.api.service.scenario.ApiScenarioService;
import io.metersphere.project.domain.Project;
import io.metersphere.project.service.FileModuleService;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
@ -130,8 +131,8 @@ public class ApiScenarioController {
@Operation(summary = "接口测试-接口场景管理-获取场景详情")
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ)
@CheckOwner(resourceId = "#scenarioId", resourceType = "api_scenario")
public ApiScenarioDetail get(@PathVariable String scenarioId) {
return apiScenarioService.get(scenarioId);
public ApiScenarioDetailDTO getApiScenarioDetailDTO(@PathVariable String scenarioId) {
return apiScenarioService.getApiScenarioDetailDTO(scenarioId, SessionUtils.getUserId());
}
@GetMapping("/step/get/{stepId}")
@ -141,6 +142,12 @@ public class ApiScenarioController {
return apiScenarioService.getStepDetail(stepId);
}
@GetMapping("/step/project-ifo/{projectId}")
@Operation(summary = "接口测试-接口场景管理-获取步骤的所属项目信息")
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ)
public Project getStepResourceProjectInfo(@PathVariable String projectId) {
return apiScenarioService.getStepResourceProjectInfo(projectId);
}
//需求补充回收站里的相关操作都不需要发通知
@GetMapping("/recover/{id}")

View File

@ -0,0 +1,16 @@
package io.metersphere.api.dto.scenario;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class ApiScenarioDetailDTO extends ApiScenarioDetail {
@Schema(description = "创建人名称")
private String createUserName;
@Schema(description = "更新人名称")
private String updateUserName;
@Schema(description = "当前用户是否关注")
private Boolean follow = false;
}

View File

@ -1868,6 +1868,22 @@ public class ApiScenarioService extends MoveNodeService {
apiScenarioMapper.updateByPrimaryKeySelective(update);
}
public ApiScenarioDetailDTO getApiScenarioDetailDTO(String scenarioId, String userId) {
ApiScenarioDetail apiScenarioDetail = get(scenarioId);
ApiScenarioDetailDTO apiScenarioDetailDTO = BeanUtils.copyBean(new ApiScenarioDetailDTO(), apiScenarioDetail);
Map<String, String> userNameMap = userLoginService.getUserNameMap(List.of(apiScenarioDetail.getCreateUser(), apiScenarioDetail.getUpdateUser()));
apiScenarioDetailDTO.setCreateUserName(userNameMap.get(apiScenarioDetail.getCreateUser()));
apiScenarioDetailDTO.setUpdateUserName(userNameMap.get(apiScenarioDetail.getUpdateUser()));
// 设置是否关注
ApiScenarioFollowerExample followerExample = new ApiScenarioFollowerExample();
followerExample.createCriteria().andApiScenarioIdEqualTo(scenarioId);
followerExample.createCriteria().andUserIdEqualTo(userId);
List<ApiScenarioFollower> followers = apiScenarioFollowerMapper.selectByExample(followerExample);
apiScenarioDetailDTO.setFollow(CollectionUtils.isNotEmpty(followers));
return apiScenarioDetailDTO;
}
public ApiScenarioDetail get(String scenarioId) {
ApiScenario apiScenario = checkResourceExist(scenarioId);
ApiScenarioDetail apiScenarioDetail = BeanUtils.copyBean(new ApiScenarioDetail(), apiScenario);
@ -2559,4 +2575,15 @@ public class ApiScenarioService extends MoveNodeService {
public List<ReferenceDTO> getReference(ReferenceRequest request) {
return extApiDefinitionMapper.getReference(request);
}
public Project getStepResourceProjectInfo(String projectId) {
Project project = projectMapper.selectByPrimaryKey(projectId);
if (project == null) {
return null;
}
Project projectInfo = new Project();
projectInfo.setId(project.getId());
projectInfo.setName(project.getName());
return projectInfo;
}
}

View File

@ -11,10 +11,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.type.CollectionType;
import io.metersphere.api.dto.request.MsCommonElement;
import io.metersphere.api.dto.request.controller.MsConstantTimerController;
import io.metersphere.api.dto.request.controller.MsIfController;
import io.metersphere.api.dto.request.controller.MsLoopController;
import io.metersphere.api.dto.request.controller.MsOnceOnlyController;
import io.metersphere.api.dto.request.controller.*;
import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.sdk.exception.MSException;
@ -42,6 +39,7 @@ public class ApiDataUtils {
namedTypes.add(new NamedType(MsLoopController.class, MsLoopController.class.getSimpleName()));
namedTypes.add(new NamedType(MsOnceOnlyController.class, MsOnceOnlyController.class.getSimpleName()));
namedTypes.add(new NamedType(MsConstantTimerController.class, MsConstantTimerController.class.getSimpleName()));
namedTypes.add(new NamedType(MsScriptElement.class, MsScriptElement.class.getSimpleName()));
setObjectMapper(objectMapper);
namedTypes.forEach(objectMapper::registerSubtypes);
}

View File

@ -30,10 +30,12 @@ import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.api.assertion.MsResponseCodeAssertion;
import io.metersphere.project.api.assertion.MsScriptAssertion;
import io.metersphere.project.domain.Project;
import io.metersphere.project.domain.ProjectVersion;
import io.metersphere.project.dto.environment.variables.CommonVariables;
import io.metersphere.project.dto.filemanagement.request.FileUploadRequest;
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.project.mapper.ProjectVersionMapper;
import io.metersphere.project.service.FileMetadataService;
import io.metersphere.sdk.constants.*;
@ -57,6 +59,7 @@ import io.metersphere.system.dto.request.PluginUpdateRequest;
import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.ScheduleMapper;
import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.service.PluginService;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator;
@ -97,6 +100,7 @@ public class ApiScenarioControllerTests extends BaseTest {
protected static final String UPLOAD_TEMP_FILE = "upload/temp/file";
protected static final String DELETE_TO_GC = "delete-to-gc/{0}";
protected static final String STEP_GET = "step/get/{0}";
protected static final String STEP_PROJECT_INFO = "step/project-ifo/{0}";
protected static final String DEBUG = "debug";
protected static final String RUN = "run/{0}";
protected static final String RUN_REAL_TIME = "run/{0}?reportId={1}";
@ -164,6 +168,10 @@ public class ApiScenarioControllerTests extends BaseTest {
private BaseFileManagementTestService baseFileManagementTestService;
@Resource
private ApiCommonService apiCommonService;
@Resource
private ProjectMapper projectMapper;
@Resource
private UserMapper userMapper;
private static String fileMetadataId;
private static String localFileId;
@ -1174,12 +1182,18 @@ public class ApiScenarioControllerTests extends BaseTest {
@Order(7)
public void get() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(DEFAULT_GET, addApiScenario.getId());
ApiScenarioDetail apiScenarioDetail = getResultData(mvcResult, ApiScenarioDetail.class);
ApiScenarioDetailDTO apiScenarioDetail = getResultData(mvcResult, ApiScenarioDetailDTO.class);
Assertions.assertEquals(apiScenarioDetail.getCreateUserName(), userMapper.selectByPrimaryKey(apiScenarioDetail.getCreateUser()).getName());
Assertions.assertEquals(apiScenarioDetail.getUpdateUserName(), userMapper.selectByPrimaryKey(apiScenarioDetail.getUpdateUser()).getName());
Assertions.assertFalse(apiScenarioDetail.getFollow());
// 验证数据
asserGetApiScenarioSteps(this.addApiScenarioSteps, apiScenarioDetail.getSteps());
apiScenarioService.follow(anOtherAddApiScenario.getId(), "admin");
mvcResult = this.requestGetWithOkAndReturn(DEFAULT_GET, anOtherAddApiScenario.getId());
apiScenarioDetail = getResultData(mvcResult, ApiScenarioDetail.class);
apiScenarioDetail = getResultData(mvcResult, ApiScenarioDetailDTO.class);
Assertions.assertTrue(apiScenarioDetail.getFollow());
// 验证数据
Assertions.assertEquals(this.anOtherAddApiScenarioSteps.size(), apiScenarioDetail.getSteps().size());
// @@校验权限
@ -1201,6 +1215,21 @@ public class ApiScenarioControllerTests extends BaseTest {
requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, STEP_GET, addApiScenario.getId());
}
@Test
@Order(7)
public void getStepResourceProjectInfo() throws Exception {
MvcResult mvcResult = this.requestGetAndReturn(STEP_PROJECT_INFO, DEFAULT_PROJECT_ID);
Project project = getResultData(mvcResult, Project.class);
Assertions.assertEquals(project.getName(), projectMapper.selectByPrimaryKey(project.getId()).getName());
mvcResult = this.requestGetAndReturn(STEP_PROJECT_INFO, "tyuio");
project = getResultData(mvcResult, Project.class);
Assertions.assertNull(project);
// @@校验权限
requestGetPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, STEP_PROJECT_INFO, DEFAULT_PROJECT_ID);
}
private void requestGetStepDetail(List<? extends ApiScenarioStepCommonDTO> steps) throws Exception {
if (CollectionUtils.isEmpty(steps)) {
return;