mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 12:09:13 +08:00
feat(接口测试): 增加回收站查询列表接口
This commit is contained in:
parent
7285248b72
commit
587e105a4f
@ -30,7 +30,7 @@ public class ApiDefinitionModuleController {
|
||||
@Operation(summary = "接口测试-接口管理-模块-查找模块")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
|
||||
public List<BaseTreeNode> getTree(@RequestBody @Validated ApiModuleRequest request) {
|
||||
return apiDefinitionModuleService.getTree(request);
|
||||
return apiDefinitionModuleService.getTree(request, false);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@ -66,6 +66,20 @@ public class ApiDefinitionModuleController {
|
||||
@Operation(summary = "接口测试-接口管理-模块-统计模块数量")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
|
||||
public Map<String, Long> moduleCount(@Validated @RequestBody ApiModuleRequest request) {
|
||||
return apiDefinitionModuleService.moduleCount(request);
|
||||
return apiDefinitionModuleService.moduleCount(request, false);
|
||||
}
|
||||
|
||||
@PostMapping("/trash/count")
|
||||
@Operation(summary = "接口测试-接口管理-模块-统计回收站模块数量")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
|
||||
public Map<String, Long> moduleCountTrash(@Validated @RequestBody ApiModuleRequest request) {
|
||||
return apiDefinitionModuleService.moduleCount(request, true);
|
||||
}
|
||||
|
||||
@PostMapping("/trash/tree")
|
||||
@Operation(summary = "接口测试-接口管理-模块-查找模块")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
|
||||
public List<BaseTreeNode> getTrashTree(@RequestBody @Validated ApiModuleRequest request) {
|
||||
return apiDefinitionModuleService.getTree(request, true);
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public class ApiTestCaseController {
|
||||
public Pager<List<ApiTestCaseDTO>> page(@Validated @RequestBody ApiTestCasePageRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc");
|
||||
return PageUtils.setPageInfo(page, apiTestCaseService.page(request));
|
||||
return PageUtils.setPageInfo(page, apiTestCaseService.page(request, false));
|
||||
}
|
||||
|
||||
@PostMapping("/batch/delete")
|
||||
@ -133,5 +133,13 @@ public class ApiTestCaseController {
|
||||
apiTestCaseService.batchEdit(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@PostMapping(value = "/trash/page")
|
||||
@Operation(summary = "接口测试-接口管理-接口用例-回收站-分页查询")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ)
|
||||
public Pager<List<ApiTestCaseDTO>> pageTrash(@Validated @RequestBody ApiTestCasePageRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc");
|
||||
return PageUtils.setPageInfo(page, apiTestCaseService.page(request, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ApiTestCaseAddRequest implements Serializable {
|
||||
@ -49,4 +50,8 @@ public class ApiTestCaseAddRequest implements Serializable {
|
||||
@Schema(description = "请求内容")
|
||||
@NotBlank
|
||||
private String request;
|
||||
|
||||
@Schema(description = "接口用例所需的所有文件资源ID")
|
||||
private List<String> fileIds;
|
||||
|
||||
}
|
||||
|
@ -83,4 +83,7 @@ public class ApiTestCaseDTO {
|
||||
|
||||
@Schema(description = "请求内容")
|
||||
private AbstractMsTestElement request;
|
||||
|
||||
@Schema(description = "接口用例所关联的文件ID列表,修改时需要作为参数传入")
|
||||
private List<String> fileIds;
|
||||
}
|
||||
|
@ -45,4 +45,15 @@ public class ApiTestCaseUpdateRequest implements Serializable {
|
||||
@NotBlank
|
||||
private String request;
|
||||
|
||||
@Schema(description = "接口用例所需的所有文件资源ID")
|
||||
private List<String> fileIds;
|
||||
|
||||
/**
|
||||
* 新上传的文件ID
|
||||
* 为了解决文件名称重复的问题,需要把文件和ID一一对应
|
||||
* 创建时先按ID创建目录,再把文件放入目录
|
||||
*/
|
||||
@Schema(description = "新上传的文件ID,与上传的文件顺序保持一致")
|
||||
private List<String> addFileIds;
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
<update id="deleteApiToGc">
|
||||
update api_definition
|
||||
set delete_user = #{userId},delete_time = #{time}, deleted = 1
|
||||
set delete_user = #{userId},delete_time = #{time}, deleted = 1 , module_id = 'root'
|
||||
where ref_id in
|
||||
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||
#{v}
|
||||
@ -39,7 +39,7 @@
|
||||
api_test_case t1
|
||||
LEFT JOIN api_report t2 ON t1.last_report_id = t2.id
|
||||
WHERE
|
||||
t1.project_id = #{projectId} and t1.deleted = 0
|
||||
t1.project_id = #{projectId} and t1.deleted = 0
|
||||
|
||||
GROUP BY
|
||||
t1.api_definition_id
|
||||
@ -55,7 +55,7 @@
|
||||
FROM api_definition
|
||||
WHERE project_id = #{projectId}
|
||||
ORDER BY pos DESC
|
||||
LIMIT 1;
|
||||
LIMIT 1;
|
||||
</select>
|
||||
|
||||
<select id="getIds" resultType="java.lang.String">
|
||||
@ -79,16 +79,13 @@
|
||||
group by ref_id
|
||||
</select>
|
||||
<select id="getApiDefinitionByRefId" resultType="io.metersphere.api.dto.definition.ApiDefinitionVersionDTO">
|
||||
SELECT
|
||||
id,
|
||||
`name`,
|
||||
version_id,
|
||||
ref_id,
|
||||
project_id
|
||||
FROM
|
||||
api_definition
|
||||
WHERE
|
||||
ref_id = #{refId}
|
||||
SELECT id,
|
||||
`name`,
|
||||
version_id,
|
||||
ref_id,
|
||||
project_id
|
||||
FROM api_definition
|
||||
WHERE ref_id = #{refId}
|
||||
</select>
|
||||
<select id="getTagsByIds" resultType="io.metersphere.api.domain.ApiDefinition">
|
||||
select id, tags from api_definition
|
||||
|
@ -27,9 +27,9 @@ public interface ExtApiDefinitionModuleMapper {
|
||||
|
||||
BaseModule selectModuleByParentIdAndPosOperator(NodeSortQueryParam nodeSortQueryParam);
|
||||
|
||||
List<ApiTreeNode> selectApiDataByRequest(@Param("request") ApiModuleRequest request);
|
||||
List<ApiTreeNode> selectApiDataByRequest(@Param("request") ApiModuleRequest request, @Param("deleted") boolean deleted);
|
||||
|
||||
List<ModuleCountDTO> countModuleIdByRequest(@Param("request") ApiModuleRequest request);
|
||||
List<ModuleCountDTO> countModuleIdByRequest(@Param("request") ApiModuleRequest request, @Param("deleted") boolean deleted);
|
||||
|
||||
List<BaseTreeNode> selectNodeByIds(@Param("ids") List<String> ids);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@
|
||||
|
||||
<sql id="api_request">
|
||||
<where>
|
||||
api_definition.deleted = 0
|
||||
api_definition.deleted = #{deleted}
|
||||
<if test="request.projectId != null and request.projectId != ''">
|
||||
AND api_definition.project_id = #{request.projectId}
|
||||
</if>
|
||||
|
@ -33,10 +33,11 @@
|
||||
t1.update_user,
|
||||
t1.create_time,
|
||||
t1.update_time,
|
||||
t1.delete_user,
|
||||
t1.delete_time,
|
||||
t1.num,
|
||||
t1.last_report_status,
|
||||
t1.last_report_id,
|
||||
t1.delete_time,
|
||||
t1.environment_id
|
||||
FROM
|
||||
api_test_case t1
|
||||
|
@ -9,9 +9,11 @@ import io.metersphere.api.mapper.ApiDebugBlobMapper;
|
||||
import io.metersphere.api.mapper.ApiDebugMapper;
|
||||
import io.metersphere.api.mapper.ApiDebugModuleMapper;
|
||||
import io.metersphere.api.mapper.ExtApiDebugModuleMapper;
|
||||
import io.metersphere.api.service.ApiFileResourceService;
|
||||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
import io.metersphere.project.dto.NodeSortDTO;
|
||||
import io.metersphere.project.service.ModuleTreeService;
|
||||
import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
@ -52,6 +54,8 @@ public class ApiDebugModuleService extends ModuleTreeService {
|
||||
private ApiDebugBlobMapper apiDebugBlobMapper;
|
||||
@Resource
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
@Resource
|
||||
private ApiFileResourceService apiFileResourceService;
|
||||
|
||||
public List<BaseTreeNode> getTree(String protocol, String userId) {
|
||||
List<BaseTreeNode> fileModuleList = extApiDebugModuleMapper.selectBaseByProtocolAndUser(protocol, userId);
|
||||
@ -198,6 +202,11 @@ public class ApiDebugModuleService extends ModuleTreeService {
|
||||
ApiDebugBlobExample blobExample = new ApiDebugBlobExample();
|
||||
blobExample.createCriteria().andIdIn(apiDebugIds);
|
||||
apiDebugBlobMapper.deleteByExample(blobExample);
|
||||
//删除文件关联关系
|
||||
apiDebugs.forEach(apiDebug -> {
|
||||
String apiDebugDir = DefaultRepositoryDir.getApiDebugDir(apiDebug.getProjectId(), apiDebug.getId());
|
||||
apiFileResourceService.deleteByResourceId(apiDebugDir, apiDebug.getId());
|
||||
});
|
||||
apiDebugModuleLogService.saveDeleteDataLog(apiDebugs, currentUser, projectId);
|
||||
}
|
||||
|
||||
|
@ -55,11 +55,11 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||
@Resource
|
||||
private ApiTestCaseService apiTestCaseService;
|
||||
|
||||
public List<BaseTreeNode> getTree(ApiModuleRequest request) {
|
||||
public List<BaseTreeNode> getTree(ApiModuleRequest request, boolean deleted) {
|
||||
//接口的树结构是 模块:子模块+接口 接口为非delete状态的
|
||||
List<BaseTreeNode> fileModuleList = extApiDefinitionModuleMapper.selectBaseByRequest(request);
|
||||
List<BaseTreeNode> baseTreeNodes = super.buildTreeAndCountResource(fileModuleList, true, Translator.get(UNPLANNED_API));
|
||||
List<ApiTreeNode> apiTreeNodeList = extApiDefinitionModuleMapper.selectApiDataByRequest(request);
|
||||
List<ApiTreeNode> apiTreeNodeList = extApiDefinitionModuleMapper.selectApiDataByRequest(request, deleted);
|
||||
return apiDebugModuleService.getBaseTreeNodes(apiTreeNodeList, baseTreeNodes);
|
||||
|
||||
}
|
||||
@ -245,10 +245,10 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
|
||||
public Map<String, Long> moduleCount(ApiModuleRequest request) {
|
||||
public Map<String, Long> moduleCount(ApiModuleRequest request, boolean deleted) {
|
||||
request.setModuleIds(null);
|
||||
//查找根据moduleIds查找模块下的接口数量 查非delete状态的
|
||||
List<ModuleCountDTO> moduleCountDTOList = extApiDefinitionModuleMapper.countModuleIdByRequest(request);
|
||||
List<ModuleCountDTO> moduleCountDTOList = extApiDefinitionModuleMapper.countModuleIdByRequest(request, deleted);
|
||||
long allCount = getAllCount(moduleCountDTOList);
|
||||
Map<String, Long> moduleCountMap = getModuleCountMap(request, moduleCountDTOList);
|
||||
moduleCountMap.put(DEBUG_MODULE_COUNT_ALL, allCount);
|
||||
|
@ -1,24 +1,24 @@
|
||||
package io.metersphere.api.service.definition;
|
||||
|
||||
import io.metersphere.api.constants.ApiResourceType;
|
||||
import io.metersphere.api.domain.*;
|
||||
import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest;
|
||||
import io.metersphere.api.dto.definition.*;
|
||||
import io.metersphere.api.mapper.*;
|
||||
import io.metersphere.api.service.ApiFileResourceService;
|
||||
import io.metersphere.api.util.ApiDataUtils;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.ApplicationNumScope;
|
||||
import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.sdk.domain.Environment;
|
||||
import io.metersphere.sdk.domain.EnvironmentExample;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
@ -30,6 +30,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mybatis.spring.SqlSessionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -73,37 +74,21 @@ public class ApiTestCaseService {
|
||||
private ApiTestCaseLogService apiTestCaseLogService;
|
||||
@Resource
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
@Resource
|
||||
private ApiFileResourceService apiFileResourceService;
|
||||
|
||||
public ApiTestCase addCase(ApiTestCaseAddRequest request, List<MultipartFile> files, String userId) {
|
||||
ApiTestCase testCase = new ApiTestCase();
|
||||
testCase.setId(IDGenerator.nextStr());
|
||||
BeanUtils.copyBean(testCase, request);
|
||||
ApiDefinition apiDefinition = getApiDefinition(request.getApiDefinitionId());
|
||||
testCase.setNum(NumGenerator.nextNum(request.getProjectId() + "_" + apiDefinition.getNum(), ApplicationNumScope.API_TEST_CASE));
|
||||
testCase.setApiDefinitionId(request.getApiDefinitionId());
|
||||
testCase.setName(request.getName());
|
||||
testCase.setPos(getNextOrder(request.getProjectId()));
|
||||
testCase.setProjectId(request.getProjectId());
|
||||
checkProjectExist(testCase.getProjectId());
|
||||
checkNameExist(testCase);
|
||||
testCase.setVersionId(apiDefinition.getVersionId());
|
||||
testCase.setPriority(request.getPriority());
|
||||
testCase.setStatus(request.getStatus());
|
||||
testCase.setCreateUser(userId);
|
||||
testCase.setUpdateUser(userId);
|
||||
testCase.setCreateTime(System.currentTimeMillis());
|
||||
testCase.setUpdateTime(System.currentTimeMillis());
|
||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||
testCase.setTags(JSON.toJSONString(request.getTags()));
|
||||
}
|
||||
apiTestCaseMapper.insertSelective(testCase);
|
||||
|
||||
ApiTestCaseBlob caseBlob = new ApiTestCaseBlob();
|
||||
caseBlob.setId(testCase.getId());
|
||||
caseBlob.setRequest(request.getRequest().getBytes());
|
||||
apiTestCaseBlobMapper.insert(caseBlob);
|
||||
uploadBodyFile(files, testCase.getId(), request.getProjectId());
|
||||
return testCase;
|
||||
@NotNull
|
||||
private static ApiFileResourceUpdateRequest getFileResourceRequest(ApiTestCase testCase, List<String> filed, List<String> addFiled) {
|
||||
String apiCaseDir = DefaultRepositoryDir.getApiCaseDir(testCase.getProjectId(), testCase.getId());
|
||||
// 处理文件
|
||||
ApiFileResourceUpdateRequest resourceUpdateRequest = new ApiFileResourceUpdateRequest();
|
||||
resourceUpdateRequest.setProjectId(testCase.getProjectId());
|
||||
resourceUpdateRequest.setFileIds(filed);
|
||||
resourceUpdateRequest.setAddFileIds(addFiled);
|
||||
resourceUpdateRequest.setFolder(apiCaseDir);
|
||||
resourceUpdateRequest.setResourceId(testCase.getId());
|
||||
resourceUpdateRequest.setApiResourceType(ApiResourceType.API_CASE);
|
||||
return resourceUpdateRequest;
|
||||
}
|
||||
|
||||
private void checkProjectExist(String projectId) {
|
||||
@ -140,21 +125,40 @@ public class ApiTestCaseService {
|
||||
return (pos == null ? 0 : pos) + ORDER_STEP;
|
||||
}
|
||||
|
||||
public void uploadBodyFile(List<MultipartFile> files, String caseId, String projectId) {
|
||||
if (CollectionUtils.isNotEmpty(files)) {
|
||||
files.forEach(file -> {
|
||||
FileRequest fileRequest = new FileRequest();
|
||||
fileRequest.setFileName(file.getName());
|
||||
fileRequest.setFolder(DefaultRepositoryDir.getApiCaseDir(projectId, caseId));
|
||||
fileRequest.setStorage(StorageType.MINIO.name());
|
||||
try {
|
||||
minioRepository.saveFile(file, fileRequest);
|
||||
} catch (Exception e) {
|
||||
LogUtils.info("上传body文件失败: 文件名称:" + file.getName(), e);
|
||||
throw new MSException(Translator.get("file_upload_fail"));
|
||||
}
|
||||
});
|
||||
public ApiTestCase addCase(ApiTestCaseAddRequest request, List<MultipartFile> files, String userId) {
|
||||
ApiTestCase testCase = new ApiTestCase();
|
||||
testCase.setId(IDGenerator.nextStr());
|
||||
BeanUtils.copyBean(testCase, request);
|
||||
ApiDefinition apiDefinition = getApiDefinition(request.getApiDefinitionId());
|
||||
testCase.setNum(NumGenerator.nextNum(request.getProjectId() + "_" + apiDefinition.getNum(), ApplicationNumScope.API_TEST_CASE));
|
||||
testCase.setApiDefinitionId(request.getApiDefinitionId());
|
||||
testCase.setName(request.getName());
|
||||
testCase.setPos(getNextOrder(request.getProjectId()));
|
||||
testCase.setProjectId(request.getProjectId());
|
||||
checkProjectExist(testCase.getProjectId());
|
||||
checkNameExist(testCase);
|
||||
testCase.setVersionId(apiDefinition.getVersionId());
|
||||
testCase.setPriority(request.getPriority());
|
||||
testCase.setStatus(request.getStatus());
|
||||
testCase.setCreateUser(userId);
|
||||
testCase.setUpdateUser(userId);
|
||||
testCase.setCreateTime(System.currentTimeMillis());
|
||||
testCase.setUpdateTime(System.currentTimeMillis());
|
||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||
testCase.setTags(JSON.toJSONString(request.getTags()));
|
||||
}
|
||||
apiTestCaseMapper.insertSelective(testCase);
|
||||
|
||||
ApiTestCaseBlob caseBlob = new ApiTestCaseBlob();
|
||||
caseBlob.setId(testCase.getId());
|
||||
caseBlob.setRequest(request.getRequest().getBytes());
|
||||
apiTestCaseBlobMapper.insert(caseBlob);
|
||||
|
||||
// 处理文件
|
||||
ApiFileResourceUpdateRequest resourceRequest =
|
||||
getFileResourceRequest(testCase, request.getFileIds(), request.getFileIds());
|
||||
apiFileResourceService.addFileResource(resourceRequest, files);
|
||||
return testCase;
|
||||
}
|
||||
|
||||
private ApiTestCase checkResourceExist(String id) {
|
||||
@ -183,6 +187,7 @@ public class ApiTestCaseService {
|
||||
List<ApiTestCaseFollower> followers = apiTestCaseFollowerMapper.selectByExample(example);
|
||||
apiTestCaseDTO.setFollow(CollectionUtils.isNotEmpty(followers));
|
||||
apiTestCaseDTO.setRequest(ApiDataUtils.parseObject(new String(testCaseBlob.getRequest()), AbstractMsTestElement.class));
|
||||
apiTestCaseDTO.setFileIds(apiFileResourceService.getFileIdsByResourceId(id));
|
||||
return apiTestCaseDTO;
|
||||
}
|
||||
|
||||
@ -240,7 +245,10 @@ public class ApiTestCaseService {
|
||||
apiTestCaseBlob.setId(request.getId());
|
||||
apiTestCaseBlob.setRequest(request.getRequest().getBytes());
|
||||
apiTestCaseBlobMapper.updateByPrimaryKeySelective(apiTestCaseBlob);
|
||||
uploadBodyFile(files, request.getId(), testCase.getProjectId());
|
||||
|
||||
ApiFileResourceUpdateRequest resourceRequest =
|
||||
getFileResourceRequest(testCase, request.getFileIds(), request.getAddFileIds());
|
||||
apiFileResourceService.updateFileResource(resourceRequest, files);
|
||||
return testCase;
|
||||
}
|
||||
|
||||
@ -254,8 +262,8 @@ public class ApiTestCaseService {
|
||||
apiTestCaseMapper.updateByPrimaryKeySelective(update);
|
||||
}
|
||||
|
||||
public List<ApiTestCaseDTO> page(ApiTestCasePageRequest request) {
|
||||
List<ApiTestCaseDTO> apiCaseLists = extApiTestCaseMapper.listByRequest(request, false);
|
||||
public List<ApiTestCaseDTO> page(ApiTestCasePageRequest request, boolean deleted) {
|
||||
List<ApiTestCaseDTO> apiCaseLists = extApiTestCaseMapper.listByRequest(request, deleted);
|
||||
buildApiTestCaseDTO(apiCaseLists);
|
||||
return apiCaseLists;
|
||||
}
|
||||
@ -327,15 +335,10 @@ public class ApiTestCaseService {
|
||||
ApiTestCaseBlobExample blobExample = new ApiTestCaseBlobExample();
|
||||
blobExample.createCriteria().andIdIn(ids);
|
||||
apiTestCaseBlobMapper.deleteByExample(blobExample);
|
||||
//删除body文件
|
||||
FileRequest request = new FileRequest();
|
||||
//删除文件关联关系
|
||||
ids.forEach(id -> {
|
||||
try {
|
||||
request.setFolder(DefaultRepositoryDir.getApiCaseDir(projectId, id));
|
||||
minioRepository.deleteFolder(request);
|
||||
} catch (Exception e) {
|
||||
LogUtils.info("删除body文件失败: 文件名称:" + id, e);
|
||||
}
|
||||
String apiCaseDir = DefaultRepositoryDir.getApiCaseDir(projectId, id);
|
||||
apiFileResourceService.deleteByResourceId(apiCaseDir, id);
|
||||
});
|
||||
//记录删除日志
|
||||
apiTestCaseLogService.deleteBatchLog(caseLists, userId, projectId);
|
||||
|
@ -52,6 +52,8 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
|
||||
private static final String URL_MODULE_TREE = "/api/definition/module/tree";
|
||||
private static final String URL_MODULE_MOVE = "/api/definition/module/move";
|
||||
private static final String URL_FILE_MODULE_COUNT = "/api/definition/module/count";
|
||||
private static final String URL_MODULE_TRASH_TREE = "/api/definition/module/trash/tree";
|
||||
private static final String URL_MODULE_TRASH_COUNT = "/api/definition/module/trash/count";
|
||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
private static Project project;
|
||||
@ -762,7 +764,7 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
@Order(9)
|
||||
public void TestModuleCountError() throws Exception {
|
||||
ApiDebugRequest request = new ApiDebugRequest();
|
||||
request.setProtocol(null);
|
||||
@ -801,6 +803,35 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
public void getModuleTrashTreeNode() throws Exception {
|
||||
MvcResult result = this.requestPostWithOkAndReturn(URL_MODULE_TRASH_TREE, new ApiModuleRequest() {{
|
||||
this.setProtocol("HTTP");
|
||||
this.setProjectId(project.getId());
|
||||
}});
|
||||
String returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
public void getModuleTrashTreeCount() throws Exception {
|
||||
ApiModuleRequest request = new ApiModuleRequest() {{
|
||||
this.setProtocol("HTTP");
|
||||
this.setProjectId(project.getId());
|
||||
}};
|
||||
MvcResult moduleCountMvcResult = this.requestPostWithOkAndReturn(URL_MODULE_TRASH_COUNT, request);
|
||||
Map<String, Integer> moduleCountResult = JSON.parseObject(JSON.toJSONString(
|
||||
JSON.parseObject(moduleCountMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
|
||||
Map.class);
|
||||
Assertions.assertTrue(moduleCountResult.containsKey("all"));
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_READ, URL_MODULE_TRASH_COUNT, request);
|
||||
}
|
||||
|
||||
|
||||
private List<BaseTreeNode> getModuleTreeNode() throws Exception {
|
||||
MvcResult result = this.requestPostWithOkAndReturn(URL_MODULE_TREE, new ApiModuleRequest() {{
|
||||
this.setProtocol("HTTP");
|
||||
|
@ -4,6 +4,7 @@ import io.metersphere.api.controller.param.ApiTestCaseAddRequestDefinition;
|
||||
import io.metersphere.api.domain.*;
|
||||
import io.metersphere.api.dto.definition.*;
|
||||
import io.metersphere.api.mapper.*;
|
||||
import io.metersphere.api.service.ApiFileResourceService;
|
||||
import io.metersphere.api.util.ApiDataUtils;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import io.metersphere.sdk.constants.ApplicationNumScope;
|
||||
@ -62,6 +63,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||
private static final String DELETE = BASE_PATH + "delete/";
|
||||
private static final String UPDATE = BASE_PATH + "update";
|
||||
private static final String PAGE = BASE_PATH + "page";
|
||||
private static final String TRASH_PAGE = BASE_PATH + "trash/page";
|
||||
private static final String UPDATE_STATUS = BASE_PATH + "update-status";
|
||||
private static final String BATCH_EDIT = BASE_PATH + "batch/edit";
|
||||
private static final String BATCH_DELETE = BASE_PATH + "batch/delete";
|
||||
@ -83,6 +85,8 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||
private ApiTestCaseFollowerMapper apiTestCaseFollowerMapper;
|
||||
@Resource
|
||||
private EnvironmentMapper environmentMapper;
|
||||
@Resource
|
||||
private ApiFileResourceService apiFileResourceService;
|
||||
|
||||
public static <T> T parseObjectFromMvcResult(MvcResult mvcResult, Class<T> parseClass) {
|
||||
try {
|
||||
@ -180,6 +184,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||
request.setEnvironmentId(environments.get(0).getId());
|
||||
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
|
||||
request.setRequest(ApiDataUtils.toJSONString(msHttpElement));
|
||||
request.setFileIds(List.of("fileId1"));
|
||||
LinkedMultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
FileInputStream inputStream = new FileInputStream(new File(
|
||||
@ -267,6 +272,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||
List<ApiTestCaseFollower> followers = apiTestCaseFollowerMapper.selectByExample(example);
|
||||
copyApiDebugDTO.setFollow(CollectionUtils.isNotEmpty(followers));
|
||||
copyApiDebugDTO.setRequest(ApiDataUtils.parseObject(new String(apiDebugBlob.getRequest()), AbstractMsTestElement.class));
|
||||
copyApiDebugDTO.setFileIds(apiFileResourceService.getFileIdsByResourceId(apiTestCase.getId()));
|
||||
Assertions.assertEquals(apiDebugDTO, copyApiDebugDTO);
|
||||
this.requestGetWithOk(GET + anotherApiTestCase.getId())
|
||||
.andReturn();
|
||||
@ -361,7 +367,14 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
|
||||
request.setRequest(ApiDataUtils.toJSONString(msHttpElement));
|
||||
LinkedMultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
request.setFileIds(List.of("fileId1"));
|
||||
request.setAddFileIds(List.of("fileId2"));
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
FileInputStream inputStream = new FileInputStream(new File(
|
||||
this.getClass().getClassLoader().getResource("file/file_upload.JPG")
|
||||
.getPath()));
|
||||
MockMultipartFile file = new MockMultipartFile("file_upload.JPG", "file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, inputStream);
|
||||
paramMap.add("files", List.of(file));
|
||||
MvcResult mvcResult = this.requestMultipartWithOkAndReturn(UPDATE, paramMap);
|
||||
// 校验请求成功数据
|
||||
ApiTestCase resultData = getResultData(mvcResult, ApiTestCase.class);
|
||||
@ -602,6 +615,57 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE, BATCH_MOVE_GC, request);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
public void trashPage() throws Exception {
|
||||
// @@请求成功
|
||||
ApiTestCasePageRequest pageRequest = new ApiTestCasePageRequest();
|
||||
pageRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||
pageRequest.setPageSize(10);
|
||||
pageRequest.setCurrent(1);
|
||||
MvcResult mvcResult = responsePost(TRASH_PAGE, pageRequest);
|
||||
Pager<?> returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
|
||||
//返回值不为空
|
||||
Assertions.assertNotNull(returnPager);
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(returnPager.getCurrent(), pageRequest.getCurrent());
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
Assertions.assertTrue(((List<ApiTestCaseDTO>) returnPager.getList()).size() <= pageRequest.getPageSize());
|
||||
|
||||
//查询apiDefinitionId1的数据
|
||||
pageRequest.setApiDefinitionId("apiDefinitionId1");
|
||||
mvcResult = responsePost(TRASH_PAGE, pageRequest);
|
||||
returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
|
||||
//返回值不为空
|
||||
Assertions.assertNotNull(returnPager);
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(returnPager.getCurrent(), pageRequest.getCurrent());
|
||||
|
||||
List<ApiTestCaseDTO> caseDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ApiTestCaseDTO.class);
|
||||
caseDTOS.forEach(caseDTO -> Assertions.assertEquals(caseDTO.getApiDefinitionId(), "apiDefinitionId1"));
|
||||
|
||||
//查询模块为moduleId1的数据
|
||||
pageRequest.setApiDefinitionId(null);
|
||||
pageRequest.setModuleIds(List.of("moduleId1"));
|
||||
mvcResult = responsePost(TRASH_PAGE, pageRequest);
|
||||
returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
|
||||
//返回值不为空
|
||||
Assertions.assertNotNull(returnPager);
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(returnPager.getCurrent(), pageRequest.getCurrent());
|
||||
caseDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ApiTestCaseDTO.class);
|
||||
caseDTOS.forEach(caseDTO -> Assertions.assertEquals(apiDefinitionMapper.selectByPrimaryKey(caseDTO.getApiDefinitionId()).getModuleId(), "moduleId1"));
|
||||
|
||||
pageRequest.setModuleIds(null);
|
||||
pageRequest.setSort(new HashMap<>() {{
|
||||
put("createTime", "asc");
|
||||
}});
|
||||
responsePost(TRASH_PAGE, pageRequest);
|
||||
//校验权限
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, TRASH_PAGE, pageRequest);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
public void delete() throws Exception {
|
||||
|
@ -85,6 +85,6 @@ minio.endpoint=http://${embedded.minio.host}:${embedded.minio.port}
|
||||
minio.access-key=${embedded.minio.accessKey}
|
||||
minio.secret-key=${embedded.minio.secretKey}
|
||||
|
||||
logging.level.org.springframework.jdbc.core=debug
|
||||
logging.level.io.metersphere.sdk.mapper=debug
|
||||
logging.level.io.metersphere.project.mapper=debug
|
||||
logging.level.org.springframework.jdbc.core=info
|
||||
logging.level.io.metersphere.sdk.mapper=info
|
||||
logging.level.io.metersphere.project.mapper=info
|
@ -135,12 +135,12 @@ public class EnvironmentService {
|
||||
if (CollectionUtils.isNotEmpty(sslFiles)) {
|
||||
sslFiles.forEach(sslFile -> {
|
||||
FileRequest fileRequest = new FileRequest();
|
||||
fileRequest.setFileName(sslFile.getName());
|
||||
fileRequest.setFileName(sslFile.getOriginalFilename());
|
||||
fileRequest.setFolder(DefaultRepositoryDir.getEnvSslDir(environment.getProjectId(), environment.getId()));
|
||||
try {
|
||||
minioRepository.saveFile(sslFile, fileRequest);
|
||||
} catch (Exception e) {
|
||||
LogUtils.info("上传ssl文件失败: 文件名称:" + sslFile.getName(), e);
|
||||
LogUtils.info("上传ssl文件失败: 文件名称:" + sslFile.getOriginalFilename(), e);
|
||||
throw new MSException(Translator.get("api_test_environment_ssl_file_upload_failed"));
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user