refactor(系统设置): 优化测试用例的初始化项目的sql
This commit is contained in:
parent
b2924b1a58
commit
8630778df6
|
@ -8,7 +8,6 @@ import io.metersphere.project.dto.environment.host.HostConfig;
|
|||
import io.metersphere.project.dto.environment.http.HttpConfig;
|
||||
import io.metersphere.project.dto.environment.script.post.EnvironmentPostScript;
|
||||
import io.metersphere.project.dto.environment.script.pre.EnvironmentPreScript;
|
||||
import io.metersphere.project.dto.environment.tcp.TCPConfig;
|
||||
import io.metersphere.project.dto.environment.variables.CommonVariables;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
@ -31,8 +30,6 @@ public class EnvironmentConfig implements Serializable {
|
|||
private List<DataSource> dataSources;
|
||||
@Schema(description = "Host配置")
|
||||
private HostConfig hostConfig;
|
||||
@Schema(description = "TCP配置")
|
||||
private TCPConfig tcpConfig;
|
||||
@Schema(description = "认证配置")
|
||||
private AuthConfig authConfig;
|
||||
@Schema(description = "全局前置脚本")
|
||||
|
@ -49,7 +46,6 @@ public class EnvironmentConfig implements Serializable {
|
|||
this.httpConfig = List.of(new HttpConfig());
|
||||
this.dataSources = List.of(new DataSource());
|
||||
this.hostConfig = new HostConfig();
|
||||
this.tcpConfig = new TCPConfig();
|
||||
this.authConfig = new AuthConfig();
|
||||
this.preScript = new EnvironmentPreScript();
|
||||
this.postScript = new EnvironmentPostScript();
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package io.metersphere.project.dto.environment.tcp;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class TCPConfig implements Serializable {
|
||||
@Schema(description = "TCPClient 选项为TCPClientImpl、BinaryTCPClientImpl、LengthPrefixedBinaryTCPClientImpl")
|
||||
private String className = "TCPClientImpl";
|
||||
@Schema(description = "服务器名或IP")
|
||||
private String server;
|
||||
@Schema(description = "端口")
|
||||
private int port = 0;
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
@Schema(description = "密码")
|
||||
private String password;
|
||||
@Schema(description = "连接超时")
|
||||
private String connectTimeout;
|
||||
@Schema(description = "响应超时")
|
||||
private String timeout;
|
||||
@Schema(description = "So Linger")
|
||||
private String soLinger;
|
||||
@Schema(description = "Re-use connection")
|
||||
private Boolean reUseConnection = false;
|
||||
@Schema(description = "设置无延迟")
|
||||
private Boolean nodelay = false;
|
||||
@Schema(description = "Close Connection")
|
||||
private Boolean closeConnection = false;
|
||||
@Schema(description = "行尾(EOL)字节值")
|
||||
private String eolByte;
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -17,7 +17,6 @@ import io.metersphere.project.dto.environment.script.pre.UiPreScript;
|
|||
import io.metersphere.project.dto.environment.ssl.KeyStoreConfig;
|
||||
import io.metersphere.project.dto.environment.ssl.KeyStoreEntry;
|
||||
import io.metersphere.project.dto.environment.ssl.KeyStoreFile;
|
||||
import io.metersphere.project.dto.environment.tcp.TCPConfig;
|
||||
import io.metersphere.project.dto.environment.variables.CommonVariables;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
|
@ -259,24 +258,6 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
return hostConfig;
|
||||
}
|
||||
|
||||
private TCPConfig createTCPConfig() {
|
||||
TCPConfig tcpConfig = new TCPConfig();
|
||||
tcpConfig.setClassName("className");
|
||||
tcpConfig.setPort(8080);
|
||||
tcpConfig.setServer("server");
|
||||
tcpConfig.setPassword("password");
|
||||
tcpConfig.setUsername("username");
|
||||
tcpConfig.setConnectTimeout("connectTimeout");
|
||||
tcpConfig.setTimeout("timeout");
|
||||
tcpConfig.setSoLinger("soLinger");
|
||||
tcpConfig.setReUseConnection(true);
|
||||
tcpConfig.setNodelay(true);
|
||||
tcpConfig.setCloseConnection(true);
|
||||
tcpConfig.setEolByte("eolByte");
|
||||
|
||||
return tcpConfig;
|
||||
}
|
||||
|
||||
private AuthConfig createAuthConfig() {
|
||||
AuthConfig authConfig = new AuthConfig();
|
||||
authConfig.setUsername("username");
|
||||
|
@ -376,7 +357,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
|
||||
public void testAddSuccess() throws Exception {
|
||||
EnvironmentRequest request = new EnvironmentRequest();
|
||||
request.setProjectId("projectId");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setName("name");
|
||||
request.setConfig(new EnvironmentConfig());
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
|
@ -500,31 +481,6 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
//校验日志
|
||||
checkLog(response.getId(), OperationLogType.ADD);
|
||||
|
||||
//tcp配置
|
||||
envConfig.setTcpConfig(createTCPConfig());
|
||||
request.setName("tcpConfig");
|
||||
request.setConfig(envConfig);
|
||||
paramMap.set("request", JSON.toJSONString(request));
|
||||
mvcResult = this.requestMultipartWithOkAndReturn(add, paramMap);
|
||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
||||
Assertions.assertNotNull(response);
|
||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||
Assertions.assertNotNull(environment);
|
||||
Assertions.assertEquals(response.getId(), environment.getId());
|
||||
Assertions.assertEquals(response.getName(), environment.getName());
|
||||
Assertions.assertEquals(response.getProjectId(), environment.getProjectId());
|
||||
environmentBlob = environmentBlobMapper.selectByPrimaryKey(response.getId());
|
||||
Assertions.assertNotNull(environmentBlob);
|
||||
config = new String(environmentBlob.getConfig());
|
||||
if (StringUtils.isNotBlank(config)) {
|
||||
EnvironmentConfig environmentConfig = JSON.parseObject(config, EnvironmentConfig.class);
|
||||
Assertions.assertNotNull(environmentConfig);
|
||||
Assertions.assertNotNull(environmentConfig.getTcpConfig());
|
||||
Assertions.assertEquals(envConfig.getTcpConfig(), environmentConfig.getTcpConfig());
|
||||
}
|
||||
//校验日志
|
||||
checkLog(response.getId(), OperationLogType.ADD);
|
||||
|
||||
//host配置
|
||||
envConfig.setHostConfig(crateHostConfig());
|
||||
request.setName("hostConfig");
|
||||
|
@ -688,7 +644,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
MockMultipartFile file11 = new MockMultipartFile("file", "测试一下a", MediaType.APPLICATION_OCTET_STREAM_VALUE, "Test content".getBytes());
|
||||
paramMap.add("file", List.of(file, file11));
|
||||
paramMap.set("request", JSON.toJSONString(request));
|
||||
mvcResult = requestMultipartWithOk(add, paramMap, "projectId");
|
||||
mvcResult = requestMultipartWithOk(add, paramMap, DEFAULT_PROJECT_ID);
|
||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
||||
Assertions.assertNotNull(response);
|
||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||
|
@ -723,7 +679,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
paramMap.set("request", JSON.toJSONString(request));
|
||||
requestMultipart(add, paramMap, BAD_REQUEST_MATCHER);
|
||||
//名称为空
|
||||
request.setProjectId("projectId");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setName(null);
|
||||
paramMap.set("request", JSON.toJSONString(request));
|
||||
requestMultipart(add, paramMap, BAD_REQUEST_MATCHER);
|
||||
|
@ -745,7 +701,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
public void testGetSuccess() throws Exception {
|
||||
//校验参数
|
||||
EnvironmentExample example = new EnvironmentExample();
|
||||
example.createCriteria().andProjectIdEqualTo("projectId").andNameEqualTo("name");
|
||||
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andNameEqualTo("name");
|
||||
List<Environment> environments = environmentMapper.selectByExample(example);
|
||||
String id = environments.get(0).getId();
|
||||
MvcResult mvcResult = this.responseGet(get + id);
|
||||
|
@ -757,7 +713,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
Environment environment = new Environment();
|
||||
environment.setId("environmentId1");
|
||||
environment.setName("环境1");
|
||||
environment.setProjectId("projectId");
|
||||
environment.setProjectId(DEFAULT_PROJECT_ID);
|
||||
environment.setUpdateUser("updateUser");
|
||||
environment.setUpdateTime(System.currentTimeMillis());
|
||||
environment.setCreateUser("createUser");
|
||||
|
@ -773,7 +729,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
Assertions.assertNotNull(response);
|
||||
Assertions.assertEquals("environmentId1", response.getId());
|
||||
//校验权限
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_ENVIRONMENT_READ, get + "projectId");
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_ENVIRONMENT_READ, get + DEFAULT_PROJECT_ID);
|
||||
EnvironmentExample environmentExample = new EnvironmentExample();
|
||||
environmentExample.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andMockEqualTo(true);
|
||||
List<Environment> environmentList = environmentMapper.selectByExample(environmentExample);
|
||||
|
@ -851,12 +807,12 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
public void testUpdateSuccess() throws Exception {
|
||||
//校验参数
|
||||
EnvironmentExample example = new EnvironmentExample();
|
||||
example.createCriteria().andProjectIdEqualTo("projectId").andNameEqualTo("name");
|
||||
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andNameEqualTo("name");
|
||||
List<Environment> environments = environmentMapper.selectByExample(example);
|
||||
String id = environments.get(0).getId();
|
||||
EnvironmentRequest request = new EnvironmentRequest();
|
||||
request.setId(id);
|
||||
request.setProjectId("projectId");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setName("name");
|
||||
request.setConfig(new EnvironmentConfig());
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
|
@ -870,7 +826,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
Assertions.assertEquals(response.getName(), environment.getName());
|
||||
|
||||
example = new EnvironmentExample();
|
||||
example.createCriteria().andProjectIdEqualTo("projectId").andNameEqualTo("commonParams");
|
||||
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andNameEqualTo("commonParams");
|
||||
environments = environmentMapper.selectByExample(example);
|
||||
request.setId(environments.get(0).getId());
|
||||
request.setName("commonParams");
|
||||
|
@ -882,7 +838,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
MockMultipartFile file11 = new MockMultipartFile("file", "测试一下a", MediaType.APPLICATION_OCTET_STREAM_VALUE, "Test content".getBytes());
|
||||
paramMap.add("file", List.of(file, file11));
|
||||
paramMap.set("request", JSON.toJSONString(request));
|
||||
mvcResult = requestMultipartWithOk(update, paramMap, "projectId");
|
||||
mvcResult = requestMultipartWithOk(update, paramMap, DEFAULT_PROJECT_ID);
|
||||
response = parseObjectFromMvcResult(mvcResult, EnvironmentRequest.class);
|
||||
Assertions.assertNotNull(response);
|
||||
environment = environmentMapper.selectByPrimaryKey(response.getId());
|
||||
|
@ -915,7 +871,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
//校验环境不存在
|
||||
EnvironmentRequest request = new EnvironmentRequest();
|
||||
request.setId("environmentId2");
|
||||
request.setProjectId("projectId");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setName("name");
|
||||
request.setConfig(new EnvironmentConfig());
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
|
@ -923,12 +879,12 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
requestMultipart(update, paramMap, ERROR_REQUEST_MATCHER);
|
||||
//重名
|
||||
EnvironmentExample example = new EnvironmentExample();
|
||||
example.createCriteria().andProjectIdEqualTo("projectId").andNameEqualTo("name");
|
||||
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andNameEqualTo("name");
|
||||
List<Environment> environments = environmentMapper.selectByExample(example);
|
||||
String id = environments.get(0).getId();
|
||||
request = new EnvironmentRequest();
|
||||
request.setId(id);
|
||||
request.setProjectId("projectId");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setName("uploadFile");
|
||||
request.setConfig(new EnvironmentConfig());
|
||||
paramMap.set("request", JSON.toJSONString(request));
|
||||
|
@ -936,7 +892,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
//配置为空
|
||||
request = new EnvironmentRequest();
|
||||
request.setId("environmentId2");
|
||||
request.setProjectId("projectId");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setName("name");
|
||||
request.setConfig(null);
|
||||
paramMap = new LinkedMultiValueMap<>();
|
||||
|
@ -950,7 +906,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
public void testDeleteSuccess() throws Exception {
|
||||
//校验参数
|
||||
EnvironmentExample example = new EnvironmentExample();
|
||||
example.createCriteria().andProjectIdEqualTo("projectId").andNameEqualTo("name");
|
||||
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andNameEqualTo("name");
|
||||
List<Environment> environments = environmentMapper.selectByExample(example);
|
||||
String id = environments.get(0).getId();
|
||||
this.requestGet(delete + id);
|
||||
|
@ -966,13 +922,13 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
|
||||
//删除包含文件的环境
|
||||
example = new EnvironmentExample();
|
||||
example.createCriteria().andProjectIdEqualTo("projectId").andNameEqualTo("uploadFile");
|
||||
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andNameEqualTo("uploadFile");
|
||||
environments = environmentMapper.selectByExample(example);
|
||||
id = environments.get(0).getId();
|
||||
this.requestGet(delete + id);
|
||||
//查询文件
|
||||
FileRequest fileRequest = new FileRequest();
|
||||
fileRequest.setProjectId(StringUtils.join(DIR_PATH, "projectId"));
|
||||
fileRequest.setProjectId(StringUtils.join(DIR_PATH, DEFAULT_PROJECT_ID));
|
||||
fileRequest.setResourceId(id);
|
||||
MinioRepository minioRepository = CommonBeanFactory.getBean(MinioRepository.class);
|
||||
assert minioRepository != null;
|
||||
|
@ -987,7 +943,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
@Order(11)
|
||||
public void testList() throws Exception {
|
||||
EnvironmentDTO environmentDTO = new EnvironmentDTO();
|
||||
environmentDTO.setProjectId("projectId");
|
||||
environmentDTO.setProjectId(DEFAULT_PROJECT_ID);
|
||||
MvcResult mvcResult = this.responsePost(list, environmentDTO);
|
||||
List<Environment> response = parseObjectFromMvcResult(mvcResult, List.class);
|
||||
Assertions.assertNotNull(response);
|
||||
|
@ -1021,7 +977,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
paramMap.add("file", List.of(file));
|
||||
paramMap.set("request", password);
|
||||
MvcResult mvcResult = requestMultipartWithOk(getEnTry, paramMap, "projectId");
|
||||
MvcResult mvcResult = requestMultipartWithOk(getEnTry, paramMap, DEFAULT_PROJECT_ID);
|
||||
List<KeyStoreEntry> response = parseObjectFromMvcResult(mvcResult, List.class);
|
||||
Assertions.assertNotNull(response);
|
||||
|
||||
|
@ -1053,7 +1009,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
public void testExport() throws Exception {
|
||||
//指定id
|
||||
EnvironmentExportDTO environmentExportDTO = new EnvironmentExportDTO();
|
||||
environmentExportDTO.setProjectId("projectId");
|
||||
environmentExportDTO.setProjectId(DEFAULT_PROJECT_ID);
|
||||
environmentExportDTO.setSelectIds(List.of("environmentId1"));
|
||||
|
||||
MvcResult mvcResult = this.responsePost(exportEnv, environmentExportDTO);
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.dto.environment.GlobalParams;
|
||||
import io.metersphere.project.dto.environment.GlobalParamsRequest;
|
||||
import io.metersphere.project.dto.environment.KeyValue;
|
||||
import io.metersphere.project.dto.environment.variables.CommonVariables;
|
||||
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.sdk.constants.VariableTypeConstants;
|
||||
|
||||
import io.metersphere.sdk.domain.ProjectParameters;
|
||||
import io.metersphere.sdk.domain.ProjectParametersExample;
|
||||
import io.metersphere.sdk.mapper.ProjectParametersMapper;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -51,6 +53,14 @@ public class GlobalParamsControllerTests extends BaseTest {
|
|||
|
||||
@Resource
|
||||
private ProjectParametersMapper projectParametersMapper;
|
||||
private final ProjectServiceInvoker serviceInvoker;
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
@Autowired
|
||||
public GlobalParamsControllerTests(ProjectServiceInvoker serviceInvoker) {
|
||||
this.serviceInvoker = serviceInvoker;
|
||||
}
|
||||
|
||||
public static <T> T parseObjectFromMvcResult(MvcResult mvcResult, Class<T> parseClass) {
|
||||
try {
|
||||
|
@ -120,12 +130,110 @@ public class GlobalParamsControllerTests extends BaseTest {
|
|||
return headers;
|
||||
}
|
||||
|
||||
public void initData() {
|
||||
if (projectMapper.selectByPrimaryKey("projectId") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目");
|
||||
initProject.setDescription("项目");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId1") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId1");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目1");
|
||||
initProject.setDescription("项目1");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId2") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId2");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目2");
|
||||
initProject.setDescription("项目2");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId3") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId3");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目3");
|
||||
initProject.setDescription("项目3");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId4") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId4");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目4");
|
||||
initProject.setDescription("项目4");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\",\"loadTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId5") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId5");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目5");
|
||||
initProject.setDescription("项目5");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@Sql(scripts = {"/dml/init_project.sql"},
|
||||
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
|
||||
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
|
||||
public void testAddSuccess() throws Exception {
|
||||
initData();
|
||||
//添加全局参数 有headers 有envVariables
|
||||
GlobalParamsRequest request = new GlobalParamsRequest();
|
||||
request.setProjectId("projectId1");
|
||||
|
@ -206,7 +314,7 @@ public class GlobalParamsControllerTests extends BaseTest {
|
|||
|
||||
//校验权限
|
||||
request = new GlobalParamsRequest();
|
||||
request.setProjectId("100001100001");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
//权限校验
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_ENVIRONMENT_READ_ADD, add, request);
|
||||
}
|
||||
|
|
|
@ -14,11 +14,13 @@ import io.metersphere.system.controller.handler.ResultHolder;
|
|||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectRequest;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -53,6 +55,12 @@ public class ProjectControllerTests extends BaseTest {
|
|||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
private final ProjectServiceInvoker serviceInvoker;
|
||||
|
||||
@Autowired
|
||||
public ProjectControllerTests(ProjectServiceInvoker serviceInvoker) {
|
||||
this.serviceInvoker = serviceInvoker;
|
||||
}
|
||||
|
||||
public static <T> T parseObjectFromMvcResult(MvcResult mvcResult, Class<T> parseClass) {
|
||||
try {
|
||||
|
@ -133,6 +141,37 @@ public class ProjectControllerTests extends BaseTest {
|
|||
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
|
||||
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
|
||||
public void testGetProject() throws Exception {
|
||||
if (projectMapper.selectByPrimaryKey("projectId") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目");
|
||||
initProject.setDescription("项目");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId1") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId1");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("接口调试的项目1");
|
||||
initProject.setDescription("接口调试的项目1");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
MvcResult mvcResult = responseGet(prefix + "/get/projectId");
|
||||
ProjectDTO getProjects = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
Assertions.assertNotNull(getProjects);
|
||||
|
@ -154,11 +193,11 @@ public class ProjectControllerTests extends BaseTest {
|
|||
@Order(3)
|
||||
public void testGetOptionsSuccess() throws Exception {
|
||||
|
||||
MvcResult mvcResult = this.responseGet(getOptions + "100001");
|
||||
MvcResult mvcResult = this.responseGet(getOptions + DEFAULT_ORGANIZATION_ID);
|
||||
List<Project> list = parseObjectFromMvcResult(mvcResult, List.class);
|
||||
Assertions.assertNotNull(list);
|
||||
ProjectExample example = new ProjectExample();
|
||||
example.createCriteria().andOrganizationIdEqualTo("100001").andEnableEqualTo(true);
|
||||
example.createCriteria().andOrganizationIdEqualTo(DEFAULT_ORGANIZATION_ID).andEnableEqualTo(true);
|
||||
Assertions.assertEquals(projectMapper.countByExample(example), list.size());
|
||||
|
||||
mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login")
|
||||
|
@ -169,7 +208,7 @@ public class ProjectControllerTests extends BaseTest {
|
|||
.andReturn();
|
||||
String sessionId = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.sessionId");
|
||||
String csrfToken = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.csrfToken");
|
||||
mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(getOptions + "100001")
|
||||
mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(getOptions + DEFAULT_ORGANIZATION_ID)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
|
@ -187,7 +226,7 @@ public class ProjectControllerTests extends BaseTest {
|
|||
.andReturn();
|
||||
sessionId = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.sessionId");
|
||||
csrfToken = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.csrfToken");
|
||||
mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(getOptions + "100001")
|
||||
mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(getOptions + DEFAULT_ORGANIZATION_ID)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
|
@ -198,7 +237,7 @@ public class ProjectControllerTests extends BaseTest {
|
|||
Assertions.assertEquals(0, list.size());
|
||||
|
||||
//权限校验
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_BASE_INFO_READ, getOptions + "100001");
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_BASE_INFO_READ, getOptions + DEFAULT_ORGANIZATION_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -219,7 +258,7 @@ public class ProjectControllerTests extends BaseTest {
|
|||
UserDTO userDTO = parseObjectFromMvcResult(mvcResult, UserDTO.class);
|
||||
Assertions.assertNotNull(userDTO);
|
||||
Assertions.assertEquals("projectId", userDTO.getLastProjectId());
|
||||
request.setProjectId("100001100001");
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
//权限校验
|
||||
requestPostPermissionTest(PermissionConstants.PROJECT_BASE_INFO_READ, prefix + "/switch", request);
|
||||
}
|
||||
|
@ -264,7 +303,7 @@ public class ProjectControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(7)
|
||||
public void testUpdateProject() throws Exception {
|
||||
UpdateProjectRequest project = this.generatorUpdate("organizationId", "projectId1", "project-TestName", "Edit name", true, List.of("admin1"));
|
||||
UpdateProjectRequest project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1", "project-TestName", "Edit name", true, List.of("admin1"));
|
||||
Project projectExtend = projectMapper.selectByPrimaryKey("projectId1");
|
||||
List<String> moduleIds = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(projectExtend.getModuleSetting())) {
|
||||
|
@ -281,19 +320,7 @@ public class ProjectControllerTests extends BaseTest {
|
|||
|
||||
// 校验日志
|
||||
checkLog("projectId1", OperationLogType.UPDATE);
|
||||
// 修改模块设置
|
||||
project = this.generatorUpdate("organizationId", "projectId3", "project-Module", "Edit name", true, new ArrayList<>());
|
||||
moduleIds = new ArrayList<>();
|
||||
moduleIds.add("apiTest");
|
||||
moduleIds.add("uiTest");
|
||||
project.setModuleIds(moduleIds);
|
||||
mvcResult = this.responsePost(updateProject, project);
|
||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
||||
compareProjectDTO(currentProject, result);
|
||||
//断言模块设置
|
||||
projectExtend = projectMapper.selectByPrimaryKey("projectId3");
|
||||
Assertions.assertEquals(projectExtend.getModuleSetting(), JSON.toJSONString(moduleIds));
|
||||
|
||||
// @@校验权限
|
||||
project.setName("project-TestName2");
|
||||
project.setId(DEFAULT_PROJECT_ID);
|
||||
|
@ -307,19 +334,19 @@ public class ProjectControllerTests extends BaseTest {
|
|||
@Order(8)
|
||||
public void testUpdateProjectError() throws Exception {
|
||||
//项目名称存在 500
|
||||
UpdateProjectRequest project = this.generatorUpdate("organizationId", "projectId3", "project-TestName", "description", true, List.of("admin"));
|
||||
UpdateProjectRequest project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1", "project-TestName", "description", true, List.of("admin"));
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
//参数组织Id为空
|
||||
project = this.generatorUpdate(null, "projectId", null, null, true, List.of("admin"));
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目Id为空
|
||||
project = this.generatorUpdate("organizationId", null, null, null, true, List.of("admin"));
|
||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, null, null, null, true, List.of("admin"));
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目名称为空
|
||||
project = this.generatorUpdate("organizationId", "projectId", null, null, true, List.of("admin"));
|
||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId", null, null, true, List.of("admin"));
|
||||
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
|
||||
//项目不存在
|
||||
project = this.generatorUpdate("organizationId", "1111", "123", null, true, List.of("admin"));
|
||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "1111", "123", null, true, List.of("admin"));
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
|
||||
}
|
||||
|
|
|
@ -11,13 +11,6 @@ replace into user(id, name, email, password, create_time, update_time, language,
|
|||
last_project_id, create_user, update_user,deleted)
|
||||
VALUES ('delete', 'test2', 'deleted@metersphere.io', MD5('deleted@metersphere.io'),
|
||||
UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin',1);
|
||||
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, enable,module_setting) VALUES ('projectId', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1, '["apiTest","uiTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,enable) VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000,1);
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable ) VALUES ('projectId2', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目2', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1);
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId3', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目3', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId4', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目4', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest","loadTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable,module_setting) VALUES ('projectId5', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目5', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest"]');
|
||||
replace INTO organization(id,num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||
('organizationId',null, 'test-org', 'project', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||
|
||||
|
|
|
@ -9,27 +9,29 @@ import io.metersphere.project.mapper.ProjectTestResourcePoolMapper;
|
|||
import io.metersphere.sdk.constants.InternalUserRole;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.domain.UserRoleRelationExample;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.dto.request.OrganizationProjectRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.service.OrganizationService;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -87,6 +89,12 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
|
||||
private final ProjectServiceInvoker serviceInvoker;
|
||||
|
||||
@Autowired
|
||||
public OrganizationProjectControllerTests(ProjectServiceInvoker serviceInvoker) {
|
||||
this.serviceInvoker = serviceInvoker;
|
||||
}
|
||||
|
||||
private OrganizationDTO getDefault() {
|
||||
return organizationService.getDefault();
|
||||
|
@ -180,6 +188,103 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
updateProjectDTO.setUserIds(userIds);
|
||||
return updateProjectDTO;
|
||||
}
|
||||
|
||||
public void initData() {
|
||||
if (projectMapper.selectByPrimaryKey("projectId") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目");
|
||||
initProject.setDescription("项目");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId1") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId1");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目1");
|
||||
initProject.setDescription("项目1");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId2") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId2");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目2");
|
||||
initProject.setDescription("项目2");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId3") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId3");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目3");
|
||||
initProject.setDescription("项目3");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId4") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId4");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目4");
|
||||
initProject.setDescription("项目4");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\",\"loadTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId5") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId5");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目5");
|
||||
initProject.setDescription("项目5");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
@Order(1)
|
||||
@Sql(scripts = {"/dml/init_org_project.sql"},
|
||||
|
@ -189,6 +294,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
* 测试添加项目成功的情况
|
||||
*/
|
||||
public void testAddProjectSuccess() throws Exception {
|
||||
initData();
|
||||
AddProjectRequest project = this.generatorAdd("organizationId","organization-name", "description", true, List.of("admin"));
|
||||
MvcResult mvcResult = this.responsePost(addProject, project);
|
||||
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
|
@ -394,6 +500,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
projectRequest.setSort(new HashMap<>() {{
|
||||
put("organizationName", "asc");
|
||||
}});
|
||||
projectRequest.setFilter(new HashMap<>());
|
||||
mvcResult = this.responsePost(getProjectList, projectRequest);
|
||||
returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
|
||||
//第一个数据的organizationName是最小的
|
||||
|
|
|
@ -7,29 +7,31 @@ import io.metersphere.project.domain.ProjectTestResourcePoolExample;
|
|||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.project.mapper.ProjectTestResourcePoolMapper;
|
||||
import io.metersphere.sdk.constants.*;
|
||||
import io.metersphere.system.dto.request.DefaultFunctionalCustomField;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.domain.*;
|
||||
import io.metersphere.system.dto.*;
|
||||
import io.metersphere.system.dto.request.DefaultFunctionalCustomField;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectRequest;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import io.metersphere.system.job.CleanProjectJob;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.OrganizationParameterMapper;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectMemberRequest;
|
||||
import io.metersphere.system.dto.request.ProjectRequest;
|
||||
import io.metersphere.system.service.*;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -99,6 +101,12 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
private OrganizationParameterMapper organizationParameterMapper;
|
||||
@Resource
|
||||
private CleanProjectJob cleanProjectJob;
|
||||
private final ProjectServiceInvoker serviceInvoker;
|
||||
|
||||
@Autowired
|
||||
public SystemProjectControllerTests(ProjectServiceInvoker serviceInvoker) {
|
||||
this.serviceInvoker = serviceInvoker;
|
||||
}
|
||||
|
||||
private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(url)
|
||||
|
@ -188,6 +196,103 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
updateProjectDTO.setUserIds(userIds);
|
||||
return updateProjectDTO;
|
||||
}
|
||||
|
||||
public void initData() {
|
||||
if (projectMapper.selectByPrimaryKey("projectId") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目");
|
||||
initProject.setDescription("项目");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId1") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId1");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目1");
|
||||
initProject.setDescription("项目1");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId2") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId2");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目2");
|
||||
initProject.setDescription("项目2");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId3") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId3");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目3");
|
||||
initProject.setDescription("项目3");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId4") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId4");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目4");
|
||||
initProject.setDescription("项目4");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\",\"loadTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
if (projectMapper.selectByPrimaryKey("projectId5") == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId("projectId5");
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId(DEFAULT_ORGANIZATION_ID);
|
||||
initProject.setName("项目5");
|
||||
initProject.setDescription("项目5");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
@Order(1)
|
||||
/**
|
||||
|
@ -197,6 +302,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
|
||||
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
|
||||
public void testAddProjectSuccess() throws Exception {
|
||||
initData();
|
||||
AddProjectRequest project = this.generatorAdd(DEFAULT_ORGANIZATION_ID,"name", "description", true, List.of("admin"));
|
||||
MvcResult mvcResult = this.responsePost(addProject, project);
|
||||
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
|
@ -482,10 +588,6 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
Project getProjects = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
assert getProjects != null;
|
||||
Assertions.assertTrue(StringUtils.equals(getProjects.getId(), projectId));
|
||||
mvcResult = this.responseGet(getProject + "projectId");
|
||||
getProjects = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
assert getProjects != null;
|
||||
Assertions.assertTrue(StringUtils.equals(getProjects.getId(), "projectId"));
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getProject + projectId);
|
||||
}
|
||||
|
@ -541,6 +643,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
projectRequest.setSort(new HashMap<>() {{
|
||||
put("organizationName", "asc");
|
||||
}});
|
||||
projectRequest.setFilter(new HashMap<>());
|
||||
mvcResult = this.responsePost(getProjectList, projectRequest);
|
||||
returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
|
||||
//第一个数据的organizationName是最小的
|
||||
|
|
|
@ -16,12 +16,6 @@ replace into user(id, name, email, password, create_time, update_time, language,
|
|||
VALUES ('test', 'test', 'admin3@metersphere.io', MD5('admin2@metersphere.io'),
|
||||
UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
|
||||
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, enable,module_setting) VALUES ('projectId', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1, '["apiTest","uiTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,enable) VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000,1);
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable ) VALUES ('projectId2', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目2', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1);
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId3', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目3', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId4', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目4', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest","loadTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable,module_setting) VALUES ('projectId5', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目5', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest"]');
|
||||
replace INTO organization(id,num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
|
||||
('organizationId',null, 'test-org', 'project', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
|
||||
|
||||
|
|
|
@ -3,30 +3,6 @@ replace INTO project (id, num, organization_id, name, description, create_user,
|
|||
module_setting)
|
||||
VALUES ('projectId', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目', '系统默认创建的项目',
|
||||
'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, '["apiTest","uiTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,
|
||||
enable, module_setting)
|
||||
VALUES ('projectId', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目', '系统默认创建的项目',
|
||||
'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, 1, '["apiTest","uiTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,
|
||||
enable)
|
||||
VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目',
|
||||
'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000, 1);
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,
|
||||
enable)
|
||||
VALUES ('projectId2', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目2', '系统默认创建的项目',
|
||||
'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, 1);
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,
|
||||
enable, module_setting)
|
||||
VALUES ('projectId3', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目3', '系统默认创建的项目',
|
||||
'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, 1, '["apiTest","uiTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,
|
||||
enable, module_setting)
|
||||
VALUES ('projectId4', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目4', '系统默认创建的项目',
|
||||
'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, 1, '["apiTest","uiTest","loadTest"]');
|
||||
replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,
|
||||
enable, module_setting)
|
||||
VALUES ('projectId5', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目5', '系统默认创建的项目',
|
||||
'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000, 1, '["apiTest","uiTest"]');
|
||||
|
||||
replace INTO organization(id, num, name, description, create_time, update_time, create_user, update_user, delete_user,
|
||||
delete_time) VALUE
|
||||
|
|
Loading…
Reference in New Issue