refactor(项目管理): 优化环境

This commit is contained in:
wxg0103 2024-01-19 16:02:57 +08:00 committed by Craftsman
parent a3e0e5cbe2
commit a0058f6f30
6 changed files with 1470 additions and 44 deletions

View File

@ -12,8 +12,5 @@ public class KeyValueEnableParam extends KeyValueParam {
* 描述
*/
private String description;
/**
* 是否必填
*/
private Boolean required = false;
}

View File

@ -17,7 +17,7 @@ public class CommonVariables implements Serializable {
@Schema(description = "id")
private String id;
@Schema(description = "变量名")
private String name;
private String key;
@Schema(description = "变量类型 CONSTANT LIST JSON")
private String type = VariableTypeConstants.CONSTANT.name();
@Schema(description = "变量值")
@ -32,17 +32,17 @@ public class CommonVariables implements Serializable {
@JsonIgnore
public boolean isConstantValid() {
return StringUtils.isEmpty(this.type) || (StringUtils.equals("text", this.type) && StringUtils.isNotEmpty(name)) || (StringUtils.equals(this.type, VariableTypeConstants.CONSTANT.name()) && StringUtils.isNotEmpty(name));
return StringUtils.isEmpty(this.type) || (StringUtils.equals("text", this.type) && StringUtils.isNotEmpty(key)) || (StringUtils.equals(this.type, VariableTypeConstants.CONSTANT.name()) && StringUtils.isNotEmpty(key));
}
@JsonIgnore
public boolean isListValid() {
return StringUtils.equals(this.type, VariableTypeConstants.LIST.name()) && StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(value) && value.indexOf(",") != -1;
return StringUtils.equals(this.type, VariableTypeConstants.LIST.name()) && StringUtils.isNotEmpty(key) && StringUtils.isNotEmpty(value) && value.indexOf(",") != -1;
}
@JsonIgnore
public boolean isJsonValid() {
return StringUtils.equals(this.type, VariableTypeConstants.JSON.name()) && StringUtils.isNotEmpty(name);
return StringUtils.equals(this.type, VariableTypeConstants.JSON.name()) && StringUtils.isNotEmpty(key);
}
}

View File

@ -19,7 +19,10 @@ 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.variables.CommonVariables;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.MsAssertionCondition;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.domain.EnvironmentBlob;
import io.metersphere.sdk.domain.EnvironmentExample;
@ -57,6 +60,7 @@ import org.springframework.util.MultiValueMap;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@ -225,7 +229,7 @@ public class EnvironmentControllerTests extends BaseTest {
List<CommonVariables> commonVariables = new ArrayList<>();
for (int i = 0; i < count; i++) {
CommonVariables commonVariable = new CommonVariables();
commonVariable.setName("key" + i);
commonVariable.setKey("key" + i);
commonVariable.setValue("value" + i);
commonVariable.setDescription("description" + i);
commonVariables.add(commonVariable);
@ -1088,31 +1092,6 @@ public class EnvironmentControllerTests extends BaseTest {
}
private List<CommonVariables> getEnvVariables(int length) {
List<CommonVariables> commonVariables = new ArrayList<>();
for (int i = 0; i < length; i++) {
CommonVariables envVariable = new CommonVariables();
envVariable.setName("name" + i);
envVariable.setValue("value" + i);
envVariable.setDescription("desc" + i);
envVariable.setType(VariableTypeConstants.CONSTANT.name());
commonVariables.add(envVariable);
}
return commonVariables;
}
//根据需要多长的list 生成不同的List<KeyValue> headers
private List<KeyValue> getHeaders(int length) {
List<KeyValue> headers = new ArrayList<>();
for (int i = 0; i < length; i++) {
KeyValue header = new KeyValue();
header.setName("key" + i);
header.setValue("value" + i);
headers.add(header);
}
return headers;
}
@Test
@Order(14)
public void testExport() throws Exception {
@ -1128,6 +1107,10 @@ public class EnvironmentControllerTests extends BaseTest {
request.setExcludeIds(List.of("environmentId1"));
MvcResult mvcResult1 = this.requestPostDownloadFile(exportEnv, null, request, DEFAULT_PROJECT_ID);
byte[] fileBytes1 = mvcResult1.getResponse().getContentAsByteArray();
File file = new File("test.json");
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(fileBytes1);
fileOutputStream.close();
Assertions.assertNotNull(fileBytes1);
request.setSelectIds(List.of("不存在blob"));
request.setSelectAll(false);

View File

@ -126,7 +126,7 @@ public class GlobalParamsControllerTests extends BaseTest {
List<CommonVariables> commonVariables = new ArrayList<>();
for (int i = 0; i < length; i++) {
CommonVariables envVariable = new CommonVariables();
envVariable.setName("name" + i);
envVariable.setKey("name" + i);
envVariable.setValue("value" + i);
envVariable.setDescription("desc" + i);
envVariable.setTags(List.of("tag" + i));

View File

@ -4,17 +4,17 @@
"globalParams":{
"headers":[
{
"name":"key0",
"key":"key0",
"value":"value0",
"enable":true
},
{
"name":"key1",
"key":"key1",
"value":"value1",
"enable":true
},
{
"name":"key2",
"key":"key2",
"value":"value2",
"enable":true
}
@ -22,7 +22,7 @@
"commonVariables":[
{
"id":null,
"name":"name0",
"key":"name0",
"type":"CONSTANT",
"value":"value0",
"enable":true,
@ -33,7 +33,7 @@
},
{
"id":null,
"name":"name1",
"key":"name1",
"type":"CONSTANT",
"value":"value1",
"enable":true,
@ -44,7 +44,7 @@
},
{
"id":null,
"name":"name2",
"key":"name2",
"type":"CONSTANT",
"value":"value2",
"enable":true,
@ -55,7 +55,7 @@
},
{
"id":null,
"name":"name4",
"key":"name4",
"type":"CONSTANT",
"value":"value4",
"enable":true,

File diff suppressed because one or more lines are too long