refactor(资源池): 资源池部分功能移动到xpack调整测试覆盖率

This commit is contained in:
guoyuqi 2023-11-17 13:47:11 +08:00 committed by 刘瑞斌
parent cc66c92b40
commit b03cdc6191
2 changed files with 117 additions and 85 deletions

View File

@ -77,15 +77,14 @@ public class TestResourcePoolService {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
} }
public boolean checkLoadConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) { public void checkLoadConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) {
if (testResourcePool.getLoadTest() == null || !testResourcePool.getLoadTest()) { if (testResourcePool.getLoadTest() == null || !testResourcePool.getLoadTest()) {
return true; return;
} }
boolean validate = checkNodeOrK8s(testResourceDTO, type, false); boolean validate = checkNodeOrK8s(testResourceDTO, type, false);
if (!validate) { if (!validate) {
testResourcePool.setEnable(false); testResourcePool.setEnable(false);
} }
return validate;
} }
private static boolean checkNodeOrK8s(TestResourceDTO testResourceDTO, String type, Boolean usedApiType) { private static boolean checkNodeOrK8s(TestResourceDTO testResourceDTO, String type, Boolean usedApiType) {
@ -116,15 +115,14 @@ public class TestResourcePoolService {
resourcePoolService.validate(testResourceDTO); resourcePoolService.validate(testResourceDTO);
} }
public boolean checkApiConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) { public void checkApiConfig(TestResourceDTO testResourceDTO, TestResourcePool testResourcePool, String type) {
if (testResourcePool.getApiTest() == null || !testResourcePool.getApiTest()) { if (testResourcePool.getApiTest() == null || !testResourcePool.getApiTest()) {
return true; return;
} }
boolean validate = checkNodeOrK8s(testResourceDTO, type, true); boolean validate = checkNodeOrK8s(testResourceDTO, type, true);
if (!validate) { if (!validate) {
testResourcePool.setEnable(false); testResourcePool.setEnable(false);
} }
return validate;
} }
public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) { public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) {
@ -185,12 +183,6 @@ public class TestResourcePoolService {
public void checkTestResourcePool(TestResourcePool testResourcePool) { public void checkTestResourcePool(TestResourcePool testResourcePool) {
String resourcePoolName = testResourcePool.getName(); 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 example = new TestResourcePoolExample();
TestResourcePoolExample.Criteria criteria = example.createCriteria(); TestResourcePoolExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(resourcePoolName); criteria.andNameEqualTo(resourcePoolName);

View File

@ -25,6 +25,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.mockserver.client.MockServerClient; import org.mockserver.client.MockServerClient;
import org.mockserver.model.Header;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -40,6 +41,8 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -116,8 +119,25 @@ class TestResourcePoolControllerTests extends BaseTest {
"\"girdConcurrentNumber\":2\n" + "\"girdConcurrentNumber\":2\n" +
"}"; "}";
private static final String configurationNoNode = "{\n" +
" \"loadTestImage\": \"123\",\n" +
" \"loadTestHeap\": \"123\",\n" +
" \"nodesList\": [\n" +
" ],\n" +
" \"orgIds\": [\"sys_default_organization_2\",\"sys_default_organization_3\",\"sys_default_organization_gyq\"],\n" +
" \"ip\": \"172.2.130.1\",\n" +
" \"token\": \"dsdfssdsvgsd\",\n" +
" \"namespace\": \"测试\",\n" +
" \"concurrentNumber\": 3,\n" +
" \"podThreads\": 2,\n" +
" \"jobDefinition\": \"jsfsjs\",\n" +
" \"deployName\": \"hello\",\n" +
" \"uiGrid\": \"localhost:4444\",\n" +
"\"girdConcurrentNumber\":2\n" +
"}";
private TestResourcePool addTestResourcePoolSuccess(String name, Boolean allOrg, Boolean partOrg, Boolean useApi, Boolean useLoad, Boolean useUi, String type) throws Exception {
private TestResourcePool addTestResourcePoolSuccess(String name, Boolean allOrg, Boolean partOrg, Boolean useApi, Boolean useLoad, Boolean useUi, Boolean noNode, String type) throws Exception {
TestResourcePoolRequest testResourcePoolRequest = new TestResourcePoolRequest(); TestResourcePoolRequest testResourcePoolRequest = new TestResourcePoolRequest();
testResourcePoolRequest.setId(""); testResourcePoolRequest.setId("");
testResourcePoolRequest.setName(name); testResourcePoolRequest.setName(name);
@ -128,7 +148,7 @@ class TestResourcePoolControllerTests extends BaseTest {
//添加成功 需要加应用组织的 全部 部分组织的测试 既有全部又有list //添加成功 需要加应用组织的 全部 部分组织的测试 既有全部又有list
//应用全部 //应用全部
testResourcePoolRequest.setAllOrg(allOrg); testResourcePoolRequest.setAllOrg(allOrg);
setResources(testResourcePoolRequest, partOrg); setResources(testResourcePoolRequest, partOrg, noNode);
String userId = SessionUtils.getUserId(); String userId = SessionUtils.getUserId();
TestResourcePoolDTO testResourcePool = new TestResourcePoolDTO(); TestResourcePoolDTO testResourcePool = new TestResourcePoolDTO();
BeanUtils.copyBean(testResourcePool, testResourcePoolRequest); BeanUtils.copyBean(testResourcePool, testResourcePoolRequest);
@ -140,24 +160,15 @@ class TestResourcePoolControllerTests extends BaseTest {
if (allOrg) { if (allOrg) {
Assertions.assertTrue(CollectionUtils.isEmpty(testResourcePoolOrganizations)); Assertions.assertTrue(CollectionUtils.isEmpty(testResourcePoolOrganizations));
} }
if (!allOrg) {
Assertions.assertTrue((CollectionUtils.isNotEmpty(testResourcePoolOrganizations) && testResourcePoolOrganizations.size() == 2));
}
return testResourcePoolRequest1; return testResourcePoolRequest1;
} }
public TestResourcePool addTestResourcePool(TestResourcePoolDTO testResourcePool) { public TestResourcePool addTestResourcePool(TestResourcePoolDTO testResourcePool) {
testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class); testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
String id = IDGenerator.nextStr(); String id = IDGenerator.nextStr();
testResourcePoolService.checkTestResourcePool(testResourcePool);
TestResourcePoolBlob testResourcePoolBlob = new TestResourcePoolBlob(); TestResourcePoolBlob testResourcePoolBlob = new TestResourcePoolBlob();
testResourcePoolBlob.setId(id); testResourcePoolBlob.setId(id);
TestResourceDTO testResourceDTO = testResourcePool.getTestResourceDTO(); TestResourceDTO testResourceDTO = testResourcePool.getTestResourceDTO();
testResourcePoolService.checkAndSaveOrgRelation(testResourcePool, id, testResourceDTO);
testResourcePoolService.checkApiConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
testResourcePoolService.checkLoadConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
testResourcePoolService.checkUiConfig(testResourceDTO, testResourcePool);
if (CollectionUtils.isEmpty(testResourceDTO.getNodesList())) { if (CollectionUtils.isEmpty(testResourceDTO.getNodesList())) {
testResourceDTO.setNodesList(new ArrayList<>()); testResourceDTO.setNodesList(new ArrayList<>());
} }
@ -183,7 +194,7 @@ class TestResourcePoolControllerTests extends BaseTest {
@Order(1) @Order(1)
void addTestResourcePoolOne() throws Exception { void addTestResourcePoolOne() throws Exception {
// 选全部资源池部分没值 资源池节点为NODE use api load ui // 选全部资源池部分没值 资源池节点为NODE use api load ui
this.addTestResourcePoolSuccess("test_pool_1", true, false, true, true, true, ResourcePoolTypeEnum.NODE.name()); this.addTestResourcePoolSuccess("test_pool_1", true, false, true, true, true, false, ResourcePoolTypeEnum.NODE.name());
} }
@ -191,7 +202,7 @@ class TestResourcePoolControllerTests extends BaseTest {
@Order(2) @Order(2)
void addTestResourcePoolTwo() throws Exception { void addTestResourcePoolTwo() throws Exception {
// 选全部资源池部分没值 资源池节点为NODE use api load // 选全部资源池部分没值 资源池节点为NODE use api load
this.addTestResourcePoolSuccess("test_pool_2", true, false, true, true, false, ResourcePoolTypeEnum.NODE.name()); this.addTestResourcePoolSuccess("test_pool_2", true, false, true, true, false, false, ResourcePoolTypeEnum.NODE.name());
} }
@ -199,7 +210,7 @@ class TestResourcePoolControllerTests extends BaseTest {
@Order(3) @Order(3)
void addTestResourcePoolThree() throws Exception { void addTestResourcePoolThree() throws Exception {
// 选全部资源池部分没值 资源池节点为NODE use api // 选全部资源池部分没值 资源池节点为NODE use api
this.addTestResourcePoolSuccess("test_pool_3", true, false, true, false, false, ResourcePoolTypeEnum.NODE.name()); this.addTestResourcePoolSuccess("test_pool_3", true, false, true, false, false, false, ResourcePoolTypeEnum.NODE.name());
} }
@ -207,7 +218,7 @@ class TestResourcePoolControllerTests extends BaseTest {
@Order(4) @Order(4)
void addTestResourcePoolFour() throws Exception { void addTestResourcePoolFour() throws Exception {
// 选全部资源池部分没值 资源池节点为NODE use // 选全部资源池部分没值 资源池节点为NODE use
this.addTestResourcePoolSuccess("test_pool_4", true, false, false, false, false, ResourcePoolTypeEnum.NODE.name()); this.addTestResourcePoolSuccess("test_pool_4", true, false, false, false, false,false, ResourcePoolTypeEnum.NODE.name());
} }
@ -216,7 +227,7 @@ class TestResourcePoolControllerTests extends BaseTest {
void addTestResourcePoolFive() throws Exception { void addTestResourcePoolFive() throws Exception {
//用途只是标记没有实际影响所以这里每种只测一遍其余以api为例 //用途只是标记没有实际影响所以这里每种只测一遍其余以api为例
// 选全部资源池部分有值 资源池节点为NODE use api // 选全部资源池部分有值 资源池节点为NODE use api
this.addTestResourcePoolSuccess("test_pool_5", true, true, true, false, false, ResourcePoolTypeEnum.NODE.name()); this.addTestResourcePoolSuccess("test_pool_5", true, true, true, false, false, false, ResourcePoolTypeEnum.NODE.name());
} }
@ -224,7 +235,7 @@ class TestResourcePoolControllerTests extends BaseTest {
@Order(6) @Order(6)
void addTestResourcePoolSix() throws Exception { void addTestResourcePoolSix() throws Exception {
// 不选全部资源池部分有值 资源池节点为NODE use api // 不选全部资源池部分有值 资源池节点为NODE use api
this.addTestResourcePoolSuccess("test_pool_6", false, true, true, false, false, ResourcePoolTypeEnum.NODE.name()); this.addTestResourcePoolSuccess("test_pool_6", false, true, true, false, false, false, ResourcePoolTypeEnum.NODE.name());
} }
@ -233,7 +244,7 @@ class TestResourcePoolControllerTests extends BaseTest {
void addTestResourcePoolSeven() throws Exception { void addTestResourcePoolSeven() throws Exception {
//资源池的应用与类型无关 这里资源池正确的顺序就到此为止换个类型只测一遍就行 //资源池的应用与类型无关 这里资源池正确的顺序就到此为止换个类型只测一遍就行
// 不选全部资源池部分有值 资源池节点为NODE use api // 不选全部资源池部分有值 资源池节点为NODE use api
this.addTestResourcePoolSuccess("test_pool_7", false, true, true, false, false, ResourcePoolTypeEnum.K8S.name()); this.addTestResourcePoolSuccess("test_pool_7", false, true, true, false, false, false, ResourcePoolTypeEnum.K8S.name());
} }
@ -244,7 +255,7 @@ class TestResourcePoolControllerTests extends BaseTest {
} }
@Test @Test
@Order(10) @Order(8)
/*@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), config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)*/ executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)*/
@ -253,11 +264,12 @@ class TestResourcePoolControllerTests extends BaseTest {
} }
@Test @Test
@Order(11) @Order(9)
void listResourcePoolsNoSearch() throws Exception { void listResourcePoolsNoSearch() throws Exception {
QueryResourcePoolRequest request = new QueryResourcePoolRequest(); QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1); request.setCurrent(1);
request.setPageSize(5); request.setPageSize(5);
request.setEnable(true);
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/page") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/page")
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CSRF_TOKEN, csrfToken)
@ -270,31 +282,22 @@ class TestResourcePoolControllerTests extends BaseTest {
Pager<?> sortPageData = JSON.parseObject(JSON.toJSONString(sortHolder.getData()), Pager.class); Pager<?> sortPageData = JSON.parseObject(JSON.toJSONString(sortHolder.getData()), Pager.class);
// 返回值中取出第一条ID最大的数据, 并判断是否是default-admin // 返回值中取出第一条ID最大的数据, 并判断是否是default-admin
TestResourcePoolDTO testResourcePoolDTO = JSON.parseArray(JSON.toJSONString(sortPageData.getList()), TestResourcePoolDTO.class).get(0); TestResourcePoolDTO testResourcePoolDTO = JSON.parseArray(JSON.toJSONString(sortPageData.getList()), TestResourcePoolDTO.class).get(0);
Assertions.assertTrue(testResourcePoolDTO.getInUsed()); Assertions.assertNull(testResourcePoolDTO.getInUsed());
} }
@Test @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), config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Order(12) @Order(10)
void getResourcePoolsDetail() throws Exception { void getResourcePoolsDetail() throws Exception {
QueryResourcePoolRequest request = new QueryResourcePoolRequest(); getDetail("/test/resource/pool/detail/103", status().isOk());
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())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
} }
@Test @Test
@Order(13) @Order(11)
void getResourcePoolsDetailWidthBlobK8s() throws Exception { void getResourcePoolsDetailWidthBlobK8s() throws Exception {
TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob_k8s", false, true, true, true, true, ResourcePoolTypeEnum.K8S.name()); TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob_k8s", false, true, true, true, true, false, ResourcePoolTypeEnum.K8S.name());
String id = testResourcePoolRequest1.getId(); String id = testResourcePoolRequest1.getId();
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/detail/" + id) MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/detail/" + id)
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -331,9 +334,9 @@ class TestResourcePoolControllerTests extends BaseTest {
} }
@Test @Test
@Order(14) @Order(12)
void getResourcePoolsDetailWidthBlobNode() throws Exception { void getResourcePoolsDetailWidthBlobNode() throws Exception {
TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob_node", false, true, true, true, true, ResourcePoolTypeEnum.NODE.name()); TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob_node", false, true, true, true, true, false, ResourcePoolTypeEnum.NODE.name());
String id = testResourcePoolRequest1.getId(); String id = testResourcePoolRequest1.getId();
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/detail/" + id) MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/detail/" + id)
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -372,9 +375,9 @@ class TestResourcePoolControllerTests extends BaseTest {
} }
@Test @Test
@Order(15) @Order(13)
void getResourcePoolsDetailWidthBlobNoOtgIds() throws Exception { void getResourcePoolsDetailWidthBlobNoOrgIds() throws Exception {
TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob_no_org_id", true, false, true, false, false, ResourcePoolTypeEnum.K8S.name()); TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob_no_org_id", true, false, true, false, false, false, ResourcePoolTypeEnum.K8S.name());
String id = testResourcePoolRequest1.getId(); String id = testResourcePoolRequest1.getId();
QueryResourcePoolRequest request = new QueryResourcePoolRequest(); QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1); request.setCurrent(1);
@ -395,30 +398,40 @@ class TestResourcePoolControllerTests extends BaseTest {
@Test @Test
@Order(16) @Order(14)
void getResourcePoolsDetailFiled() throws Exception { void getResourcePoolsDetailFiled() throws Exception {
String id = "1034";
getDetail("/test/resource/pool/detail/" + id, ERROR_REQUEST_MATCHER);
TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob_no_node", true, false, true, false, false, true,ResourcePoolTypeEnum.K8S.name());
getDetail("/test/resource/pool/detail/" + testResourcePoolRequest1.getId(), status().isOk());
}
private void getDetail(String id, ResultMatcher errorRequestMatcher) throws Exception {
QueryResourcePoolRequest request = new QueryResourcePoolRequest(); QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1); request.setCurrent(1);
request.setPageSize(5); request.setPageSize(5);
mockMvc.perform(MockMvcRequestBuilders.get("/test/resource/pool/detail/1034") mockMvc.perform(MockMvcRequestBuilders.get(id)
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(request)) .content(JSON.toJSONString(request))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(ERROR_REQUEST_MATCHER) .andExpect(errorRequestMatcher)
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); .andExpect(content().contentType(MediaType.APPLICATION_JSON));
} }
@Test @Test
@Order(17) @Order(15)
void updateTestResourcePool() throws Exception { void updateTestResourcePool() throws Exception {
TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob2", false, true, true, false, false, ResourcePoolTypeEnum.K8S.name()); createMockUrl();
TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob2", false, true, true, false, false, false, ResourcePoolTypeEnum.K8S.name());
String id = testResourcePoolRequest1.getId(); String id = testResourcePoolRequest1.getId();
TestResourcePoolRequest testResourcePoolRequest = new TestResourcePoolRequest(); TestResourcePoolRequest testResourcePoolRequest = new TestResourcePoolRequest();
testResourcePoolRequest.setId(id); testResourcePoolRequest.setId(id);
testResourcePoolRequest.setName("test_pool_update"); testResourcePoolRequest.setName("test_pool_update");
testResourcePoolRequest.setType(ResourcePoolTypeEnum.NODE.name()); testResourcePoolRequest.setType(ResourcePoolTypeEnum.NODE.name());
setResources(testResourcePoolRequest, false); setResources(testResourcePoolRequest, false, false);
testResourcePoolRequest.setApiTest(true); testResourcePoolRequest.setApiTest(true);
testResourcePoolRequest.setLoadTest(false); testResourcePoolRequest.setLoadTest(false);
testResourcePoolRequest.setUiTest(false); testResourcePoolRequest.setUiTest(false);
@ -433,7 +446,48 @@ class TestResourcePoolControllerTests extends BaseTest {
listByKeyWord("test_pool_update"); listByKeyWord("test_pool_update");
} }
private void setResources(TestResourcePoolRequest testResourcePoolDTO, boolean isPart) { @Test
@Order(16)
void updateTestResourcePoolWithOrgIds() throws Exception {
createMockUrl();
TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob3", false, true, true, false, false, false, ResourcePoolTypeEnum.K8S.name());
String id = testResourcePoolRequest1.getId();
TestResourcePoolRequest testResourcePoolRequest = new TestResourcePoolRequest();
testResourcePoolRequest.setId(id);
testResourcePoolRequest.setName("test_pool_update_1");
testResourcePoolRequest.setType(ResourcePoolTypeEnum.NODE.name());
setResources(testResourcePoolRequest, true, false);
testResourcePoolRequest.setApiTest(true);
testResourcePoolRequest.setLoadTest(false);
testResourcePoolRequest.setUiTest(false);
testResourcePoolRequest.setAllOrg(false);
mockMvc.perform(MockMvcRequestBuilders.post(TEST_RESOURCE_POOL_UPDATE)
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(testResourcePoolRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
listByKeyWord("test_pool_update_1");
}
private void createMockUrl() {
mockServerClient
.when(
request()
.withMethod("GET")
.withPath("/status"))
.respond(
response()
.withStatusCode(200)
.withHeaders(
new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400"))
.withBody(JSON.toJSONString(ResultHolder.success("OK")))
);
}
private void setResources(TestResourcePoolRequest testResourcePoolDTO, boolean isPart, boolean noNode) {
TestResourceDTO testResourceDTO; TestResourceDTO testResourceDTO;
if (isPart) { if (isPart) {
testResourceDTO = JSON.parseObject(configuration, TestResourceDTO.class); testResourceDTO = JSON.parseObject(configuration, TestResourceDTO.class);
@ -444,11 +498,14 @@ class TestResourcePoolControllerTests extends BaseTest {
} else { } else {
testResourceDTO = JSON.parseObject(configurationWidthOutOrgIds, TestResourceDTO.class); testResourceDTO = JSON.parseObject(configurationWidthOutOrgIds, TestResourceDTO.class);
} }
if (noNode) {
testResourceDTO = JSON.parseObject(configurationNoNode, TestResourceDTO.class);
}
testResourcePoolDTO.setTestResourceDTO(testResourceDTO); testResourcePoolDTO.setTestResourceDTO(testResourceDTO);
} }
@Test @Test
@Order(18) @Order(17)
void updateUiTestResourcePoolFiled() throws Exception { void updateUiTestResourcePoolFiled() throws Exception {
this.dealTestResourcePoolFiled("UPDATE"); this.dealTestResourcePoolFiled("UPDATE");
} }
@ -465,13 +522,15 @@ class TestResourcePoolControllerTests extends BaseTest {
testResourcePoolRequest.setId(""); testResourcePoolRequest.setId("");
this.requestPost(urlType, url, id, testResourcePoolRequest, status().isBadRequest()); this.requestPost(urlType, url, id, testResourcePoolRequest, status().isBadRequest());
TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob2", false, true, true, false, false, ResourcePoolTypeEnum.K8S.name()); TestResourcePool testResourcePoolRequest1 = this.addTestResourcePoolSuccess("test_pool_blob2", false, true, true, false, false, false, ResourcePoolTypeEnum.K8S.name());
id = testResourcePoolRequest1.getId(); id = testResourcePoolRequest1.getId();
} }
//资源池名称为空 //资源池名称重复
TestResourcePoolRequest testResourcePoolRequest = generatorDto(true, true, false, false, false, false, false, false, false); TestResourcePoolDTO testPool4 = listByKeyWord("test_pool_4");
this.requestPost(urlType, url, id, testResourcePoolRequest, status().isBadRequest()); TestResourcePoolRequest testResourcePoolRequest = generatorDto(true, false, false, false, false, false, false, false, false);
testResourcePoolRequest.setName("test_pool_blob2");
this.requestPost(urlType, url, testPool4.getId(), testResourcePoolRequest, status().is5xxServerError());
//资源池类型为空 //资源池类型为空
testResourcePoolRequest = generatorDto(true, false, true, false, false, false, false, false, false); testResourcePoolRequest = generatorDto(true, false, true, false, false, false, false, false, false);
this.requestPost(urlType, url, id, testResourcePoolRequest, status().isBadRequest()); this.requestPost(urlType, url, id, testResourcePoolRequest, status().isBadRequest());
@ -512,7 +571,7 @@ class TestResourcePoolControllerTests extends BaseTest {
this.requestPost(urlType, url, id, testResourcePoolRequest, ERROR_REQUEST_MATCHER); this.requestPost(urlType, url, id, testResourcePoolRequest, ERROR_REQUEST_MATCHER);
} }
void listByKeyWord(String keyWord) throws Exception { public TestResourcePoolDTO listByKeyWord(String keyWord) throws Exception {
QueryResourcePoolRequest request = new QueryResourcePoolRequest(); QueryResourcePoolRequest request = new QueryResourcePoolRequest();
request.setCurrent(1); request.setCurrent(1);
request.setPageSize(5); request.setPageSize(5);
@ -530,6 +589,7 @@ class TestResourcePoolControllerTests extends BaseTest {
// 返回值中取出第一条ID最大的数据, 并判断是否是default-admin // 返回值中取出第一条ID最大的数据, 并判断是否是default-admin
TestResourcePoolDTO testResourcePoolDTO = JSON.parseArray(JSON.toJSONString(sortPageData.getList()), TestResourcePoolDTO.class).get(0); TestResourcePoolDTO testResourcePoolDTO = JSON.parseArray(JSON.toJSONString(sortPageData.getList()), TestResourcePoolDTO.class).get(0);
Assertions.assertTrue(StringUtils.equals(testResourcePoolDTO.getName(), keyWord)); Assertions.assertTrue(StringUtils.equals(testResourcePoolDTO.getName(), keyWord));
return testResourcePoolDTO;
} }
private void requestPost(String urlType, String url, String id, TestResourcePoolRequest testResourcePoolRequest, ResultMatcher resultMatcher) throws Exception { private void requestPost(String urlType, String url, String id, TestResourcePoolRequest testResourcePoolRequest, ResultMatcher resultMatcher) throws Exception {
@ -558,7 +618,7 @@ class TestResourcePoolControllerTests extends BaseTest {
//没资源池用途为API 或者 性能测试的校验 //没资源池用途为API 或者 性能测试的校验
if (!noResources) { if (!noResources) {
testResourcePoolDTO.setApiTest(true); testResourcePoolDTO.setApiTest(true);
setResources(testResourcePoolDTO, true); setResources(testResourcePoolDTO, true, false);
} else { } else {
testResourcePoolDTO.setApiTest(useApiType); testResourcePoolDTO.setApiTest(useApiType);
testResourcePoolDTO.setLoadTest(!useApiType); testResourcePoolDTO.setLoadTest(!useApiType);
@ -604,24 +664,4 @@ class TestResourcePoolControllerTests extends BaseTest {
return testResourcePoolDTO; return testResourcePoolDTO;
} }
/* @Test
@Order(22)
void createExpectationForInvalidAuth() throws Exception {
mockServerClient
.when(
request()
.withMethod("GET")
.withPath("/status"))
.respond(
response()
.withStatusCode(200)
.withHeaders(
new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400"))
.withBody(JSON.toJSONString(ResultHolder.success("OK")))
);
this.addTestResourcePoolSuccess("test_pool_blob3", false, true, true, false, false, ResourcePoolTypeEnum.NODE.name());
}*/
} }