refactor(接口测试): 优化接口用例的展示字段
This commit is contained in:
parent
6fff1c5f20
commit
5172dcc91d
|
@ -80,6 +80,6 @@ public class ApiDefinitionModuleController {
|
||||||
@Operation(summary = "接口测试-接口管理-模块-查找模块")
|
@Operation(summary = "接口测试-接口管理-模块-查找模块")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
|
||||||
public List<BaseTreeNode> getTrashTree(@RequestBody @Validated ApiModuleRequest request) {
|
public List<BaseTreeNode> getTrashTree(@RequestBody @Validated ApiModuleRequest request) {
|
||||||
return apiDefinitionModuleService.getTree(request, true);
|
return apiDefinitionModuleService.getTrashTree(request, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.api.domain.ApiTestCase;
|
||||||
import io.metersphere.api.dto.definition.*;
|
import io.metersphere.api.dto.definition.*;
|
||||||
import io.metersphere.api.service.definition.ApiTestCaseLogService;
|
import io.metersphere.api.service.definition.ApiTestCaseLogService;
|
||||||
import io.metersphere.api.service.definition.ApiTestCaseNoticeService;
|
import io.metersphere.api.service.definition.ApiTestCaseNoticeService;
|
||||||
|
import io.metersphere.api.service.definition.ApiTestCaseRecoverService;
|
||||||
import io.metersphere.api.service.definition.ApiTestCaseService;
|
import io.metersphere.api.service.definition.ApiTestCaseService;
|
||||||
import io.metersphere.sdk.constants.PermissionConstants;
|
import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||||
|
@ -35,6 +36,8 @@ import java.util.List;
|
||||||
public class ApiTestCaseController {
|
public class ApiTestCaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private ApiTestCaseService apiTestCaseService;
|
private ApiTestCaseService apiTestCaseService;
|
||||||
|
@Resource
|
||||||
|
private ApiTestCaseRecoverService apiTestCaseRecoverService;
|
||||||
|
|
||||||
@PostMapping(value = "/add")
|
@PostMapping(value = "/add")
|
||||||
@Operation(summary = "接口测试-接口管理-接口用例-新增")
|
@Operation(summary = "接口测试-接口管理-接口用例-新增")
|
||||||
|
@ -118,23 +121,33 @@ public class ApiTestCaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/batch/delete")
|
@PostMapping("/batch/delete")
|
||||||
|
@Operation(summary = "接口测试-接口管理-接口用例-批量删除")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
||||||
public void deleteBatchByParam(@RequestBody ApiTestCaseBatchRequest request) {
|
public void deleteBatchByParam(@RequestBody ApiTestCaseBatchRequest request) {
|
||||||
apiTestCaseService.batchDelete(request, SessionUtils.getUserId());
|
apiTestCaseService.batchDelete(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/batch/move-gc")
|
@PostMapping("/batch/move-gc")
|
||||||
|
@Operation(summary = "接口测试-接口管理-接口用例-批量移动到回收站")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
||||||
public void deleteToGcByParam(@RequestBody ApiTestCaseBatchRequest request) {
|
public void deleteToGcByParam(@RequestBody ApiTestCaseBatchRequest request) {
|
||||||
apiTestCaseService.batchMoveGc(request, SessionUtils.getUserId());
|
apiTestCaseService.batchMoveGc(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/batch/edit")
|
@PostMapping("/batch/edit")
|
||||||
|
@Operation(summary = "接口测试-接口管理-接口用例-批量编辑")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE)
|
||||||
public void batchUpdate(@Validated @RequestBody ApiCaseBatchEditRequest request) {
|
public void batchUpdate(@Validated @RequestBody ApiCaseBatchEditRequest request) {
|
||||||
apiTestCaseService.batchEdit(request, SessionUtils.getUserId());
|
apiTestCaseService.batchEdit(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/batch/recover")
|
||||||
|
@Operation(summary = "接口测试-接口管理-接口用例-批量恢复")
|
||||||
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_RECOVER)
|
||||||
|
public void batchRecover(@Validated @RequestBody ApiTestCaseBatchRequest request) {
|
||||||
|
apiTestCaseRecoverService.batchRecover(request, SessionUtils.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/trash/page")
|
@PostMapping(value = "/trash/page")
|
||||||
@Operation(summary = "接口测试-接口管理-接口用例-回收站-分页查询")
|
@Operation(summary = "接口测试-接口管理-接口用例-回收站-分页查询")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ)
|
||||||
|
|
|
@ -87,4 +87,10 @@ public class ApiTestCaseDTO {
|
||||||
@Schema(description = "请求内容")
|
@Schema(description = "请求内容")
|
||||||
private AbstractMsTestElement request;
|
private AbstractMsTestElement request;
|
||||||
|
|
||||||
|
@Schema(description = "所属模块")
|
||||||
|
private String modulePath;
|
||||||
|
|
||||||
|
@Schema(description = "模块id")
|
||||||
|
private String moduleId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package io.metersphere.api.dto.importdto;
|
||||||
|
|
||||||
|
import io.metersphere.api.domain.ApiDefinition;
|
||||||
|
import io.metersphere.api.dto.definition.HttpResponse;
|
||||||
|
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class ApiDefinitionImportDTO extends ApiDefinition {
|
||||||
|
|
||||||
|
@Schema(description = "请求内容")
|
||||||
|
private AbstractMsTestElement request;
|
||||||
|
|
||||||
|
@Schema(description = "响应内容")
|
||||||
|
private List<HttpResponse> response;
|
||||||
|
|
||||||
|
@Schema(description = "模块path")
|
||||||
|
private String modulePath;
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.mapper;
|
||||||
|
|
||||||
import io.metersphere.api.domain.ApiDefinition;
|
import io.metersphere.api.domain.ApiDefinition;
|
||||||
import io.metersphere.api.dto.definition.*;
|
import io.metersphere.api.dto.definition.*;
|
||||||
|
import io.metersphere.api.dto.importdto.ApiDefinitionImportDTO;
|
||||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
@ -40,4 +41,7 @@ public interface ExtApiDefinitionMapper {
|
||||||
|
|
||||||
void updateLatestVersion(@Param("id") String id, @Param("projectId") String projectId);
|
void updateLatestVersion(@Param("id") String id, @Param("projectId") String projectId);
|
||||||
|
|
||||||
|
List<ApiDefinitionImportDTO> importList(@Param("request") ApiDefinitionPageRequest request);
|
||||||
|
|
||||||
|
List<String> selectIdsByIdsAndDeleted(@Param("ids")List<String> ids, @Param("deleted") boolean deleted);
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,24 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
and deleted = #{deleted}
|
and deleted = #{deleted}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="importList" resultType="io.metersphere.api.dto.importdto.ApiDefinitionImportDTO">
|
||||||
|
select
|
||||||
|
api_definition.id, api_definition.`name`, api_definition.protocol, api_definition.`method`,
|
||||||
|
api_definition.`path`, api_definition.version_id,
|
||||||
|
api_definition.ref_id
|
||||||
|
from api_definition
|
||||||
|
LEFT JOIN project_version ON project_version.id = api_definition.version_id
|
||||||
|
where api_definition.deleted = true
|
||||||
|
<include refid="queryWhereCondition"/>
|
||||||
|
</select>
|
||||||
|
<select id="selectIdsByIdsAndDeleted" resultType="java.lang.String">
|
||||||
|
select id from api_definition
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
and deleted = #{deleted}
|
||||||
|
</select>
|
||||||
|
|
||||||
<update id="batchDeleteByRefId">
|
<update id="batchDeleteByRefId">
|
||||||
update api_definition
|
update api_definition
|
||||||
|
|
|
@ -32,4 +32,6 @@ public interface ExtApiDefinitionModuleMapper {
|
||||||
List<ModuleCountDTO> countModuleIdByRequest(@Param("request") ApiModuleRequest request, @Param("deleted") boolean deleted);
|
List<ModuleCountDTO> countModuleIdByRequest(@Param("request") ApiModuleRequest request, @Param("deleted") boolean deleted);
|
||||||
|
|
||||||
List<BaseTreeNode> selectNodeByIds(@Param("ids") List<String> ids);
|
List<BaseTreeNode> selectNodeByIds(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
List<BaseTreeNode> selectBaseByIds(@Param("ids") List<String> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,17 @@
|
||||||
ORDER BY pos
|
ORDER BY pos
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectBaseByIds" resultType="io.metersphere.system.dto.sdk.BaseTreeNode">
|
||||||
|
SELECT id, name, parent_id AS parentId, 'module' AS type
|
||||||
|
FROM api_definition_module
|
||||||
|
WHERE id IN
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
ORDER BY pos
|
||||||
|
</select>
|
||||||
|
|
||||||
<sql id="api_request">
|
<sql id="api_request">
|
||||||
<where>
|
<where>
|
||||||
api_definition.deleted = #{deleted}
|
api_definition.deleted = #{deleted}
|
||||||
|
|
|
@ -24,8 +24,7 @@ public interface ExtApiTestCaseMapper {
|
||||||
|
|
||||||
List<String> getIds(@Param("request") ApiTestCaseBatchRequest request, @Param("deleted") boolean deleted);
|
List<String> getIds(@Param("request") ApiTestCaseBatchRequest request, @Param("deleted") boolean deleted);
|
||||||
|
|
||||||
|
void batchMoveGc(@Param("ids") List<String> ids, @Param("userId") String userId, @Param("deleteTime") long deleteTime);
|
||||||
void batchMoveGc(@Param("ids") List<String> ids, @Param("userId") String userId);
|
|
||||||
|
|
||||||
List<ApiTestCase> getCaseInfoByApiIds(@Param("ids") List<String> apiIds, @Param("deleted") boolean deleted);
|
List<ApiTestCase> getCaseInfoByApiIds(@Param("ids") List<String> apiIds, @Param("deleted") boolean deleted);
|
||||||
|
|
||||||
|
@ -36,4 +35,8 @@ public interface ExtApiTestCaseMapper {
|
||||||
Long getLastPos(@Param("projectId") String projectId, @Param("basePos") Long basePos);
|
Long getLastPos(@Param("projectId") String projectId, @Param("basePos") Long basePos);
|
||||||
|
|
||||||
List<CasePassDTO> findPassRateByIds(@Param("ids") List<String> ids);
|
List<CasePassDTO> findPassRateByIds(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
List<String> selectIdsByCaseIds(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
List<String> getCaseIds(@Param("ids")List<String> ids, @Param("deleted")boolean deleted);
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
<update id="batchMoveGc">
|
<update id="batchMoveGc">
|
||||||
UPDATE api_test_case
|
UPDATE api_test_case
|
||||||
SET deleted = 1,
|
SET deleted = 1,
|
||||||
delete_time = UNIX_TIMESTAMP()*1000,
|
delete_time = #{deleteTime},
|
||||||
delete_user = #{userId}
|
delete_user = #{userId}
|
||||||
WHERE id in
|
WHERE id in
|
||||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
@ -38,7 +38,8 @@
|
||||||
t1.num,
|
t1.num,
|
||||||
t1.last_report_status,
|
t1.last_report_status,
|
||||||
t1.last_report_id,
|
t1.last_report_id,
|
||||||
t1.environment_id
|
t1.environment_id,
|
||||||
|
a.module_id
|
||||||
FROM
|
FROM
|
||||||
api_test_case t1
|
api_test_case t1
|
||||||
LEFT JOIN api_report t3 ON t1.last_report_id = t3.id
|
LEFT JOIN api_report t3 ON t1.last_report_id = t3.id
|
||||||
|
@ -116,6 +117,30 @@
|
||||||
GROUP BY
|
GROUP BY
|
||||||
t2.resource_id
|
t2.resource_id
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectIdsByCaseIds" resultType="java.lang.String">
|
||||||
|
SELECT
|
||||||
|
t1.api_definition_id
|
||||||
|
FROM
|
||||||
|
api_test_case t1
|
||||||
|
WHERE
|
||||||
|
t1.deleted = 1
|
||||||
|
AND t1.id IN
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
<select id="getCaseIds" resultType="java.lang.String">
|
||||||
|
SELECT
|
||||||
|
t1.id
|
||||||
|
FROM
|
||||||
|
api_test_case t1
|
||||||
|
WHERE
|
||||||
|
t1.deleted = #{deleted}
|
||||||
|
AND t1.api_definition_id IN
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
<sql id="queryWhereConditionByBatch">
|
<sql id="queryWhereConditionByBatch">
|
||||||
<if test="request.protocol != null and request.protocol!=''">
|
<if test="request.protocol != null and request.protocol!=''">
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.mybatis.spring.SqlSessionUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||||
this.checkDataValidity(module);
|
this.checkDataValidity(module);
|
||||||
module.setCreateTime(System.currentTimeMillis());
|
module.setCreateTime(System.currentTimeMillis());
|
||||||
module.setUpdateTime(module.getCreateTime());
|
module.setUpdateTime(module.getCreateTime());
|
||||||
module.setPos(this.countPos(request.getParentId()));
|
module.setPos(this.getNextOrder(request.getParentId()));
|
||||||
module.setUpdateUser(operator);
|
module.setUpdateUser(operator);
|
||||||
apiDefinitionModuleMapper.insert(module);
|
apiDefinitionModuleMapper.insert(module);
|
||||||
//记录日志
|
//记录日志
|
||||||
|
@ -89,7 +90,7 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||||
return module.getId();
|
return module.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long countPos(String parentId) {
|
public Long getNextOrder(String parentId) {
|
||||||
Long maxPos = extApiDefinitionModuleMapper.getMaxPosByParentId(parentId);
|
Long maxPos = extApiDefinitionModuleMapper.getMaxPosByParentId(parentId);
|
||||||
if (maxPos == null) {
|
if (maxPos == null) {
|
||||||
return LIMIT_POS;
|
return LIMIT_POS;
|
||||||
|
@ -255,4 +256,17 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
|
||||||
return moduleCountMap;
|
return moduleCountMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<BaseTreeNode> getTrashTree(ApiModuleRequest request, boolean deleted) {
|
||||||
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
|
example.createCriteria().andProjectIdEqualTo(request.getProjectId()).andDeletedEqualTo(true).andProtocolEqualTo(request.getProtocol());
|
||||||
|
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||||
|
if (CollectionUtils.isEmpty(apiDefinitions)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
List<String> moduleIds = apiDefinitions.stream().map(ApiDefinition::getModuleId).distinct().toList();
|
||||||
|
List<BaseTreeNode> baseTreeNodes = extApiDefinitionModuleMapper.selectBaseByIds(moduleIds);
|
||||||
|
super.buildTreeAndCountResource(baseTreeNodes, true, Translator.get(UNPLANNED_API));
|
||||||
|
List<ApiTreeNode> apiTreeNodeList = extApiDefinitionModuleMapper.selectApiDataByRequest(request, deleted);
|
||||||
|
return apiDebugModuleService.getBaseTreeNodes(apiTreeNodeList, baseTreeNodes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -652,7 +652,7 @@ public class ApiDefinitionService {
|
||||||
// 恢复接口到接口列表
|
// 恢复接口到接口列表
|
||||||
handleRestoreApiDefinition(Collections.singletonList(request.getId()), userId, request.getProjectId(), false);
|
handleRestoreApiDefinition(Collections.singletonList(request.getId()), userId, request.getProjectId(), false);
|
||||||
}
|
}
|
||||||
private void handleRestoreApiDefinition(List<String> ids, String userId, String projectId, boolean isBatch){
|
public void handleRestoreApiDefinition(List<String> ids, String userId, String projectId, boolean isBatch){
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
SubListUtils.dealForSubList(ids, 2000, subList -> doRestore(subList, userId, projectId, isBatch));
|
SubListUtils.dealForSubList(ids, 2000, subList -> doRestore(subList, userId, projectId, isBatch));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
package io.metersphere.api.service.definition;
|
||||||
|
|
||||||
|
import io.metersphere.api.domain.ApiTestCase;
|
||||||
|
import io.metersphere.api.domain.ApiTestCaseExample;
|
||||||
|
import io.metersphere.api.dto.definition.ApiTestCaseBatchRequest;
|
||||||
|
import io.metersphere.api.mapper.ApiTestCaseMapper;
|
||||||
|
import io.metersphere.api.mapper.ExtApiDefinitionMapper;
|
||||||
|
import io.metersphere.api.mapper.ExtApiTestCaseMapper;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ApiTestCaseRecoverService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ApiTestCaseMapper apiTestCaseMapper;
|
||||||
|
@Resource
|
||||||
|
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
||||||
|
@Resource
|
||||||
|
private ExtApiDefinitionMapper extApiDefinitionMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiDefinitionService apiDefinitionService;
|
||||||
|
@Resource
|
||||||
|
private ApiTestCaseService apiTestCaseService;
|
||||||
|
|
||||||
|
public void batchRecover(ApiTestCaseBatchRequest request, String userId) {
|
||||||
|
List<String> ids = doSelectIds(request, true);
|
||||||
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//检查用例的接口是否存在 需要分开两批处理 一个是接口被删的 一个是只恢复用例的
|
||||||
|
List<String> definitionIds = extApiTestCaseMapper.selectIdsByCaseIds(ids);
|
||||||
|
if (CollectionUtils.isNotEmpty(definitionIds)) {
|
||||||
|
List<String> apiIds = extApiDefinitionMapper.selectIdsByIdsAndDeleted(definitionIds, true);
|
||||||
|
apiDefinitionService.handleRestoreApiDefinition(apiIds, userId, request.getProjectId(), true);
|
||||||
|
definitionIds.removeAll(apiIds);
|
||||||
|
if (CollectionUtils.isNotEmpty(definitionIds)) {
|
||||||
|
//接口被删的用例
|
||||||
|
List<String> caseIds = extApiTestCaseMapper.getCaseIds(definitionIds, true);
|
||||||
|
ids.retainAll(caseIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
|
example.createCriteria().andIdIn(ids).andDeletedEqualTo(true);
|
||||||
|
List<ApiTestCase> caseList = apiTestCaseMapper.selectByExample(example);
|
||||||
|
apiTestCaseService.batchRecover(caseList, userId, request.getProjectId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> doSelectIds(ApiTestCaseBatchRequest request, boolean deleted) {
|
||||||
|
if (request.isSelectAll()) {
|
||||||
|
List<String> ids = extApiTestCaseMapper.getIds(request, deleted);
|
||||||
|
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||||
|
ids.removeAll(request.getExcludeIds());
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
} else {
|
||||||
|
return request.getSelectIds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -73,6 +73,8 @@ public class ApiTestCaseService {
|
||||||
private SqlSessionFactory sqlSessionFactory;
|
private SqlSessionFactory sqlSessionFactory;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiFileResourceService apiFileResourceService;
|
private ApiFileResourceService apiFileResourceService;
|
||||||
|
@Resource
|
||||||
|
private ApiDefinitionModuleMapper apiDefinitionModuleMapper;
|
||||||
|
|
||||||
private void checkProjectExist(String projectId) {
|
private void checkProjectExist(String projectId) {
|
||||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||||
|
@ -196,14 +198,6 @@ public class ApiTestCaseService {
|
||||||
apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCase);
|
apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkApiExist(String id) {
|
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
|
||||||
example.createCriteria().andIdEqualTo(id).andDeletedEqualTo(false);
|
|
||||||
if (apiDefinitionMapper.countByExample(example) == 0) {
|
|
||||||
throw new MSException(Translator.get("please_recover_the_interface_data_first"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void follow(String id, String userId) {
|
public void follow(String id, String userId) {
|
||||||
checkResourceExist(id);
|
checkResourceExist(id);
|
||||||
ApiTestCaseFollowerExample example = new ApiTestCaseFollowerExample();
|
ApiTestCaseFollowerExample example = new ApiTestCaseFollowerExample();
|
||||||
|
@ -281,11 +275,19 @@ public class ApiTestCaseService {
|
||||||
List<String> ids = apiCaseLists.stream().map(ApiTestCaseDTO::getId).collect(Collectors.toList());
|
List<String> ids = apiCaseLists.stream().map(ApiTestCaseDTO::getId).collect(Collectors.toList());
|
||||||
List<CasePassDTO> passRateList = extApiTestCaseMapper.findPassRateByIds(ids);
|
List<CasePassDTO> passRateList = extApiTestCaseMapper.findPassRateByIds(ids);
|
||||||
Map<String, String> passRates = passRateList.stream().collect(Collectors.toMap(CasePassDTO::getId, CasePassDTO::getValue));
|
Map<String, String> passRates = passRateList.stream().collect(Collectors.toMap(CasePassDTO::getId, CasePassDTO::getValue));
|
||||||
|
//取模块id为新的set
|
||||||
|
List<String> moduleIds = apiCaseLists.stream().map(ApiTestCaseDTO::getModuleId).distinct().toList();
|
||||||
|
ApiDefinitionModuleExample moduleExample = new ApiDefinitionModuleExample();
|
||||||
|
moduleExample.createCriteria().andIdIn(moduleIds);
|
||||||
|
List<ApiDefinitionModule> modules = apiDefinitionModuleMapper.selectByExample(moduleExample);
|
||||||
|
//生成map key为id value为name
|
||||||
|
Map<String, String> moduleMap = modules.stream().collect(Collectors.toMap(ApiDefinitionModule::getId, ApiDefinitionModule::getName));
|
||||||
apiCaseLists.forEach(apiCase -> {
|
apiCaseLists.forEach(apiCase -> {
|
||||||
apiCase.setPassRate(passRates.get(apiCase.getId()));
|
apiCase.setPassRate(passRates.get(apiCase.getId()));
|
||||||
apiCase.setCreateName(userMap.get(apiCase.getCreateUser()));
|
apiCase.setCreateName(userMap.get(apiCase.getCreateUser()));
|
||||||
apiCase.setUpdateName(userMap.get(apiCase.getUpdateUser()));
|
apiCase.setUpdateName(userMap.get(apiCase.getUpdateUser()));
|
||||||
apiCase.setDeleteName(userMap.get(apiCase.getDeleteUser()));
|
apiCase.setDeleteName(userMap.get(apiCase.getDeleteUser()));
|
||||||
|
apiCase.setModulePath(StringUtils.isNotBlank(moduleMap.get(apiCase.getModuleId())) ? moduleMap.get(apiCase.getModuleId()) : Translator.get("api_unplanned_request"));
|
||||||
if (StringUtils.isNotBlank(apiCase.getEnvironmentId())
|
if (StringUtils.isNotBlank(apiCase.getEnvironmentId())
|
||||||
&& MapUtils.isNotEmpty(envMap)
|
&& MapUtils.isNotEmpty(envMap)
|
||||||
&& envMap.containsKey(apiCase.getEnvironmentId())) {
|
&& envMap.containsKey(apiCase.getEnvironmentId())) {
|
||||||
|
@ -301,9 +303,9 @@ public class ApiTestCaseService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchRecover(List<ApiTestCase> apiTestCases, String userId, String projectId) {
|
public void batchRecover(List<ApiTestCase> apiTestCases, String userId, String projectId) {
|
||||||
|
if (CollectionUtils.isNotEmpty(apiTestCases)) {
|
||||||
apiTestCases.forEach(apiTestCase -> {
|
apiTestCases.forEach(apiTestCase -> {
|
||||||
checkResourceExist(apiTestCase.getId());
|
checkResourceExist(apiTestCase.getId());
|
||||||
checkApiExist(apiTestCase.getApiDefinitionId());
|
|
||||||
checkNameExist(apiTestCase);
|
checkNameExist(apiTestCase);
|
||||||
apiTestCase.setDeleted(false);
|
apiTestCase.setDeleted(false);
|
||||||
apiTestCase.setDeleteUser(null);
|
apiTestCase.setDeleteUser(null);
|
||||||
|
@ -313,6 +315,7 @@ public class ApiTestCaseService {
|
||||||
//记录恢复日志
|
//记录恢复日志
|
||||||
apiTestCaseLogService.batchRecoverLog(apiTestCases, userId, projectId);
|
apiTestCaseLogService.batchRecoverLog(apiTestCases, userId, projectId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void delete(String id, String userId) {
|
public void delete(String id, String userId) {
|
||||||
ApiTestCase apiCase = checkResourceExist(id);
|
ApiTestCase apiCase = checkResourceExist(id);
|
||||||
|
@ -375,11 +378,12 @@ public class ApiTestCaseService {
|
||||||
if (CollectionUtils.isEmpty(ids)) {
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SubListUtils.dealForSubList(ids, 2000, subList -> batchMoveToGc(subList, userId, projectId, saveLog));
|
long deleteTime = System.currentTimeMillis();
|
||||||
|
SubListUtils.dealForSubList(ids, 2000, subList -> batchMoveToGc(subList, userId, projectId, saveLog, deleteTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void batchMoveToGc(List<String> ids, String userId, String projectId, boolean saveLog) {
|
private void batchMoveToGc(List<String> ids, String userId, String projectId, boolean saveLog, long deleteTime) {
|
||||||
extApiTestCaseMapper.batchMoveGc(ids, userId);
|
extApiTestCaseMapper.batchMoveGc(ids, userId, deleteTime);
|
||||||
if (saveLog) {
|
if (saveLog) {
|
||||||
List<ApiTestCase> apiTestCases = extApiTestCaseMapper.getCaseInfoByIds(ids, true);
|
List<ApiTestCase> apiTestCases = extApiTestCaseMapper.getCaseInfoByIds(ids, true);
|
||||||
apiTestCaseLogService.batchToGcLog(apiTestCases, userId, projectId);
|
apiTestCaseLogService.batchToGcLog(apiTestCases, userId, projectId);
|
||||||
|
@ -485,4 +489,5 @@ public class ApiTestCaseService {
|
||||||
public String uploadTempFile(MultipartFile file) {
|
public String uploadTempFile(MultipartFile file) {
|
||||||
return apiFileResourceService.uploadTempFile(file);
|
return apiFileResourceService.uploadTempFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -786,6 +786,7 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
|
||||||
@Order(10)
|
@Order(10)
|
||||||
public void deleteModuleTestSuccess() throws Exception {
|
public void deleteModuleTestSuccess() throws Exception {
|
||||||
this.preliminaryData();
|
this.preliminaryData();
|
||||||
|
this.getModuleTrashTreeNode();
|
||||||
|
|
||||||
// 删除没有文件的节点a1-b1-c1 检查是否级联删除根节点
|
// 删除没有文件的节点a1-b1-c1 检查是否级联删除根节点
|
||||||
BaseTreeNode a1b1Node = getNodeByName(this.getModuleTreeNode(), "a1-b1");
|
BaseTreeNode a1b1Node = getNodeByName(this.getModuleTreeNode(), "a1-b1");
|
||||||
|
|
|
@ -79,6 +79,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
private static final String BATCH_EDIT = BASE_PATH + "batch/edit";
|
private static final String BATCH_EDIT = BASE_PATH + "batch/edit";
|
||||||
private static final String BATCH_DELETE = BASE_PATH + "batch/delete";
|
private static final String BATCH_DELETE = BASE_PATH + "batch/delete";
|
||||||
private static final String BATCH_MOVE_GC = BASE_PATH + "batch/move-gc";
|
private static final String BATCH_MOVE_GC = BASE_PATH + "batch/move-gc";
|
||||||
|
private static final String BATCH_RECOVER = BASE_PATH + "batch/recover";
|
||||||
private static final String POS_URL = BASE_PATH + "/edit/pos";
|
private static final String POS_URL = BASE_PATH + "/edit/pos";
|
||||||
private static final String UPLOAD_TEMP_FILE = BASE_PATH + "/upload/temp/file";
|
private static final String UPLOAD_TEMP_FILE = BASE_PATH + "/upload/temp/file";
|
||||||
|
|
||||||
|
@ -151,8 +152,8 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
apiDefinitionMapper.insertSelective(apiDefinition);
|
apiDefinitionMapper.insertSelective(apiDefinition);
|
||||||
ApiDefinitionBlob apiDefinitionBlob = new ApiDefinitionBlob();
|
ApiDefinitionBlob apiDefinitionBlob = new ApiDefinitionBlob();
|
||||||
apiDefinitionBlob.setId(apiDefinition.getId());
|
apiDefinitionBlob.setId(apiDefinition.getId());
|
||||||
apiDefinitionBlob.setRequest(new byte[0]);
|
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
|
||||||
apiDefinitionBlob.setResponse(new byte[0]);
|
apiDefinitionBlob.setRequest(JSON.toJSONBytes(msHttpElement));
|
||||||
apiDefinitionBlobMapper.insertSelective(apiDefinitionBlob);
|
apiDefinitionBlobMapper.insertSelective(apiDefinitionBlob);
|
||||||
apiDefinition.setId("apiDefinitionId1");
|
apiDefinition.setId("apiDefinitionId1");
|
||||||
apiDefinition.setModuleId("moduleId1");
|
apiDefinition.setModuleId("moduleId1");
|
||||||
|
@ -772,6 +773,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
|
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
request.setExcludeIds(new ArrayList<>());
|
request.setExcludeIds(new ArrayList<>());
|
||||||
|
request.setApiDefinitionId("apiDefinitionId");
|
||||||
request.setModuleIds(List.of("case-moduleId"));
|
request.setModuleIds(List.of("case-moduleId"));
|
||||||
responsePost(BATCH_MOVE_GC, request);
|
responsePost(BATCH_MOVE_GC, request);
|
||||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
|
@ -839,6 +841,42 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, TRASH_PAGE, pageRequest);
|
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, TRASH_PAGE, pageRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(14)
|
||||||
|
public void batchRecover() throws Exception {
|
||||||
|
// @@请求成功
|
||||||
|
ApiTestCaseBatchRequest request = new ApiTestCaseBatchRequest();
|
||||||
|
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
|
request.setSelectAll(false);
|
||||||
|
request.setSelectIds(List.of(apiTestCase.getId()));
|
||||||
|
request.setExcludeIds(List.of(apiTestCase.getId()));
|
||||||
|
responsePost(BATCH_RECOVER, request);
|
||||||
|
|
||||||
|
ApiDefinition apiDefinition = new ApiDefinition();
|
||||||
|
apiDefinition.setId("apiDefinitionId");
|
||||||
|
apiDefinition.setDeleted(true);
|
||||||
|
apiDefinitionMapper.updateByPrimaryKeySelective(apiDefinition);
|
||||||
|
request.setSelectAll(true);
|
||||||
|
request.setSelectIds(List.of(apiTestCase.getId()));
|
||||||
|
request.setExcludeIds(List.of(apiTestCase.getId()));
|
||||||
|
request.setModuleIds(List.of("case-moduleId"));
|
||||||
|
responsePost(BATCH_RECOVER, request);
|
||||||
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
|
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andApiDefinitionIdEqualTo("apiDefinitionId").andDeletedEqualTo(false);
|
||||||
|
List<ApiTestCase> caseList = apiTestCaseMapper.selectByExample(example);
|
||||||
|
caseList.forEach(apiTestCase -> Assertions.assertFalse(apiTestCase.getDeleted()));
|
||||||
|
|
||||||
|
request.setSelectAll(true);
|
||||||
|
request.setExcludeIds(new ArrayList<>());
|
||||||
|
request.setModuleIds(List.of("case-moduleId"));
|
||||||
|
responsePost(BATCH_RECOVER, request);
|
||||||
|
//校验日志
|
||||||
|
checkLog(apiTestCase.getId(), OperationLogType.DELETE);
|
||||||
|
//校验权限
|
||||||
|
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_RECOVER, BATCH_RECOVER, request);
|
||||||
|
this.batchMoveGc();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(20)
|
@Order(20)
|
||||||
|
@ -880,6 +918,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
request.setModuleIds(List.of("case-moduleId"));
|
request.setModuleIds(List.of("case-moduleId"));
|
||||||
|
request.setApiDefinitionId("apiDefinitionId");
|
||||||
responsePost(BATCH_DELETE, request);
|
responsePost(BATCH_DELETE, request);
|
||||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andApiDefinitionIdEqualTo("apiDefinitionId");
|
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andApiDefinitionIdEqualTo("apiDefinitionId");
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package io.metersphere.project.controller;
|
package io.metersphere.project.controller;
|
||||||
|
|
||||||
import io.metersphere.project.dto.environment.EnvironmentExportRequest;
|
import io.metersphere.project.dto.environment.*;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentFilterRequest;
|
|
||||||
import io.metersphere.project.dto.environment.EnvironmentImportRequest;
|
|
||||||
import io.metersphere.project.dto.environment.EnvironmentRequest;
|
|
||||||
import io.metersphere.project.dto.environment.datasource.DataSource;
|
import io.metersphere.project.dto.environment.datasource.DataSource;
|
||||||
import io.metersphere.project.dto.environment.ssl.KeyStoreEntry;
|
import io.metersphere.project.dto.environment.ssl.KeyStoreEntry;
|
||||||
import io.metersphere.project.service.CommandService;
|
import io.metersphere.project.service.CommandService;
|
||||||
|
@ -50,7 +47,7 @@ public class EnvironmentController {
|
||||||
@GetMapping("/get/{environmentId}")
|
@GetMapping("/get/{environmentId}")
|
||||||
@Operation(summary = "项目管理-环境-环境目录-详情")
|
@Operation(summary = "项目管理-环境-环境目录-详情")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ)
|
||||||
public EnvironmentRequest get(@PathVariable String environmentId) {
|
public EnvironmentInfoDTO get(@PathVariable String environmentId) {
|
||||||
return environmentService.get(environmentId);
|
return environmentService.get(environmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +56,7 @@ public class EnvironmentController {
|
||||||
@Operation(summary = "项目管理-环境-环境目录-新增")
|
@Operation(summary = "项目管理-环境-环境目录-新增")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_ADD)
|
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_ADD)
|
||||||
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = EnvironmentLogService.class)
|
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = EnvironmentLogService.class)
|
||||||
public EnvironmentRequest add(@Validated({Created.class}) @RequestPart(value = "request") EnvironmentRequest request,
|
public Environment add(@Validated({Created.class}) @RequestPart(value = "request") EnvironmentRequest request,
|
||||||
@RequestPart(value = "file", required = false) List<MultipartFile> sslFiles) {
|
@RequestPart(value = "file", required = false) List<MultipartFile> sslFiles) {
|
||||||
return environmentService.add(request, SessionUtils.getUserId(), sslFiles);
|
return environmentService.add(request, SessionUtils.getUserId(), sslFiles);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +65,7 @@ public class EnvironmentController {
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_UPDATE)
|
||||||
@Operation(summary = "项目管理-环境-环境目录-修改")
|
@Operation(summary = "项目管理-环境-环境目录-修改")
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = EnvironmentLogService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = EnvironmentLogService.class)
|
||||||
public EnvironmentRequest update(@Validated({Updated.class}) @RequestPart("request") EnvironmentRequest request,
|
public Environment update(@Validated({Updated.class}) @RequestPart("request") EnvironmentRequest request,
|
||||||
@RequestPart(value = "file", required = false) List<MultipartFile> sslFiles) {
|
@RequestPart(value = "file", required = false) List<MultipartFile> sslFiles) {
|
||||||
return environmentService.update(request, SessionUtils.getUserId(), sslFiles);
|
return environmentService.update(request, SessionUtils.getUserId(), sslFiles);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package io.metersphere.project.dto.environment;
|
||||||
|
|
||||||
|
import io.metersphere.validation.groups.Created;
|
||||||
|
import io.metersphere.validation.groups.Updated;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EnvironmentInfoDTO implements Serializable {
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Schema(description = "ID")
|
||||||
|
@NotBlank(message = "{project_parameters.id.not_blank}", groups = {Updated.class})
|
||||||
|
@Size(min = 1, max = 50, message = "{project_parameters.id.length_range}", groups = {Updated.class})
|
||||||
|
private String id;
|
||||||
|
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotBlank(message = "{project_application.project_id.not_blank}", groups = {Created.class, Updated.class})
|
||||||
|
@Size(min = 1, max = 50, message = "{project_parameters.project_id.length_range}", groups = {Created.class, Updated.class})
|
||||||
|
private String projectId;
|
||||||
|
@Schema(description = "环境名称")
|
||||||
|
@NotBlank(message = "{environment_name_is_null}", groups = {Created.class, Updated.class})
|
||||||
|
private String name;
|
||||||
|
@Schema(description = "环境配置")
|
||||||
|
@NotNull(message = "{environment_config_is_null}", groups = {Created.class, Updated.class})
|
||||||
|
private EnvironmentConfig config;
|
||||||
|
@Schema(description = "是否是mock环境")
|
||||||
|
private Boolean mock;
|
||||||
|
@Schema(description = "描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
}
|
|
@ -114,7 +114,7 @@ public class EnvironmentService {
|
||||||
return extEnvironmentMapper.selectByKeyword(request.getKeyword(), false, request.getProjectId());
|
return extEnvironmentMapper.selectByKeyword(request.getKeyword(), false, request.getProjectId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnvironmentRequest add(EnvironmentRequest request, String userId, List<MultipartFile> sslFiles) {
|
public Environment add(EnvironmentRequest request, String userId, List<MultipartFile> sslFiles) {
|
||||||
Environment environment = new Environment();
|
Environment environment = new Environment();
|
||||||
environment.setId(IDGenerator.nextStr());
|
environment.setId(IDGenerator.nextStr());
|
||||||
environment.setCreateUser(userId);
|
environment.setCreateUser(userId);
|
||||||
|
@ -134,7 +134,7 @@ public class EnvironmentService {
|
||||||
environmentBlob.setConfig(JSON.toJSONBytes(request.getConfig()));
|
environmentBlob.setConfig(JSON.toJSONBytes(request.getConfig()));
|
||||||
environmentBlobMapper.insert(environmentBlob);
|
environmentBlobMapper.insert(environmentBlob);
|
||||||
uploadFileToMinio(sslFiles, environment);
|
uploadFileToMinio(sslFiles, environment);
|
||||||
return request;
|
return environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadFileToMinio(List<MultipartFile> sslFiles, Environment environment) {
|
private void uploadFileToMinio(List<MultipartFile> sslFiles, Environment environment) {
|
||||||
|
@ -153,20 +153,20 @@ public class EnvironmentService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnvironmentRequest get(String environmentId) {
|
public EnvironmentInfoDTO get(String environmentId) {
|
||||||
EnvironmentRequest environmentRequest = new EnvironmentRequest();
|
EnvironmentInfoDTO environmentInfoDTO = new EnvironmentInfoDTO();
|
||||||
Environment environment = environmentMapper.selectByPrimaryKey(environmentId);
|
Environment environment = environmentMapper.selectByPrimaryKey(environmentId);
|
||||||
if (environment == null) {
|
if (environment == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
environmentRequest.setProjectId(environment.getProjectId());
|
environmentInfoDTO.setProjectId(environment.getProjectId());
|
||||||
environmentRequest.setName(environment.getName());
|
environmentInfoDTO.setName(environment.getName());
|
||||||
environmentRequest.setId(environment.getId());
|
environmentInfoDTO.setId(environment.getId());
|
||||||
EnvironmentBlob environmentBlob = environmentBlobMapper.selectByPrimaryKey(environmentId);
|
EnvironmentBlob environmentBlob = environmentBlobMapper.selectByPrimaryKey(environmentId);
|
||||||
if (environmentBlob == null) {
|
if (environmentBlob == null) {
|
||||||
environmentRequest.setConfig(new EnvironmentConfig());
|
environmentInfoDTO.setConfig(new EnvironmentConfig());
|
||||||
} else {
|
} else {
|
||||||
environmentRequest.setConfig(JSON.parseObject(new String(environmentBlob.getConfig()), EnvironmentConfig.class));
|
environmentInfoDTO.setConfig(JSON.parseObject(new String(environmentBlob.getConfig()), EnvironmentConfig.class));
|
||||||
}
|
}
|
||||||
if (BooleanUtils.isTrue(environment.getMock())) {
|
if (BooleanUtils.isTrue(environment.getMock())) {
|
||||||
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||||
|
@ -175,11 +175,11 @@ public class EnvironmentService {
|
||||||
String baseUrl = baseSystemConfigDTO.getUrl();
|
String baseUrl = baseSystemConfigDTO.getUrl();
|
||||||
if (StringUtils.isNotEmpty(baseUrl)) {
|
if (StringUtils.isNotEmpty(baseUrl)) {
|
||||||
Project project = projectMapper.selectByPrimaryKey(environment.getProjectId());
|
Project project = projectMapper.selectByPrimaryKey(environment.getProjectId());
|
||||||
environmentRequest.getConfig().getHttpConfig().get(0).setUrl(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, project.getNum()));
|
environmentInfoDTO.getConfig().getHttpConfig().get(0).setUrl(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, project.getNum()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return environmentRequest;
|
return environmentInfoDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getNextOrder(String projectId) {
|
public Long getNextOrder(String projectId) {
|
||||||
|
@ -294,7 +294,7 @@ public class EnvironmentService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnvironmentRequest update(EnvironmentRequest request, String userId, List<MultipartFile> sslFiles) {
|
public Environment update(EnvironmentRequest request, String userId, List<MultipartFile> sslFiles) {
|
||||||
Environment environment = new Environment();
|
Environment environment = new Environment();
|
||||||
environment.setId(request.getId());
|
environment.setId(request.getId());
|
||||||
environment.setUpdateUser(userId);
|
environment.setUpdateUser(userId);
|
||||||
|
@ -308,7 +308,7 @@ public class EnvironmentService {
|
||||||
environmentBlob.setConfig(JSON.toJSONBytes(request.getConfig()));
|
environmentBlob.setConfig(JSON.toJSONBytes(request.getConfig()));
|
||||||
environmentBlobMapper.updateByPrimaryKeySelective(environmentBlob);
|
environmentBlobMapper.updateByPrimaryKeySelective(environmentBlob);
|
||||||
uploadFileToMinio(sslFiles, environment);
|
uploadFileToMinio(sslFiles, environment);
|
||||||
return request;
|
return environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create(EnvironmentImportRequest request, MultipartFile file, String userId, String currentProjectId) {
|
public void create(EnvironmentImportRequest request, MultipartFile file, String userId, String currentProjectId) {
|
||||||
|
|
|
@ -370,7 +370,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||||
paramMap.add("request", JSON.toJSONString(request));
|
paramMap.add("request", JSON.toJSONString(request));
|
||||||
MvcResult mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
MvcResult mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
EnvironmentRequest response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
Environment response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
Environment environment = environmentMapper.selectByPrimaryKey(response.getId());
|
Environment environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -394,7 +394,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -419,7 +419,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -444,7 +444,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -469,7 +469,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -494,7 +494,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -519,7 +519,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -546,7 +546,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -571,7 +571,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -596,7 +596,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -622,7 +622,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setConfig(envConfig);
|
request.setConfig(envConfig);
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertEquals(response.getName(), environment.getName());
|
Assertions.assertEquals(response.getName(), environment.getName());
|
||||||
|
@ -652,7 +652,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
paramMap.add("file", List.of(file, file11));
|
paramMap.add("file", List.of(file, file11));
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = requestMultipartWithOk(add, paramMap, DEFAULT_PROJECT_ID);
|
mvcResult = requestMultipartWithOk(add, paramMap, DEFAULT_PROJECT_ID);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertEquals(response.getName(), environment.getName());
|
Assertions.assertEquals(response.getName(), environment.getName());
|
||||||
|
@ -703,7 +703,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
List<Environment> environments = environmentMapper.selectByExample(example);
|
List<Environment> environments = environmentMapper.selectByExample(example);
|
||||||
String id = environments.get(0).getId();
|
String id = environments.get(0).getId();
|
||||||
MvcResult mvcResult = this.responseGet(get + id);
|
MvcResult mvcResult = this.responseGet(get + id);
|
||||||
EnvironmentRequest response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
EnvironmentInfoDTO response = parseObjectFromMvcResult(mvcResult, EnvironmentInfoDTO.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
Assertions.assertEquals(id, response.getId());
|
Assertions.assertEquals(id, response.getId());
|
||||||
Assertions.assertEquals("name", response.getName());
|
Assertions.assertEquals("name", response.getName());
|
||||||
|
@ -724,7 +724,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
environmentBlob.setConfig(JSON.toJSONBytes(new EnvironmentConfig()));
|
environmentBlob.setConfig(JSON.toJSONBytes(new EnvironmentConfig()));
|
||||||
environmentBlobMapper.insert(environmentBlob);
|
environmentBlobMapper.insert(environmentBlob);
|
||||||
mvcResult = this.responseGet(get + "environmentId1");
|
mvcResult = this.responseGet(get + "environmentId1");
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, EnvironmentInfoDTO.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
Assertions.assertEquals("environmentId1", response.getId());
|
Assertions.assertEquals("environmentId1", response.getId());
|
||||||
//校验权限
|
//校验权限
|
||||||
|
@ -817,7 +817,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
MvcResult mvcResult = requestMultipartWithOkAndReturn(update, paramMap, ERROR_REQUEST_MATCHER);
|
MvcResult mvcResult = requestMultipartWithOkAndReturn(update, paramMap, ERROR_REQUEST_MATCHER);
|
||||||
EnvironmentRequest response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
Environment response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
Environment environment = environmentMapper.selectByPrimaryKey(response.getId());
|
Environment environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertNotNull(environment);
|
Assertions.assertNotNull(environment);
|
||||||
|
@ -838,7 +838,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
paramMap.add("file", List.of(file, file11));
|
paramMap.add("file", List.of(file, file11));
|
||||||
paramMap.set("request", JSON.toJSONString(request));
|
paramMap.set("request", JSON.toJSONString(request));
|
||||||
mvcResult = requestMultipartWithOk(update, paramMap, DEFAULT_PROJECT_ID);
|
mvcResult = requestMultipartWithOk(update, paramMap, DEFAULT_PROJECT_ID);
|
||||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
response = parseObjectFromMvcResult(mvcResult, Environment.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||||
Assertions.assertEquals(response.getName(), environment.getName());
|
Assertions.assertEquals(response.getName(), environment.getName());
|
||||||
|
|
Loading…
Reference in New Issue