feat(接口测试): 接口管理模块接口定义接口文档查看
This commit is contained in:
parent
9f810c0c36
commit
359d03662d
|
@ -231,6 +231,7 @@ api_definition_module.parent_id.not_blank=父级ID不能为空
|
|||
api_definition_module.project_id.length_range=项目ID长度必须在1-50之间
|
||||
api_definition_module.project_id.not_blank=项目ID不能为空
|
||||
api_definition_module.pos.not_blank=模块位置不能为空
|
||||
api_definition_module.api.all=全部接口
|
||||
#module:ApiDefinitionMockConfig
|
||||
api_definition_mock_config.api_definition_mock_id.not_blank=接口mock pk不能为空
|
||||
#module:ApiScenarioModule
|
||||
|
|
|
@ -231,6 +231,7 @@ api_definition_module.parent_id.not_blank=parent fk cannot be empty
|
|||
api_definition_module.project_id.length_range=Item fk length must be between 1-50
|
||||
api_definition_module.project_id.not_blank=Item fk cannot be empty
|
||||
api_definition_module.pos.not_blank=Module position cannot be empty
|
||||
api_definition_module.api.all=All interfaces
|
||||
#module:ApiDefinitionMockConfig
|
||||
api_definition_mock_config.api_definition_mock_id.not_blank=Interface mock pk cannot be empty
|
||||
#module:ApiScenarioModule
|
||||
|
|
|
@ -231,6 +231,7 @@ api_definition_module.parent_id.not_blank=父级ID不能为空
|
|||
api_definition_module.project_id.length_range=项目ID长度必须在1-50之间
|
||||
api_definition_module.project_id.not_blank=项目ID不能为空
|
||||
api_definition_module.pos.not_blank=模块位置不能为空
|
||||
api_definition_module.api.all=全部接口
|
||||
#module:ApiDefinitionMockConfig
|
||||
api_definition_mock_config.api_definition_mock_id.not_blank=接口mock pk不能为空
|
||||
#module:ApiScenarioModule
|
||||
|
|
|
@ -231,6 +231,7 @@ api_definition_module.parent_id.not_blank=父級ID不能為空
|
|||
api_definition_module.project_id.length_range=項目ID長度必須在1-50之間
|
||||
api_definition_module.project_id.not_blank=項目ID不能為空
|
||||
api_definition_module.pos.not_blank=模塊位置不能為空
|
||||
api_definition_module.api.all=全部接口
|
||||
#module:ApiDefinitionMockConfig
|
||||
api_definition_mock_config.api_definition_mock_id.not_blank=接口mock pk不能為空
|
||||
#module:ApiScenarioModule
|
||||
|
|
|
@ -13,6 +13,7 @@ import io.metersphere.system.utils.PageUtils;
|
|||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -30,6 +31,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/definition")
|
||||
@Tag(name = "接口测试-接口管理-接口定义")
|
||||
public class ApiDefinitionController {
|
||||
@Resource
|
||||
private ApiDefinitionService apiDefinitionService;
|
||||
|
@ -169,4 +171,11 @@ public class ApiDefinitionController {
|
|||
return apiDefinitionService.uploadTempFile(file);
|
||||
}
|
||||
|
||||
@PostMapping("/doc")
|
||||
@Operation(summary = "接口测试-接口管理-接口文档列表")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ)
|
||||
public ApiDefinitionDocDTO getDocInfo(@Validated @RequestBody ApiDefinitionDocRequest request) {
|
||||
return apiDefinitionService.getDocInfo(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ public enum ApiResultCode implements IResultCode {
|
|||
|
||||
API_DEBUG_EXIST(104001, "api_debug_exist"),
|
||||
API_DEFINITION_EXIST(104002, "api_definition_exist"),
|
||||
API_DEFINITION_NOT_EXIST(104003, "resource_not_exist");
|
||||
API_DEFINITION_NOT_EXIST(104003, "resource_not_exist"),
|
||||
API_DEFINITION_MODULE_NOT_EXIST(10404, "resource_not_exist");
|
||||
|
||||
|
||||
private final int code;
|
||||
|
|
|
@ -80,4 +80,8 @@ public class ApiDefinitionAddRequest implements Serializable {
|
|||
*/
|
||||
@Schema(description = "关联文件ID")
|
||||
private List<String> linkFileIds;
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = (path != null) ? path.trim() : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import jakarta.validation.constraints.Size;
|
|||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
/**
|
||||
|
@ -15,6 +16,7 @@ import java.util.LinkedHashSet;
|
|||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ApiDefinitionBatchUpdateRequest extends ApiDefinitionBatchRequest {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "所需更新的字段名", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lan
|
||||
*/
|
||||
@Data
|
||||
public class ApiDefinitionDocDTO{
|
||||
|
||||
@Schema(description = "文档标题名称")
|
||||
private String docTitle;
|
||||
|
||||
@Schema(description = "类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "接口文档内容")
|
||||
List<ApiDefinitionDTO> docList;
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lan
|
||||
*/
|
||||
@Data
|
||||
public class ApiDefinitionDocRequest implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "关键字")
|
||||
private String keyword;
|
||||
|
||||
@Schema(description = "接口pk")
|
||||
@Size(min = 1, max = 50, message = "{api_definition.id.length_range}")
|
||||
private String apiId;
|
||||
|
||||
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_definition.project_id.not_blank}")
|
||||
@Size(min = 1, max = 50, message = "{api_definition.project_id.length_range}")
|
||||
private String projectId;
|
||||
|
||||
@Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Size(min = 1, max = 20, message = "{api_debug.protocol.length_range}")
|
||||
private String protocol = ModuleConstants.NODE_PROTOCOL_HTTP;
|
||||
|
||||
@Schema(description = "模块ID(根据模块树查询时要把当前节点以及子节点都放在这里。)")
|
||||
private List<@NotBlank String> moduleIds;
|
||||
|
||||
@Schema(description = "类型(ALL,MODULE,API)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String type;
|
||||
|
||||
@Schema(description = "版本fk")
|
||||
@Size(min = 1, max = 50, message = "{api_definition.version_id.length_range}")
|
||||
private String versionId;
|
||||
|
||||
@Schema(description = "删除状态(状态为 1 时为回收站数据)")
|
||||
private Boolean deleted = false;
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.dto.api.request.http.Header;
|
||||
import io.metersphere.sdk.dto.api.request.http.body.Body;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
@ -21,12 +20,6 @@ public class HttpResponse implements Serializable {
|
|||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "响应编号")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "响应类型")
|
||||
private String type = ModuleConstants.NODE_PROTOCOL_HTTP;
|
||||
|
||||
@Schema(description = "响应名称")
|
||||
private String name;
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
List<ApiDefinitionDTO> list(@Param("request") ApiDefinitionPageRequest request);
|
||||
|
||||
List<ApiDefinitionDTO> listDoc(@Param("request") ApiDefinitionDocRequest request);
|
||||
|
||||
List<ApiCaseComputeDTO> selectApiCaseByIdsAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
||||
|
||||
Long getPos(@Param("projectId") String projectId);
|
||||
|
|
|
@ -21,11 +21,25 @@
|
|||
api_definition.deleted, project_version.name as version_name
|
||||
from api_definition
|
||||
LEFT JOIN project_version ON project_version.id = api_definition.version_id
|
||||
where deleted = #{request.deleted}
|
||||
where api_definition.deleted = #{request.deleted}
|
||||
<include refid="queryWhereCondition"/>
|
||||
|
||||
</select>
|
||||
|
||||
<select id="listDoc" resultType="io.metersphere.api.dto.definition.ApiDefinitionDTO">
|
||||
select
|
||||
api_definition.id, api_definition.`name`, api_definition.protocol, api_definition.`method`,
|
||||
api_definition.`path`, api_definition.`status`, api_definition.num, api_definition.tags, api_definition.pos,
|
||||
api_definition.project_id, api_definition.module_id, api_definition.latest, api_definition.version_id,
|
||||
api_definition.ref_id, api_definition.description, api_definition.create_time, api_definition.create_user,
|
||||
api_definition.update_time, api_definition.update_user, api_definition.delete_user, api_definition.delete_time,
|
||||
api_definition.deleted, project_version.name as version_name
|
||||
from api_definition
|
||||
LEFT JOIN project_version ON project_version.id = api_definition.version_id
|
||||
where api_definition.deleted = #{request.deleted}
|
||||
<include refid="queryDocWhereCondition"/>
|
||||
</select>
|
||||
|
||||
<select id="selectApiCaseByIdsAndStatusIsNotTrash"
|
||||
resultType="io.metersphere.api.dto.definition.ApiCaseComputeDTO">
|
||||
select
|
||||
|
@ -220,6 +234,32 @@
|
|||
</include>
|
||||
</sql>
|
||||
|
||||
<sql id="queryDocWhereCondition">
|
||||
<if test="request.keyword != null and request.keyword != ''">
|
||||
and (
|
||||
api_definition.num like concat('%', #{request.keyword},'%')
|
||||
or api_definition.name like concat('%', #{request.keyword},'%')
|
||||
or api_definition.tags like JSON_CONTAINS(tags, concat('["',#{request.keyword},'"]'))
|
||||
)
|
||||
</if>
|
||||
<if test="request.projectId != null and request.projectId != ''">
|
||||
and api_definition.project_id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.protocol != null and request.protocol != ''">
|
||||
AND api_definition.protocol = #{request.protocol}
|
||||
</if>
|
||||
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||
and api_definition.module_id in
|
||||
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||
#{nodeId}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<include refid="queryDocVersionCondition">
|
||||
<property name="versionTable" value="api_definition"/>
|
||||
</include>
|
||||
</sql>
|
||||
|
||||
<sql id="filters">
|
||||
<if test="${filter} != null and ${filter}.size() > 0">
|
||||
<foreach collection="${filter}.entrySet()" index="key" item="values">
|
||||
|
@ -324,6 +364,14 @@
|
|||
AND ${versionTable}.latest = 1
|
||||
</if>
|
||||
</sql>
|
||||
<sql id="queryDocVersionCondition">
|
||||
<if test="request.versionId != null and request.versionId != ''">
|
||||
and ${versionTable}.version_id = #{request.versionId}
|
||||
</if>
|
||||
<if test="request.versionId == null and request.apiId == null">
|
||||
AND ${versionTable}.latest = 1
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="queryWhereConditionByBaseQueryRequest">
|
||||
<if test="request.condition.combine != null">
|
||||
|
|
|
@ -3,16 +3,17 @@ package io.metersphere.api.service.definition;
|
|||
import io.metersphere.api.domain.ApiDefinition;
|
||||
import io.metersphere.api.domain.ApiDefinitionExample;
|
||||
import io.metersphere.api.dto.definition.*;
|
||||
import io.metersphere.api.mapper.ApiDefinitionBlobMapper;
|
||||
import io.metersphere.api.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -34,6 +35,9 @@ public class ApiDefinitionLogService {
|
|||
@Resource
|
||||
private ApiDefinitionService apiDefinitionService;
|
||||
|
||||
@Resource
|
||||
private ApiDefinitionBlobMapper apiDefinitionBlobMapper;
|
||||
|
||||
/**
|
||||
* 添加接口日志
|
||||
*
|
||||
|
@ -49,7 +53,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.ADD.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
request.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/add");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
|
@ -63,7 +67,7 @@ public class ApiDefinitionLogService {
|
|||
* @return
|
||||
*/
|
||||
public LogDTO updateLog(ApiDefinitionUpdateRequest request) {
|
||||
ApiDefinitionDTO apiDefinition = apiDefinitionService.getInfo(request.getId(), SessionUtils.getUserId());
|
||||
ApiDefinitionDTO apiDefinition = getOriginalValue(request.getId());
|
||||
if(apiDefinition.getId() != null){
|
||||
LogDTO dto = new LogDTO(
|
||||
request.getProjectId(),
|
||||
|
@ -73,7 +77,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
request.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||
|
@ -89,7 +93,7 @@ public class ApiDefinitionLogService {
|
|||
* @return
|
||||
*/
|
||||
public LogDTO delLog(ApiDefinitionDeleteRequest request) {
|
||||
ApiDefinitionDTO apiDefinition = apiDefinitionService.getInfo(request.getId(), SessionUtils.getUserId());
|
||||
ApiDefinitionDTO apiDefinition = getOriginalValue(request.getId());
|
||||
if(apiDefinition.getId() != null){
|
||||
LogDTO dto = new LogDTO(
|
||||
request.getProjectId(),
|
||||
|
@ -99,7 +103,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
apiDefinition.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/delete");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||
|
@ -130,7 +134,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
item.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/batch-delete");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||
|
@ -162,7 +166,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
item.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/batch-update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||
|
@ -173,7 +177,7 @@ public class ApiDefinitionLogService {
|
|||
}
|
||||
|
||||
public LogDTO copyLog(ApiDefinitionCopyRequest request) {
|
||||
ApiDefinitionDTO apiDefinition = apiDefinitionService.getInfo(request.getId(), SessionUtils.getUserId());
|
||||
ApiDefinitionDTO apiDefinition = getOriginalValue(request.getId());
|
||||
if(apiDefinition.getId() != null){
|
||||
LogDTO dto = new LogDTO(
|
||||
apiDefinition.getProjectId(),
|
||||
|
@ -183,7 +187,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
apiDefinition.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/copy");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||
|
@ -208,7 +212,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
item.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/batch-move");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||
|
@ -219,7 +223,7 @@ public class ApiDefinitionLogService {
|
|||
}
|
||||
|
||||
public LogDTO followLog(String id) {
|
||||
ApiDefinitionDTO apiDefinition = apiDefinitionService.getInfo(id, SessionUtils.getUserId());
|
||||
ApiDefinitionDTO apiDefinition = getOriginalValue(id);
|
||||
if(apiDefinition.getId() != null){
|
||||
Project project = projectMapper.selectByPrimaryKey(apiDefinition.getProjectId());
|
||||
LogDTO dto = new LogDTO(
|
||||
|
@ -246,7 +250,7 @@ public class ApiDefinitionLogService {
|
|||
* @return
|
||||
*/
|
||||
public LogDTO restoreLog(ApiDefinitionDeleteRequest request) {
|
||||
ApiDefinitionDTO apiDefinition = apiDefinitionService.getInfo(request.getId(), SessionUtils.getUserId());
|
||||
ApiDefinitionDTO apiDefinition = getOriginalValue(request.getId());
|
||||
if(apiDefinition.getId() != null){
|
||||
LogDTO dto = new LogDTO(
|
||||
request.getProjectId(),
|
||||
|
@ -256,7 +260,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
apiDefinition.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/restore");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||
|
@ -288,7 +292,7 @@ public class ApiDefinitionLogService {
|
|||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
item.getName());
|
||||
|
||||
dto.setHistory(true);
|
||||
dto.setPath("/api/definition/batch-restore");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(item));
|
||||
|
@ -304,7 +308,7 @@ public class ApiDefinitionLogService {
|
|||
* 删除回收站接口定义接口日志
|
||||
*/
|
||||
public LogDTO trashDelLog(ApiDefinitionDeleteRequest request) {
|
||||
ApiDefinitionDTO apiDefinition = apiDefinitionService.getInfo(request.getId(), SessionUtils.getUserId());
|
||||
ApiDefinitionDTO apiDefinition = getOriginalValue(request.getId());
|
||||
if(apiDefinition.getId() != null){
|
||||
LogDTO dto = new LogDTO(
|
||||
request.getProjectId(),
|
||||
|
@ -354,4 +358,17 @@ public class ApiDefinitionLogService {
|
|||
return dtoList;
|
||||
}
|
||||
|
||||
private ApiDefinitionDTO getOriginalValue(String id){
|
||||
ApiDefinitionDTO apiDefinitionDTO = new ApiDefinitionDTO();
|
||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||
if(null != apiDefinition){
|
||||
// 2. 使用Optional避免空指针异常
|
||||
apiDefinitionService.handleBlob(id, apiDefinitionDTO);
|
||||
}
|
||||
BeanUtils.copyBean(apiDefinitionDTO, apiDefinition);
|
||||
return apiDefinitionDTO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import io.metersphere.api.dto.definition.*;
|
|||
import io.metersphere.api.enums.ApiReportStatus;
|
||||
import io.metersphere.api.mapper.*;
|
||||
import io.metersphere.api.service.ApiFileResourceService;
|
||||
import io.metersphere.sdk.util.ApiDataUtils;
|
||||
import io.metersphere.sdk.util.*;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
|
||||
import io.metersphere.project.service.ProjectService;
|
||||
|
@ -16,10 +16,6 @@ import io.metersphere.sdk.constants.ApplicationNumScope;
|
|||
import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.FileAssociationSourceUtil;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
|
@ -41,12 +37,16 @@ import java.util.function.Function;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.metersphere.api.controller.result.ApiResultCode.*;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class ApiDefinitionService {
|
||||
|
||||
public static final Long ORDER_STEP = 5000L;
|
||||
|
||||
private static final String ALL_API = "api_definition_module.api.all";
|
||||
|
||||
@Resource
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
|
||||
|
@ -78,6 +78,9 @@ public class ApiDefinitionService {
|
|||
@Resource
|
||||
private ApiFileResourceService apiFileResourceService;
|
||||
|
||||
@Resource
|
||||
private ApiDefinitionModuleMapper apiDefinitionModuleMapper;
|
||||
|
||||
public List<ApiDefinitionDTO> getApiDefinitionPage(ApiDefinitionPageRequest request){
|
||||
List<ApiDefinitionDTO> list = extApiDefinitionMapper.list(request);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
|
@ -440,7 +443,6 @@ public class ApiDefinitionService {
|
|||
List<String> refIds = extApiDefinitionMapper.getRefIds(ids, false);
|
||||
if(CollectionUtils.isNotEmpty(refIds)){
|
||||
SubListUtils.dealForSubList(refIds, 2000, subRefIds -> {
|
||||
extApiDefinitionMapper.batchDeleteByRefId(subRefIds, userId, projectId);
|
||||
List<String> delApiIds = extApiDefinitionMapper.getIdsByRefId(subRefIds, false);
|
||||
SubListUtils.dealForSubList(delApiIds, 2000, subList -> {
|
||||
if(CollectionUtils.isNotEmpty(delApiIds)){
|
||||
|
@ -448,6 +450,7 @@ public class ApiDefinitionService {
|
|||
deleteApiRelatedData(subList, userId, projectId);
|
||||
}
|
||||
});
|
||||
extApiDefinitionMapper.batchDeleteByRefId(subRefIds, userId, projectId);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
@ -478,7 +481,7 @@ public class ApiDefinitionService {
|
|||
apiDefinitionExample.setOrderByClause("update_time DESC");
|
||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByExample(apiDefinitionExample).stream().findFirst().orElse(null);
|
||||
if (apiDefinition == null) {
|
||||
throw new MSException(ApiResultCode.API_DEFINITION_EXIST);
|
||||
throw new MSException(ApiResultCode.API_DEFINITION_NOT_EXIST);
|
||||
}
|
||||
return apiDefinition;
|
||||
}
|
||||
|
@ -490,7 +493,6 @@ public class ApiDefinitionService {
|
|||
|
||||
private void doDelete(List<String> ids, String userId, String projectId) {
|
||||
if(CollectionUtils.isNotEmpty(ids)){
|
||||
extApiDefinitionMapper.batchDeleteById(ids, userId, projectId);
|
||||
// 需要判断是否存在多个版本问题
|
||||
ids.forEach(id -> {
|
||||
ApiDefinition apiDefinition = checkApiDefinition(id);
|
||||
|
@ -504,6 +506,7 @@ public class ApiDefinitionService {
|
|||
});
|
||||
// 删除 case
|
||||
deleteApiRelatedData(ids, userId, projectId);
|
||||
extApiDefinitionMapper.batchDeleteById(ids, userId, projectId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -603,7 +606,7 @@ public class ApiDefinitionService {
|
|||
apiDefinitionFollowerMapper.deleteByExample(apiDefinitionFollowerExample);
|
||||
|
||||
// 删除接口关联数据
|
||||
recycleDelApiRelatedData(ids, userId, projectId);
|
||||
trashDelApiRelatedData(ids, userId, projectId);
|
||||
|
||||
// 删除接口
|
||||
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
||||
|
@ -612,7 +615,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
}
|
||||
|
||||
private void recycleDelApiRelatedData(List<String> apiIds, String userId, String projectId){
|
||||
private void trashDelApiRelatedData(List<String> apiIds, String userId, String projectId){
|
||||
// 是否存在 case 删除 case
|
||||
List<ApiTestCase> caseLists = extApiTestCaseMapper.getCaseInfoByApiIds(apiIds, true);
|
||||
if(CollectionUtils.isNotEmpty(caseLists)) {
|
||||
|
@ -641,26 +644,10 @@ public class ApiDefinitionService {
|
|||
return apiFileResourceService.uploadTempFile(file);
|
||||
}
|
||||
|
||||
public ApiDefinitionDTO getInfo(String id, String userId){
|
||||
ApiDefinitionDTO apiDefinitionDTO = new ApiDefinitionDTO();
|
||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||
if(apiDefinition != null){
|
||||
apiDefinitionDTO = getApiDefinitionInfo(id, userId, apiDefinition);
|
||||
}
|
||||
return apiDefinitionDTO;
|
||||
}
|
||||
|
||||
public ApiDefinitionDTO getApiDefinitionInfo(String id, String userId, ApiDefinition apiDefinition) {
|
||||
ApiDefinitionDTO apiDefinitionDTO = new ApiDefinitionDTO();
|
||||
// 2. 使用Optional避免空指针异常
|
||||
Optional<ApiDefinitionBlob> apiDefinitionBlobOptional = Optional.ofNullable(apiDefinitionBlobMapper.selectByPrimaryKey(id));
|
||||
apiDefinitionBlobOptional.ifPresent(blob -> {
|
||||
apiDefinitionDTO.setRequest(ApiDataUtils.parseObject(new String(blob.getRequest()), AbstractMsTestElement.class));
|
||||
// blob.getResponse() 为 null 时不进行转换
|
||||
if (blob.getResponse() != null) {
|
||||
apiDefinitionDTO.setResponse(ApiDataUtils.parseArray(new String(blob.getResponse()), HttpResponse.class));
|
||||
}
|
||||
});
|
||||
handleBlob(id, apiDefinitionDTO);
|
||||
// 3. 使用Stream简化集合操作
|
||||
ApiDefinitionFollowerExample example = new ApiDefinitionFollowerExample();
|
||||
example.createCriteria().andApiDefinitionIdEqualTo(id).andUserIdEqualTo(userId);
|
||||
|
@ -669,4 +656,44 @@ public class ApiDefinitionService {
|
|||
return apiDefinitionDTO;
|
||||
}
|
||||
|
||||
public void handleBlob(String id, ApiDefinitionDTO apiDefinitionDTO) {
|
||||
Optional<ApiDefinitionBlob> apiDefinitionBlobOptional = Optional.ofNullable(apiDefinitionBlobMapper.selectByPrimaryKey(id));
|
||||
apiDefinitionBlobOptional.ifPresent(blob -> {
|
||||
apiDefinitionDTO.setRequest(ApiDataUtils.parseObject(new String(blob.getRequest()), AbstractMsTestElement.class));
|
||||
// blob.getResponse() 为 null 时不进行转换
|
||||
if (blob.getResponse() != null) {
|
||||
apiDefinitionDTO.setResponse(ApiDataUtils.parseArray(new String(blob.getResponse()), HttpResponse.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ApiDefinitionDocDTO getDocInfo(ApiDefinitionDocRequest request, String userId) {
|
||||
ApiDefinitionDocDTO apiDefinitionDocDTO = new ApiDefinitionDocDTO();
|
||||
apiDefinitionDocDTO.setType(request.getType());
|
||||
// @@TODO 下载所有/一个模块接口文档时,不做分页数据量大的时候会不会有性能问题
|
||||
if ("ALL".equals(request.getType()) || "MODULE".equals(request.getType())) {
|
||||
List<ApiDefinitionDTO> list = extApiDefinitionMapper.listDoc(request);
|
||||
if(null != list){
|
||||
list.forEach(item-> handleBlob(item.getId(), item));
|
||||
apiDefinitionDocDTO.setDocTitle("ALL".equals(request.getType()) ? Translator.get(ALL_API) : getModuleTitle(list));
|
||||
apiDefinitionDocDTO.setDocList(list);
|
||||
}
|
||||
} else if ("API".equals(request.getType())) {
|
||||
ApiDefinitionDTO apiDefinitionDTO = get(request.getApiId(), userId);
|
||||
apiDefinitionDocDTO.setDocTitle(apiDefinitionDTO.getName());
|
||||
apiDefinitionDocDTO.setDocList(Collections.singletonList(apiDefinitionDTO));
|
||||
}
|
||||
|
||||
return apiDefinitionDocDTO;
|
||||
}
|
||||
|
||||
private String getModuleTitle(List<ApiDefinitionDTO> list) {
|
||||
ApiDefinitionDTO first = list.stream().findFirst().orElseThrow(() -> new MSException(API_DEFINITION_NOT_EXIST));
|
||||
ApiDefinitionModule apiDefinitionModule = apiDefinitionModuleMapper.selectByPrimaryKey(first.getModuleId());
|
||||
if (StringUtils.isNotBlank(apiDefinitionModule.getName())) {
|
||||
return apiDefinitionModule.getName();
|
||||
} else {
|
||||
throw new MSException(API_DEFINITION_MODULE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import io.metersphere.system.utils.Pager;
|
|||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.platform.commons.util.StringUtils;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -63,12 +64,15 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
|
||||
private final static String PAGE = BASE_PATH + "page";
|
||||
private final static String PAGE_DOC = BASE_PATH + "page-doc";
|
||||
private final static String DOC = BASE_PATH + "doc";
|
||||
private static final String GET = BASE_PATH + "get-detail/";
|
||||
private static final String FOLLOW = BASE_PATH + "follow/";
|
||||
private static final String VERSION = BASE_PATH + "version/";
|
||||
private static final String UPLOAD_TEMP_FILE = BASE_PATH + "/upload/temp/file";
|
||||
|
||||
private static final String DEFAULT_MODULE_ID = "10001";
|
||||
|
||||
private static final String ALL_API = "api_definition_module.api.all";
|
||||
private static ApiDefinition apiDefinition;
|
||||
|
||||
@Resource
|
||||
|
@ -91,11 +95,16 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
@Resource
|
||||
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
||||
|
||||
@Resource
|
||||
private ApiDefinitionModuleMapper apiDefinitionModuleMapper;
|
||||
|
||||
@Resource
|
||||
private FileMetadataService fileMetadataService;
|
||||
private static String fileMetadataId;
|
||||
private static String uploadFileId;
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Order(0)
|
||||
public void uploadTempFile() throws Exception {
|
||||
|
@ -252,9 +261,10 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
ApiDefinitionUpdateRequest request = new ApiDefinitionUpdateRequest();
|
||||
BeanUtils.copyBean(request, apiDefinition);
|
||||
request.setPath("test.com/admin/test");
|
||||
request.setName("test1");
|
||||
request.setName("test1test1test1test1test1test1");
|
||||
request.setMethod("POST");
|
||||
request.setModuleId("default1");
|
||||
request.setTags(new LinkedHashSet<>(List.of("tag1", "tag2-update")));
|
||||
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
|
||||
request.setRequest(ApiDataUtils.toJSONString(msHttpElement));
|
||||
List<HttpResponse> msHttpResponse = MsHTTPElementTest.getMsHttpResponse();
|
||||
|
@ -474,7 +484,6 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(5)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void copy() throws Exception {
|
||||
LogUtils.info("copy api test");
|
||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
|
@ -483,7 +492,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
MvcResult mvcResult = this.requestPostWithOkAndReturn(COPY, request);
|
||||
ApiDefinition resultData = getResultData(mvcResult, ApiDefinition.class);
|
||||
// @数据验证
|
||||
Assertions.assertEquals("copy_" + apiDefinition.getName(), resultData.getName());
|
||||
Assertions.assertTrue(resultData.getName().contains("copy_"));
|
||||
// @@校验日志
|
||||
checkLog(resultData.getId(), OperationLogType.UPDATE);
|
||||
request.setId("121");
|
||||
|
@ -494,7 +503,6 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void batchMove() throws Exception {
|
||||
LogUtils.info("batch move api test");
|
||||
ApiDefinitionBatchMoveRequest request = new ApiDefinitionBatchMoveRequest();
|
||||
|
@ -526,7 +534,6 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(7)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void follow() throws Exception {
|
||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1006");
|
||||
// @@关注
|
||||
|
@ -556,7 +563,6 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(8)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void version() throws Exception {
|
||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
// @@请求成功
|
||||
|
@ -572,118 +578,9 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_READ, VERSION + apiDefinition.getId());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void testDel() throws Exception {
|
||||
LogUtils.info("delete api test");
|
||||
if(apiDefinition == null){
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
}
|
||||
// @只存在一个版本
|
||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
// @@请求成功
|
||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||
checkLog(apiDefinition.getId(), OperationLogType.DELETE);
|
||||
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||
Assertions.assertTrue(apiDefinitionInfo.getDeleted());
|
||||
Assertions.assertEquals("admin", apiDefinitionInfo.getDeleteUser());
|
||||
Assertions.assertNotNull(apiDefinitionInfo.getDeleteTime());
|
||||
|
||||
// @存在多个版本
|
||||
// 列表删除
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
apiDefinitionDeleteRequest.setId("1004");
|
||||
ApiDefinition delApiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
||||
MvcResult mvcResult = this.requestGetWithOk(VERSION + apiDefinitionDeleteRequest.getId()).andReturn();
|
||||
ApiDataUtils.setResolver(MsHTTPElement.class);
|
||||
List<ApiDefinitionVersionDTO> apiDefinitionVersionDTO = getResultDataArray(mvcResult, ApiDefinitionVersionDTO.class);
|
||||
if(!apiDefinitionVersionDTO.isEmpty()){
|
||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||
// 效验数据
|
||||
// 删除的数据为最新版本需要更新最近一条数据为最新数据
|
||||
if(delApiDefinition.getLatest()){
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andRefIdEqualTo(delApiDefinition.getRefId()).andDeletedEqualTo(false).andProjectIdEqualTo(delApiDefinition.getProjectId());
|
||||
example.setOrderByClause("update_time DESC");
|
||||
ApiDefinition updateApiDefinition = apiDefinitionMapper.selectByExample(example).stream().findFirst().orElse(null);
|
||||
if(updateApiDefinition != null) {
|
||||
Assertions.assertTrue(updateApiDefinition.getLatest());
|
||||
Assertions.assertFalse(updateApiDefinition.getDeleted());
|
||||
}
|
||||
}
|
||||
ApiDefinition delApiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
||||
if(delApiDefinitionInfo != null){
|
||||
Assertions.assertTrue(delApiDefinitionInfo.getDeleted());
|
||||
Assertions.assertEquals("admin", delApiDefinitionInfo.getDeleteUser());
|
||||
Assertions.assertNotNull(delApiDefinitionInfo.getDeleteTime());
|
||||
}
|
||||
checkLog(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE);
|
||||
|
||||
}
|
||||
// 全部删除
|
||||
apiDefinitionDeleteRequest.setDeleteAll(true);
|
||||
apiDefinitionDeleteRequest.setId("1002");
|
||||
// @@请求成功
|
||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||
|
||||
List<String> ids = extApiDefinitionMapper.getApiDefinitionByRefId(apiDefinitionDeleteRequest.getId()).stream().map(ApiDefinitionVersionDTO::getId).toList();
|
||||
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
||||
apiDefinitionExample.createCriteria().andIdIn(ids);
|
||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(apiDefinitionExample);
|
||||
if(CollectionUtils.isNotEmpty(apiDefinitions)){
|
||||
apiDefinitions.forEach(item -> {
|
||||
Assertions.assertTrue(item.getDeleted());
|
||||
Assertions.assertEquals("admin", item.getDeleteUser());
|
||||
Assertions.assertNotNull(item.getDeleteTime());
|
||||
});
|
||||
}
|
||||
checkLog(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE);
|
||||
apiDefinitionDeleteRequest.setId("121");
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
assertErrorCode(this.requestPost(DELETE, apiDefinitionDeleteRequest), ApiResultCode.API_DEFINITION_NOT_EXIST);
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, DELETE, apiDefinitionDeleteRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void testBatchDel() throws Exception {
|
||||
LogUtils.info("batch delete api test");
|
||||
ApiDefinitionBatchRequest request = new ApiDefinitionBatchRequest();
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
|
||||
// 删除选中
|
||||
request.setSelectIds(List.of("1002","1004"));
|
||||
request.setDeleteAll(false);
|
||||
request.setSelectAll(false);
|
||||
this.requestPostWithOkAndReturn(BATCH_DELETE, request);
|
||||
// @@校验日志
|
||||
checkLog("1002", OperationLogType.DELETE);
|
||||
checkLog("1004", OperationLogType.DELETE);
|
||||
// 删除全部 条件为关键字为st-6的数据
|
||||
request.setDeleteAll(true);
|
||||
request.setExcludeIds(List.of("1005"));
|
||||
request.setSelectAll(true);
|
||||
BaseCondition baseCondition = new BaseCondition();
|
||||
baseCondition.setKeyword("st-6");
|
||||
request.setCondition(baseCondition);
|
||||
this.requestPostWithOkAndReturn(BATCH_DELETE, request);
|
||||
// @@校验日志
|
||||
checkLog("1006", OperationLogType.DELETE);
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, BATCH_DELETE, request);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void getPage() throws Exception {
|
||||
doApiDefinitionPage("All", PAGE);
|
||||
doApiDefinitionPage("KEYWORD", PAGE);
|
||||
|
@ -767,14 +664,223 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
request.setDeleted(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void getPageDoc() throws Exception {
|
||||
doApiDefinitionPage("All", PAGE_DOC);
|
||||
doApiDefinitionPage("KEYWORD", PAGE_DOC);
|
||||
doApiDefinitionPage("FILTER", PAGE_DOC);
|
||||
doApiDefinitionPage("COMBINE", PAGE_DOC);
|
||||
doApiDefinitionPage("DELETED", PAGE_DOC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
public void getDoc() throws Exception {
|
||||
ApiDefinitionDocRequest request = new ApiDefinitionDocRequest();
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
request.setApiId(apiDefinition.getId());
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setType("API");
|
||||
// @@请求成功
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(DOC, request);
|
||||
ApiDataUtils.setResolver(MsHTTPElement.class);
|
||||
ApiDefinitionDocDTO apiDefinitionDocDTO = ApiDataUtils.parseObject(JSON.toJSONString(parseResponse(mvcResult).get("data")), ApiDefinitionDocDTO.class);
|
||||
// 校验数据是否正确
|
||||
ApiDefinitionDocDTO copyApiDefinitionDocDTO = new ApiDefinitionDocDTO();
|
||||
ApiDefinitionDTO copyApiDefinitionDTO = BeanUtils.copyBean(new ApiDefinitionDTO(), apiDefinition);
|
||||
ApiDefinitionBlob apiDefinitionBlob = apiDefinitionBlobMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||
if(apiDefinitionBlob != null){
|
||||
copyApiDefinitionDTO.setRequest(ApiDataUtils.parseObject(new String(apiDefinitionBlob.getRequest()), AbstractMsTestElement.class));
|
||||
copyApiDefinitionDTO.setResponse(ApiDataUtils.parseArray(new String(apiDefinitionBlob.getResponse()), HttpResponse.class));
|
||||
}
|
||||
copyApiDefinitionDocDTO.setDocTitle(apiDefinition.getName());
|
||||
copyApiDefinitionDocDTO.setType("API");
|
||||
copyApiDefinitionDocDTO.setDocList(Collections.singletonList(copyApiDefinitionDTO));
|
||||
Assertions.assertEquals(apiDefinitionDocDTO.getType(), copyApiDefinitionDocDTO.getType());
|
||||
Assertions.assertEquals(apiDefinitionDocDTO.getDocTitle(), copyApiDefinitionDocDTO.getDocTitle());
|
||||
Assertions.assertEquals(apiDefinitionDocDTO.getDocList().size(), copyApiDefinitionDocDTO.getDocList().size());
|
||||
|
||||
request.setApiId("111");
|
||||
assertErrorCode(this.requestPost(DOC, request), ApiResultCode.API_DEFINITION_NOT_EXIST);
|
||||
|
||||
// @@模块查看文档
|
||||
request.setApiId(null);
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setType("MODULE");
|
||||
request.setModuleIds(List.of("10001"));
|
||||
MvcResult mvcResultModule = this.requestPostWithOkAndReturn(DOC, request);
|
||||
ApiDataUtils.setResolver(MsHTTPElement.class);
|
||||
ApiDefinitionDocDTO moduleApiDefinitionDocDTO = ApiDataUtils.parseObject(JSON.toJSONString(parseResponse(mvcResultModule).get("data")), ApiDefinitionDocDTO.class);
|
||||
// 校验数据是否正确
|
||||
ApiDefinitionDocDTO copyModuleApiDefinitionDocDTO = new ApiDefinitionDocDTO();
|
||||
List<ApiDefinitionDTO> list = extApiDefinitionMapper.listDoc(request);
|
||||
if(null != list){
|
||||
list.forEach(item-> {
|
||||
ApiDefinitionBlob moduleApiDefinitionBlob = apiDefinitionBlobMapper.selectByPrimaryKey(item.getId());
|
||||
if(moduleApiDefinitionBlob != null){
|
||||
item.setRequest(ApiDataUtils.parseObject(new String(moduleApiDefinitionBlob.getRequest()), AbstractMsTestElement.class));
|
||||
item.setResponse(ApiDataUtils.parseArray(new String(moduleApiDefinitionBlob.getResponse()), HttpResponse.class));
|
||||
}
|
||||
ApiDefinitionModule apiDefinitionModule = apiDefinitionModuleMapper.selectByPrimaryKey(item.getModuleId());
|
||||
if(StringUtils.isBlank(copyModuleApiDefinitionDocDTO.getDocTitle())){
|
||||
copyModuleApiDefinitionDocDTO.setDocTitle(apiDefinitionModule.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
copyModuleApiDefinitionDocDTO.setType("MODULE");
|
||||
copyModuleApiDefinitionDocDTO.setDocList(list);
|
||||
Assertions.assertEquals(moduleApiDefinitionDocDTO.getType(), copyModuleApiDefinitionDocDTO.getType());
|
||||
Assertions.assertEquals(moduleApiDefinitionDocDTO.getDocTitle(), copyModuleApiDefinitionDocDTO.getDocTitle());
|
||||
Assertions.assertEquals(moduleApiDefinitionDocDTO.getDocList().size(), copyModuleApiDefinitionDocDTO.getDocList().size());
|
||||
|
||||
// @@查看全部文档
|
||||
request.setApiId(null);
|
||||
request.setModuleIds(null);
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setType("ALL");
|
||||
MvcResult mvcResultAll = this.requestPostWithOkAndReturn(DOC, request);
|
||||
ApiDataUtils.setResolver(MsHTTPElement.class);
|
||||
ApiDefinitionDocDTO allApiDefinitionDocDTO = ApiDataUtils.parseObject(JSON.toJSONString(parseResponse(mvcResultAll).get("data")), ApiDefinitionDocDTO.class);
|
||||
// 校验数据是否正确
|
||||
ApiDefinitionDocDTO copyAllApiDefinitionDocDTO = new ApiDefinitionDocDTO();
|
||||
List<ApiDefinitionDTO> allList = extApiDefinitionMapper.listDoc(request);
|
||||
if(null != allList){
|
||||
allList.forEach(item-> {
|
||||
ApiDefinitionBlob allApiDefinitionBlob = apiDefinitionBlobMapper.selectByPrimaryKey(item.getId());
|
||||
if(allApiDefinitionBlob != null){
|
||||
item.setRequest(ApiDataUtils.parseObject(new String(allApiDefinitionBlob.getRequest()), AbstractMsTestElement.class));
|
||||
item.setResponse(ApiDataUtils.parseArray(new String(allApiDefinitionBlob.getResponse()), HttpResponse.class));
|
||||
}
|
||||
if(StringUtils.isBlank(copyAllApiDefinitionDocDTO.getDocTitle())){
|
||||
copyAllApiDefinitionDocDTO.setDocTitle(Translator.get(ALL_API));
|
||||
}
|
||||
});
|
||||
}
|
||||
copyAllApiDefinitionDocDTO.setType("ALL");
|
||||
copyAllApiDefinitionDocDTO.setDocList(allList);
|
||||
Assertions.assertEquals(allApiDefinitionDocDTO.getType(), copyAllApiDefinitionDocDTO.getType());
|
||||
Assertions.assertEquals(allApiDefinitionDocDTO.getDocTitle(), copyAllApiDefinitionDocDTO.getDocTitle());
|
||||
Assertions.assertEquals(allApiDefinitionDocDTO.getDocList().size(), copyAllApiDefinitionDocDTO.getDocList().size());
|
||||
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_READ, DOC, request);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void testDel() throws Exception {
|
||||
LogUtils.info("delete api test");
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
// @只存在一个版本
|
||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
// @@请求成功
|
||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||
checkLog(apiDefinition.getId(), OperationLogType.DELETE);
|
||||
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||
Assertions.assertTrue(apiDefinitionInfo.getDeleted());
|
||||
Assertions.assertEquals("admin", apiDefinitionInfo.getDeleteUser());
|
||||
Assertions.assertNotNull(apiDefinitionInfo.getDeleteTime());
|
||||
|
||||
// @存在多个版本
|
||||
// 列表删除
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
apiDefinitionDeleteRequest.setId("1004");
|
||||
ApiDefinition delApiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
||||
MvcResult mvcResult = this.requestGetWithOk(VERSION + apiDefinitionDeleteRequest.getId()).andReturn();
|
||||
ApiDataUtils.setResolver(MsHTTPElement.class);
|
||||
List<ApiDefinitionVersionDTO> apiDefinitionVersionDTO = getResultDataArray(mvcResult, ApiDefinitionVersionDTO.class);
|
||||
if(!apiDefinitionVersionDTO.isEmpty()){
|
||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||
// 效验数据
|
||||
// 删除的数据为最新版本需要更新最近一条数据为最新数据
|
||||
if(delApiDefinition.getLatest()){
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andRefIdEqualTo(delApiDefinition.getRefId()).andDeletedEqualTo(false).andProjectIdEqualTo(delApiDefinition.getProjectId());
|
||||
example.setOrderByClause("update_time DESC");
|
||||
ApiDefinition updateApiDefinition = apiDefinitionMapper.selectByExample(example).stream().findFirst().orElse(null);
|
||||
if(updateApiDefinition != null) {
|
||||
Assertions.assertTrue(updateApiDefinition.getLatest());
|
||||
Assertions.assertFalse(updateApiDefinition.getDeleted());
|
||||
}
|
||||
}
|
||||
ApiDefinition delApiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
||||
if(delApiDefinitionInfo != null){
|
||||
Assertions.assertTrue(delApiDefinitionInfo.getDeleted());
|
||||
Assertions.assertEquals("admin", delApiDefinitionInfo.getDeleteUser());
|
||||
Assertions.assertNotNull(delApiDefinitionInfo.getDeleteTime());
|
||||
}
|
||||
checkLog(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE);
|
||||
|
||||
}
|
||||
// 全部删除
|
||||
apiDefinitionDeleteRequest.setDeleteAll(true);
|
||||
apiDefinitionDeleteRequest.setId("1002");
|
||||
// @@请求成功
|
||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||
|
||||
List<String> ids = extApiDefinitionMapper.getApiDefinitionByRefId(apiDefinitionDeleteRequest.getId()).stream().map(ApiDefinitionVersionDTO::getId).toList();
|
||||
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
||||
apiDefinitionExample.createCriteria().andIdIn(ids);
|
||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(apiDefinitionExample);
|
||||
if(CollectionUtils.isNotEmpty(apiDefinitions)){
|
||||
apiDefinitions.forEach(item -> {
|
||||
Assertions.assertTrue(item.getDeleted());
|
||||
Assertions.assertEquals("admin", item.getDeleteUser());
|
||||
Assertions.assertNotNull(item.getDeleteTime());
|
||||
});
|
||||
}
|
||||
checkLog(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE);
|
||||
apiDefinitionDeleteRequest.setId("121");
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
assertErrorCode(this.requestPost(DELETE, apiDefinitionDeleteRequest), ApiResultCode.API_DEFINITION_NOT_EXIST);
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, DELETE, apiDefinitionDeleteRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
public void testBatchDel() throws Exception {
|
||||
LogUtils.info("batch delete api test");
|
||||
ApiDefinitionBatchRequest request = new ApiDefinitionBatchRequest();
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
|
||||
// 删除选中
|
||||
request.setSelectIds(List.of("1004"));
|
||||
request.setDeleteAll(false);
|
||||
request.setSelectAll(false);
|
||||
this.requestPostWithOkAndReturn(BATCH_DELETE, request);
|
||||
// @@校验日志
|
||||
checkLog("1004", OperationLogType.DELETE);
|
||||
|
||||
request.setSelectIds(List.of("1002"));
|
||||
request.setDeleteAll(false);
|
||||
request.setSelectAll(false);
|
||||
assertErrorCode(this.requestPost(BATCH_DELETE, request), ApiResultCode.API_DEFINITION_NOT_EXIST);
|
||||
// 删除全部 条件为关键字为st-6的数据
|
||||
request.setDeleteAll(true);
|
||||
request.setExcludeIds(List.of("1005"));
|
||||
request.setSelectAll(true);
|
||||
BaseCondition baseCondition = new BaseCondition();
|
||||
baseCondition.setKeyword("st-6");
|
||||
request.setCondition(baseCondition);
|
||||
this.requestPostWithOkAndReturn(BATCH_DELETE, request);
|
||||
// @@校验日志
|
||||
checkLog("1006", OperationLogType.DELETE);
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, BATCH_DELETE, request);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
public void testRestore() throws Exception {
|
||||
LogUtils.info("restore api test");
|
||||
if(apiDefinition == null){
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
}
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
// @恢复一条数据
|
||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
||||
|
@ -815,53 +921,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void testTrashDel() throws Exception {
|
||||
LogUtils.info("trashDel api test");
|
||||
if(apiDefinition == null){
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
}
|
||||
if(!apiDefinition.getDeleted()){
|
||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
// @@请求成功
|
||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||
checkLog(apiDefinition.getId(), OperationLogType.DELETE);
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||
Assertions.assertTrue(apiDefinition.getDeleted());
|
||||
Assertions.assertEquals("admin", apiDefinition.getDeleteUser());
|
||||
Assertions.assertNotNull(apiDefinition.getDeleteTime());
|
||||
}
|
||||
// @只存在一个版本
|
||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
// @@请求成功
|
||||
this.requestPostWithOk(TRASH_DEL, apiDefinitionDeleteRequest);
|
||||
checkLog(apiDefinition.getId(), OperationLogType.DELETE);
|
||||
// 验证数据
|
||||
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||
Assertions.assertNull(apiDefinitionInfo);
|
||||
|
||||
// 文件是否删除
|
||||
List<ApiFileResource> apiFileResources = apiFileResourceService.getByResourceId(apiDefinition.getId());
|
||||
Assertions.assertEquals(0, apiFileResources.size());
|
||||
|
||||
// 效验 关联数据
|
||||
List<ApiTestCase> caseLists = extApiTestCaseMapper.getCaseInfoByApiIds(Collections.singletonList(apiDefinition.getId()), false);
|
||||
Assertions.assertEquals(0, caseLists.size());
|
||||
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, TRASH_DEL, apiDefinitionDeleteRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
@Order(15)
|
||||
public void testBatchRestore() throws Exception {
|
||||
LogUtils.info("batch restore api test");
|
||||
ApiDefinitionBatchRequest request = new ApiDefinitionBatchRequest();
|
||||
|
@ -912,16 +972,56 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void testBatchRecycleDel() throws Exception {
|
||||
LogUtils.info("batch recycle delete api test");
|
||||
testBatchDel();
|
||||
@Order(16)
|
||||
public void testTrashDel() throws Exception {
|
||||
LogUtils.info("trashDel api test");
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||
if(!apiDefinition.getDeleted()){
|
||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
// @@请求成功
|
||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
||||
checkLog(apiDefinition.getId(), OperationLogType.DELETE);
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||
Assertions.assertTrue(apiDefinition.getDeleted());
|
||||
Assertions.assertEquals("admin", apiDefinition.getDeleteUser());
|
||||
Assertions.assertNotNull(apiDefinition.getDeleteTime());
|
||||
}
|
||||
// @只存在一个版本
|
||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
||||
// @@请求成功
|
||||
this.requestPostWithOk(TRASH_DEL, apiDefinitionDeleteRequest);
|
||||
checkLog(apiDefinition.getId(), OperationLogType.DELETE);
|
||||
// 验证数据
|
||||
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||
Assertions.assertNull(apiDefinitionInfo);
|
||||
|
||||
// 文件是否删除
|
||||
List<ApiFileResource> apiFileResources = apiFileResourceService.getByResourceId(apiDefinition.getId());
|
||||
Assertions.assertEquals(0, apiFileResources.size());
|
||||
|
||||
// 效验 关联数据
|
||||
List<ApiTestCase> caseLists = extApiTestCaseMapper.getCaseInfoByApiIds(Collections.singletonList(apiDefinition.getId()), false);
|
||||
Assertions.assertEquals(0, caseLists.size());
|
||||
|
||||
// @@校验权限
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, TRASH_DEL, apiDefinitionDeleteRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
public void testBatchTrashDel() throws Exception {
|
||||
LogUtils.info("batch trash delete api test");
|
||||
ApiDefinitionBatchRequest request = new ApiDefinitionBatchRequest();
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
|
||||
// 删除选中
|
||||
request.setSelectIds(List.of("1002","1004"));
|
||||
request.setSelectIds(List.of("1003"));
|
||||
request.setSelectAll(false);
|
||||
this.requestPostWithOk(BATCH_TRASH_DEL, request);
|
||||
// 效验数据结果
|
||||
|
@ -940,8 +1040,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
Assertions.assertEquals(0, caseLists.size());
|
||||
|
||||
// @@校验日志
|
||||
checkLog("1002", OperationLogType.DELETE);
|
||||
checkLog("1004", OperationLogType.DELETE);
|
||||
checkLog("1003", OperationLogType.DELETE);
|
||||
// 删除全部 条件为关键字为st-6的数据
|
||||
request.setSelectAll(true);
|
||||
request.setExcludeIds(List.of("1005"));
|
||||
|
@ -955,15 +1054,5 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, BATCH_TRASH_DEL, request);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
@Sql(scripts = {"/dml/init_api_definition.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
public void getPageDoc() throws Exception {
|
||||
doApiDefinitionPage("All", PAGE_DOC);
|
||||
doApiDefinitionPage("KEYWORD", PAGE_DOC);
|
||||
doApiDefinitionPage("FILTER", PAGE_DOC);
|
||||
doApiDefinitionPage("COMBINE", PAGE_DOC);
|
||||
doApiDefinitionPage("DELETED", PAGE_DOC);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -269,7 +269,6 @@ public class MsHTTPElementTest {
|
|||
public static List<HttpResponse> getMsHttpResponse() {
|
||||
List<HttpResponse> httpResponses = new ArrayList<>();
|
||||
HttpResponse httpResponse = new HttpResponse();
|
||||
httpResponse.setId(1);
|
||||
httpResponse.setName("Response1");
|
||||
httpResponse.setStatusCode("200");
|
||||
httpResponse.setDefaultFlag(true);
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
-- 插入测试数据
|
||||
|
||||
DELETE FROM `api_definition` WHERE `id` in ('1001','1002','1003','1004','1005','1006');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1001', 'test-1', 'HTTP', 'POST', '/api/admin/1', 'Prepare', 1001, '[\"test1\",\"te\"]', 1, '100001100001', 'root', b'1', '100570499574136985', '1001', NULL, 1699500298164, 'admin', 1699500298162, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1002', 'test-2', 'HTTP', 'GET', '/api/admin/2', 'Underway', 1002, '[\"test2\",\"te\"]', 1, '100001100001', 'root', b'1', '1005704995741369851', '1002', NULL, 1699500298165, 'admin', 1699500298163, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1003', 'test-3', 'HTTP', 'POST', '/api/admin/3', 'Completed', 1003, '[\"test3\",\"te\"]', 1, '100001100001', 'root', b'1', '100570499574136985', '1002', NULL, 1699500298166, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1004', 'test-4', 'HTTP', 'GET', '/api/admin/4', 'Prepare', 1004, '[\"test4\",\"te\"]', 1, '100001100001', 'root', b'1', '100570499574136985', '1004', NULL, 1699500298167, 'admin', 1699500298165, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1005', 'test-65', 'HTTP', 'POST', '/api/admin/5', 'Underway', 1005, '[\"test5\",\"te\"]', 1, '100001100001', 'root', b'0', '100570499574136985', '1004', NULL, 1699500298168, 'admin', 1699500298166, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1006', 'test-6', 'HTTP', 'GET', '/api/admin/6', 'Completed', 1006, '[\"test6\",\"te\"]', 1, '100001100001', 'root', b'1', '100570499574136985', '1006', NULL, 1699500298169, 'admin', 1699500298167, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1001', 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test', 'HTTP', 'POST', '/api/admin/1', 'Prepare', 1001, '[\"test3\",\"te\"]', 1, '100001100001', 'root', b'1', '100570499574136985', '1001', NULL, 1699500298164, 'admin', 1699500298162, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1002', 'test-2', 'HTTP', 'GET', '/api/admin/2', 'Underway', 1002, null, 1, '100001100001', '10001', b'1', '1005704995741369851', '1002', NULL, 1699500298165, 'admin', 1699500298163, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1003', 'test-3', 'HTTP', 'POST', '/api/admin/3', 'Completed', 1003, '[\"test3\",\"te\"]', 1, '100001100001', '10001', b'1', '100570499574136985', '1002', NULL, 1699500298166, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1004', 'test-4', 'HTTP', 'GET', '/api/admin/4', 'Prepare', 1004, '[\"test4\",\"te\"]', 1, '100001100001', '10001', b'1', '100570499574136985', '1004', NULL, 1699500298167, 'admin', 1699500298165, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1005', 'test-65', 'HTTP', 'POST', '/api/admin/5', 'Underway', 1005, '[\"test5\",\"te\"]', 1, '100001100001', '10001', b'0', '100570499574136985', '1004', NULL, 1699500298168, 'admin', 1699500298166, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `status`, `num`, `tags`, `pos`, `project_id`, `module_id`, `latest`, `version_id`, `ref_id`, `description`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_user`, `delete_time`, `deleted`) VALUES ('1006', 'test-6', 'HTTP', 'GET', '/api/admin/6', 'Completed', 1006, '[\"test6\",\"te\"]', 1, '100001100001', '10001', b'1', '100570499574136985', '1006', NULL, 1699500298169, 'admin', 1699500298167, 'admin', NULL, NULL, b'0');
|
||||
|
||||
DELETE FROM `project_version` WHERE `id` = '100570499574136985';
|
||||
INSERT INTO project_version (id, project_id, name, description, status, latest, publish_time, start_time, end_time, create_time, create_user) VALUES ('100570499574136985', '100001100001', 'v1.0.0', NULL, 'open', 1, UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin');
|
||||
|
||||
DELETE FROM `api_test_case` WHERE `id` in ('12df5721-c5e6-a38b-e999-3eafcb992094','12df5721-c5e6-a38b-e999-3eafcb992100','12df5721-c5e6-a38b-e999-3eafcb992233','3ee2ae9c-a680-4ed6-b115-1f6ab8980973','3ee2ae9c-a680-4ed6-b115-1f6ab8980100','3ee2ae9c-a680-4ed6-b115-1f6ab8980589','3ee2ae9c-a680-4ed6-b115-1f6ab8980553','3ee2ae9c-a680-4ed6-b115-1f6ab8980104','3ee2ae9c-a680-4ed6-b115-1f6ab8980545');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('12df5721-c5e6-a38b-e999-3eafcb992094', '查询windows主机', 'P0', 100002001, NULL, 'PENDING', NULL, '10001', 10000, '100001100001', '1001', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('12df5721-c5e6-a38b-e999-3eafcb992100', '查询windows主机', 'P0', 100002002, NULL, 'PENDING', NULL, '10002', 10000, '100001100001', '1001', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('12df5721-c5e6-a38b-e999-3eafcb992233', '查询windows主机', 'P0', 100002003, NULL, 'PENDING', NULL, '10003', 10000, '100001100001', '1002', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980973', '查询Linux主机', 'P0', 100002004, NULL, 'PENDING', NULL, '10004', 10000, '100001100001', '1002', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980100', '查询Linux主机', 'P0', 100002005, NULL, 'PENDING', NULL, '10005', 10000, '100001100001', '1003', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980589', '查询Linux主机', 'P0', 100002006, NULL, 'PENDING', NULL, '10006', 10000, '100001100001', '1004', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980553', '查询Linux主机', 'P0', 100002007, NULL, 'PENDING', NULL, '10007', 10000, '100001100001', '1005', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980104', '查询Linux主机', 'P0', 100002008, NULL, 'PENDING', NULL, '10008', 10000, '100001100001', '1005', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980545', '查询Linux主机', 'P0', 100002009, NULL, 'PENDING', NULL, NULL, 10000, '100001100001', '1005', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('12df5721-c5e6-a38b-e999-3eafcb992094', '查询windows主机1', 'P0', 100002001, NULL, 'PENDING', NULL, '10001', 10000, '100001100001', '1001', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('12df5721-c5e6-a38b-e999-3eafcb992100', '查询windows主机2', 'P0', 100002002, NULL, 'PENDING', NULL, '10002', 10000, '100001100001', '1001', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('12df5721-c5e6-a38b-e999-3eafcb992233', '查询windows主机3', 'P0', 100002003, NULL, 'PENDING', NULL, '10003', 10000, '100001100001', '1002', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980973', '查询Linux主机1', 'P0', 100002004, NULL, 'PENDING', NULL, '10004', 10000, '100001100001', '1002', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980100', '查询Linux主机2', 'P0', 100002005, NULL, 'PENDING', NULL, '10005', 10000, '100001100001', '1003', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980589', '查询Linux主机3', 'P0', 100002006, NULL, 'PENDING', NULL, '10006', 10000, '100001100001', '1004', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980553', '查询Linux主机4', 'P0', 100002007, NULL, 'PENDING', NULL, '10007', 10000, '100001100001', '1005', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980104', '查询Linux主机5', 'P0', 100002008, NULL, 'PENDING', NULL, '10008', 10000, '100001100001', '1005', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
INSERT INTO `api_test_case` (`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) VALUES ('3ee2ae9c-a680-4ed6-b115-1f6ab8980545', '查询Linux主机6', 'P0', 100002009, NULL, 'PENDING', NULL, NULL, 10000, '100001100001', '1005', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
|
||||
DELETE FROM `api_report` WHERE `id` in ('10001','10002','10003','10004','10005','10006','10007','10008');
|
||||
INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_time`, `create_user`, `update_user`, `deleted`, `status`, `start_time`, `end_time`, `run_mode`, `pool_id`, `trigger_mode`, `version_id`, `project_id`, `integrated_report_id`, `integrated`) VALUES ('10001', '报告001', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'SUCCESS', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
|
||||
|
|
Loading…
Reference in New Issue