refactor(接口测试): 优化接口模块,去除模块协议

This commit is contained in:
wxg0103 2023-12-25 17:30:56 +08:00 committed by 刘瑞斌
parent 828f89b130
commit 1a723bc0f7
16 changed files with 157 additions and 287 deletions

View File

@ -1,16 +1,12 @@
package io.metersphere.api.domain;
import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated;
import io.metersphere.validation.groups.*;
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 jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import lombok.Data;
@Data
public class ApiDebugModule implements Serializable {
@ -24,11 +20,6 @@ public class ApiDebugModule implements Serializable {
@Size(min = 1, max = 255, message = "{api_debug_module.name.length_range}", groups = {Created.class, Updated.class})
private String name;
@Schema(description = "协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{api_debug.protocol.not_blank}", groups = {Created.class})
@Size(min = 1, max = 20, message = "{api_debug.protocol.length_range}", groups = {Created.class, Updated.class})
private String protocol;
@Schema(description = "父级fk", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{api_debug_module.parent_id.not_blank}", groups = {Created.class})
@Size(min = 1, max = 50, message = "{api_debug_module.parent_id.length_range}", groups = {Created.class, Updated.class})
@ -60,7 +51,6 @@ public class ApiDebugModule implements Serializable {
public enum Column {
id("id", "id", "VARCHAR", false),
name("name", "name", "VARCHAR", true),
protocol("protocol", "protocol", "VARCHAR", false),
parentId("parent_id", "parentId", "VARCHAR", false),
projectId("project_id", "projectId", "VARCHAR", false),
pos("pos", "pos", "BIGINT", false),

View File

@ -244,76 +244,6 @@ public class ApiDebugModuleExample {
return (Criteria) this;
}
public Criteria andProtocolIsNull() {
addCriterion("protocol is null");
return (Criteria) this;
}
public Criteria andProtocolIsNotNull() {
addCriterion("protocol is not null");
return (Criteria) this;
}
public Criteria andProtocolEqualTo(String value) {
addCriterion("protocol =", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotEqualTo(String value) {
addCriterion("protocol <>", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolGreaterThan(String value) {
addCriterion("protocol >", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolGreaterThanOrEqualTo(String value) {
addCriterion("protocol >=", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLessThan(String value) {
addCriterion("protocol <", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLessThanOrEqualTo(String value) {
addCriterion("protocol <=", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLike(String value) {
addCriterion("protocol like", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotLike(String value) {
addCriterion("protocol not like", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolIn(List<String> values) {
addCriterion("protocol in", values, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotIn(List<String> values) {
addCriterion("protocol not in", values, "protocol");
return (Criteria) this;
}
public Criteria andProtocolBetween(String value1, String value2) {
addCriterion("protocol between", value1, value2, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotBetween(String value1, String value2) {
addCriterion("protocol not between", value1, value2, "protocol");
return (Criteria) this;
}
public Criteria andParentIdIsNull() {
addCriterion("parent_id is null");
return (Criteria) this;

View File

@ -20,11 +20,6 @@ public class ApiDefinitionModule implements Serializable {
@Size(min = 1, max = 255, message = "{api_definition_module.name.length_range}", groups = {Created.class, Updated.class})
private String name;
@Schema(description = "协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{api_definition_module.protocol.not_blank}", groups = {Created.class})
@Size(min = 1, max = 20, message = "{api_definition_module.protocol.length_range}", groups = {Created.class, Updated.class})
private String protocol;
@Schema(description = "父级fk", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{api_definition_module.parent_id.not_blank}", groups = {Created.class})
@Size(min = 1, max = 50, message = "{api_definition_module.parent_id.length_range}", groups = {Created.class, Updated.class})
@ -56,7 +51,6 @@ public class ApiDefinitionModule implements Serializable {
public enum Column {
id("id", "id", "VARCHAR", false),
name("name", "name", "VARCHAR", true),
protocol("protocol", "protocol", "VARCHAR", false),
parentId("parent_id", "parentId", "VARCHAR", false),
projectId("project_id", "projectId", "VARCHAR", false),
pos("pos", "pos", "BIGINT", false),

View File

@ -244,76 +244,6 @@ public class ApiDefinitionModuleExample {
return (Criteria) this;
}
public Criteria andProtocolIsNull() {
addCriterion("protocol is null");
return (Criteria) this;
}
public Criteria andProtocolIsNotNull() {
addCriterion("protocol is not null");
return (Criteria) this;
}
public Criteria andProtocolEqualTo(String value) {
addCriterion("protocol =", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotEqualTo(String value) {
addCriterion("protocol <>", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolGreaterThan(String value) {
addCriterion("protocol >", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolGreaterThanOrEqualTo(String value) {
addCriterion("protocol >=", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLessThan(String value) {
addCriterion("protocol <", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLessThanOrEqualTo(String value) {
addCriterion("protocol <=", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolLike(String value) {
addCriterion("protocol like", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotLike(String value) {
addCriterion("protocol not like", value, "protocol");
return (Criteria) this;
}
public Criteria andProtocolIn(List<String> values) {
addCriterion("protocol in", values, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotIn(List<String> values) {
addCriterion("protocol not in", values, "protocol");
return (Criteria) this;
}
public Criteria andProtocolBetween(String value1, String value2) {
addCriterion("protocol between", value1, value2, "protocol");
return (Criteria) this;
}
public Criteria andProtocolNotBetween(String value1, String value2) {
addCriterion("protocol not between", value1, value2, "protocol");
return (Criteria) this;
}
public Criteria andParentIdIsNull() {
addCriterion("parent_id is null");
return (Criteria) this;

View File

@ -4,7 +4,6 @@
<resultMap id="BaseResultMap" type="io.metersphere.api.domain.ApiDebugModule">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="protocol" jdbcType="VARCHAR" property="protocol" />
<result column="parent_id" jdbcType="VARCHAR" property="parentId" />
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="pos" jdbcType="BIGINT" property="pos" />
@ -72,8 +71,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, `name`, protocol, parent_id, project_id, pos, create_time, update_time, update_user,
create_user
id, `name`, parent_id, project_id, pos, create_time, update_time, update_user, create_user
</sql>
<select id="selectByExample" parameterType="io.metersphere.api.domain.ApiDebugModuleExample" resultMap="BaseResultMap">
select
@ -106,14 +104,14 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.api.domain.ApiDebugModule">
insert into api_debug_module (id, `name`, protocol,
parent_id, project_id, pos,
create_time, update_time, update_user,
create_user)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{protocol,jdbcType=VARCHAR},
#{parentId,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{updateUser,jdbcType=VARCHAR},
#{createUser,jdbcType=VARCHAR})
insert into api_debug_module (id, `name`, parent_id,
project_id, pos, create_time,
update_time, update_user, create_user
)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{parentId,jdbcType=VARCHAR},
#{projectId,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{updateUser,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.api.domain.ApiDebugModule">
insert into api_debug_module
@ -124,9 +122,6 @@
<if test="name != null">
`name`,
</if>
<if test="protocol != null">
protocol,
</if>
<if test="parentId != null">
parent_id,
</if>
@ -156,9 +151,6 @@
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="protocol != null">
#{protocol,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
#{parentId,jdbcType=VARCHAR},
</if>
@ -197,9 +189,6 @@
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.protocol != null">
protocol = #{record.protocol,jdbcType=VARCHAR},
</if>
<if test="record.parentId != null">
parent_id = #{record.parentId,jdbcType=VARCHAR},
</if>
@ -230,7 +219,6 @@
update api_debug_module
set id = #{record.id,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
protocol = #{record.protocol,jdbcType=VARCHAR},
parent_id = #{record.parentId,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR},
pos = #{record.pos,jdbcType=BIGINT},
@ -248,9 +236,6 @@
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="protocol != null">
protocol = #{protocol,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
parent_id = #{parentId,jdbcType=VARCHAR},
</if>
@ -278,7 +263,6 @@
<update id="updateByPrimaryKey" parameterType="io.metersphere.api.domain.ApiDebugModule">
update api_debug_module
set `name` = #{name,jdbcType=VARCHAR},
protocol = #{protocol,jdbcType=VARCHAR},
parent_id = #{parentId,jdbcType=VARCHAR},
project_id = #{projectId,jdbcType=VARCHAR},
pos = #{pos,jdbcType=BIGINT},
@ -290,14 +274,14 @@
</update>
<insert id="batchInsert" parameterType="map">
insert into api_debug_module
(id, `name`, protocol, parent_id, project_id, pos, create_time, update_time, update_user,
create_user)
(id, `name`, parent_id, project_id, pos, create_time, update_time, update_user, create_user
)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.protocol,jdbcType=VARCHAR},
#{item.parentId,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT},
#{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT}, #{item.updateUser,jdbcType=VARCHAR},
#{item.createUser,jdbcType=VARCHAR})
(#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.parentId,jdbcType=VARCHAR},
#{item.projectId,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT}, #{item.createTime,jdbcType=BIGINT},
#{item.updateTime,jdbcType=BIGINT}, #{item.updateUser,jdbcType=VARCHAR}, #{item.createUser,jdbcType=VARCHAR}
)
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -316,9 +300,6 @@
<if test="'name'.toString() == column.value">
#{item.name,jdbcType=VARCHAR}
</if>
<if test="'protocol'.toString() == column.value">
#{item.protocol,jdbcType=VARCHAR}
</if>
<if test="'parent_id'.toString() == column.value">
#{item.parentId,jdbcType=VARCHAR}
</if>

View File

@ -4,7 +4,6 @@
<resultMap id="BaseResultMap" type="io.metersphere.api.domain.ApiDefinitionModule">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="protocol" jdbcType="VARCHAR" property="protocol" />
<result column="parent_id" jdbcType="VARCHAR" property="parentId" />
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="pos" jdbcType="BIGINT" property="pos" />
@ -72,8 +71,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, `name`, protocol, parent_id, project_id, pos, create_time, update_time, update_user,
create_user
id, `name`, parent_id, project_id, pos, create_time, update_time, update_user, create_user
</sql>
<select id="selectByExample" parameterType="io.metersphere.api.domain.ApiDefinitionModuleExample" resultMap="BaseResultMap">
select
@ -106,14 +104,14 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.api.domain.ApiDefinitionModule">
insert into api_definition_module (id, `name`, protocol,
parent_id, project_id, pos,
create_time, update_time, update_user,
create_user)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{protocol,jdbcType=VARCHAR},
#{parentId,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{updateUser,jdbcType=VARCHAR},
#{createUser,jdbcType=VARCHAR})
insert into api_definition_module (id, `name`, parent_id,
project_id, pos, create_time,
update_time, update_user, create_user
)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{parentId,jdbcType=VARCHAR},
#{projectId,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{updateUser,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.api.domain.ApiDefinitionModule">
insert into api_definition_module
@ -124,9 +122,6 @@
<if test="name != null">
`name`,
</if>
<if test="protocol != null">
protocol,
</if>
<if test="parentId != null">
parent_id,
</if>
@ -156,9 +151,6 @@
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="protocol != null">
#{protocol,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
#{parentId,jdbcType=VARCHAR},
</if>
@ -197,9 +189,6 @@
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.protocol != null">
protocol = #{record.protocol,jdbcType=VARCHAR},
</if>
<if test="record.parentId != null">
parent_id = #{record.parentId,jdbcType=VARCHAR},
</if>
@ -230,7 +219,6 @@
update api_definition_module
set id = #{record.id,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
protocol = #{record.protocol,jdbcType=VARCHAR},
parent_id = #{record.parentId,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR},
pos = #{record.pos,jdbcType=BIGINT},
@ -248,9 +236,6 @@
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="protocol != null">
protocol = #{protocol,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
parent_id = #{parentId,jdbcType=VARCHAR},
</if>
@ -278,7 +263,6 @@
<update id="updateByPrimaryKey" parameterType="io.metersphere.api.domain.ApiDefinitionModule">
update api_definition_module
set `name` = #{name,jdbcType=VARCHAR},
protocol = #{protocol,jdbcType=VARCHAR},
parent_id = #{parentId,jdbcType=VARCHAR},
project_id = #{projectId,jdbcType=VARCHAR},
pos = #{pos,jdbcType=BIGINT},
@ -290,14 +274,14 @@
</update>
<insert id="batchInsert" parameterType="map">
insert into api_definition_module
(id, `name`, protocol, parent_id, project_id, pos, create_time, update_time, update_user,
create_user)
(id, `name`, parent_id, project_id, pos, create_time, update_time, update_user, create_user
)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.protocol,jdbcType=VARCHAR},
#{item.parentId,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT},
#{item.createTime,jdbcType=BIGINT}, #{item.updateTime,jdbcType=BIGINT}, #{item.updateUser,jdbcType=VARCHAR},
#{item.createUser,jdbcType=VARCHAR})
(#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.parentId,jdbcType=VARCHAR},
#{item.projectId,jdbcType=VARCHAR}, #{item.pos,jdbcType=BIGINT}, #{item.createTime,jdbcType=BIGINT},
#{item.updateTime,jdbcType=BIGINT}, #{item.updateUser,jdbcType=VARCHAR}, #{item.createUser,jdbcType=VARCHAR}
)
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -316,9 +300,6 @@
<if test="'name'.toString() == column.value">
#{item.name,jdbcType=VARCHAR}
</if>
<if test="'protocol'.toString() == column.value">
#{item.protocol,jdbcType=VARCHAR}
</if>
<if test="'parent_id'.toString() == column.value">
#{item.parentId,jdbcType=VARCHAR}
</if>

View File

@ -39,7 +39,6 @@ CREATE TABLE IF NOT EXISTS api_debug_blob(
CREATE TABLE IF NOT EXISTS api_debug_module(
`id` VARCHAR(50) NOT NULL COMMENT '接口模块pk' ,
`name` VARCHAR(255) NOT NULL COMMENT '模块名称' ,
`protocol` VARCHAR(20) NOT NULL COMMENT '协议' ,
`parent_id` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '父级fk' ,
`project_id` VARCHAR(50) NOT NULL COMMENT '项目fk' ,
`pos` BIGINT NOT NULL COMMENT '排序' ,
@ -53,9 +52,9 @@ CREATE TABLE IF NOT EXISTS api_debug_module(
COLLATE = utf8mb4_general_ci COMMENT = '接口调试模块';
CREATE INDEX idx_project_id ON api_debug_module(project_id);
CREATE INDEX idx_protocol ON api_debug_module(protocol);
CREATE INDEX idx_pos ON api_debug_module(pos);
CREATE INDEX idx_create_user ON api_debug_module(create_user);
CREATE UNIQUE INDEX uq_name_project_parent_type ON api_debug_module (project_id, name, parent_id);
CREATE TABLE IF NOT EXISTS api_definition
@ -142,7 +141,6 @@ CREATE TABLE IF NOT EXISTS api_definition_follower(
CREATE TABLE IF NOT EXISTS api_definition_module(
`id` VARCHAR(50) NOT NULL COMMENT '接口模块pk' ,
`name` VARCHAR(255) NOT NULL COMMENT '模块名称' ,
`protocol` VARCHAR(20) NOT NULL COMMENT '协议' ,
`parent_id` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '父级fk' ,
`project_id` VARCHAR(50) NOT NULL COMMENT '项目fk' ,
`pos` INT NOT NULL COMMENT '排序' ,
@ -157,8 +155,8 @@ CREATE TABLE IF NOT EXISTS api_definition_module(
CREATE INDEX idx_project_id ON api_definition_module(project_id);
CREATE INDEX idx_protocol ON api_definition_module(protocol);
CREATE INDEX idx_pos ON api_definition_module(pos);
CREATE UNIQUE INDEX uq_name_project_parent_type ON api_definition_module (project_id, name, parent_id);
CREATE TABLE IF NOT EXISTS api_scenario(
`id` VARCHAR(50) NOT NULL COMMENT '' ,

View File

@ -8,5 +8,7 @@ import lombok.Data;
public class ApiTreeNode extends BaseTreeNode {
@Schema(description = "方法")
private String method;
@Schema(description = "协议")
private String protocol;
}

View File

@ -26,9 +26,5 @@ public class ModuleCreateRequest {
@NotEmpty(message = "{parent.node.not_blank}")
private String parentId = ModuleConstants.ROOT_NODE_PARENT_ID;
@Schema(description = "协议", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{api_debug_module.protocol.not_blank}", groups = {Created.class})
@Size(min = 1, max = 20, message = "{api_debug.protocol.length_range}", groups = {Created.class, Updated.class})
private String protocol = ModuleConstants.NODE_PROTOCOL_HTTP;
}

View File

@ -7,22 +7,14 @@
parent_id AS parentId,
'MODULE' AS type
FROM api_debug_module
WHERE protocol = #{protocol}
AND create_user = #{userId}
WHERE create_user = #{userId}
ORDER BY pos
</select>
<select id="selectIdAndParentIdByProtocolAndUserId" resultType="io.metersphere.system.dto.sdk.BaseTreeNode">
SELECT id,
parent_id AS parentId
FROM api_debug_module
WHERE protocol = #{protocol}
AND create_user = #{userId}
</select>
<select id="selectIdsByProjectId" resultType="java.lang.String">
SELECT id
FROM api_debug_module
WHERE project_id = #{0}
WHERE create_user = #{userId}
</select>
<select id="selectChildrenIdsByParentIds" resultType="java.lang.String">
SELECT id
@ -52,24 +44,15 @@
ORDER BY pos ASC
</select>
<select id="getLastModuleByParentId" resultType="io.metersphere.api.domain.ApiDebugModule">
SELECT *
FROM api_debug_module
WHERE parent_id = #{0}
ORDER BY pos DESC
LIMIT 1
</select>
<select id="selectApiDebugByProtocolAndUser" resultType="io.metersphere.api.dto.debug.ApiTreeNode">
SELECT id,
NAME,
module_id AS parentId,
'API' AS type,
method
method,
protocol
FROM api_debug
WHERE protocol = #{protocol}
AND create_user = #{userId}
WHERE create_user = #{userId}
ORDER BY update_time DESC
</select>

View File

@ -8,11 +8,6 @@
<include refid="module_request"/>
ORDER BY pos
</select>
<select id="selectIdsByProjectId" resultType="java.lang.String">
SELECT id
FROM api_definition_module
WHERE project_id = #{0}
</select>
<select id="selectChildrenIdsByParentIds" resultType="java.lang.String">
SELECT id
FROM api_definition_module
@ -41,20 +36,13 @@
ORDER BY pos ASC
</select>
<select id="getLastModuleByParentId" resultType="io.metersphere.api.domain.ApiDebugModule">
SELECT *
FROM api_definition_module
WHERE parent_id = #{0}
ORDER BY pos DESC
LIMIT 1
</select>
<select id="selectApiDataByRequest" resultType="io.metersphere.api.dto.debug.ApiTreeNode">
SELECT id,
NAME,
module_id AS parentId,
'API' AS type,
method
method,
protocol
FROM api_definition
<include refid="api_request"/>
ORDER BY update_time DESC
@ -171,9 +159,7 @@
#{item}
</foreach>
</if>
<if test="request.protocol != null and request.protocol != ''">
AND m.protocol = #{request.protocol}
</if>
</where>
</sql>

View File

@ -42,6 +42,7 @@ public class ApiDebugModuleService extends ModuleTreeService {
private static final String UNPLANNED = "api_debug_module.unplanned_request";
private static final String MODULE_NO_EXIST = "api_module.not.exist";
private static final String METHOD = "method";
private static final String PROTOCOL = "protocol";
private static final String DEBUG_MODULE_COUNT_ALL = "all";
@Resource
private ApiDebugModuleLogService apiDebugModuleLogService;
@ -76,7 +77,11 @@ public class ApiDebugModuleService extends ModuleTreeService {
baseTreeNode.setName(apiTreeNode.getName());
baseTreeNode.setParentId(apiTreeNode.getParentId());
baseTreeNode.setType(apiTreeNode.getType());
baseTreeNode.putAttachInfo(METHOD, apiTreeNode.getMethod());
if (StringUtils.equals(apiTreeNode.getProtocol(), ModuleConstants.NODE_PROTOCOL_HTTP)) {
baseTreeNode.putAttachInfo(METHOD, apiTreeNode.getMethod());
} else {
baseTreeNode.putAttachInfo(PROTOCOL, apiTreeNode.getProtocol());
}
return baseTreeNode;
}).toList();
//apiTreeNodeList使用stream实现将parentId分组生成map
@ -110,7 +115,6 @@ public class ApiDebugModuleService extends ModuleTreeService {
apiDebugModule.setName(request.getName());
apiDebugModule.setParentId(request.getParentId());
apiDebugModule.setProjectId(request.getProjectId());
apiDebugModule.setProtocol(request.getProtocol());
apiDebugModule.setCreateUser(operator);
this.checkDataValidity(apiDebugModule);
apiDebugModule.setCreateTime(System.currentTimeMillis());
@ -140,8 +144,7 @@ public class ApiDebugModuleService extends ModuleTreeService {
if (!StringUtils.equals(apiDebugModule.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
//检查父ID是否存在 调试模块的逻辑是 同一个用户下的同级模块不能重名 每个协议是不同的模块
example.createCriteria().andIdEqualTo(apiDebugModule.getParentId())
.andCreateUserEqualTo(apiDebugModule.getCreateUser())
.andProtocolEqualTo(apiDebugModule.getProtocol());
.andCreateUserEqualTo(apiDebugModule.getCreateUser());
if (apiDebugModuleMapper.countByExample(example) == 0) {
throw new MSException(Translator.get("parent.node.not_blank"));
}
@ -150,12 +153,24 @@ public class ApiDebugModuleService extends ModuleTreeService {
example.createCriteria().andParentIdEqualTo(apiDebugModule.getParentId())
.andNameEqualTo(apiDebugModule.getName())
.andIdNotEqualTo(apiDebugModule.getId())
.andCreateUserEqualTo(apiDebugModule.getCreateUser())
.andProtocolEqualTo(apiDebugModule.getProtocol());
.andCreateUserEqualTo(apiDebugModule.getCreateUser());
if (apiDebugModuleMapper.countByExample(example) > 0) {
throw new MSException(Translator.get("node.name.repeat"));
}
example.clear();
//非默认节点检查该节点所在分支的总长度确保不超过阈值
if (!StringUtils.equals(apiDebugModule.getId(), ModuleConstants.DEFAULT_NODE_ID)) {
this.checkBranchModules(this.getRootNodeId(apiDebugModule), extApiDebugModuleMapper::selectChildrenIdsByParentIds);
}
}
private String getRootNodeId(ApiDebugModule module) {
if (StringUtils.equals(module.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
return module.getId();
} else {
ApiDebugModule parentModule = apiDebugModuleMapper.selectByPrimaryKey(module.getParentId());
return this.getRootNodeId(parentModule);
}
}
public void update(ModuleUpdateRequest request, String userId, String projectId) {
@ -167,7 +182,6 @@ public class ApiDebugModuleService extends ModuleTreeService {
updateModule.setId(request.getId());
updateModule.setName(request.getName());
updateModule.setParentId(module.getParentId());
updateModule.setProtocol(module.getProtocol());
updateModule.setCreateUser(module.getCreateUser());
this.checkDataValidity(updateModule);
updateModule.setUpdateTime(System.currentTimeMillis());

View File

@ -77,7 +77,6 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
module.setName(request.getName());
module.setParentId(request.getParentId());
module.setProjectId(request.getProjectId());
module.setProtocol(request.getProtocol());
module.setCreateUser(operator);
this.checkDataValidity(module);
module.setCreateTime(System.currentTimeMillis());
@ -107,7 +106,6 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
if (!StringUtils.equals(module.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
//检查父ID是否存在 接口模块的逻辑是 同一个协议下的 同一个项目的同层级节点下不能有相同的名称
example.createCriteria().andIdEqualTo(module.getParentId())
.andProtocolEqualTo(module.getProtocol())
.andProjectIdEqualTo(module.getProjectId());
if (apiDefinitionModuleMapper.countByExample(example) == 0) {
throw new MSException(Translator.get("parent.node.not_blank"));
@ -116,11 +114,25 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
}
example.createCriteria().andParentIdEqualTo(module.getParentId())
.andNameEqualTo(module.getName()).andIdNotEqualTo(module.getId())
.andProtocolEqualTo(module.getProtocol()).andProjectIdEqualTo(module.getProjectId());
.andProjectIdEqualTo(module.getProjectId());
if (apiDefinitionModuleMapper.countByExample(example) > 0) {
throw new MSException(Translator.get("node.name.repeat"));
}
example.clear();
//非默认节点检查该节点所在分支的总长度确保不超过阈值
if (!StringUtils.equals(module.getId(), ModuleConstants.DEFAULT_NODE_ID)) {
this.checkBranchModules(this.getRootNodeId(module), extApiDefinitionModuleMapper::selectChildrenIdsByParentIds);
}
}
private String getRootNodeId(ApiDefinitionModule module) {
if (StringUtils.equals(module.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
return module.getId();
} else {
ApiDefinitionModule parentModule = apiDefinitionModuleMapper.selectByPrimaryKey(module.getParentId());
return this.getRootNodeId(parentModule);
}
}
public void update(ModuleUpdateRequest request, String userId) {
@ -133,7 +145,6 @@ public class ApiDefinitionModuleService extends ModuleTreeService {
updateModule.setName(request.getName());
updateModule.setParentId(module.getParentId());
updateModule.setProjectId(module.getProjectId());
updateModule.setProtocol(module.getProtocol());
this.checkDataValidity(updateModule);
updateModule.setUpdateTime(System.currentTimeMillis());
updateModule.setUpdateUser(userId);

View File

@ -128,6 +128,24 @@ public class ApiDebugModuleControllerTests extends BaseTest {
apiDebugBlob.setResponse(new byte[0]);
apiDebugBlobMapper.insertSelective(apiDebugBlob);
}
public void initApiDebugTCPData(String moduleId) {
ApiDebug apiDebug = new ApiDebug();
apiDebug.setId(IDGenerator.nextStr());
apiDebug.setProjectId(project.getId());
apiDebug.setName(StringUtils.join("接口调试", apiDebug.getId()));
apiDebug.setModuleId(moduleId);
apiDebug.setProtocol("TCP");
apiDebug.setCreateTime(System.currentTimeMillis());
apiDebug.setUpdateTime(System.currentTimeMillis());
apiDebug.setCreateUser("admin");
apiDebug.setUpdateUser("admin");
apiDebugMapper.insertSelective(apiDebug);
ApiDebugBlob apiDebugBlob = new ApiDebugBlob();
apiDebugBlob.setId(apiDebug.getId());
apiDebugBlob.setRequest(new byte[0]);
apiDebugBlob.setResponse(new byte[0]);
apiDebugBlobMapper.insertSelective(apiDebugBlob);
}
@Test
@Order(2)
@ -149,6 +167,7 @@ public class ApiDebugModuleControllerTests extends BaseTest {
}
Assertions.assertNotNull(a1Node);
initApiDebugData(a1Node.getId());
initApiDebugTCPData(a1Node.getId());
checkLog(a1Node.getId(), OperationLogType.ADD, URL_MODULE_ADD);
//根目录下创建节点a2和a3在a1下创建子节点a1-b1
@ -186,7 +205,9 @@ public class ApiDebugModuleControllerTests extends BaseTest {
Assertions.assertNotNull(a2Node);
Assertions.assertNotNull(a1b1Node);
initApiDebugData(a2Node.getId());
initApiDebugTCPData(a2Node.getId());
initApiDebugData(a1b1Node.getId());
initApiDebugTCPData(a1b1Node.getId());
checkLog(a2Node.getId(), OperationLogType.ADD, URL_MODULE_ADD);
checkLog(a1b1Node.getId(), OperationLogType.ADD, URL_MODULE_ADD);
@ -274,6 +295,32 @@ public class ApiDebugModuleControllerTests extends BaseTest {
request.setProjectId(DEFAULT_PROJECT_ID);
request.setName("defaultProject");
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEBUG_ADD, URL_MODULE_ADD, request);
/**
测试能否正常做200个节点
*/
String parentId = null;
for (int i = 0; i < 210; i++) {
ModuleCreateRequest perfRequest = new ModuleCreateRequest();
perfRequest.setProjectId(project.getId());
perfRequest.setName("500-test-root-" + i);
if (StringUtils.isNotEmpty(parentId)) {
perfRequest.setParentId(parentId);
}
if (i < 200) {
MvcResult result = this.requestPostWithOkAndReturn(URL_MODULE_ADD, perfRequest);
ResultHolder holder = JSON.parseObject(result.getResponse().getContentAsString(), ResultHolder.class);
if (i % 50 == 0) {
//到20换下一层级
parentId = holder.getData().toString();
}
} else {
//测试超过500会报错
this.requestPost(URL_MODULE_ADD, perfRequest).andExpect(status().is5xxServerError());
}
}
treeNodes = this.getDebugModuleTreeNode();
preliminaryTreeNodes = treeNodes;
}
@Test
@ -758,6 +805,7 @@ public class ApiDebugModuleControllerTests extends BaseTest {
MvcResult result = this.requestGetWithOkAndReturn(String.format(URL_MODULE_TREE, ModuleConstants.NODE_PROTOCOL_HTTP));
String returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
this.requestGetWithOkAndReturn(String.format(URL_MODULE_TREE, "TCP"));
return JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class);
}

View File

@ -325,6 +325,32 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
request.setProjectId(DEFAULT_PROJECT_ID);
request.setName("defaultProject");
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_ADD, URL_MODULE_ADD, request);
/**
测试能否正常做200个节点
*/
String parentId = null;
for (int i = 0; i < 210; i++) {
ModuleCreateRequest perfRequest = new ModuleCreateRequest();
perfRequest.setProjectId(project.getId());
perfRequest.setName("500-test-root-" + i);
if (StringUtils.isNotEmpty(parentId)) {
perfRequest.setParentId(parentId);
}
if (i < 200) {
MvcResult result = this.requestPostWithOkAndReturn(URL_MODULE_ADD, perfRequest);
ResultHolder holder = JSON.parseObject(result.getResponse().getContentAsString(), ResultHolder.class);
if (i % 50 == 0) {
//到20换下一层级
parentId = holder.getData().toString();
}
} else {
//测试超过500会报错
this.requestPost(URL_MODULE_ADD, perfRequest).andExpect(status().is5xxServerError());
}
}
treeNodes = this.getModuleTreeNode();
preliminaryTreeNodes = treeNodes;
}
@Test

View File

@ -33,8 +33,8 @@ INSERT INTO `api_report` (`id`, `name`, `resource_id`, `create_time`, `update_ti
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 ('10008', '报告005', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'ERROR', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
DELETE FROM `api_definition_module` WHERE `id` in ('10001', 'case-moduleId');
INSERT INTO `api_definition_module` (`id`, `name`, `protocol`, `parent_id`, `project_id`, `pos`, `create_time`, `update_time`, `update_user`, `create_user`) VALUES ('10001', 'module1', 'HTTP', 'NONE', '100001100001', 10, 0, 0, 'admin', 'admin');
INSERT INTO `api_definition_module` (`id`, `name`, `protocol`, `parent_id`, `project_id`, `pos`, `create_time`, `update_time`, `update_user`, `create_user`) VALUES ('case-moduleId', 'case-moduleId', 'HTTP', 'NONE', '100001100001', 10, 0, 0, 'admin', 'admin');
INSERT INTO `api_definition_module` (`id`, `name`, `parent_id`, `project_id`, `pos`, `create_time`, `update_time`, `update_user`, `create_user`) VALUES ('10001', 'module1', 'NONE', '100001100001', 10, 0, 0, 'admin', 'admin');
INSERT INTO `api_definition_module` (`id`, `name`, `parent_id`, `project_id`, `pos`, `create_time`, `update_time`, `update_user`, `create_user`) VALUES ('case-moduleId', 'case-moduleId', 'NONE', '100001100001', 10, 0, 0, 'admin', 'admin');
DELETE FROM `api_definition_blob` WHERE `id` in ('1001','1002','1003','1004','1005','1006');
INSERT INTO `api_definition_blob` (`id`, `request`, `response`) VALUES ('1001', 0x504B03041400080808004A547857000000000000000000000000030000007A6970CD92B14EC3301040FFE5E6A8296B36842A180055281B62709D4B6D61FBDCF3991055FD779C840C949185C5A77BB6CFEF6C9F21921B3D7134563F2B8FD0C0537A68DBFDCEA1C720504158F01C2AC0A00EAEE4BD72092BD0C6BA8E314013B27315647665AD11894D5D0FC3B0114CB2D1E4CBD6A8C494C97A4225F52886BA02EE776D490FD48D6B1583AA434ED0BC9EE11D0B9EC70A3E94CB93CB127FC9749834DB28968ACF9CC1E5AD029ECEFB7BA9A90156BE1D23AE9E8CA76C194B13C2B9ECF2363C62384E6D2E0BBCFAFC093068EAD66326B953461EFFAD1D8941BEA3D0DB233467D014026A69AD47CAE54E6FB6DBED7CBF9142C22BAC91C5F6562BC15B6755794D5073ACA027E76878C1AEE86949ABA0CA4257F03253B32A2C9A9171CFA431259A3EC937A424D7F4F205504B070852639A522B010000E0020000504B010214001400080808004A54785752639A522B010000E00200000300000000000000000000000000000000007A6970504B05060000000001000100310000005C0100000000, 0x504B03041400080808004A547857000000000000000000000000030000007A6970A58F414BC4301085FFCB9C03B69EA4B74559141465295E9622B3CD743798263199C82EA5FFDD49EB82772F19DECB9BEF25FB098C86A656C09740D0C063DBBE81028763513B4AC1BB44B55827424D3141B39FE0932E725B4E05DF6873C9AE5301393C583106B48914684A7D34818D77122A0AE64EC1C16B414CCB6CD7EAEDEBEEE5E361D36E0432443FBE17E03FFB98124B2660C4F1B786E95CAC485FD94492CF73CCB2371AF74CEEC82768EE44E1F9AAEA4A41EF1D93E33F849B60D1B8A5BEF79AAE94C1587A12A6CBD6CEDDAC2031724EF74B046EAB0ACA0B07CC96B7168FEBDADCFD00504B0708FF595995E400000087010000504B010214001400080808004A547857FF595995E4000000870100000300000000000000000000000000000000007A6970504B0506000000000100010031000000150100000000);