diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResource.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResource.java index 096072da57..c45ef1f2cd 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResource.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResource.java @@ -1,39 +1,42 @@ package io.metersphere.system.domain; -import io.metersphere.validation.groups.*; +import io.metersphere.validation.groups.Created; +import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.*; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.io.Serializable; import lombok.Data; @Data public class TestResource implements Serializable { @Schema(title = "资源节点ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{test_resource.id.not_blank}", groups = {Updated.class}) + @NotBlank(message = "{test_resource.id.not_blank}", groups = {Created.class, Updated.class}) @Size(min = 1, max = 50, message = "{test_resource.id.length_range}", groups = {Created.class, Updated.class}) private String id; @Schema(title = "资源池ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{test_resource.test_resource_pool_id.not_blank}", groups = {Created.class}) + @NotBlank(message = "{test_resource.test_resource_pool_id.not_blank}", groups = {Updated.class}) @Size(min = 1, max = 50, message = "{test_resource.test_resource_pool_id.length_range}", groups = {Created.class, Updated.class}) private String testResourcePoolId; - @Schema(title = "资源节点状态", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "{test_resource.enable.not_blank}", groups = {Created.class}) - private Boolean enable; - @Schema(title = "创建时间") private Long createTime; @Schema(title = "更新时间") private Long updateTime; + @Schema(title = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "{test_resource.enable.not_blank}", groups = {Updated.class}) + private Boolean enable; + + @Schema(title = "是否删除", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "{test_resource.deleted.not_blank}", groups = {Created.class}) + private Boolean deleted; + @Schema(title = "资源节点配置") private byte[] configuration; - @Schema(title = "是否删除", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "{test_resource_pool.deleted.not_blank}", groups = {Created.class}) - private Boolean deleted; - private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResourceExample.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResourceExample.java index 556550efb8..8ff825fe52 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResourceExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResourceExample.java @@ -244,76 +244,6 @@ public class TestResourceExample { return (Criteria) this; } - public Criteria andStatusIsNull() { - addCriterion("`status` is null"); - return (Criteria) this; - } - - public Criteria andStatusIsNotNull() { - addCriterion("`status` is not null"); - return (Criteria) this; - } - - public Criteria andStatusEqualTo(String value) { - addCriterion("`status` =", value, "status"); - return (Criteria) this; - } - - public Criteria andStatusNotEqualTo(String value) { - addCriterion("`status` <>", value, "status"); - return (Criteria) this; - } - - public Criteria andStatusGreaterThan(String value) { - addCriterion("`status` >", value, "status"); - return (Criteria) this; - } - - public Criteria andStatusGreaterThanOrEqualTo(String value) { - addCriterion("`status` >=", value, "status"); - return (Criteria) this; - } - - public Criteria andStatusLessThan(String value) { - addCriterion("`status` <", value, "status"); - return (Criteria) this; - } - - public Criteria andStatusLessThanOrEqualTo(String value) { - addCriterion("`status` <=", value, "status"); - return (Criteria) this; - } - - public Criteria andStatusLike(String value) { - addCriterion("`status` like", value, "status"); - return (Criteria) this; - } - - public Criteria andStatusNotLike(String value) { - addCriterion("`status` not like", value, "status"); - return (Criteria) this; - } - - public Criteria andStatusIn(List values) { - addCriterion("`status` in", values, "status"); - return (Criteria) this; - } - - public Criteria andStatusNotIn(List values) { - addCriterion("`status` not in", values, "status"); - return (Criteria) this; - } - - public Criteria andStatusBetween(String value1, String value2) { - addCriterion("`status` between", value1, value2, "status"); - return (Criteria) this; - } - - public Criteria andStatusNotBetween(String value1, String value2) { - addCriterion("`status` not between", value1, value2, "status"); - return (Criteria) this; - } - public Criteria andCreateTimeIsNull() { addCriterion("create_time is null"); return (Criteria) this; @@ -433,6 +363,126 @@ public class TestResourceExample { addCriterion("update_time not between", value1, value2, "updateTime"); return (Criteria) this; } + + public Criteria andEnableIsNull() { + addCriterion("`enable` is null"); + return (Criteria) this; + } + + public Criteria andEnableIsNotNull() { + addCriterion("`enable` is not null"); + return (Criteria) this; + } + + public Criteria andEnableEqualTo(Boolean value) { + addCriterion("`enable` =", value, "enable"); + return (Criteria) this; + } + + public Criteria andEnableNotEqualTo(Boolean value) { + addCriterion("`enable` <>", value, "enable"); + return (Criteria) this; + } + + public Criteria andEnableGreaterThan(Boolean value) { + addCriterion("`enable` >", value, "enable"); + return (Criteria) this; + } + + public Criteria andEnableGreaterThanOrEqualTo(Boolean value) { + addCriterion("`enable` >=", value, "enable"); + return (Criteria) this; + } + + public Criteria andEnableLessThan(Boolean value) { + addCriterion("`enable` <", value, "enable"); + return (Criteria) this; + } + + public Criteria andEnableLessThanOrEqualTo(Boolean value) { + addCriterion("`enable` <=", value, "enable"); + return (Criteria) this; + } + + public Criteria andEnableIn(List values) { + addCriterion("`enable` in", values, "enable"); + return (Criteria) this; + } + + public Criteria andEnableNotIn(List values) { + addCriterion("`enable` not in", values, "enable"); + return (Criteria) this; + } + + public Criteria andEnableBetween(Boolean value1, Boolean value2) { + addCriterion("`enable` between", value1, value2, "enable"); + return (Criteria) this; + } + + public Criteria andEnableNotBetween(Boolean value1, Boolean value2) { + addCriterion("`enable` not between", value1, value2, "enable"); + return (Criteria) this; + } + + public Criteria andDeletedIsNull() { + addCriterion("deleted is null"); + return (Criteria) this; + } + + public Criteria andDeletedIsNotNull() { + addCriterion("deleted is not null"); + return (Criteria) this; + } + + public Criteria andDeletedEqualTo(Boolean value) { + addCriterion("deleted =", value, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedNotEqualTo(Boolean value) { + addCriterion("deleted <>", value, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedGreaterThan(Boolean value) { + addCriterion("deleted >", value, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedGreaterThanOrEqualTo(Boolean value) { + addCriterion("deleted >=", value, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedLessThan(Boolean value) { + addCriterion("deleted <", value, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedLessThanOrEqualTo(Boolean value) { + addCriterion("deleted <=", value, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedIn(List values) { + addCriterion("deleted in", values, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedNotIn(List values) { + addCriterion("deleted not in", values, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedBetween(Boolean value1, Boolean value2) { + addCriterion("deleted between", value1, value2, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedNotBetween(Boolean value1, Boolean value2) { + addCriterion("deleted not between", value1, value2, "deleted"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResourcePool.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResourcePool.java index 2a59dda19c..383f595fa0 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResourcePool.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/TestResourcePool.java @@ -1,25 +1,28 @@ package io.metersphere.system.domain; -import io.metersphere.validation.groups.*; +import io.metersphere.validation.groups.Created; +import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.*; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.io.Serializable; import lombok.Data; @Data public class TestResourcePool implements Serializable { @Schema(title = "资源池ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{test_resource_pool.id.not_blank}", groups = {Updated.class}) + @NotBlank(message = "{test_resource_pool.id.not_blank}", groups = {Created.class, 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}) + @NotBlank(message = "{test_resource_pool.name.not_blank}", groups = {Updated.class}) @Size(min = 1, max = 255, message = "{test_resource_pool.name.length_range}", groups = {Created.class, Updated.class}) private String name; @Schema(title = "类型", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{test_resource_pool.type.not_blank}", groups = {Created.class}) + @NotBlank(message = "{test_resource_pool.type.not_blank}", groups = {Updated.class}) @Size(min = 1, max = 30, message = "{test_resource_pool.type.length_range}", groups = {Created.class, Updated.class}) private String type; @@ -27,7 +30,7 @@ public class TestResourcePool implements Serializable { private String description; @Schema(title = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "{test_resource_pool.enable.not_blank}", groups = {Created.class}) + @NotNull(message = "{test_resource_pool.enable.not_blank}", groups = {Updated.class}) private Boolean enable; @Schema(title = "创建时间") diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/TestResourceMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/TestResourceMapper.xml index 7a3bef2845..f532d45eaf 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/TestResourceMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/TestResourceMapper.xml @@ -4,9 +4,10 @@ - + + @@ -70,7 +71,7 @@ - id, test_resource_pool_id, `status`, create_time, update_time + id, test_resource_pool_id, create_time, update_time, `enable`, deleted configuration @@ -124,12 +125,12 @@ - insert into test_resource (id, test_resource_pool_id, `status`, - create_time, update_time, configuration - ) - values (#{id,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, - #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{configuration,jdbcType=LONGVARBINARY} - ) + insert into test_resource (id, test_resource_pool_id, create_time, + update_time, `enable`, deleted, + configuration) + values (#{id,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, + #{updateTime,jdbcType=BIGINT}, #{enable,jdbcType=BIT}, #{deleted,jdbcType=BIT}, + #{configuration,jdbcType=LONGVARBINARY}) insert into test_resource @@ -140,15 +141,18 @@ test_resource_pool_id, - - `status`, - create_time, update_time, + + `enable`, + + + deleted, + configuration, @@ -160,15 +164,18 @@ #{testResourcePoolId,jdbcType=VARCHAR}, - - #{status,jdbcType=VARCHAR}, - #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, + + #{enable,jdbcType=BIT}, + + + #{deleted,jdbcType=BIT}, + #{configuration,jdbcType=LONGVARBINARY}, @@ -189,15 +196,18 @@ test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR}, - - `status` = #{record.status,jdbcType=VARCHAR}, - create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, + + `enable` = #{record.enable,jdbcType=BIT}, + + + deleted = #{record.deleted,jdbcType=BIT}, + configuration = #{record.configuration,jdbcType=LONGVARBINARY}, @@ -210,9 +220,10 @@ update test_resource set id = #{record.id,jdbcType=VARCHAR}, test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR}, - `status` = #{record.status,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, + `enable` = #{record.enable,jdbcType=BIT}, + deleted = #{record.deleted,jdbcType=BIT}, configuration = #{record.configuration,jdbcType=LONGVARBINARY} @@ -222,9 +233,10 @@ update test_resource set id = #{record.id,jdbcType=VARCHAR}, test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR}, - `status` = #{record.status,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, - update_time = #{record.updateTime,jdbcType=BIGINT} + update_time = #{record.updateTime,jdbcType=BIGINT}, + `enable` = #{record.enable,jdbcType=BIT}, + deleted = #{record.deleted,jdbcType=BIT} @@ -235,15 +247,18 @@ test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR}, - - `status` = #{status,jdbcType=VARCHAR}, - create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, + + `enable` = #{enable,jdbcType=BIT}, + + + deleted = #{deleted,jdbcType=BIT}, + configuration = #{configuration,jdbcType=LONGVARBINARY}, @@ -253,18 +268,20 @@ update test_resource set test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR}, - `status` = #{status,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, + `enable` = #{enable,jdbcType=BIT}, + deleted = #{deleted,jdbcType=BIT}, configuration = #{configuration,jdbcType=LONGVARBINARY} where id = #{id,jdbcType=VARCHAR} update test_resource set test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR}, - `status` = #{status,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, - update_time = #{updateTime,jdbcType=BIGINT} + update_time = #{updateTime,jdbcType=BIGINT}, + `enable` = #{enable,jdbcType=BIT}, + deleted = #{deleted,jdbcType=BIT} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_ddl.sql index 7ba5afc208..ce00a5feea 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_ddl.sql @@ -255,56 +255,57 @@ CREATE TABLE system_parameter COLLATE = utf8mb4_general_ci COMMENT = '系统参数'; DROP TABLE IF EXISTS test_resource; -CREATE TABLE test_resource -( - `id` VARCHAR(50) NOT NULL COMMENT '资源节点ID', - `test_resource_pool_id` VARCHAR(50) NOT NULL COMMENT '资源池ID', - `configuration` BLOB COMMENT '资源节点配置', - `status` VARCHAR(20) NOT NULL COMMENT '资源节点状态', - `create_time` BIGINT NOT NULL COMMENT '创建时间', - `update_time` BIGINT NOT NULL COMMENT '更新时间', - PRIMARY KEY (id) +CREATE TABLE test_resource( + `id` VARCHAR(50) NOT NULL COMMENT '资源节点ID' , + `test_resource_pool_id` VARCHAR(50) NOT NULL COMMENT '资源池ID' , + `configuration` BLOB COMMENT '资源节点配置' , + `create_time` BIGINT NOT NULL COMMENT '创建时间' , + `update_time` BIGINT NOT NULL COMMENT '更新时间' , + `enable` BIT NOT NULL DEFAULT 1 COMMENT '是否启用' , + `deleted` BIT NOT NULL DEFAULT 0 COMMENT '是否删除' , + PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '测试资源池节点'; -CREATE INDEX idx_resource_pool_id ON test_resource (`test_resource_pool_id`); -CREATE INDEX idx_status ON test_resource (`status`); -CREATE INDEX idx_create_time ON test_resource (`create_time`); -CREATE INDEX idx_update_time ON test_resource (`update_time`); +CREATE INDEX idx_resource_pool_id ON test_resource(`test_resource_pool_id`); +CREATE INDEX idx_deleted ON test_resource(`deleted`); +CREATE INDEX idx_create_time ON test_resource(`create_time`); +CREATE INDEX idx_enable ON test_resource(`enable`); +CREATE INDEX idx_update_time ON test_resource(`update_time`); DROP TABLE IF EXISTS test_resource_pool; -CREATE TABLE test_resource_pool -( - `id` VARCHAR(50) NOT NULL COMMENT '资源池ID', - `name` VARCHAR(255) NOT NULL COMMENT '名称', - `type` VARCHAR(30) NOT NULL COMMENT '类型', - `description` VARCHAR(500) COMMENT '描述', - `enable` BIT NOT NULL DEFAULT 1 COMMENT '是否启用', - `create_time` BIGINT NOT NULL COMMENT '创建时间', - `update_time` BIGINT NOT NULL COMMENT '更新时间', - `load_test_image` VARCHAR(100) COMMENT '性能测试镜像', - `load_test_heap` VARCHAR(200) COMMENT '性能测试jvm配置', - `create_user` VARCHAR(50) COMMENT '创建人', - `api_test` BIT COMMENT '是否用于接口测试', - `load_test` BIT COMMENT '是否用于性能测试', - `ui_test` BIT COMMENT '是否用于ui测试', - `grid` VARCHAR(255) COMMENT 'ui测试grid配置', - `server_url` VARCHAR(255) COMMENT 'ms部署地址', - `deleted` BIT NOT NULL DEFAULT 0 COMMENT '是否删除', - PRIMARY KEY (id) +CREATE TABLE test_resource_pool( + `id` VARCHAR(50) NOT NULL COMMENT '资源池ID' , + `name` VARCHAR(255) NOT NULL COMMENT '名称' , + `type` VARCHAR(30) NOT NULL COMMENT '类型' , + `description` VARCHAR(500) COMMENT '描述' , + `enable` BIT NOT NULL DEFAULT 1 COMMENT '是否启用' , + `create_time` BIGINT NOT NULL COMMENT '创建时间' , + `update_time` BIGINT NOT NULL COMMENT '更新时间' , + `load_test_image` VARCHAR(100) COMMENT '性能测试镜像' , + `load_test_heap` VARCHAR(200) COMMENT '性能测试jvm配置' , + `create_user` VARCHAR(50) COMMENT '创建人' , + `api_test` BIT COMMENT '是否用于接口测试' , + `load_test` BIT COMMENT '是否用于性能测试' , + `ui_test` BIT COMMENT '是否用于ui测试' , + `grid` VARCHAR(255) COMMENT 'ui测试grid配置' , + `server_url` VARCHAR(255) COMMENT 'ms部署地址' , + `deleted` BIT NOT NULL DEFAULT 0 COMMENT '是否删除' , + PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '测试资源池'; -CREATE INDEX idx_name ON test_resource_pool (`name`); -CREATE INDEX idx_type ON test_resource_pool (`type`); -CREATE INDEX idx_status 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_name ON test_resource_pool(`name`); +CREATE INDEX idx_type ON test_resource_pool(`type`); +CREATE INDEX idx_deleted ON test_resource_pool(`deleted`); +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`); DROP TABLE IF EXISTS user; CREATE TABLE user diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/constants/OperationLogModule.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/constants/OperationLogModule.java index 983e96d715..10a95f1941 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/constants/OperationLogModule.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/log/constants/OperationLogModule.java @@ -4,6 +4,7 @@ public class OperationLogModule { public static final String UNKNOWN_MODULE = "UNKNOWN_MODULE"; public static final String SYSTEM_PARAMETER_SETTING = "SYSTEM_PARAMETER_SETTING"; public static final String SYSTEM_TEST_RESOURCE = "SYSTEM_TEST_RESOURCE"; + public static final String SYSTEM_TEST_RESOURCE_POOL = "SYSTEM_TEST_RESOURCE_POOL"; public static final String SYSTEM_USER = "SYSTEM_USER"; public static final String SYSTEM_WORKSPACE = "SYSTEM_WORKSPACE"; public static final String WORKSPACE_TEMPLATE_SETTINGS = "WORKSPACE_TEMPLATE_SETTINGS"; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TestResourcePoolController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TestResourcePoolController.java index e88b70caf5..a8a17d606e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TestResourcePoolController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TestResourcePoolController.java @@ -2,6 +2,10 @@ 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.log.annotation.RequestLog; +import io.metersphere.sdk.log.constants.OperationLogModule; +import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.Pager; import io.metersphere.system.consul.CacheNode; @@ -9,6 +13,7 @@ import io.metersphere.system.dto.TestResourcePoolDTO; import io.metersphere.system.request.QueryResourcePoolRequest; import io.metersphere.system.service.TestResourcePoolService; import jakarta.annotation.Resource; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -22,23 +27,31 @@ public class TestResourcePoolController { private TestResourcePoolService testResourcePoolService; @PostMapping("/add") + @RequiresPermissions(PermissionConstants.SYSTEM_TEST_POOL_READ_ADD) + @RequestLog(type = OperationLogType.ADD, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL, + sourceId = "#testResourcePoolDTO.id", projectId = "#testResourcePoolDTO.projectId", details = "#testResourcePoolDTO.name") public TestResourcePoolDTO addTestResourcePool(@RequestBody TestResourcePoolDTO testResourcePoolDTO) { return testResourcePoolService.addTestResourcePool(testResourcePoolDTO); } @GetMapping("/delete/{poolId}") @CacheNode // 把监控节点缓存起来 + @RequiresPermissions(PermissionConstants.SYSTEM_TEST_POOL_READ_DELETE) public void deleteTestResourcePool(@PathVariable(value = "poolId") String testResourcePoolId) { testResourcePoolService.deleteTestResourcePool(testResourcePoolId); } @PostMapping("/update") @CacheNode // 把监控节点缓存起来 + @RequiresPermissions(PermissionConstants.SYSTEM_TEST_POOL_READ_UPDATE) + @RequestLog(type = OperationLogType.UPDATE, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL, + sourceId = "#testResourcePoolDTO.id", projectId = "#testResourcePoolDTO.projectId", details = "#testResourcePoolDTO.name") public void updateTestResourcePool(@RequestBody TestResourcePoolDTO testResourcePoolDTO) { testResourcePoolService.updateTestResourcePool(testResourcePoolDTO); } @PostMapping("/page") + @RequiresPermissions(PermissionConstants.SYSTEM_TEST_POOL_READ) public Pager> listResourcePools( @RequestBody QueryResourcePoolRequest request) { Page page = PageHelper.startPage(request.getCurrent(),request.getPageSize(), true); return PageUtils.setPageInfo(page, testResourcePoolService.listResourcePools(request)); diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestResourcePoolControllerTest.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestResourcePoolControllerTest.java index 55f0f2de8d..c19db14c2a 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestResourcePoolControllerTest.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestResourcePoolControllerTest.java @@ -1,6 +1,8 @@ package io.metersphere.system.controller; import base.BaseTest; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.util.JSON; import io.metersphere.system.domain.TestResource; @@ -12,7 +14,10 @@ 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.request.MockMvcRequestBuilders; @@ -20,13 +25,14 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @SpringBootTest @AutoConfigureMockMvc @TestMethodOrder(MethodOrderer.OrderAnnotation.class) - class TestResourcePoolControllerTest extends BaseTest { +class TestResourcePoolControllerTest extends BaseTest { @Resource private MockMvc mockMvc; @@ -38,13 +44,18 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. testResourcePoolDTO.setName("test_pool_1"); testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name()); setResources(testResourcePoolDTO); - mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/add") + + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/add") .header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken) .content(JSON.toJSONString(testResourcePoolDTO)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)); + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + //获取数据 + JSONObject jsonObject = new JSONObject(Boolean.parseBoolean(mvcResult.getResponse().getContentAsString())); + JSONArray jsonArrayData = (JSONArray) jsonObject.get("data"); + System.out.println(jsonArrayData); } @Test @@ -66,6 +77,22 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @Test @Order(3) + void listResourcePools() throws Exception { + QueryResourcePoolRequest request = new QueryResourcePoolRequest(); + request.setCurrent(1); + request.setPageSize(5); + request.setName("test_pool"); + mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/page") + .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(4) void updateTestResourcePool() throws Exception { TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO(); testResourcePoolDTO.setName("test_pool"); @@ -92,7 +119,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. } @Test - @Order(4) + @Order(5) void updateTestResourcePoolFiled() throws Exception { TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO(); testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name()); @@ -106,24 +133,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. } @Test - @Order(5) - void listResourcePools() throws Exception { - QueryResourcePoolRequest request = new QueryResourcePoolRequest(); - request.setCurrent(1); - request.setPageSize(5); - request.setName("test_pool"); - mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/page") + @Sql(scripts = {"/sql/init_test_resource_pool.sql"}, + config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED), + executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + @Order(6) + void deleteTestResourcePool() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/delete/102") .header(SessionConstants.HEADER_TOKEN, sessionId) - .header(SessionConstants.CSRF_TOKEN, csrfToken) - .content(JSON.toJSONString(request)) - .contentType(MediaType.APPLICATION_JSON)) + .header(SessionConstants.CSRF_TOKEN, csrfToken)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)); - } - - @Test - @Order(6) - void deleteTestResourcePool() { } diff --git a/backend/services/system-setting/src/test/resources/sql/init_test_resource_pool.sql b/backend/services/system-setting/src/test/resources/sql/init_test_resource_pool.sql new file mode 100644 index 0000000000..d059e5008c --- /dev/null +++ b/backend/services/system-setting/src/test/resources/sql/init_test_resource_pool.sql @@ -0,0 +1,3 @@ +# 插入测试数据 +INSERT INTO `test_resource_pool` VALUES ('102','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', NULL, NULL, 'TCP', 0, 0, 0, NULL, null, 1); +INSERT INTO `test_resource_pool` VALUES ('102','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', NULL, NULL, 'TCP', 0, 0, 0, NULL, null, 1);