feat: 增加资源池应用组织

This commit is contained in:
guoyuqi 2023-06-30 19:37:50 +08:00 committed by Yuki Guo
parent 06f2d9229c
commit 0c1cde2a65
28 changed files with 1401 additions and 329 deletions

View File

@ -50,6 +50,10 @@ public class TestResourcePool implements Serializable {
@Schema(title = "ms部署地址")
private String serverUrl;
@Schema(title = "资源池应用类型(组织/全部)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "{test_resource_pool.all_org.not_blank}", groups = {Created.class})
private Boolean allOrg;
@Schema(title = "是否删除", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "{test_resource_pool.deleted.not_blank}", groups = {Created.class})
private Boolean deleted;

View File

@ -884,6 +884,66 @@ public class TestResourcePoolExample {
return (Criteria) this;
}
public Criteria andAllOrgIsNull() {
addCriterion("all_org is null");
return (Criteria) this;
}
public Criteria andAllOrgIsNotNull() {
addCriterion("all_org is not null");
return (Criteria) this;
}
public Criteria andAllOrgEqualTo(Boolean value) {
addCriterion("all_org =", value, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgNotEqualTo(Boolean value) {
addCriterion("all_org <>", value, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgGreaterThan(Boolean value) {
addCriterion("all_org >", value, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgGreaterThanOrEqualTo(Boolean value) {
addCriterion("all_org >=", value, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgLessThan(Boolean value) {
addCriterion("all_org <", value, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgLessThanOrEqualTo(Boolean value) {
addCriterion("all_org <=", value, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgIn(List<Boolean> values) {
addCriterion("all_org in", values, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgNotIn(List<Boolean> values) {
addCriterion("all_org not in", values, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgBetween(Boolean value1, Boolean value2) {
addCriterion("all_org between", value1, value2, "allOrg");
return (Criteria) this;
}
public Criteria andAllOrgNotBetween(Boolean value1, Boolean value2) {
addCriterion("all_org not between", value1, value2, "allOrg");
return (Criteria) this;
}
public Criteria andDeletedIsNull() {
addCriterion("deleted is null");
return (Criteria) this;

View File

@ -0,0 +1,27 @@
package io.metersphere.system.domain;
import io.metersphere.validation.groups.*;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import lombok.Data;
@Data
public class TestResourcePoolOrganization implements Serializable {
@Schema(title = "测试资源池项目关系ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{test_resource_pool_organization.id.not_blank}", groups = {Updated.class})
@Size(min = 1, max = 50, message = "{test_resource_pool_organization.id.length_range}", groups = {Created.class, Updated.class})
private String id;
@Schema(title = "资源池ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{test_resource_pool_organization.test_resource_pool_id.not_blank}", groups = {Created.class})
@Size(min = 1, max = 50, message = "{test_resource_pool_organization.test_resource_pool_id.length_range}", groups = {Created.class, Updated.class})
private String testResourcePoolId;
@Schema(title = "组织ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{test_resource_pool_organization.org_id.not_blank}", groups = {Created.class})
@Size(min = 1, max = 50, message = "{test_resource_pool_organization.org_id.length_range}", groups = {Created.class, Updated.class})
private String orgId;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,410 @@
package io.metersphere.system.domain;
import java.util.ArrayList;
import java.util.List;
public class TestResourcePoolOrganizationExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public TestResourcePoolOrganizationExample() {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(String value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(String value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(String value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(String value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(String value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(String value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdLike(String value) {
addCriterion("id like", value, "id");
return (Criteria) this;
}
public Criteria andIdNotLike(String value) {
addCriterion("id not like", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<String> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(String value1, String value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(String value1, String value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdIsNull() {
addCriterion("test_resource_pool_id is null");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdIsNotNull() {
addCriterion("test_resource_pool_id is not null");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdEqualTo(String value) {
addCriterion("test_resource_pool_id =", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdNotEqualTo(String value) {
addCriterion("test_resource_pool_id <>", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdGreaterThan(String value) {
addCriterion("test_resource_pool_id >", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdGreaterThanOrEqualTo(String value) {
addCriterion("test_resource_pool_id >=", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdLessThan(String value) {
addCriterion("test_resource_pool_id <", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdLessThanOrEqualTo(String value) {
addCriterion("test_resource_pool_id <=", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdLike(String value) {
addCriterion("test_resource_pool_id like", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdNotLike(String value) {
addCriterion("test_resource_pool_id not like", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdIn(List<String> values) {
addCriterion("test_resource_pool_id in", values, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdNotIn(List<String> values) {
addCriterion("test_resource_pool_id not in", values, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdBetween(String value1, String value2) {
addCriterion("test_resource_pool_id between", value1, value2, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdNotBetween(String value1, String value2) {
addCriterion("test_resource_pool_id not between", value1, value2, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andOrgIdIsNull() {
addCriterion("org_id is null");
return (Criteria) this;
}
public Criteria andOrgIdIsNotNull() {
addCriterion("org_id is not null");
return (Criteria) this;
}
public Criteria andOrgIdEqualTo(String value) {
addCriterion("org_id =", value, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdNotEqualTo(String value) {
addCriterion("org_id <>", value, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdGreaterThan(String value) {
addCriterion("org_id >", value, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdGreaterThanOrEqualTo(String value) {
addCriterion("org_id >=", value, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdLessThan(String value) {
addCriterion("org_id <", value, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdLessThanOrEqualTo(String value) {
addCriterion("org_id <=", value, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdLike(String value) {
addCriterion("org_id like", value, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdNotLike(String value) {
addCriterion("org_id not like", value, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdIn(List<String> values) {
addCriterion("org_id in", values, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdNotIn(List<String> values) {
addCriterion("org_id not in", values, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdBetween(String value1, String value2) {
addCriterion("org_id between", value1, value2, "orgId");
return (Criteria) this;
}
public Criteria andOrgIdNotBetween(String value1, String value2) {
addCriterion("org_id not between", value1, value2, "orgId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@ -14,6 +14,7 @@
<result column="load_test" jdbcType="BIT" property="loadTest" />
<result column="ui_test" jdbcType="BIT" property="uiTest" />
<result column="server_url" jdbcType="VARCHAR" property="serverUrl" />
<result column="all_org" jdbcType="BIT" property="allOrg" />
<result column="deleted" jdbcType="BIT" property="deleted" />
</resultMap>
<sql id="Example_Where_Clause">
@ -76,7 +77,7 @@
</sql>
<sql id="Base_Column_List">
id, `name`, `type`, description, `enable`, create_time, update_time, create_user,
api_test, load_test, ui_test, server_url, deleted
api_test, load_test, ui_test, server_url, all_org, deleted
</sql>
<select id="selectByExample" parameterType="io.metersphere.system.domain.TestResourcePoolExample" resultMap="BaseResultMap">
select
@ -113,12 +114,12 @@
description, `enable`, create_time,
update_time, create_user, api_test,
load_test, ui_test, server_url,
deleted)
all_org, deleted)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{enable,jdbcType=BIT}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{apiTest,jdbcType=BIT},
#{loadTest,jdbcType=BIT}, #{uiTest,jdbcType=BIT}, #{serverUrl,jdbcType=VARCHAR},
#{deleted,jdbcType=BIT})
#{allOrg,jdbcType=BIT}, #{deleted,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.system.domain.TestResourcePool">
insert into test_resource_pool
@ -159,6 +160,9 @@
<if test="serverUrl != null">
server_url,
</if>
<if test="allOrg != null">
all_org,
</if>
<if test="deleted != null">
deleted,
</if>
@ -200,6 +204,9 @@
<if test="serverUrl != null">
#{serverUrl,jdbcType=VARCHAR},
</if>
<if test="allOrg != null">
#{allOrg,jdbcType=BIT},
</if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</if>
@ -250,6 +257,9 @@
<if test="record.serverUrl != null">
server_url = #{record.serverUrl,jdbcType=VARCHAR},
</if>
<if test="record.allOrg != null">
all_org = #{record.allOrg,jdbcType=BIT},
</if>
<if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT},
</if>
@ -272,6 +282,7 @@
load_test = #{record.loadTest,jdbcType=BIT},
ui_test = #{record.uiTest,jdbcType=BIT},
server_url = #{record.serverUrl,jdbcType=VARCHAR},
all_org = #{record.allOrg,jdbcType=BIT},
deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -313,6 +324,9 @@
<if test="serverUrl != null">
server_url = #{serverUrl,jdbcType=VARCHAR},
</if>
<if test="allOrg != null">
all_org = #{allOrg,jdbcType=BIT},
</if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
@ -332,6 +346,7 @@
load_test = #{loadTest,jdbcType=BIT},
ui_test = #{uiTest,jdbcType=BIT},
server_url = #{serverUrl,jdbcType=VARCHAR},
all_org = #{allOrg,jdbcType=BIT},
deleted = #{deleted,jdbcType=BIT}
where id = #{id,jdbcType=VARCHAR}
</update>

View File

@ -0,0 +1,30 @@
package io.metersphere.system.mapper;
import io.metersphere.system.domain.TestResourcePoolOrganization;
import io.metersphere.system.domain.TestResourcePoolOrganizationExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface TestResourcePoolOrganizationMapper {
long countByExample(TestResourcePoolOrganizationExample example);
int deleteByExample(TestResourcePoolOrganizationExample example);
int deleteByPrimaryKey(String id);
int insert(TestResourcePoolOrganization record);
int insertSelective(TestResourcePoolOrganization record);
List<TestResourcePoolOrganization> selectByExample(TestResourcePoolOrganizationExample example);
TestResourcePoolOrganization selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") TestResourcePoolOrganization record, @Param("example") TestResourcePoolOrganizationExample example);
int updateByExample(@Param("record") TestResourcePoolOrganization record, @Param("example") TestResourcePoolOrganizationExample example);
int updateByPrimaryKeySelective(TestResourcePoolOrganization record);
int updateByPrimaryKey(TestResourcePoolOrganization record);
}

View File

@ -0,0 +1,181 @@
<?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.system.mapper.TestResourcePoolOrganizationMapper">
<resultMap id="BaseResultMap" type="io.metersphere.system.domain.TestResourcePoolOrganization">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="test_resource_pool_id" jdbcType="VARCHAR" property="testResourcePoolId" />
<result column="org_id" jdbcType="VARCHAR" property="orgId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, test_resource_pool_id, org_id
</sql>
<select id="selectByExample" parameterType="io.metersphere.system.domain.TestResourcePoolOrganizationExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from test_resource_pool_organization
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from test_resource_pool_organization
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from test_resource_pool_organization
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.system.domain.TestResourcePoolOrganizationExample">
delete from test_resource_pool_organization
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.system.domain.TestResourcePoolOrganization">
insert into test_resource_pool_organization (id, test_resource_pool_id, org_id
)
values (#{id,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}, #{orgId,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.system.domain.TestResourcePoolOrganization">
insert into test_resource_pool_organization
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="testResourcePoolId != null">
test_resource_pool_id,
</if>
<if test="orgId != null">
org_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="testResourcePoolId != null">
#{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="orgId != null">
#{orgId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.system.domain.TestResourcePoolOrganizationExample" resultType="java.lang.Long">
select count(*) from test_resource_pool_organization
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update test_resource_pool_organization
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.testResourcePoolId != null">
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="record.orgId != null">
org_id = #{record.orgId,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update test_resource_pool_organization
set id = #{record.id,jdbcType=VARCHAR},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
org_id = #{record.orgId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.system.domain.TestResourcePoolOrganization">
update test_resource_pool_organization
<set>
<if test="testResourcePoolId != null">
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="orgId != null">
org_id = #{orgId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.system.domain.TestResourcePoolOrganization">
update test_resource_pool_organization
set test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
org_id = #{orgId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -264,6 +264,7 @@ CREATE TABLE test_resource_pool(
`load_test` BIT COMMENT '是否用于性能测试' ,
`ui_test` BIT COMMENT '是否用于ui测试' ,
`server_url` VARCHAR(255) COMMENT 'ms部署地址' ,
`all_org` BIT NOT NULL DEFAULT 1 COMMENT '资源池应用类型(组织/全部)' ,
`deleted` BIT NOT NULL DEFAULT 0 COMMENT '是否删除' ,
PRIMARY KEY (id)
) ENGINE = InnoDB
@ -278,6 +279,7 @@ CREATE INDEX idx_enable ON test_resource_pool(`enable`);
CREATE INDEX idx_create_time ON test_resource_pool(`create_time`);
CREATE INDEX idx_update_time ON test_resource_pool(`update_time`);
CREATE INDEX idx_create_user ON test_resource_pool(`create_user`);
CREATE INDEX idx_all_org ON test_resource_pool(`all_org`);
CREATE TABLE IF NOT EXISTS user
(
@ -420,5 +422,19 @@ CREATE TABLE IF NOT EXISTS plugin_blob
COLLATE = utf8mb4_general_ci COMMENT = '插件大字段';
DROP TABLE IF EXISTS test_resource_pool_organization;
CREATE TABLE test_resource_pool_organization(
`id` VARCHAR(50) NOT NULL COMMENT '测试资源池项目关系ID' ,
`test_resource_pool_id` VARCHAR(50) NOT NULL COMMENT '资源池ID' ,
`org_id` VARCHAR(50) NOT NULL COMMENT '组织ID' ,
PRIMARY KEY (id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = '测试资源池项目关系';
CREATE INDEX idx_test_resource_pool_id ON test_resource_pool_organization(`test_resource_pool_id`);
CREATE INDEX idx_org_id ON test_resource_pool_organization(`org_id`);
-- set innodb lock wait timeout to default
SET SESSION innodb_lock_wait_timeout = DEFAULT;

View File

@ -0,0 +1,16 @@
package io.metersphere.sdk.constants;
public enum ResourcePoolTypeEnum {
/**
* node controller 资源池
*/
NODE("Node"),
K8S("Kubernetes");
private String name;
ResourcePoolTypeEnum(String name) {
this.name = name;
}
}

View File

@ -1,4 +1,4 @@
package io.metersphere.system.request;
package io.metersphere.sdk.dto;
import io.metersphere.sdk.dto.BasePageRequest;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package io.metersphere.system.dto;
package io.metersphere.sdk.dto;
import lombok.Getter;
import lombok.Setter;
@ -38,7 +38,7 @@ public class TestResourceDTO {
/**
* type为 k8s 接口测试性能测试的命名空间
*/
private String namespaces;
private String nameSpaces;
/**
* type为 k8s 接口测试性能测试UI测试的最大并发数
*/
@ -68,10 +68,10 @@ public class TestResourceDTO {
*/
private String uiGrid;
/**
* 关联的组织id集合
*/
private List<String>orgIds;
}

View File

@ -1,4 +1,4 @@
package io.metersphere.system.dto;
package io.metersphere.sdk.dto;
import lombok.Getter;
import lombok.Setter;

View File

@ -0,0 +1,9 @@
package io.metersphere.sdk.dto;
import io.metersphere.system.domain.TestResourcePool;
import lombok.Data;
@Data
public class TestResourcePoolDTO extends TestResourcePool {
private TestResourceDTO testResourceDTO;
}

View File

@ -0,0 +1,54 @@
package io.metersphere.sdk.dto;
import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
@Data
public class TestResourcePoolRequest {
@Schema(title = "资源池ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{test_resource_pool.id.not_blank}", groups = {Updated.class})
@Size(min = 1, max = 50, message = "{test_resource_pool.id.length_range}", groups = {Created.class, Updated.class})
private String id;
@Schema(title = "名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{test_resource_pool.name.not_blank}", groups = {Created.class})
@Size(min = 1, max = 255, message = "{test_resource_pool.name.length_range}", groups = {Created.class, Updated.class})
private String name;
@Schema(title = "描述")
private String description;
@Schema(title = "类型", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = { "Node","Kubernetes"})
@NotBlank(message = "{test_resource_pool.type.not_blank}", groups = {Created.class})
@Size(min = 1, max = 30, message = "{test_resource_pool.type.length_range}", groups = {Created.class, Updated.class})
private String type;
@Schema(title = "是否启用")
private Boolean enable;
@Schema(title = "是否用于接口测试")
private Boolean apiTest;
@Schema(title = "是否用于性能测试")
private Boolean loadTest;
@Schema(title = "是否用于ui测试")
private Boolean uiTest;
@Schema(title = "ms部署地址")
private String serverUrl;
@Schema(title = "资源池应用类型(组织/全部)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "{test_resource_pool.all_org.not_blank}", groups = {Created.class})
private Boolean allOrg;
@Schema(title = "其余配置")
private TestResourceDTO testResourceDTO;
}

View File

@ -1,7 +1,7 @@
package io.metersphere.system.service;
package io.metersphere.sdk.service;
import io.metersphere.system.dto.TestResourceDTO;
import io.metersphere.sdk.dto.TestResourceDTO;
public interface KubernetesResourcePoolService {

View File

@ -1,6 +1,7 @@
package io.metersphere.system.service;
package io.metersphere.sdk.service;
import io.metersphere.system.dto.TestResourceDTO;
import io.metersphere.sdk.dto.TestResourceDTO;
public interface LoadResourceService {

View File

@ -1,7 +1,10 @@
package io.metersphere.system.service;
package io.metersphere.sdk.service;
import io.metersphere.system.dto.TestResourceDTO;
import io.metersphere.sdk.dto.TestResourceDTO;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.Translator;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -10,10 +13,9 @@ import org.springframework.transaction.annotation.Transactional;
public class NodeResourcePoolService {
public boolean validate(TestResourceDTO testResourceDTO) {
/*TestResourcePoolBlob testResourcePoolBlob = testResourcePool.getConfiguration();
if (testResourcePoolBlob == null || testResourcePoolBlob.getConfiguration()==null){
if (CollectionUtils.isEmpty(testResourceDTO.getNodesList())) {
throw new MSException(Translator.get("no_nodes_message"));
}*/
}
//校验节点
return true;
}

View File

@ -0,0 +1,236 @@
package io.metersphere.sdk.service;
import groovy.util.logging.Slf4j;
import io.metersphere.sdk.constants.ResourcePoolTypeEnum;
import io.metersphere.sdk.dto.QueryResourcePoolRequest;
import io.metersphere.sdk.dto.TestResourceDTO;
import io.metersphere.sdk.dto.TestResourcePoolDTO;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.*;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.domain.TestResourcePoolBlob;
import io.metersphere.system.domain.TestResourcePoolExample;
import io.metersphere.system.domain.TestResourcePoolOrganization;
import io.metersphere.system.mapper.TestResourcePoolBlobMapper;
import io.metersphere.system.mapper.TestResourcePoolMapper;
import io.metersphere.system.mapper.TestResourcePoolOrganizationMapper;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Slf4j
@Service
@Transactional
public class TestResourcePoolService {
@Resource
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private TestResourcePoolBlobMapper testResourcePoolBlobMapper;
@Resource
private SqlSessionFactory sqlSessionFactory;
public TestResourcePool addTestResourcePool(TestResourcePoolDTO testResourcePool) {
String id = UUID.randomUUID().toString();
checkTestResourcePool(testResourcePool);
TestResourcePoolBlob testResourcePoolBlob = new TestResourcePoolBlob();
testResourcePoolBlob.setId(id);
TestResourceDTO testResourceDTO = testResourcePool.getTestResourceDTO();
checkAndSaveOrgRelation(testResourcePool, id, testResourceDTO);
checkApiConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
checkLoadConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
checkUiConfig(testResourceDTO, testResourcePool);
String configuration = JSON.toJSONString(testResourceDTO);
testResourcePoolBlob.setConfiguration(configuration.getBytes());
buildTestPoolBaseInfo(testResourcePool, id);
testResourcePoolMapper.insert(testResourcePool);
testResourcePoolBlobMapper.insert(testResourcePoolBlob);
testResourcePool.setId(id);
return testResourcePool;
}
private void checkAndSaveOrgRelation(TestResourcePool testResourcePool, String id, TestResourceDTO testResourceDTO) {
//防止前端传入的应用组织为空
if ((testResourcePool.getAllOrg() == null || !testResourcePool.getAllOrg())&& CollectionUtils.isEmpty(testResourceDTO.getOrgIds())){
throw new MSException(Translator.get("resource_pool_application_organization_is_empty"));
}
//前端应用组织选择了全部但是也传了部分组织以全部组织为主
if ((testResourcePool.getAllOrg() != null && testResourcePool.getAllOrg()) && CollectionUtils.isNotEmpty(testResourceDTO.getOrgIds()) ) {
testResourceDTO.setOrgIds(new ArrayList<>());
}
//前端选择部分组织保存资源池与组织关系
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestResourcePoolOrganizationMapper poolOrganizationMapper = sqlSession.getMapper(TestResourcePoolOrganizationMapper.class);
if ((testResourcePool.getAllOrg() == null || !testResourcePool.getAllOrg())&& CollectionUtils.isNotEmpty(testResourceDTO.getOrgIds())){
testResourcePool.setAllOrg(false);
testResourceDTO.getOrgIds().forEach(orgId->{
TestResourcePoolOrganization testResourcePoolOrganization = new TestResourcePoolOrganization();
testResourcePoolOrganization.setId(UUID.randomUUID().toString());
testResourcePoolOrganization.setOrgId(orgId);
testResourcePoolOrganization.setTestResourcePoolId(id);
poolOrganizationMapper.insert(testResourcePoolOrganization);
});
}
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
private static void buildTestPoolBaseInfo(TestResourcePool testResourcePool, String id) {
testResourcePool.setId(id);
testResourcePool.setUpdateTime(System.currentTimeMillis());
testResourcePool.setEnable(true);
testResourcePool.setDeleted(false);
}
private boolean checkLoadConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) {
if (testResourcePool.getLoadTest() == null || !testResourcePool.getLoadTest()) {
return true;
}
LoadResourceService resourcePoolService = CommonBeanFactory.getBean(LoadResourceService.class);
if (resourcePoolService == null) {
return false;
}
return resourcePoolService.validate(testResourceDTO,type);
}
private boolean checkUiConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool) {
if (testResourcePool.getUiTest() == null || !testResourcePool.getUiTest()) {
return true;
}
UiResourceService resourcePoolService = CommonBeanFactory.getBean(UiResourceService.class);
if (resourcePoolService == null) {
return false;
}
return resourcePoolService.validate(testResourceDTO);
}
private boolean checkApiConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) {
if (testResourcePool.getApiTest() == null || !testResourcePool.getApiTest()) {
return false;
}
if (StringUtils.equalsIgnoreCase(type,ResourcePoolTypeEnum.NODE.name())) {
NodeResourcePoolService resourcePoolService = CommonBeanFactory.getBean(NodeResourcePoolService.class);
return resourcePoolService.validate(testResourceDTO);
} else {
KubernetesResourcePoolService resourcePoolService = CommonBeanFactory.getBean(KubernetesResourcePoolService.class);
if (resourcePoolService == null) {
return false;
}
return resourcePoolService.validate(testResourceDTO);
}
}
public void deleteTestResourcePool(String testResourcePoolId) {
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(testResourcePoolId);
if (testResourcePool == null) {
throw new MSException(Translator.get("test_resource_pool_not_exists"));
}
testResourcePool.setUpdateTime(System.currentTimeMillis());
testResourcePool.setEnable(false);
testResourcePool.setDeleted(true);
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
}
public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) {
checkTestResourcePool(testResourcePool);
testResourcePool.setUpdateTime(System.currentTimeMillis());
TestResourceDTO testResourceDTO = testResourcePool.getTestResourceDTO();
checkAndSaveOrgRelation(testResourcePool, testResourcePool.getId(), testResourceDTO);
checkApiConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
checkLoadConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
checkUiConfig(testResourceDTO, testResourcePool);
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
}
public List<TestResourcePoolDTO> listResourcePools(QueryResourcePoolRequest request) {
TestResourcePoolExample example = new TestResourcePoolExample();
TestResourcePoolExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotBlank(request.getName())) {
criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%"));
}
if (request.getEnable() != null) {
criteria.andEnableEqualTo(request.getEnable());
}
criteria.andDeletedEqualTo(false);
example.setOrderByClause("update_time desc");
List<TestResourcePool> testResourcePools = testResourcePoolMapper.selectByExample(example);
List<TestResourcePoolDTO> testResourcePoolDTOS = new ArrayList<>();
testResourcePools.forEach(pool -> {
TestResourcePoolBlob testResourcePoolBlob = testResourcePoolBlobMapper.selectByPrimaryKey(pool.getId());
byte[] configuration = testResourcePoolBlob.getConfiguration();
String testResourceDTOStr = new String(configuration);
TestResourceDTO testResourceDTO = JSON.parseObject(testResourceDTOStr, TestResourceDTO.class);
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
BeanUtils.copyBean(testResourcePoolDTO, pool);
testResourcePoolDTO.setTestResourceDTO(testResourceDTO);
testResourcePoolDTOS.add(testResourcePoolDTO);
});
return testResourcePoolDTOS;
}
public void checkTestResourcePool(TestResourcePool testResourcePool) {
String resourcePoolName = testResourcePool.getName();
if (StringUtils.isBlank(resourcePoolName)) {
throw new MSException(Translator.get("test_resource_pool_name_is_null"));
}
if (StringUtils.isBlank(testResourcePool.getType())) {
throw new MSException(Translator.get("test_resource_pool_type_is_null"));
}
TestResourcePoolExample example = new TestResourcePoolExample();
TestResourcePoolExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(resourcePoolName);
if (StringUtils.isNotBlank(testResourcePool.getId())) {
criteria.andIdNotEqualTo(testResourcePool.getId());
}
criteria.andDeletedEqualTo(false);
if (testResourcePoolMapper.countByExample(example) > 0) {
throw new MSException(Translator.get("test_resource_pool_name_already_exists"));
}
}
public TestResourcePoolDTO getTestResourcePoolDetail(String testResourcePoolId) {
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(testResourcePoolId);
if (testResourcePool == null) {
throw new MSException(Translator.get("test_resource_pool_not_exists"));
}
TestResourcePoolBlob testResourcePoolBlob = testResourcePoolBlobMapper.selectByPrimaryKey(testResourcePoolId);
if (testResourcePoolBlob == null) {
BeanUtils.copyBean(testResourcePoolDTO, testResourcePool);
return testResourcePoolDTO;
}
byte[] configuration = testResourcePoolBlob.getConfiguration();
String testResourceDTOStr = new String(configuration);
TestResourceDTO testResourceDTO = JSON.parseObject(testResourceDTOStr, TestResourceDTO.class);
BeanUtils.copyBean(testResourcePoolDTO, testResourcePool);
testResourcePoolDTO.setTestResourceDTO(testResourceDTO);
return testResourcePoolDTO;
}
public String getLogDetails(String id) {
TestResourcePool pool = testResourcePoolMapper.selectByPrimaryKey(id);
if (pool != null) {
return pool.getName();
}
return null;
}
}

View File

@ -1,6 +1,7 @@
package io.metersphere.system.service;
package io.metersphere.sdk.service;
import io.metersphere.system.dto.TestResourceDTO;
import io.metersphere.sdk.dto.TestResourceDTO;
public interface UiResourceService {

View File

@ -65,6 +65,9 @@ test_resource_pool_id_is_null=Test Resource Pool ID cannot be null
test_resource_pool_name_is_null=Test Resource Pool name cannot be null
test_resource_pool_name_already_exists=The test resource pool name already exists
test_resource_pool_type_is_null=Test Resource Pool type cannot be null
resource_pool_application_organization_is_empty = Resource pool application organization is empty
test_resource_pool_used_content_is_null = Resource pool use-related configuration is empty
load_test=Load Test
test_resource_pool_is_use=This resource pool is in use and cannot be deleted
only_one_k8s=Only one K8S can be added

View File

@ -64,6 +64,9 @@ organization_not_exists=工作空间不存在
test_resource_pool_id_is_null=资源池ID不能为空
test_resource_pool_name_is_null=资源池名称不能为空
test_resource_pool_name_already_exists=资源池名称已存在
resource_pool_application_organization_is_empty= 资源池应用组织为空
test_resource_pool_type_is_null=资源池类型不能为空
test_resource_pool_used_content_is_null = 资源池用途相关配置为空
load_test=性能测试
test_resource_pool_is_use=正在使用此资源池,无法删除
only_one_k8s=只能添加一个 K8S

View File

@ -64,6 +64,10 @@ organization_not_exists=工作空間不存在
test_resource_pool_id_is_null=資源池ID不能為空
test_resource_pool_name_is_null=資源池名稱不能為空
test_resource_pool_name_already_exists=資源池名稱已存在
resource_pool_application_organization_is_empty= 資源池應用組織為空
test_resource_pool_type_is_null=資源池類型不能為空
test_resource_pool_used_content_is_null = 資源池用途相關配置為空
load_test=性能測試
test_resource_pool_is_use=正在使用此資源池,無法刪除
only_one_k8s=只能添加一個 K8S

View File

@ -3,15 +3,19 @@ package io.metersphere.system.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.TestResourcePoolDTO;
import io.metersphere.sdk.dto.TestResourcePoolRequest;
import io.metersphere.sdk.log.annotation.Log;
import io.metersphere.sdk.log.constants.OperationLogModule;
import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.PageUtils;
import io.metersphere.sdk.util.Pager;
import io.metersphere.sdk.util.SessionUtils;
import io.metersphere.system.consul.CacheNode;
import io.metersphere.system.dto.TestResourcePoolDTO;
import io.metersphere.system.request.QueryResourcePoolRequest;
import io.metersphere.system.service.TestResourcePoolService;
import io.metersphere.sdk.dto.QueryResourcePoolRequest;
import io.metersphere.sdk.service.TestResourcePoolService;
import io.metersphere.system.domain.TestResourcePool;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
@ -29,15 +33,20 @@ public class TestResourcePoolController {
@PostMapping("/add")
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_ADD)
@Log(type = OperationLogType.ADD, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL, details = "#poolDTO.name")
public TestResourcePoolDTO addTestResourcePool(@Validated @RequestBody TestResourcePoolDTO poolDTO) {
return testResourcePoolService.addTestResourcePool(poolDTO);
@Log(type = OperationLogType.ADD, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL, details = "#request.name")
public TestResourcePool addTestResourcePool(@Validated @RequestBody TestResourcePoolRequest request) {
String userId = SessionUtils.getUserId();
TestResourcePoolDTO testResourcePool = new TestResourcePoolDTO();
BeanUtils.copyBean(testResourcePool, request);
testResourcePool.setCreateUser(userId);
testResourcePool.setCreateTime(System.currentTimeMillis());
return testResourcePoolService.addTestResourcePool(testResourcePool);
}
@GetMapping("/delete/{poolId}")
@CacheNode // 把监控节点缓存起来
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_DELETE)
@Log(isBefore = true, type = OperationLogType.UPDATE, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL,
@Log(isBefore = true, type = OperationLogType.DELETE, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL,
details = "#msClass.getLogDetails(#testResourcePoolId)", msClass = TestResourcePoolService.class)
public void deleteTestResourcePool(@PathVariable(value = "poolId") String testResourcePoolId) {
testResourcePoolService.deleteTestResourcePool(testResourcePoolId);
@ -47,9 +56,13 @@ public class TestResourcePoolController {
@CacheNode // 把监控节点缓存起来
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_UPDATE)
@Log(type = OperationLogType.UPDATE, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL,
sourceId = "#testResourcePoolDTO.id", details = "#testResourcePoolDTO.name")
public void updateTestResourcePool(@Validated @RequestBody TestResourcePoolDTO testResourcePoolDTO) {
testResourcePoolService.updateTestResourcePool(testResourcePoolDTO);
sourceId = "#request.id", details = "#request.name")
public void updateTestResourcePool(@Validated @RequestBody TestResourcePoolRequest request) {
TestResourcePoolDTO testResourcePool = new TestResourcePoolDTO();
BeanUtils.copyBean(testResourcePool, request);
testResourcePool.setCreateUser(null);
testResourcePool.setCreateTime(null);
testResourcePoolService.updateTestResourcePool(testResourcePool);
}
@PostMapping("/page")
@ -59,5 +72,11 @@ public class TestResourcePoolController {
return PageUtils.setPageInfo(page, testResourcePoolService.listResourcePools(request));
}
@GetMapping("/detail/{poolId}")
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ)
public TestResourcePoolDTO getTestResourcePoolDetail(@PathVariable(value = "poolId") String testResourcePoolId) {
return testResourcePoolService.getTestResourcePoolDetail(testResourcePoolId);
}
}

View File

@ -1,8 +0,0 @@
package io.metersphere.system.dto;
public enum ResourcePoolTypeEnum {
/**
* node controller 资源池
*/
NODE, K8S
}

View File

@ -1,14 +0,0 @@
package io.metersphere.system.dto;
import io.metersphere.system.domain.TestResourcePool;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class TestResourcePoolDTO extends TestResourcePool {
private String configuration;
}

View File

@ -1,188 +0,0 @@
package io.metersphere.system.service;
import groovy.util.logging.Slf4j;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.domain.TestResourcePoolBlob;
import io.metersphere.system.domain.TestResourcePoolExample;
import io.metersphere.system.dto.ResourcePoolTypeEnum;
import io.metersphere.system.dto.TestResourceDTO;
import io.metersphere.system.dto.TestResourcePoolDTO;
import io.metersphere.system.mapper.TestResourcePoolBlobMapper;
import io.metersphere.system.mapper.TestResourcePoolMapper;
import io.metersphere.system.request.QueryResourcePoolRequest;
import jakarta.annotation.Resource;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Slf4j
@Service
@Transactional
public class TestResourcePoolService {
@Resource
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private TestResourcePoolBlobMapper testResourcePoolBlobMapper;
public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePoolDTO) {
String id = UUID.randomUUID().toString();
checkTestResourcePool(testResourcePoolDTO);
buildTestPoolBaseInfo(testResourcePoolDTO, id);
TestResourcePoolBlob testResourcePoolBlob = new TestResourcePoolBlob();
testResourcePoolBlob.setId(id);
String configuration = testResourcePoolDTO.getConfiguration();
TestResourceDTO testResourceDTO = JSON.parseObject(configuration, TestResourceDTO.class);
checkApiConfig(testResourceDTO, testResourcePoolDTO.getApiTest(), testResourcePoolDTO.getType());
checkLoadConfig(testResourceDTO, testResourcePoolDTO.getLoadTest(), testResourcePoolDTO.getType());
checkUiConfig(testResourceDTO, testResourcePoolDTO.getUiTest());
testResourcePoolBlob.setConfiguration(configuration.getBytes());
testResourcePoolMapper.insertSelective(testResourcePoolDTO);
testResourcePoolBlobMapper.insertSelective(testResourcePoolBlob);
return testResourcePoolDTO;
}
private static void buildTestPoolBaseInfo(TestResourcePoolDTO testResourcePoolDTO, String id) {
testResourcePoolDTO.setId(id);
testResourcePoolDTO.setCreateTime(System.currentTimeMillis());
testResourcePoolDTO.setUpdateTime(System.currentTimeMillis());
testResourcePoolDTO.setEnable(true);
testResourcePoolDTO.setDeleted(false);
}
private boolean checkLoadConfig(TestResourceDTO testResourceDTO, Boolean loadTest, String type) {
if (!loadTest) {
return true;
}
LoadResourceService resourcePoolService = CommonBeanFactory.getBean(LoadResourceService.class);
if (resourcePoolService == null) {
return false;
}
return resourcePoolService.validate(testResourceDTO,type);
}
private boolean checkUiConfig(TestResourceDTO testResourceDTO, Boolean uiTest) {
if (!uiTest) {
return true;
}
UiResourceService resourcePoolService = CommonBeanFactory.getBean(UiResourceService.class);
if (resourcePoolService == null) {
return false;
}
return resourcePoolService.validate(testResourceDTO);
}
private boolean checkApiConfig(TestResourceDTO testResourceDTO, Boolean apiTest, String type) {
if (!apiTest) {
return false;
}
if (StringUtils.equalsIgnoreCase(type,ResourcePoolTypeEnum.NODE.name())) {
NodeResourcePoolService resourcePoolService = CommonBeanFactory.getBean(NodeResourcePoolService.class);
return resourcePoolService.validate(testResourceDTO);
} else {
KubernetesResourcePoolService resourcePoolService = CommonBeanFactory.getBean(KubernetesResourcePoolService.class);
if (resourcePoolService == null) {
return false;
}
return resourcePoolService.validate(testResourceDTO);
}
}
public void deleteTestResourcePool(String testResourcePoolId) {
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(testResourcePoolId);
if (testResourcePool == null) {
throw new MSException("Resource Pool not found.");
}
testResourcePool.setUpdateTime(System.currentTimeMillis());
testResourcePool.setEnable(false);
testResourcePool.setDeleted(true);
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
}
public void updateTestResourcePool(TestResourcePoolDTO testResourcePoolDTO) {
checkTestResourcePool(testResourcePoolDTO);
testResourcePoolDTO.setCreateUser(null);
testResourcePoolDTO.setUpdateTime(System.currentTimeMillis());
String configuration = testResourcePoolDTO.getConfiguration();
TestResourceDTO testResourceDTO = JSON.parseObject(configuration, TestResourceDTO.class);
checkApiConfig(testResourceDTO, testResourcePoolDTO.getApiTest(), testResourcePoolDTO.getType());
checkLoadConfig(testResourceDTO, testResourcePoolDTO.getLoadTest(), testResourcePoolDTO.getType());
checkUiConfig(testResourceDTO, testResourcePoolDTO.getUiTest());
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePoolDTO);
}
public List<TestResourcePoolDTO> listResourcePools(QueryResourcePoolRequest request) {
TestResourcePoolExample example = new TestResourcePoolExample();
TestResourcePoolExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotBlank(request.getName())) {
criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%"));
}
if (request.getEnable() != null) {
criteria.andEnableEqualTo(request.getEnable());
}
criteria.andDeletedEqualTo(false);
example.setOrderByClause("update_time desc");
List<TestResourcePool> testResourcePools = testResourcePoolMapper.selectByExample(example);
List<TestResourcePoolDTO> testResourcePoolDTOS = new ArrayList<>();
testResourcePools.forEach(pool -> {
TestResourcePoolBlob testResourcePoolBlob = testResourcePoolBlobMapper.selectByPrimaryKey(pool.getId());
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
try {
BeanUtils.copyProperties(testResourcePoolDTO, pool);
testResourcePoolDTO.setConfiguration(new String(testResourcePoolBlob.getConfiguration()));
testResourcePoolDTOS.add(testResourcePoolDTO);
} catch (IllegalAccessException | InvocationTargetException e) {
LogUtils.error(e.getMessage(), e);
}
});
return testResourcePoolDTOS;
}
public void checkTestResourcePool(TestResourcePoolDTO testResourcePoolDTO) {
String resourcePoolName = testResourcePoolDTO.getName();
if (StringUtils.isBlank(resourcePoolName)) {
throw new MSException(Translator.get("test_resource_pool_name_is_null"));
}
if (StringUtils.isBlank(testResourcePoolDTO.getType())) {
throw new MSException(Translator.get("test_resource_pool_type_is_null"));
}
TestResourcePoolExample example = new TestResourcePoolExample();
TestResourcePoolExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(resourcePoolName);
if (StringUtils.isNotBlank(testResourcePoolDTO.getId())) {
criteria.andIdNotEqualTo(testResourcePoolDTO.getId());
}
criteria.andDeletedEqualTo(false);
if (testResourcePoolMapper.countByExample(example) > 0) {
throw new MSException(Translator.get("test_resource_pool_name_already_exists"));
}
}
public String getLogDetails(String id) {
TestResourcePool pool = testResourcePoolMapper.selectByPrimaryKey(id);
if (pool != null) {
return pool.getName();
}
return null;
}
}

View File

@ -1,25 +1,35 @@
package io.metersphere.system.controller;
import base.BaseTest;
import io.metersphere.sdk.constants.ResourcePoolTypeEnum;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.controller.handler.ResultHolder;
import io.metersphere.sdk.dto.TestResourceDTO;
import io.metersphere.sdk.dto.TestResourcePoolRequest;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.dto.ResourcePoolTypeEnum;
import io.metersphere.system.dto.TestResourcePoolDTO;
import io.metersphere.system.request.QueryResourcePoolRequest;
import io.metersphere.sdk.dto.QueryResourcePoolRequest;
import io.metersphere.system.domain.TestResourcePoolOrganization;
import io.metersphere.system.domain.TestResourcePoolOrganizationExample;
import io.metersphere.system.mapper.TestResourcePoolOrganizationMapper;
import io.metersphere.utils.JsonUtils;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
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.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.io.UnsupportedEncodingException;
import java.util.List;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -32,13 +42,15 @@ class TestResourcePoolControllerTest extends BaseTest {
@Resource
private MockMvc mockMvc;
@Resource
private TestResourcePoolOrganizationMapper testResourcePoolOrganizationMapper;
private static final String TEST_RESOURCE_POOL_ADD = "/test/resource/pool/add";
private static final String TEST_RESOURCE_POOL_UPDATE = "/test/resource/pool/update";
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
private static final String configuration = "{\n" +
private static final String configurationWidthOutOrgIds = "{\n" +
" \"loadTestImage\": \"123\",\n" +
" \"loadTestHeap\": \"123\",\n" +
" \"nodesList\":[{\n" +
@ -57,51 +69,156 @@ class TestResourcePoolControllerTest extends BaseTest {
"\"deployName\":\"hello\",\n" +
"\"uiGrid\":\"localhost:4444\"\n" +
"}";
private static final String configuration = "{\n" +
" \"loadTestImage\": \"123\",\n" +
" \"loadTestHeap\": \"123\",\n" +
" \"nodesList\": [\n" +
" {\n" +
" \"ip\": \"172.2.130.1\",\n" +
" \"port\": \"3306\",\n" +
" \"monitor\": \"11\",\n" +
" \"concurrentNumber\": 1\n" +
" }\n" +
" ],\n" +
" \"orgIds\": [\"03c751bf-20e9-5068-a760-7a9fbf0f594b\",\"233445566677788\"],\n" +
" \"ip\": \"172.2.130.1\",\n" +
" \"token\": \"dsdfssdsvgsd\",\n" +
" \"namespaces\": \"测试\",\n" +
" \"concurrentNumber\": 3,\n" +
" \"podThreads\": 2,\n" +
" \"jobDefinition\": \"jsfsjs\",\n" +
" \"apiTestImage\": \"ddgd\",\n" +
" \"deployName\": \"hello\",\n" +
" \"uiGrid\": \"localhost:4444\"\n" +
"}";
@Test
@Order(1)
void addTestResourcePool() throws Exception {
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
testResourcePoolDTO.setName("test_pool_1");
testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name());
testResourcePoolDTO.setApiTest(true);
testResourcePoolDTO.setLoadTest(false);
testResourcePoolDTO.setUiTest(false);
setResources(testResourcePoolDTO);
mockMvc.perform(MockMvcRequestBuilders.post(TEST_RESOURCE_POOL_ADD)
private MvcResult addTestResourcePoolSuccess(String name,Boolean allOrg, Boolean partOrg, Boolean useApi, Boolean useLoad, Boolean useUi, String type) throws Exception {
TestResourcePoolRequest testResourcePoolRequest = new TestResourcePoolRequest();
testResourcePoolRequest.setName(name);
testResourcePoolRequest.setType(type);
testResourcePoolRequest.setApiTest(useApi);
testResourcePoolRequest.setLoadTest(useLoad);
testResourcePoolRequest.setUiTest(useUi);
//添加成功 需要加应用组织的 全部 部分组织的测试 既有全部又有list
//应用全部
testResourcePoolRequest.setAllOrg(allOrg);
setResources(testResourcePoolRequest,partOrg);
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(TEST_RESOURCE_POOL_ADD)
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(testResourcePoolDTO))
.content(JSON.toJSONString(testResourcePoolRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
//应用全部 关系表里不会存值
TestResourcePoolRequest testResourcePoolRequest1 = getResult(mvcResult);
List<TestResourcePoolOrganization> testResourcePoolOrganizations = getTestResourcePoolOrganizations(testResourcePoolRequest1);
if (allOrg) {
Assertions.assertTrue(CollectionUtils.isEmpty(testResourcePoolOrganizations));
}
if (!allOrg) {
Assertions.assertTrue((CollectionUtils.isNotEmpty(testResourcePoolOrganizations) && testResourcePoolOrganizations.size() == 2));
}
return mvcResult;
}
@Test
@Order(1)
void addTestResourcePoolOne() throws Exception {
// 选全部资源池部分没值 资源池节点为NODE use api load ui
this.addTestResourcePoolSuccess("test_pool_1", true,false,true,true,true,ResourcePoolTypeEnum.NODE.name());
}
@Test
@Order(2)
void addUiTestResourcePoolFiled() throws Exception {
//资源池名称为空
TestResourcePoolDTO testResourcePoolDTO = generatorDto(true, false, false, false, false, false);
this.requestPost(TEST_RESOURCE_POOL_ADD, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
//资源池类型为空
testResourcePoolDTO = generatorDto(false, true, false, false, false, false);
this.requestPost(TEST_RESOURCE_POOL_ADD, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
//资源池节点集合为空
testResourcePoolDTO = generatorDto(false, false, true, false, false, false);
this.requestPost(TEST_RESOURCE_POOL_ADD, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
//用途测试
testResourcePoolDTO = generatorDto(false, false, false, true, false, false);
this.requestPost(TEST_RESOURCE_POOL_ADD, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
//ui用途为空
testResourcePoolDTO = generatorDto(false, false, false, false,true, false);
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
//load用途为空
testResourcePoolDTO = generatorDto(false, false, false, false,false, true);
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
void addTestResourcePoolTwo() throws Exception {
// 选全部资源池部分没值 资源池节点为NODE use api load
this.addTestResourcePoolSuccess("test_pool_2",true,false,true,true,false,ResourcePoolTypeEnum.NODE.name());
}
@Test
@Order(3)
void addTestResourcePoolThree() throws Exception {
// 选全部资源池部分没值 资源池节点为NODE use api
this.addTestResourcePoolSuccess("test_pool_3",true,false,true,false,false,ResourcePoolTypeEnum.NODE.name());
}
@Test
@Order(4)
void addTestResourcePoolFour() throws Exception {
// 选全部资源池部分没值 资源池节点为NODE use
this.addTestResourcePoolSuccess("test_pool_4",true,false,false,false,false,ResourcePoolTypeEnum.NODE.name());
}
@Test
@Order(5)
void addTestResourcePoolFive() throws Exception {
//用途只是标记没有实际影响所以这里每种只测一遍其余以api为例
// 选全部资源池部分有值 资源池节点为NODE use api
this.addTestResourcePoolSuccess("test_pool_5",true,true,true,false,false,ResourcePoolTypeEnum.NODE.name());
}
@Test
@Order(6)
void addTestResourcePoolSix() throws Exception {
// 不选全部资源池部分有值 资源池节点为NODE use api
this.addTestResourcePoolSuccess("test_pool_6",false,true,true,false,false,ResourcePoolTypeEnum.NODE.name());
}
@Test
@Order(7)
void addTestResourcePoolSeven() throws Exception {
//资源池的应用与类型无关 这里资源池正确的顺序就到此为止换个类型只测一遍就行
// 不选全部资源池部分有值 资源池节点为NODE use api
this.addTestResourcePoolSuccess("test_pool_7",false,true,true,false,false,ResourcePoolTypeEnum.K8S.name());
}
@Test
@Order(8)
void addTestResourcePoolFailedBySameName() throws Exception {
TestResourcePoolRequest testResourcePoolRequest = new TestResourcePoolRequest();
testResourcePoolRequest.setName("test_pool_7");
testResourcePoolRequest.setType(ResourcePoolTypeEnum.K8S.name());
testResourcePoolRequest.setApiTest(true);
testResourcePoolRequest.setLoadTest(false);
testResourcePoolRequest.setUiTest(false);
//添加成功 需要加应用组织的 全部 部分组织的测试 既有全部又有list
//应用全部
testResourcePoolRequest.setAllOrg(false);
setResources(testResourcePoolRequest,true);
mockMvc.perform(MockMvcRequestBuilders.post(TEST_RESOURCE_POOL_ADD)
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(testResourcePoolRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(ERROR_REQUEST_MATCHER).andDo(print())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
private static TestResourcePoolRequest getResult(MvcResult mvcResult) throws UnsupportedEncodingException {
String contentAsString = mvcResult.getResponse().getContentAsString();
ResultHolder resultHolder = JsonUtils.parseObject(contentAsString, ResultHolder.class);
return JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestResourcePoolRequest.class);
}
private List<TestResourcePoolOrganization> getTestResourcePoolOrganizations(TestResourcePoolRequest testResourcePoolRequest1) {
TestResourcePoolOrganizationExample testResourcePoolOrganizationExample = new TestResourcePoolOrganizationExample();
testResourcePoolOrganizationExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolRequest1.getId());
return testResourcePoolOrganizationMapper.selectByExample(testResourcePoolOrganizationExample);
}
@Test
@Order(9)
void addUiTestResourcePoolFiled() throws Exception {
this.dealTestResourcePoolFiled("ADD");
}
@Test
@Order(10)
void listResourcePoolsWidthSearch() throws Exception {
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1);
@ -117,7 +234,7 @@ class TestResourcePoolControllerTest extends BaseTest {
}
@Test
@Order(4)
@Order(11)
void listResourcePoolsNoSearch() throws Exception {
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1);
@ -132,57 +249,127 @@ class TestResourcePoolControllerTest extends BaseTest {
}
@Test
@Order(5)
@Sql(scripts = {"/dml/init_test_resource_pool.sql"},
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Order(12)
void getResourcePoolsDetail() throws Exception {
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1);
request.setPageSize(5);
mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/detail/103")
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andDo(print())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
@Test
@Order(13)
void getResourcePoolsDetailWidthBlob() throws Exception {
MvcResult testPoolBlob = this.addTestResourcePoolSuccess("test_pool_blob", false, true, true, false, false, ResourcePoolTypeEnum.K8S.name());
TestResourcePoolRequest testResourcePoolRequest1 = getResult(testPoolBlob);
String id = testResourcePoolRequest1.getId();
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1);
request.setPageSize(5);
mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/detail/"+id)
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andDo(print())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
@Test
@Order(14)
void getResourcePoolsDetailFiled() throws Exception {
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1);
request.setPageSize(5);
mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/detail/1034")
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(request))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(ERROR_REQUEST_MATCHER).andDo(print())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
@Test
@Order(15)
void updateTestResourcePool() throws Exception {
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
testResourcePoolDTO.setName("test_pool");
testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name());
setResources(testResourcePoolDTO);
testResourcePoolDTO.setApiTest(true);
testResourcePoolDTO.setLoadTest(false);
testResourcePoolDTO.setUiTest(false);
TestResourcePoolRequest testResourcePoolRequest = new TestResourcePoolRequest();
testResourcePoolRequest.setName("test_pool");
testResourcePoolRequest.setType(ResourcePoolTypeEnum.NODE.name());
setResources(testResourcePoolRequest,false);
testResourcePoolRequest.setApiTest(true);
testResourcePoolRequest.setLoadTest(false);
testResourcePoolRequest.setUiTest(false);
testResourcePoolRequest.setAllOrg(true);
mockMvc.perform(MockMvcRequestBuilders.post(TEST_RESOURCE_POOL_UPDATE)
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(testResourcePoolDTO))
.content(JSON.toJSONString(testResourcePoolRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
private static void setResources(TestResourcePoolDTO testResourcePoolDTO) {
testResourcePoolDTO.setConfiguration(configuration);
private static void setResources(TestResourcePoolRequest testResourcePoolDTO, boolean isPart) {
TestResourceDTO testResourceDTO;
if (isPart) {
testResourceDTO = JSON.parseObject(configuration, TestResourceDTO.class);
} else {
testResourceDTO = JSON.parseObject(configurationWidthOutOrgIds, TestResourceDTO.class);
}
testResourcePoolDTO.setTestResourceDTO(testResourceDTO);
}
@Test
@Order(6)
void updateTestResourcePoolFiled() throws Exception {
TestResourcePoolDTO testResourcePoolDTO = generatorDto(true, false, false,false, false, false);
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
@Order(16)
void updateUiTestResourcePoolFiled() throws Exception {
this.dealTestResourcePoolFiled("UPDATE");
}
private void dealTestResourcePoolFiled(String urlType) throws Exception {
String url;
if (StringUtils.equals(urlType,"ADD")) {
url = TEST_RESOURCE_POOL_ADD;
} else {
url = TEST_RESOURCE_POOL_UPDATE;
}
TestResourcePoolRequest testResourcePoolRequest = generatorDto(true, false, false, false);
this.requestPost(url, testResourcePoolRequest, ERROR_REQUEST_MATCHER);
//资源池类型为空
testResourcePoolDTO = generatorDto(false, true, false, false, false, false);
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
testResourcePoolRequest = generatorDto(false, true, false, false);
this.requestPost(url, testResourcePoolRequest, ERROR_REQUEST_MATCHER);
//资源池节点集合为空
testResourcePoolDTO = generatorDto(false, false, true, false, false, false);
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
//api用途为空
testResourcePoolDTO = generatorDto(false, false, false, true,false, false);
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
//ui用途为空
testResourcePoolDTO = generatorDto(false, false, false, false,true, false);
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
//load用途为空
testResourcePoolDTO = generatorDto(false, false, false, false,false, true);
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
testResourcePoolRequest = generatorDto(false, false, true, false);
this.requestPost(url, testResourcePoolRequest, ERROR_REQUEST_MATCHER);
//应用组织
testResourcePoolRequest = generatorDto(false, false, false, true);
this.requestPost(url, testResourcePoolRequest, ERROR_REQUEST_MATCHER);
//部分组织
testResourcePoolRequest = generatorDto(false, false, false, false);
testResourcePoolRequest.setAllOrg(false);
testResourcePoolRequest.setTestResourceDTO(JSON.parseObject(configurationWidthOutOrgIds, TestResourceDTO.class));
this.requestPost(url, testResourcePoolRequest, ERROR_REQUEST_MATCHER);
}
@Test
@Sql(scripts = {"/dml/init_test_resource_pool.sql"},
//单独执行时请打开
/*@Sql(scripts = {"/dml/init_test_resource_pool.sql"},
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Order(7)
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)*/
@Order(17)
void deleteTestResourcePool() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/delete/102")
mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/delete/103")
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken))
.andExpect(status().isOk())
@ -191,7 +378,7 @@ class TestResourcePoolControllerTest extends BaseTest {
}
@Test
@Order(8)
@Order(18)
void deleteTestResourcePoolFiled() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/delete/105")
.header(SessionConstants.HEADER_TOKEN, sessionId)
@ -211,8 +398,8 @@ class TestResourcePoolControllerTest extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
private TestResourcePoolDTO generatorDto(boolean noName, boolean noType, boolean noResources, boolean noUseApi, boolean noUseUi, boolean noUseLoad) {
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
private TestResourcePoolRequest generatorDto(boolean noName, boolean noType, boolean noResources, boolean noAllOrg) {
TestResourcePoolRequest testResourcePoolDTO = new TestResourcePoolRequest();
//没名字
if (!noName) {
testResourcePoolDTO.setName("test_pool_test");
@ -221,20 +408,23 @@ class TestResourcePoolControllerTest extends BaseTest {
if (!noType) {
testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name());
}
//没资源池
//没资源池用途为API 或者 性能测试的校验
if (!noResources) {
setResources(testResourcePoolDTO);
}
//没api
if(!noUseApi) {
testResourcePoolDTO.setApiTest(true);
setResources(testResourcePoolDTO,true);
}else {
testResourcePoolDTO.setApiTest(true);
TestResourceDTO testResourceDTO = JSON.parseObject(configuration, TestResourceDTO.class);
testResourceDTO.setNodesList(null);
testResourcePoolDTO.setTestResourceDTO(testResourceDTO);
}
if (!noUseUi) {
testResourcePoolDTO.setUiTest(true);
}
if (!noUseLoad) {
testResourcePoolDTO.setLoadTest(true);
//没选全部
if (!noAllOrg){
testResourcePoolDTO.setAllOrg(true);
}else {
testResourcePoolDTO.getTestResourceDTO().setOrgIds(null);
}
return testResourcePoolDTO;
}

View File

@ -1,3 +1,4 @@
# 插入测试数据
INSERT INTO `test_resource_pool` VALUES ('102','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1);
INSERT INTO `test_resource_pool` VALUES ('102','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1);
INSERT INTO `test_resource_pool` VALUES ('102','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);
INSERT INTO `test_resource_pool` VALUES ('103','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);
INSERT INTO `test_resource_pool` VALUES ('104','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);