feat(接口测试): 增加接口用例添加接口
This commit is contained in:
parent
9dbb77c934
commit
3ea9341d46
|
@ -26,7 +26,7 @@ public class ApiTestCase implements Serializable {
|
|||
private String priority;
|
||||
|
||||
@Schema(description = "接口用例编号id")
|
||||
private Integer num;
|
||||
private Long num;
|
||||
|
||||
@Schema(description = "标签")
|
||||
private String tags;
|
||||
|
@ -56,14 +56,11 @@ public class ApiTestCase implements Serializable {
|
|||
@Size(min = 1, max = 50, message = "{api_test_case.api_definition_id.length_range}", groups = {Created.class, Updated.class})
|
||||
private String apiDefinitionId;
|
||||
|
||||
@Schema(description = "版本fk")
|
||||
@Schema(description = "版本fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_test_case.version_id.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 50, message = "{api_test_case.version_id.length_range}", groups = {Created.class, Updated.class})
|
||||
private String versionId;
|
||||
|
||||
@Schema(description = "责任人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_test_case.principal.not_blank}", groups = {Created.class})
|
||||
@Size(min = 1, max = 50, message = "{api_test_case.principal.length_range}", groups = {Created.class, Updated.class})
|
||||
private String principal;
|
||||
|
||||
@Schema(description = "环境fk")
|
||||
private String environmentId;
|
||||
|
||||
|
@ -95,7 +92,7 @@ public class ApiTestCase implements Serializable {
|
|||
id("id", "id", "VARCHAR", false),
|
||||
name("name", "name", "VARCHAR", true),
|
||||
priority("priority", "priority", "VARCHAR", false),
|
||||
num("num", "num", "INTEGER", false),
|
||||
num("num", "num", "BIGINT", false),
|
||||
tags("tags", "tags", "VARCHAR", false),
|
||||
status("status", "status", "VARCHAR", true),
|
||||
lastReportStatus("last_report_status", "lastReportStatus", "VARCHAR", false),
|
||||
|
@ -104,7 +101,6 @@ public class ApiTestCase implements Serializable {
|
|||
projectId("project_id", "projectId", "VARCHAR", false),
|
||||
apiDefinitionId("api_definition_id", "apiDefinitionId", "VARCHAR", false),
|
||||
versionId("version_id", "versionId", "VARCHAR", false),
|
||||
principal("principal", "principal", "VARCHAR", false),
|
||||
environmentId("environment_id", "environmentId", "VARCHAR", false),
|
||||
createTime("create_time", "createTime", "BIGINT", false),
|
||||
createUser("create_user", "createUser", "VARCHAR", false),
|
||||
|
|
|
@ -324,52 +324,52 @@ public class ApiTestCaseExample {
|
|||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumEqualTo(Integer value) {
|
||||
public Criteria andNumEqualTo(Long value) {
|
||||
addCriterion("num =", value, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumNotEqualTo(Integer value) {
|
||||
public Criteria andNumNotEqualTo(Long value) {
|
||||
addCriterion("num <>", value, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumGreaterThan(Integer value) {
|
||||
public Criteria andNumGreaterThan(Long value) {
|
||||
addCriterion("num >", value, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumGreaterThanOrEqualTo(Integer value) {
|
||||
public Criteria andNumGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("num >=", value, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumLessThan(Integer value) {
|
||||
public Criteria andNumLessThan(Long value) {
|
||||
addCriterion("num <", value, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumLessThanOrEqualTo(Integer value) {
|
||||
public Criteria andNumLessThanOrEqualTo(Long value) {
|
||||
addCriterion("num <=", value, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumIn(List<Integer> values) {
|
||||
public Criteria andNumIn(List<Long> values) {
|
||||
addCriterion("num in", values, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumNotIn(List<Integer> values) {
|
||||
public Criteria andNumNotIn(List<Long> values) {
|
||||
addCriterion("num not in", values, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumBetween(Integer value1, Integer value2) {
|
||||
public Criteria andNumBetween(Long value1, Long value2) {
|
||||
addCriterion("num between", value1, value2, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumNotBetween(Integer value1, Integer value2) {
|
||||
public Criteria andNumNotBetween(Long value1, Long value2) {
|
||||
addCriterion("num not between", value1, value2, "num");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
@ -924,76 +924,6 @@ public class ApiTestCaseExample {
|
|||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalIsNull() {
|
||||
addCriterion("principal is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalIsNotNull() {
|
||||
addCriterion("principal is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalEqualTo(String value) {
|
||||
addCriterion("principal =", value, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalNotEqualTo(String value) {
|
||||
addCriterion("principal <>", value, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalGreaterThan(String value) {
|
||||
addCriterion("principal >", value, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("principal >=", value, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalLessThan(String value) {
|
||||
addCriterion("principal <", value, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalLessThanOrEqualTo(String value) {
|
||||
addCriterion("principal <=", value, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalLike(String value) {
|
||||
addCriterion("principal like", value, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalNotLike(String value) {
|
||||
addCriterion("principal not like", value, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalIn(List<String> values) {
|
||||
addCriterion("principal in", values, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalNotIn(List<String> values) {
|
||||
addCriterion("principal not in", values, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalBetween(String value1, String value2) {
|
||||
addCriterion("principal between", value1, value2, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPrincipalNotBetween(String value1, String value2) {
|
||||
addCriterion("principal not between", value1, value2, "principal");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andEnvironmentIdIsNull() {
|
||||
addCriterion("environment_id is null");
|
||||
return (Criteria) this;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="priority" jdbcType="VARCHAR" property="priority" />
|
||||
<result column="num" jdbcType="INTEGER" property="num" />
|
||||
<result column="num" jdbcType="BIGINT" property="num" />
|
||||
<result column="tags" jdbcType="VARCHAR" property="tags" />
|
||||
<result column="status" jdbcType="VARCHAR" property="status" />
|
||||
<result column="last_report_status" jdbcType="VARCHAR" property="lastReportStatus" />
|
||||
|
@ -14,7 +14,6 @@
|
|||
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
|
||||
<result column="api_definition_id" jdbcType="VARCHAR" property="apiDefinitionId" />
|
||||
<result column="version_id" jdbcType="VARCHAR" property="versionId" />
|
||||
<result column="principal" jdbcType="VARCHAR" property="principal" />
|
||||
<result column="environment_id" jdbcType="VARCHAR" property="environmentId" />
|
||||
<result column="create_time" jdbcType="BIGINT" property="createTime" />
|
||||
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
|
||||
|
@ -84,8 +83,8 @@
|
|||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, `name`, priority, num, tags, `status`, last_report_status, last_report_id, pos,
|
||||
project_id, api_definition_id, version_id, principal, environment_id, create_time,
|
||||
create_user, update_time, update_user, delete_time, delete_user, deleted
|
||||
project_id, api_definition_id, version_id, environment_id, create_time, create_user,
|
||||
update_time, update_user, delete_time, delete_user, deleted
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.metersphere.api.domain.ApiTestCaseExample" resultMap="BaseResultMap">
|
||||
select
|
||||
|
@ -119,21 +118,19 @@
|
|||
</delete>
|
||||
<insert id="insert" parameterType="io.metersphere.api.domain.ApiTestCase">
|
||||
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,
|
||||
principal, environment_id, create_time,
|
||||
create_user, update_time, update_user,
|
||||
delete_time, delete_user, deleted
|
||||
)
|
||||
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 (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{priority,jdbcType=VARCHAR},
|
||||
#{num,jdbcType=INTEGER}, #{tags,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
|
||||
#{lastReportStatus,jdbcType=VARCHAR}, #{lastReportId,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT},
|
||||
#{projectId,jdbcType=VARCHAR}, #{apiDefinitionId,jdbcType=VARCHAR}, #{versionId,jdbcType=VARCHAR},
|
||||
#{principal,jdbcType=VARCHAR}, #{environmentId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
|
||||
#{createUser,jdbcType=VARCHAR}, #{updateTime,jdbcType=BIGINT}, #{updateUser,jdbcType=VARCHAR},
|
||||
#{deleteTime,jdbcType=BIGINT}, #{deleteUser,jdbcType=VARCHAR}, #{deleted,jdbcType=BIT}
|
||||
)
|
||||
#{num,jdbcType=BIGINT}, #{tags,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{lastReportStatus,jdbcType=VARCHAR},
|
||||
#{lastReportId,jdbcType=VARCHAR}, #{pos,jdbcType=BIGINT}, #{projectId,jdbcType=VARCHAR},
|
||||
#{apiDefinitionId,jdbcType=VARCHAR}, #{versionId,jdbcType=VARCHAR}, #{environmentId,jdbcType=VARCHAR},
|
||||
#{createTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{updateTime,jdbcType=BIGINT},
|
||||
#{updateUser,jdbcType=VARCHAR}, #{deleteTime,jdbcType=BIGINT}, #{deleteUser,jdbcType=VARCHAR},
|
||||
#{deleted,jdbcType=BIT})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.metersphere.api.domain.ApiTestCase">
|
||||
insert into api_test_case
|
||||
|
@ -174,9 +171,6 @@
|
|||
<if test="versionId != null">
|
||||
version_id,
|
||||
</if>
|
||||
<if test="principal != null">
|
||||
principal,
|
||||
</if>
|
||||
<if test="environmentId != null">
|
||||
environment_id,
|
||||
</if>
|
||||
|
@ -213,7 +207,7 @@
|
|||
#{priority,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="num != null">
|
||||
#{num,jdbcType=INTEGER},
|
||||
#{num,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="tags != null">
|
||||
#{tags,jdbcType=VARCHAR},
|
||||
|
@ -239,9 +233,6 @@
|
|||
<if test="versionId != null">
|
||||
#{versionId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="principal != null">
|
||||
#{principal,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="environmentId != null">
|
||||
#{environmentId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
@ -287,7 +278,7 @@
|
|||
priority = #{record.priority,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.num != null">
|
||||
num = #{record.num,jdbcType=INTEGER},
|
||||
num = #{record.num,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="record.tags != null">
|
||||
tags = #{record.tags,jdbcType=VARCHAR},
|
||||
|
@ -313,9 +304,6 @@
|
|||
<if test="record.versionId != null">
|
||||
version_id = #{record.versionId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.principal != null">
|
||||
principal = #{record.principal,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.environmentId != null">
|
||||
environment_id = #{record.environmentId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
@ -350,7 +338,7 @@
|
|||
set id = #{record.id,jdbcType=VARCHAR},
|
||||
`name` = #{record.name,jdbcType=VARCHAR},
|
||||
priority = #{record.priority,jdbcType=VARCHAR},
|
||||
num = #{record.num,jdbcType=INTEGER},
|
||||
num = #{record.num,jdbcType=BIGINT},
|
||||
tags = #{record.tags,jdbcType=VARCHAR},
|
||||
`status` = #{record.status,jdbcType=VARCHAR},
|
||||
last_report_status = #{record.lastReportStatus,jdbcType=VARCHAR},
|
||||
|
@ -359,7 +347,6 @@
|
|||
project_id = #{record.projectId,jdbcType=VARCHAR},
|
||||
api_definition_id = #{record.apiDefinitionId,jdbcType=VARCHAR},
|
||||
version_id = #{record.versionId,jdbcType=VARCHAR},
|
||||
principal = #{record.principal,jdbcType=VARCHAR},
|
||||
environment_id = #{record.environmentId,jdbcType=VARCHAR},
|
||||
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||
create_user = #{record.createUser,jdbcType=VARCHAR},
|
||||
|
@ -382,7 +369,7 @@
|
|||
priority = #{priority,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="num != null">
|
||||
num = #{num,jdbcType=INTEGER},
|
||||
num = #{num,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="tags != null">
|
||||
tags = #{tags,jdbcType=VARCHAR},
|
||||
|
@ -408,9 +395,6 @@
|
|||
<if test="versionId != null">
|
||||
version_id = #{versionId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="principal != null">
|
||||
principal = #{principal,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="environmentId != null">
|
||||
environment_id = #{environmentId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
@ -442,7 +426,7 @@
|
|||
update api_test_case
|
||||
set `name` = #{name,jdbcType=VARCHAR},
|
||||
priority = #{priority,jdbcType=VARCHAR},
|
||||
num = #{num,jdbcType=INTEGER},
|
||||
num = #{num,jdbcType=BIGINT},
|
||||
tags = #{tags,jdbcType=VARCHAR},
|
||||
`status` = #{status,jdbcType=VARCHAR},
|
||||
last_report_status = #{lastReportStatus,jdbcType=VARCHAR},
|
||||
|
@ -451,7 +435,6 @@
|
|||
project_id = #{projectId,jdbcType=VARCHAR},
|
||||
api_definition_id = #{apiDefinitionId,jdbcType=VARCHAR},
|
||||
version_id = #{versionId,jdbcType=VARCHAR},
|
||||
principal = #{principal,jdbcType=VARCHAR},
|
||||
environment_id = #{environmentId,jdbcType=VARCHAR},
|
||||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
create_user = #{createUser,jdbcType=VARCHAR},
|
||||
|
@ -465,18 +448,18 @@
|
|||
<insert id="batchInsert" parameterType="map">
|
||||
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, principal, environment_id, create_time,
|
||||
create_user, update_time, update_user, delete_time, delete_user, deleted)
|
||||
project_id, api_definition_id, version_id, environment_id, create_time, create_user,
|
||||
update_time, update_user, delete_time, delete_user, deleted)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.priority,jdbcType=VARCHAR},
|
||||
#{item.num,jdbcType=INTEGER}, #{item.tags,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR},
|
||||
#{item.num,jdbcType=BIGINT}, #{item.tags,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR},
|
||||
#{item.lastReportStatus,jdbcType=VARCHAR}, #{item.lastReportId,jdbcType=VARCHAR},
|
||||
#{item.pos,jdbcType=BIGINT}, #{item.projectId,jdbcType=VARCHAR}, #{item.apiDefinitionId,jdbcType=VARCHAR},
|
||||
#{item.versionId,jdbcType=VARCHAR}, #{item.principal,jdbcType=VARCHAR}, #{item.environmentId,jdbcType=VARCHAR},
|
||||
#{item.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=BIGINT},
|
||||
#{item.updateUser,jdbcType=VARCHAR}, #{item.deleteTime,jdbcType=BIGINT}, #{item.deleteUser,jdbcType=VARCHAR},
|
||||
#{item.deleted,jdbcType=BIT})
|
||||
#{item.versionId,jdbcType=VARCHAR}, #{item.environmentId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT},
|
||||
#{item.createUser,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=BIGINT}, #{item.updateUser,jdbcType=VARCHAR},
|
||||
#{item.deleteTime,jdbcType=BIGINT}, #{item.deleteUser,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<insert id="batchInsertSelective" parameterType="map">
|
||||
|
@ -499,7 +482,7 @@
|
|||
#{item.priority,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'num'.toString() == column.value">
|
||||
#{item.num,jdbcType=INTEGER}
|
||||
#{item.num,jdbcType=BIGINT}
|
||||
</if>
|
||||
<if test="'tags'.toString() == column.value">
|
||||
#{item.tags,jdbcType=VARCHAR}
|
||||
|
@ -525,9 +508,6 @@
|
|||
<if test="'version_id'.toString() == column.value">
|
||||
#{item.versionId,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'principal'.toString() == column.value">
|
||||
#{item.principal,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="'environment_id'.toString() == column.value">
|
||||
#{item.environmentId,jdbcType=VARCHAR}
|
||||
</if>
|
||||
|
|
|
@ -371,28 +371,28 @@ CREATE TABLE api_sync_config(
|
|||
CREATE INDEX idx_resource_id ON api_sync_config(resource_id);
|
||||
|
||||
DROP TABLE IF EXISTS api_test_case;
|
||||
CREATE TABLE api_test_case(
|
||||
`id` VARCHAR(50) NOT NULL COMMENT '接口用例pk' ,
|
||||
`name` VARCHAR(255) NOT NULL COMMENT '接口用例名称' ,
|
||||
`priority` VARCHAR(50) NOT NULL COMMENT '用例等级' ,
|
||||
`num` INT COMMENT '接口用例编号id' ,
|
||||
`tags` VARCHAR(1000) COMMENT '标签' ,
|
||||
`status` VARCHAR(20) NOT NULL COMMENT '用例状态' ,
|
||||
`last_report_status` VARCHAR(20) COMMENT '最新执行结果状态' ,
|
||||
`last_report_id` VARCHAR(50) COMMENT '最后执行结果报告fk' ,
|
||||
`pos` BIGINT NOT NULL COMMENT '自定义排序' ,
|
||||
`project_id` VARCHAR(50) NOT NULL COMMENT '项目fk' ,
|
||||
`api_definition_id` VARCHAR(50) NOT NULL COMMENT '接口fk' ,
|
||||
`version_id` VARCHAR(50) COMMENT '版本fk' ,
|
||||
`principal` VARCHAR(50) NOT NULL COMMENT '责任人' ,
|
||||
`environment_id` VARCHAR(50) COMMENT '环境fk' ,
|
||||
`create_time` BIGINT NOT NULL COMMENT '创建时间' ,
|
||||
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人' ,
|
||||
`update_time` BIGINT NOT NULL COMMENT '更新时间' ,
|
||||
`update_user` VARCHAR(50) NOT NULL COMMENT '更新人' ,
|
||||
`delete_time` BIGINT COMMENT '删除时间' ,
|
||||
`delete_user` VARCHAR(50) COMMENT '删除人' ,
|
||||
`deleted` BIT(1) NOT NULL DEFAULT 0 COMMENT '删除标识' ,
|
||||
CREATE TABLE api_test_case
|
||||
(
|
||||
`id` VARCHAR(50) NOT NULL COMMENT '接口用例pk',
|
||||
`name` VARCHAR(255) NOT NULL COMMENT '接口用例名称',
|
||||
`priority` VARCHAR(50) NOT NULL COMMENT '用例等级',
|
||||
`num` BIGINT NOT NULL COMMENT '接口用例编号id',
|
||||
`tags` VARCHAR(1000) COMMENT '标签',
|
||||
`status` VARCHAR(20) NOT NULL COMMENT '用例状态',
|
||||
`last_report_status` VARCHAR(20) COMMENT '最新执行结果状态',
|
||||
`last_report_id` VARCHAR(50) COMMENT '最后执行结果报告fk',
|
||||
`pos` BIGINT NOT NULL COMMENT '自定义排序',
|
||||
`project_id` VARCHAR(50) NOT NULL COMMENT '项目fk',
|
||||
`api_definition_id` VARCHAR(50) NOT NULL COMMENT '接口fk',
|
||||
`version_id` VARCHAR(50) NOT NULL COMMENT '版本fk',
|
||||
`environment_id` VARCHAR(50) COMMENT '环境fk',
|
||||
`create_time` BIGINT NOT NULL COMMENT '创建时间',
|
||||
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人',
|
||||
`update_time` BIGINT NOT NULL COMMENT '更新时间',
|
||||
`update_user` VARCHAR(50) NOT NULL COMMENT '更新人',
|
||||
`delete_time` BIGINT COMMENT '删除时间',
|
||||
`delete_user` VARCHAR(50) COMMENT '删除人',
|
||||
`deleted` BIT(1) NOT NULL DEFAULT 0 COMMENT '删除标识',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
|
@ -401,13 +401,14 @@ CREATE TABLE api_test_case(
|
|||
|
||||
CREATE INDEX idx_api_definition_id ON api_test_case(api_definition_id);
|
||||
CREATE INDEX idx_project_id ON api_test_case(project_id);
|
||||
CREATE INDEX idx_status ON api_test_case(status);
|
||||
CREATE INDEX idx_version_id ON api_test_case(version_id);
|
||||
CREATE INDEX idx_principal ON api_test_case(principal);
|
||||
CREATE INDEX idx_priority ON api_test_case(priority);
|
||||
CREATE INDEX idx_create_time ON api_test_case(create_time);
|
||||
CREATE INDEX idx_update_time ON api_test_case(update_time);
|
||||
CREATE INDEX idx_create_user ON api_test_case(create_user);
|
||||
CREATE INDEX idx_name ON api_test_case(name);
|
||||
CREATE INDEX idx_num ON api_test_case(num);
|
||||
|
||||
DROP TABLE IF EXISTS api_test_case_follower;
|
||||
CREATE TABLE api_test_case_follower(
|
||||
|
|
|
@ -244,5 +244,8 @@ public class PermissionConstants {
|
|||
public static final String PROJECT_API_DEFINITION_IMPORT = "PROJECT_API_DEFINITION:READ+IMPORT";
|
||||
public static final String PROJECT_API_DEFINITION_EXPORT = "PROJECT_API_DEFINITION:READ+EXPORT";
|
||||
public static final String PROJECT_API_DEFINITION_EXECUTE = "PROJECT_API_DEFINITION:READ+EXECUTE";
|
||||
public static final String PROJECT_API_DEFINITION_CASE_READ = "PROJECT_API_DEFINITION_CASE:READ";
|
||||
public static final String PROJECT_API_DEFINITION_CASE_ADD = "PROJECT_API_DEFINITION_CASE:READ+ADD";
|
||||
|
||||
/*------ end: API_MANAGEMENT ------*/
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ public class MsFileUtils {
|
|||
public static final String PLUGIN_DIR_NAME = "plugins";
|
||||
public static final String PLUGIN_DIR = DATA_ROOT_DIR + "/" + PLUGIN_DIR_NAME;
|
||||
public static final String FUNCTIONAL_CASE_DIR_NAME = "functionalCase";
|
||||
public static final String API_CASE_DIR_NAME = "apiCase";
|
||||
public static final String API_CASE_DIR = DATA_ROOT_DIR + "/" + API_CASE_DIR_NAME;
|
||||
public static final String BUG_MANAGEMENT_DIR = "bug";
|
||||
|
||||
public static void validateFileName(String... fileNames) {
|
||||
|
|
|
@ -174,6 +174,8 @@ api_test_case.api_definition_id.length_range=接口ID长度必须在1-50之间
|
|||
api_test_case.api_definition_id.not_blank=接口ID不能为空
|
||||
api_test_case.principal.length_range=责任人长度必须在1-50之间
|
||||
api_test_case.principal.not_blank=责任人不能为空
|
||||
api_test_case.version_id.not_blank=版本ID不能为空
|
||||
api_test_case.version_id.length_range=版本ID长度必须在1-50之间
|
||||
#module:ApiDefinitionMock
|
||||
api_definition_mock.id.not_blank=mock pk不能为空
|
||||
api_definition_mock.create_user.length_range=创建人长度必须在1-64之间
|
||||
|
|
|
@ -174,6 +174,8 @@ api_test_case.api_definition_id.length_range=Interface fk length must be between
|
|||
api_test_case.api_definition_id.not_blank=Interface fk cannot be empty
|
||||
api_test_case.principal.length_range=The responsible person length must be between 1-50
|
||||
api_test_case.principal.not_blank=Responsible person cannot be empty
|
||||
api_test_case.version_id.not_blank=Version fk cannot be empty
|
||||
api_test_case.version_id.length_range=Version fk length must be between 1-50
|
||||
#module:ApiDefinitionMock
|
||||
api_definition_mock.id.not_blank=mock pk cannot be empty
|
||||
api_definition_mock.create_user.length_range=Creator length must be between 1-64
|
||||
|
|
|
@ -174,6 +174,8 @@ api_test_case.api_definition_id.length_range=接口ID长度必须在1-50之间
|
|||
api_test_case.api_definition_id.not_blank=接口ID不能为空
|
||||
api_test_case.principal.length_range=责任人长度必须在1-50之间
|
||||
api_test_case.principal.not_blank=责任人不能为空
|
||||
api_test_case.version_id.not_blank=版本ID不能为空
|
||||
api_test_case.version_id.length_range=版本ID长度必须在1-50之间
|
||||
#module:ApiDefinitionMock
|
||||
api_definition_mock.id.not_blank=mock pk不能为空
|
||||
api_definition_mock.create_user.length_range=创建人长度必须在1-64之间
|
||||
|
|
|
@ -174,6 +174,8 @@ api_test_case.api_definition_id.length_range=接口ID長度必須在1-50之間
|
|||
api_test_case.api_definition_id.not_blank=接口ID不能為空
|
||||
api_test_case.principal.length_range=責任人長度必須在1-50之間
|
||||
api_test_case.principal.not_blank=責任人不能為空
|
||||
api_test_case.version_id.not_blank=版本ID不能為空
|
||||
api_test_case.version_id.length_range=版本ID長度必須在1-50之間
|
||||
#module:ApiDefinitionMock
|
||||
api_definition_mock.id.not_blank=mock pk不能為空
|
||||
api_definition_mock.create_user.length_range=創建人長度必須在1-64之間
|
||||
|
|
|
@ -472,3 +472,9 @@ permission.api_definition.name=接口管理
|
|||
permission.api_definition.import=导入
|
||||
permission.api_definition.export=导出
|
||||
permission.api_definition.execute=执行
|
||||
|
||||
#接口管理
|
||||
api_definition_not_exist=接口不存在
|
||||
api_test_case_name_exist=接口用例名称已存在
|
||||
file_upload_fail=文件上传失败
|
||||
|
||||
|
|
|
@ -481,3 +481,8 @@ permission.api_definition.name=API Management
|
|||
permission.api_definition.import=Import
|
||||
permission.api_definition.export=Export
|
||||
permission.api_definition.execute=Execute
|
||||
|
||||
#接口管理
|
||||
api_definition_not_exist=API definition is not exist
|
||||
api_test_case_name_exist=API test case name is exist
|
||||
file_upload_fail=File upload fail
|
|
@ -477,3 +477,8 @@ permission.api_definition.name=接口管理
|
|||
permission.api_definition.import=导入
|
||||
permission.api_definition.export=导出
|
||||
permission.api_definition.execute=执行
|
||||
|
||||
#接口管理
|
||||
api_definition_not_exist=接口不存在
|
||||
file_upload_fail=文件上传失败
|
||||
api_test_case_name_exist=接口用例名称已存在
|
|
@ -477,3 +477,8 @@ permission.api_definition.name=接口管理
|
|||
permission.api_definition.import=導入
|
||||
permission.api_definition.export=導出
|
||||
permission.api_definition.execute=執行
|
||||
|
||||
#接口管理
|
||||
api_definition_not_exist=接口不存在
|
||||
file_upload_fail=文件上傳失敗
|
||||
api_test_case_name_exist=接口用例名稱已存在
|
|
@ -0,0 +1,41 @@
|
|||
package io.metersphere.api.controller.definition;
|
||||
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseAddRequest;
|
||||
import io.metersphere.api.service.definition.ApiTestCaseLogService;
|
||||
import io.metersphere.api.service.definition.ApiTestCaseService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
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 org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/testCase")
|
||||
@Tag(name = "接口测试-接口管理-接口用例")
|
||||
public class ApiTestCaseController {
|
||||
@Resource
|
||||
private ApiTestCaseService apiTestCaseService;
|
||||
|
||||
@PostMapping(value = "/add")
|
||||
@Operation(summary = "接口测试-接口管理-接口用例-新增")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_ADD)
|
||||
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = ApiTestCaseLogService.class)
|
||||
public ApiTestCase add(@Validated @RequestPart("request") ApiTestCaseAddRequest request, @RequestPart(value = "files", required = false) List<MultipartFile> files) {
|
||||
return apiTestCaseService.addCase(request, files, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: jianxing
|
||||
* @CreateTime: 2023-11-06 10:22
|
||||
*/
|
||||
@Data
|
||||
public class ApiTestCaseAddRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "用例名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_debug.name.not_blank}")
|
||||
@Size(min = 1, max = 255, message = "{api_debug.name.length_range}")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "项目fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_debug.project_id.not_blank}")
|
||||
@Size(min = 1, max = 50, message = "{api_debug.project_id.length_range}")
|
||||
private String projectId;
|
||||
|
||||
@Schema(description = "用例等级", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_test_case.priority.not_blank}")
|
||||
@Size(min = 1, max = 50, message = "{api_test_case.priority.length_range}")
|
||||
private String priority;
|
||||
|
||||
@Schema(description = "用例状态 Underway Prepare Completed", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_test_case.status.not_blank}")
|
||||
@Size(min = 1, max = 20, message = "{api_test_case.status.length_range}")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "接口fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_test_case.api_definition_id.not_blank}")
|
||||
@Size(min = 1, max = 50, message = "{api_test_case.api_definition_id.length_range}")
|
||||
private String apiDefinitionId;
|
||||
|
||||
@Schema(description = "标签")
|
||||
private List<
|
||||
@NotBlank
|
||||
String> tags;
|
||||
|
||||
@Schema(description = "环境fk")
|
||||
private String environmentId;
|
||||
|
||||
@Schema(description = "请求内容")
|
||||
@NotBlank
|
||||
private String request;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package io.metersphere.api.mapper;
|
||||
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
* @date : 2023-11-6
|
||||
*/
|
||||
@Mapper
|
||||
public interface ExtApiTestCaseMapper {
|
||||
|
||||
Long getPos(@Param("projectId") String projectId);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="io.metersphere.api.mapper.ExtApiTestCaseMapper">
|
||||
|
||||
<select id="getPos" resultType="java.lang.Long">
|
||||
SELECT pos
|
||||
FROM api_test_case
|
||||
WHERE project_id = #{projectId}
|
||||
ORDER BY pos DESC
|
||||
LIMIT 1;
|
||||
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,46 @@
|
|||
package io.metersphere.api.service.definition;
|
||||
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseAddRequest;
|
||||
import io.metersphere.api.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ApiTestCaseLogService {
|
||||
|
||||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
/**
|
||||
* 添加接口日志
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public LogDTO addLog(ApiTestCaseAddRequest request) {
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
|
||||
LogDTO dto = new LogDTO(
|
||||
request.getProjectId(),
|
||||
project.getOrganizationId(),
|
||||
null,
|
||||
null,
|
||||
OperationLogType.ADD.name(),
|
||||
OperationLogModule.API_DEFINITION,
|
||||
request.getName());
|
||||
|
||||
dto.setPath("/api/testCase/add");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||
return dto;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package io.metersphere.api.service.definition;
|
||||
|
||||
import io.metersphere.api.domain.*;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseAddRequest;
|
||||
import io.metersphere.api.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.api.mapper.ApiTestCaseBlobMapper;
|
||||
import io.metersphere.api.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.api.mapper.ExtApiTestCaseMapper;
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.ApplicationNumScope;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.*;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.system.uid.NumGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ApiTestCaseService {
|
||||
|
||||
public static final Long ORDER_STEP = 5000L;
|
||||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
@Resource
|
||||
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
||||
@Resource
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
@Resource
|
||||
private ApiTestCaseBlobMapper apiTestCaseBlobMapper;
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
@Resource
|
||||
private MinioRepository minioRepository;
|
||||
|
||||
public ApiTestCase addCase(ApiTestCaseAddRequest request, List<MultipartFile> files, String userId) {
|
||||
ApiTestCase testCase = new ApiTestCase();
|
||||
testCase.setId(IDGenerator.nextStr());
|
||||
BeanUtils.copyBean(testCase, request);
|
||||
ApiDefinition apiDefinition = getApiDefinition(request.getApiDefinitionId());
|
||||
testCase.setNum(NumGenerator.nextNum(request.getProjectId()+ "_" + apiDefinition.getNum(), ApplicationNumScope.API_TEST_CASE));
|
||||
testCase.setApiDefinitionId(request.getApiDefinitionId());
|
||||
testCase.setName(request.getName());
|
||||
testCase.setPos(getNextOrder(request.getProjectId()));
|
||||
testCase.setProjectId(request.getProjectId());
|
||||
checkProjectExist(testCase.getProjectId());
|
||||
checkNameExist(testCase);
|
||||
testCase.setVersionId(apiDefinition.getVersionId());
|
||||
testCase.setPriority(request.getPriority());
|
||||
testCase.setStatus(request.getStatus());
|
||||
testCase.setCreateUser(userId);
|
||||
testCase.setUpdateUser(userId);
|
||||
testCase.setCreateTime(System.currentTimeMillis());
|
||||
testCase.setUpdateTime(System.currentTimeMillis());
|
||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||
testCase.setTags(JSON.toJSONString(request.getTags()));
|
||||
}
|
||||
apiTestCaseMapper.insertSelective(testCase);
|
||||
|
||||
ApiTestCaseBlob caseBlob = new ApiTestCaseBlob();
|
||||
caseBlob.setId(testCase.getId());
|
||||
caseBlob.setRequest(request.getRequest().getBytes());
|
||||
apiTestCaseBlobMapper.insert(caseBlob);
|
||||
uploadBodyFile(files, testCase.getId(), request.getProjectId());
|
||||
return testCase;
|
||||
}
|
||||
|
||||
private void checkProjectExist(String projectId) {
|
||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||
if (project == null) {
|
||||
throw new MSException(Translator.get("project_is_not_exist"));
|
||||
}
|
||||
}
|
||||
|
||||
private ApiDefinition getApiDefinition(String apiDefinitionId) {
|
||||
//判断是否存在
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andIdEqualTo(apiDefinitionId).andDeletedEqualTo(false);
|
||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(apiDefinitions)) {
|
||||
throw new MSException(Translator.get("api_definition_not_exist"));
|
||||
}
|
||||
return apiDefinitions.get(0);
|
||||
}
|
||||
|
||||
public void checkNameExist(ApiTestCase apiTestCase) {
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
example.createCriteria().andProjectIdEqualTo(apiTestCase.getProjectId())
|
||||
.andApiDefinitionIdEqualTo(apiTestCase.getApiDefinitionId())
|
||||
.andNameEqualTo(apiTestCase.getName()).andIdNotEqualTo(apiTestCase.getId()).andDeletedEqualTo(false);
|
||||
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(apiTestCases)) {
|
||||
throw new MSException(Translator.get("api_test_case_name_exist"));
|
||||
}
|
||||
}
|
||||
|
||||
public Long getNextOrder(String projectId) {
|
||||
Long pos = extApiTestCaseMapper.getPos(projectId);
|
||||
return (pos == null ? 0 : pos) + ORDER_STEP;
|
||||
}
|
||||
|
||||
public void uploadBodyFile(List<MultipartFile> files, String caseId, String projectId) {
|
||||
if (CollectionUtils.isNotEmpty(files)) {
|
||||
files.forEach(file -> {
|
||||
FileRequest fileRequest = new FileRequest();
|
||||
fileRequest.setFileName(file.getName());
|
||||
fileRequest.setProjectId(StringUtils.join(MsFileUtils.API_CASE_DIR, projectId));
|
||||
fileRequest.setResourceId(caseId);
|
||||
fileRequest.setStorage(StorageType.MINIO.name());
|
||||
try {
|
||||
minioRepository.saveFile(file, fileRequest);
|
||||
} catch (Exception e) {
|
||||
LogUtils.info("上传body文件失败: 文件名称:" + file.getName(), e);
|
||||
throw new MSException(Translator.get("file_upload_fail"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
[
|
||||
{
|
||||
"id": "API",
|
||||
"id": "API_TEST",
|
||||
"name": "permission.api_test.name",
|
||||
"type": "PROJECT",
|
||||
"children": [
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
package io.metersphere.api.controller;
|
||||
|
||||
import io.metersphere.api.controller.param.ApiTestCaseAddRequestDefinition;
|
||||
import io.metersphere.api.domain.ApiDefinition;
|
||||
import io.metersphere.api.domain.ApiDefinitionBlob;
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.api.domain.ApiTestCaseBlob;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseAddRequest;
|
||||
import io.metersphere.api.mapper.ApiDefinitionBlobMapper;
|
||||
import io.metersphere.api.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.api.mapper.ApiTestCaseBlobMapper;
|
||||
import io.metersphere.api.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.api.util.ApiDataUtils;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import io.metersphere.sdk.constants.ApplicationNumScope;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.dto.api.request.http.MsHTTPElement;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.uid.NumGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultMatcher;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
* @date : 2023-11-7
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class ApiTestCaseControllerTests extends BaseTest {
|
||||
protected static final String DEFAULT_LIST = "list/{0}";
|
||||
protected static final String HTTP_PROTOCOL = "HTTP";
|
||||
private static final String BASE_PATH = "/api/testCase/";
|
||||
private static final String ADD = BASE_PATH + "add";
|
||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
private static ApiTestCase apiTestCase;
|
||||
private static ApiTestCase anotheraddapidebug;
|
||||
@Resource
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
@Resource
|
||||
private ApiDefinitionBlobMapper apiDefinitionBlobMapper;
|
||||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
@Resource
|
||||
private ApiTestCaseBlobMapper apiTestCaseBlobMapper;
|
||||
|
||||
public void initApiData() {
|
||||
ApiDefinition apiDefinition = new ApiDefinition();
|
||||
apiDefinition.setId("apiDefinitionId");
|
||||
apiDefinition.setProjectId(DEFAULT_PROJECT_ID);
|
||||
apiDefinition.setName(StringUtils.join("接口定义", apiDefinition.getId()));
|
||||
apiDefinition.setModuleId("moduleId");
|
||||
apiDefinition.setProtocol("HTTP");
|
||||
apiDefinition.setMethod("GET");
|
||||
apiDefinition.setStatus("未规划");
|
||||
apiDefinition.setNum(NumGenerator.nextNum(DEFAULT_PROJECT_ID, ApplicationNumScope.API_DEFINITION));
|
||||
apiDefinition.setPos(0L);
|
||||
apiDefinition.setPath(StringUtils.join("api/definition/", apiDefinition.getId()));
|
||||
apiDefinition.setLatest(true);
|
||||
apiDefinition.setVersionId("1.0");
|
||||
apiDefinition.setRefId(apiDefinition.getId());
|
||||
apiDefinition.setCreateTime(System.currentTimeMillis());
|
||||
apiDefinition.setUpdateTime(System.currentTimeMillis());
|
||||
apiDefinition.setCreateUser("admin");
|
||||
apiDefinition.setUpdateUser("admin");
|
||||
apiDefinitionMapper.insertSelective(apiDefinition);
|
||||
ApiDefinitionBlob apiDefinitionBlob = new ApiDefinitionBlob();
|
||||
apiDefinitionBlob.setId(apiDefinition.getId());
|
||||
apiDefinitionBlob.setRequest(new byte[0]);
|
||||
apiDefinitionBlob.setResponse(new byte[0]);
|
||||
apiDefinitionBlobMapper.insertSelective(apiDefinitionBlob);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void add() throws Exception {
|
||||
initApiData();
|
||||
// @@请求成功
|
||||
ApiTestCaseAddRequest request = new ApiTestCaseAddRequest();
|
||||
request.setApiDefinitionId("apiDefinitionId");
|
||||
request.setName("test");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setPriority("P0");
|
||||
request.setStatus("Underway");
|
||||
request.setRequest("request");
|
||||
request.setTags(List.of("tag1", "tag2"));
|
||||
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
|
||||
request.setRequest(ApiDataUtils.toJSONString(msHttpElement));
|
||||
LinkedMultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
FileInputStream inputStream = new FileInputStream(new File(
|
||||
this.getClass().getClassLoader().getResource("file/file_upload.JPG")
|
||||
.getPath()));
|
||||
MockMultipartFile file = new MockMultipartFile("file_upload.JPG", "file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, inputStream);
|
||||
paramMap.add("files", List.of(file));
|
||||
MvcResult mvcResult = this.requestMultipartWithOkAndReturn(ADD, paramMap);
|
||||
// 校验请求成功数据
|
||||
ApiTestCase resultData = getResultData(mvcResult, ApiTestCase.class);
|
||||
this.apiTestCase = assertUpdateApiDebug(request, msHttpElement, resultData.getId());
|
||||
|
||||
// 再插入一条数据,便于修改时重名校验
|
||||
request.setName("test1");
|
||||
paramMap.clear();
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
mvcResult = this.requestMultipartWithOkAndReturn(ADD, paramMap);
|
||||
resultData = getResultData(mvcResult, ApiTestCase.class);
|
||||
this.anotheraddapidebug = assertUpdateApiDebug(request, msHttpElement, resultData.getId());
|
||||
|
||||
// @@重名校验异常
|
||||
this.requestMultipart(ADD, paramMap).andExpect(ERROR_REQUEST_MATCHER);
|
||||
// 校验接口是否存在
|
||||
request.setApiDefinitionId("111");
|
||||
paramMap.clear();
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
this.requestMultipart(ADD, paramMap).andExpect(ERROR_REQUEST_MATCHER);
|
||||
|
||||
// 校验项目是否存在
|
||||
request.setProjectId("111");
|
||||
request.setApiDefinitionId("apiDefinitionId");
|
||||
request.setName("test123");
|
||||
paramMap.clear();
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
this.requestMultipart(ADD, paramMap).andExpect(ERROR_REQUEST_MATCHER);
|
||||
|
||||
// @@校验日志
|
||||
checkLog(this.apiTestCase.getId(), OperationLogType.ADD);
|
||||
// @@异常参数校验
|
||||
createdGroupParamValidateTest(ApiTestCaseAddRequestDefinition.class, ADD);
|
||||
// @@校验权限
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
paramMap.clear();
|
||||
request.setName("permission");
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
requestMultipartPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_ADD, ADD, paramMap);
|
||||
|
||||
}
|
||||
|
||||
private ApiTestCase assertUpdateApiDebug(Object request, MsHTTPElement msHttpElement, String id) {
|
||||
ApiTestCase apiCase = apiTestCaseMapper.selectByPrimaryKey(id);
|
||||
ApiTestCaseBlob apiTestCaseBlob = apiTestCaseBlobMapper.selectByPrimaryKey(id);
|
||||
ApiTestCase copyApiDebug = BeanUtils.copyBean(new ApiTestCase(), apiCase);
|
||||
copyApiDebug = BeanUtils.copyBean(copyApiDebug, request);
|
||||
Assertions.assertEquals(apiCase, copyApiDebug);
|
||||
ApiDataUtils.setResolver(MsHTTPElement.class);
|
||||
Assertions.assertEquals(msHttpElement, ApiDataUtils.parseObject(new String(apiTestCaseBlob.getRequest()), AbstractMsTestElement.class));
|
||||
return apiCase;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package io.metersphere.api.controller.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: jianxing
|
||||
* @CreateTime: 2023-11-06 10:22
|
||||
*/
|
||||
@Data
|
||||
public class ApiTestCaseAddRequestDefinition implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "用例名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_debug.name.not_blank}")
|
||||
@Size(min = 1, max = 255, message = "{api_debug.name.length_range}")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "项目fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_debug.project_id.not_blank}")
|
||||
@Size(min = 1, max = 50, message = "{api_debug.project_id.length_range}")
|
||||
private String projectId;
|
||||
|
||||
@Schema(description = "用例等级", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_test_case.priority.not_blank}")
|
||||
@Size(min = 1, max = 50, message = "{api_test_case.priority.length_range}")
|
||||
private String priority;
|
||||
|
||||
@Schema(description = "用例状态 Underway Prepare Completed", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_test_case.status.not_blank}")
|
||||
@Size(min = 1, max = 20, message = "{api_test_case.status.length_range}")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "接口fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_test_case.api_definition_id.not_blank}")
|
||||
@Size(min = 1, max = 50, message = "{api_test_case.api_definition_id.length_range}")
|
||||
private String apiDefinitionId;
|
||||
|
||||
@Schema(description = "标签")
|
||||
private List<
|
||||
@NotBlank
|
||||
String> tags;
|
||||
|
||||
@Schema(description = "环境fk")
|
||||
private String environmentId;
|
||||
|
||||
@Schema(description = "请求内容")
|
||||
@NotBlank
|
||||
private String request;
|
||||
}
|
|
@ -10,12 +10,12 @@ INSERT INTO `api_definition` (`id`, `name`, `protocol`, `method`, `path`, `statu
|
|||
|
||||
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');
|
||||
|
||||
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`, `principal`, `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', NULL, 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`, `principal`, `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', NULL, 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`, `principal`, `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', '1001', '100570499574136985', 'admin', NULL, 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`, `principal`, `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', NULL, 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`, `principal`, `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', '1002', '100570499574136985', 'admin', NULL, 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`, `principal`, `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', '1002', '100570499574136985', 'admin', NULL, 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主机', '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', '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 ('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', '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-1f6ab8980589', '查询Linux主机', 'P0', 100002006, NULL, 'PENDING', NULL, '10006', 10000, '100001100001', '1002', '100570499574136985', 'admin', 1699500298164, 'admin', 1699500298164, 'admin', NULL, NULL, b'0');
|
||||
|
||||
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');
|
||||
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 ('10002', '报告002', 'resource_id_10001', 1680624405386, 1680624405386, 'admin', 'admin', b'0', 'ERROR', 1680624405386, 1680624405386, 'API', 'pol_id_100001', 'hand', NULL, '100001100001', 'NONE', b'0');
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Loading…
Reference in New Issue