build: add system test_resource_pool permission
This commit is contained in:
parent
90e0562c0a
commit
413fba51ba
|
@ -31,10 +31,10 @@ public class PermissionConstants {
|
|||
public static final String SYSTEM_ORGANIZATION_READ_UPDATE = "SYSTEM_ORGANIZATION:READ+UPDATE";
|
||||
public static final String SYSTEM_ORGANIZATION_READ_DELETE = "SYSTEM_ORGANIZATION:READ+DELETE";
|
||||
|
||||
public static final String SYSTEM_TEST_POOL_READ = "SYSTEM_TEST_POOL:READ";
|
||||
public static final String SYSTEM_TEST_POOL_READ_ADD = "SYSTEM_TEST_POOL:READ+ADD";
|
||||
public static final String SYSTEM_TEST_POOL_READ_UPDATE = "SYSTEM_TEST_POOL:READ+UPDATE";
|
||||
public static final String SYSTEM_TEST_POOL_READ_DELETE = "SYSTEM_TEST_POOL:READ+DELETE";
|
||||
public static final String SYSTEM_TEST_RESOURCE_POOL_READ = "SYSTEM_TEST_RESOURCE_POOL:READ";
|
||||
public static final String SYSTEM_TEST_RESOURCE_POOL_READ_ADD = "SYSTEM_TEST_RESOURCE_POOL:READ+ADD";
|
||||
public static final String SYSTEM_TEST_RESOURCE_POOL_READ_UPDATE = "SYSTEM_TEST_RESOURCE_POOL:READ+UPDATE";
|
||||
public static final String SYSTEM_TEST_RESOURCE_POOL_READ_DELETE = "SYSTEM_TEST_RESOURCE_POOL:READ+DELETE";
|
||||
|
||||
public static final String SYSTEM_GROUP_READ = "SYSTEM_GROUP:READ";
|
||||
public static final String SYSTEM_GROUP_READ_ADD = "SYSTEM_GROUP:READ+ADD";
|
||||
|
|
|
@ -64,6 +64,7 @@ organization_not_exists=Organization is not exists
|
|||
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
|
||||
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
|
||||
|
|
|
@ -64,6 +64,8 @@ organization_not_exists=工作空间不存在
|
|||
test_resource_pool_id_is_null=资源池ID不能为空
|
||||
test_resource_pool_name_is_null=资源池名称不能为空
|
||||
test_resource_pool_name_already_exists=资源池名称已存在
|
||||
test_resource_pool_type_is_null=资源池类型不能为空
|
||||
|
||||
load_test=性能测试
|
||||
test_resource_pool_is_use=正在使用此资源池,无法删除
|
||||
only_one_k8s=只能添加一个 K8S
|
||||
|
|
|
@ -64,6 +64,7 @@ organization_not_exists=工作空間不存在
|
|||
test_resource_pool_id_is_null=資源池ID不能為空
|
||||
test_resource_pool_name_is_null=資源池名稱不能為空
|
||||
test_resource_pool_name_already_exists=資源池名稱已存在
|
||||
test_resource_pool_type_is_null=資源池類型不能為空
|
||||
load_test=性能測試
|
||||
test_resource_pool_is_use=正在使用此資源池,無法刪除
|
||||
only_one_k8s=只能添加一個 K8S
|
||||
|
|
|
@ -27,7 +27,7 @@ public class TestResourcePoolController {
|
|||
private TestResourcePoolService testResourcePoolService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_POOL_READ_ADD)
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_ADD)
|
||||
@RequestLog(type = OperationLogType.ADD, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL, details = "#poolDTO.name")
|
||||
public TestResourcePoolDTO addTestResourcePool(@RequestBody TestResourcePoolDTO poolDTO) {
|
||||
return testResourcePoolService.addTestResourcePool(poolDTO);
|
||||
|
@ -35,7 +35,7 @@ public class TestResourcePoolController {
|
|||
|
||||
@GetMapping("/delete/{poolId}")
|
||||
@CacheNode // 把监控节点缓存起来
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_POOL_READ_DELETE)
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_DELETE)
|
||||
@RequestLog(isBefore = true, type = OperationLogType.UPDATE, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL,
|
||||
details = "#msClass.getLogDetails(#testResourcePoolId)", msClass = TestResourcePoolService.class)
|
||||
public void deleteTestResourcePool(@PathVariable(value = "poolId") String testResourcePoolId) {
|
||||
|
@ -44,7 +44,7 @@ public class TestResourcePoolController {
|
|||
|
||||
@PostMapping("/update")
|
||||
@CacheNode // 把监控节点缓存起来
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_POOL_READ_UPDATE)
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_UPDATE)
|
||||
@RequestLog(type = OperationLogType.UPDATE, module = OperationLogModule.SYSTEM_TEST_RESOURCE_POOL,
|
||||
sourceId = "#testResourcePoolDTO.id", details = "#testResourcePoolDTO.name")
|
||||
public void updateTestResourcePool(@RequestBody TestResourcePoolDTO testResourcePoolDTO) {
|
||||
|
@ -52,7 +52,7 @@ public class TestResourcePoolController {
|
|||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_POOL_READ)
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ)
|
||||
public Pager<List<TestResourcePoolDTO>> listResourcePools(@RequestBody QueryResourcePoolRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), true);
|
||||
return PageUtils.setPageInfo(page, testResourcePoolService.listResourcePools(request));
|
||||
|
|
|
@ -104,6 +104,9 @@ public class TestResourcePoolService {
|
|||
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);
|
||||
|
|
|
@ -21,44 +21,24 @@
|
|||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT:READ",
|
||||
"name": "permission.SYSTEM_PROJECT.read",
|
||||
"resourceId": "SYSTEM_PROJECT"
|
||||
"id": "SYSTEM_TEST_RESOURCE_POOL:READ",
|
||||
"name": "permission.system_test_resource_pool.read",
|
||||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT:READ+ADD",
|
||||
"name": "permission.SYSTEM_PROJECT.add",
|
||||
"resourceId": "SYSTEM_PROJECT"
|
||||
"id": "SYSTEM_TEST_RESOURCE_POOL:READ+ADD",
|
||||
"name": "permission.system_test_resource_pool.add",
|
||||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT:READ+EDIT",
|
||||
"name": "permission.SYSTEM_PROJECT.edit",
|
||||
"resourceId": "SYSTEM_PROJECT"
|
||||
"id": "SYSTEM_TEST_RESOURCE_POOL:READ+UPDATE",
|
||||
"name": "permission.system_test_resource_pool.update",
|
||||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT:READ+DELETE",
|
||||
"name": "permission.SYSTEM_PROJECT.delete",
|
||||
"resourceId": "SYSTEM_PROJECT"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT:READ+ENVIRONMENT_CONFIG",
|
||||
"name": "permission.SYSTEM_PROJECT.environment_config",
|
||||
"resourceId": "SYSTEM_PROJECT"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT:READ+ADD_USER",
|
||||
"name": "permission.organization_user.add",
|
||||
"resourceId": "SYSTEM_PROJECT"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT:READ+EDIT_USER",
|
||||
"name": "permission.organization_user.edit",
|
||||
"resourceId": "SYSTEM_PROJECT"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT:READ+DELETE_USER",
|
||||
"name": "permission.organization_user.delete",
|
||||
"resourceId": "SYSTEM_PROJECT"
|
||||
"id": "SYSTEM_TEST_RESOURCE_POOL:READ+DELETE",
|
||||
"name": "permission.system_test_resource_pool.delete",
|
||||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
}
|
||||
],
|
||||
"resource": [
|
||||
|
@ -67,8 +47,8 @@
|
|||
"name": "permission.system_role.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PROJECT",
|
||||
"name": "permission.system_organization.name"
|
||||
"id": "SYSTEM_TEST_RESOURCE_POOL",
|
||||
"name": "permission.system_test_resource_pool.name"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
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;
|
||||
|
@ -17,10 +15,8 @@ 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.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -37,6 +33,11 @@ class TestResourcePoolControllerTest extends BaseTest {
|
|||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
|
||||
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();
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void addTestResourcePool() throws Exception {
|
||||
|
@ -45,33 +46,30 @@ class TestResourcePoolControllerTest extends BaseTest {
|
|||
testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name());
|
||||
setResources(testResourcePoolDTO);
|
||||
|
||||
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/add")
|
||||
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)).andReturn();
|
||||
//获取数据
|
||||
JSONObject jsonObject = new JSONObject(Boolean.parseBoolean(mvcResult.getResponse().getContentAsString()));
|
||||
JSONArray jsonArrayData = (JSONArray) jsonObject.get("data");
|
||||
System.out.println(jsonArrayData);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void addUiTestResourcePoolFiled() throws Exception {
|
||||
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
|
||||
testResourcePoolDTO.setName("test_pool_filed");
|
||||
testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name());
|
||||
testResourcePoolDTO.setUiTest(true);
|
||||
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().is5xxServerError())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||
//资源池名称为空
|
||||
TestResourcePoolDTO testResourcePoolDTO = generatorDto(true,false,false,false);
|
||||
this.requestPost(TEST_RESOURCE_POOL_ADD, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
|
||||
//资源池类型为空
|
||||
testResourcePoolDTO = generatorDto(false,true,false,false);
|
||||
this.requestPost(TEST_RESOURCE_POOL_ADD, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
|
||||
//资源池节点集合为空
|
||||
testResourcePoolDTO = generatorDto(false,false,true,false);
|
||||
this.requestPost(TEST_RESOURCE_POOL_ADD, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
|
||||
//UI的grid为空
|
||||
testResourcePoolDTO = generatorDto(true,true,true,false);
|
||||
this.requestPost(TEST_RESOURCE_POOL_ADD, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
|
||||
|
||||
}
|
||||
|
||||
|
@ -98,7 +96,7 @@ class TestResourcePoolControllerTest extends BaseTest {
|
|||
testResourcePoolDTO.setName("test_pool");
|
||||
testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name());
|
||||
setResources(testResourcePoolDTO);
|
||||
mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/update")
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(TEST_RESOURCE_POOL_UPDATE)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.content(JSON.toJSONString(testResourcePoolDTO))
|
||||
|
@ -121,15 +119,17 @@ class TestResourcePoolControllerTest extends BaseTest {
|
|||
@Test
|
||||
@Order(5)
|
||||
void updateTestResourcePoolFiled() throws Exception {
|
||||
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
|
||||
testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name());
|
||||
mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/update")
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.content(JSON.toJSONString(testResourcePoolDTO))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().is5xxServerError())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||
TestResourcePoolDTO testResourcePoolDTO = generatorDto(true,false,false,false);
|
||||
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
|
||||
//资源池类型为空
|
||||
testResourcePoolDTO = generatorDto(false,true,false,false);
|
||||
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
|
||||
//资源池节点集合为空
|
||||
testResourcePoolDTO = generatorDto(false,false,true,false);
|
||||
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
|
||||
//UI的grid为空
|
||||
testResourcePoolDTO = generatorDto(true,true,true,false);
|
||||
this.requestPost(TEST_RESOURCE_POOL_UPDATE, testResourcePoolDTO, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -146,5 +146,38 @@ class TestResourcePoolControllerTest extends BaseTest {
|
|||
|
||||
}
|
||||
|
||||
private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.content(JSON.toJSONString(param))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(resultMatcher).andDo(print())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||
}
|
||||
|
||||
private TestResourcePoolDTO generatorDto(boolean noName, boolean noType, boolean noResources, boolean noUiGrid ){
|
||||
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
|
||||
//没名字
|
||||
if (!noName) {
|
||||
testResourcePoolDTO.setName("test_pool_test");
|
||||
}
|
||||
//没类型
|
||||
if (!noType) {
|
||||
testResourcePoolDTO.setType(ResourcePoolTypeEnum.NODE.name());
|
||||
}
|
||||
//没资源池
|
||||
if (!noResources) {
|
||||
setResources(testResourcePoolDTO);
|
||||
}
|
||||
|
||||
testResourcePoolDTO.setUiTest(true);
|
||||
//没UI的grid
|
||||
if (!noUiGrid) {
|
||||
testResourcePoolDTO.setGrid("localhost:4444");
|
||||
}
|
||||
return testResourcePoolDTO;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue