feat(接口测试): 支持多数据源自动切换
--story=1007191 --user=赵勇 多数据源切换环境逻辑优化 https://www.tapd.cn/55049933/s/1141228
This commit is contained in:
parent
87940f3527
commit
fc7e396b7b
|
@ -61,7 +61,7 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScenarioImport parseMsFormat(String testStr, ApiTestImportRequest importRequest) {
|
private ScenarioImport parseMsFormat(String testStr, ApiTestImportRequest importRequest) {
|
||||||
ScenarioImport scenarioImport = JSON.parseObject(testStr, ScenarioImport.class,Feature.DisableSpecialKeyDetect);
|
ScenarioImport scenarioImport = JSON.parseObject(testStr, ScenarioImport.class, Feature.DisableSpecialKeyDetect);
|
||||||
List<ApiScenarioWithBLOBs> data = scenarioImport.getData();
|
List<ApiScenarioWithBLOBs> data = scenarioImport.getData();
|
||||||
|
|
||||||
Set<String> moduleIdSet = scenarioImport.getData().stream()
|
Set<String> moduleIdSet = scenarioImport.getData().stream()
|
||||||
|
@ -80,7 +80,7 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
||||||
data.forEach(item -> {
|
data.forEach(item -> {
|
||||||
String scenarioDefinitionStr = item.getScenarioDefinition();
|
String scenarioDefinitionStr = item.getScenarioDefinition();
|
||||||
if (StringUtils.isNotBlank(scenarioDefinitionStr)) {
|
if (StringUtils.isNotBlank(scenarioDefinitionStr)) {
|
||||||
JSONObject scenarioDefinition = JSONObject.parseObject(scenarioDefinitionStr);
|
JSONObject scenarioDefinition = JSONObject.parseObject(scenarioDefinitionStr, Feature.DisableSpecialKeyDetect);
|
||||||
if (scenarioDefinition != null) {
|
if (scenarioDefinition != null) {
|
||||||
JSONObject environmentMap = scenarioDefinition.getJSONObject("environmentMap");
|
JSONObject environmentMap = scenarioDefinition.getJSONObject("environmentMap");
|
||||||
if (environmentMap != null) {
|
if (environmentMap != null) {
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
||||||
|
|
||||||
apiDefinition.setProjectId(this.projectId);
|
apiDefinition.setProjectId(this.projectId);
|
||||||
String request = apiDefinition.getRequest();
|
String request = apiDefinition.getRequest();
|
||||||
JSONObject requestObj = JSONObject.parseObject(request);
|
JSONObject requestObj = JSONObject.parseObject(request, Feature.DisableSpecialKeyDetect);
|
||||||
if(requestObj.get("projectId")!=null){
|
if(requestObj.get("projectId")!=null){
|
||||||
requestObj.put("projectId", apiDefinition.getProjectId());
|
requestObj.put("projectId", apiDefinition.getProjectId());
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
||||||
}
|
}
|
||||||
cases.forEach(item -> {
|
cases.forEach(item -> {
|
||||||
String request = item.getRequest();
|
String request = item.getRequest();
|
||||||
JSONObject requestObj = JSONObject.parseObject(request);
|
JSONObject requestObj = JSONObject.parseObject(request, Feature.DisableSpecialKeyDetect);
|
||||||
requestObj.put("useEnvironment", "");
|
requestObj.put("useEnvironment", "");
|
||||||
item.setRequest(JSONObject.toJSONString(requestObj));
|
item.setRequest(JSONObject.toJSONString(requestObj));
|
||||||
item.setApiDefinitionId(apiDefinition.getId());
|
item.setApiDefinitionId(apiDefinition.getId());
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class ApiScenarioEnvService {
|
||||||
environmentType = EnvironmentType.JSON.toString();
|
environmentType = EnvironmentType.JSON.toString();
|
||||||
}
|
}
|
||||||
String definition = apiScenarioWithBLOBs.getScenarioDefinition();
|
String definition = apiScenarioWithBLOBs.getScenarioDefinition();
|
||||||
MsScenario scenario = JSONObject.parseObject(definition, MsScenario.class);
|
MsScenario scenario = JSONObject.parseObject(definition, MsScenario.class, Feature.DisableSpecialKeyDetect);
|
||||||
GenerateHashTreeUtil.parse(definition, scenario);
|
GenerateHashTreeUtil.parse(definition, scenario);
|
||||||
if (StringUtils.equals(environmentType, EnvironmentType.JSON.toString())) {
|
if (StringUtils.equals(environmentType, EnvironmentType.JSON.toString())) {
|
||||||
scenario.setEnvironmentMap(JSON.parseObject(environmentJson, Map.class));
|
scenario.setEnvironmentMap(JSON.parseObject(environmentJson, Map.class));
|
||||||
|
@ -251,7 +251,7 @@ public class ApiScenarioEnvService {
|
||||||
boolean isEnv = true;
|
boolean isEnv = true;
|
||||||
if (apiScenarioWithBLOBs != null) {
|
if (apiScenarioWithBLOBs != null) {
|
||||||
String definition = apiScenarioWithBLOBs.getScenarioDefinition();
|
String definition = apiScenarioWithBLOBs.getScenarioDefinition();
|
||||||
MsScenario scenario = JSONObject.parseObject(definition, MsScenario.class);
|
MsScenario scenario = JSONObject.parseObject(definition, MsScenario.class, Feature.DisableSpecialKeyDetect);
|
||||||
Map<String, String> envMap = scenario.getEnvironmentMap();
|
Map<String, String> envMap = scenario.getEnvironmentMap();
|
||||||
if (testPlanApiScenarios != null) {
|
if (testPlanApiScenarios != null) {
|
||||||
String envType = testPlanApiScenarios.getEnvironmentType();
|
String envType = testPlanApiScenarios.getEnvironmentType();
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class GenerateHashTreeUtil {
|
||||||
MsThreadGroup group = new MsThreadGroup();
|
MsThreadGroup group = new MsThreadGroup();
|
||||||
group.setLabel(item.getName());
|
group.setLabel(item.getName());
|
||||||
group.setName(runRequest.getReportId());
|
group.setName(runRequest.getReportId());
|
||||||
MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class);
|
MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class, Feature.DisableSpecialKeyDetect);
|
||||||
group.setOnSampleError(scenario.getOnSampleError());
|
group.setOnSampleError(scenario.getOnSampleError());
|
||||||
if (planEnvMap != null && planEnvMap.size() > 0) {
|
if (planEnvMap != null && planEnvMap.size() > 0) {
|
||||||
scenario.setEnvironmentMap(planEnvMap);
|
scenario.setEnvironmentMap(planEnvMap);
|
||||||
|
|
|
@ -699,6 +699,35 @@ public class ApiAutomationService {
|
||||||
return scenarioWithBLOBs;
|
return scenarioWithBLOBs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static JSONObject jsonMerge(JSONObject source, JSONObject target) {
|
||||||
|
// 覆盖目标JSON为空,直接返回覆盖源
|
||||||
|
if (target == null) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
for (String key : source.keySet()) {
|
||||||
|
Object value = source.get(key);
|
||||||
|
if (!target.containsKey(key)) {
|
||||||
|
target.put(key, value);
|
||||||
|
} else {
|
||||||
|
if (value instanceof JSONObject) {
|
||||||
|
JSONObject valueJson = (JSONObject) value;
|
||||||
|
JSONObject targetValue = jsonMerge(valueJson, target.getJSONObject(key));
|
||||||
|
target.put(key, targetValue);
|
||||||
|
} else if (value instanceof JSONArray) {
|
||||||
|
JSONArray valueArray = (JSONArray) value;
|
||||||
|
for (int i = 0; i < valueArray.size(); i++) {
|
||||||
|
JSONObject obj = (JSONObject) valueArray.get(i);
|
||||||
|
JSONObject targetValue = jsonMerge(obj, (JSONObject) target.getJSONArray(key).get(i));
|
||||||
|
target.getJSONArray(key).set(i, targetValue);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
target.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
public String setDomain(ApiScenarioEnvRequest request) {
|
public String setDomain(ApiScenarioEnvRequest request) {
|
||||||
Boolean enable = request.getEnvironmentEnable();
|
Boolean enable = request.getEnvironmentEnable();
|
||||||
String scenarioDefinition = request.getDefinition();
|
String scenarioDefinition = request.getDefinition();
|
||||||
|
@ -714,11 +743,17 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String scenarioId = request.getId();
|
String scenarioId = request.getId();
|
||||||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(scenarioId);
|
ApiScenarioDTO scenario = getNewApiScenario(scenarioId);
|
||||||
if (apiScenarioWithBLOBs != null) {
|
if (scenario != null) {
|
||||||
String environmentType = apiScenarioWithBLOBs.getEnvironmentType();
|
String referenced = element.getString("referenced");
|
||||||
String environmentGroupId = apiScenarioWithBLOBs.getEnvironmentGroupId();
|
if (StringUtils.equalsIgnoreCase("REF", referenced)) {
|
||||||
String environmentJson = apiScenarioWithBLOBs.getEnvironmentJson();
|
JSONObject source = JSON.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||||
|
element = jsonMerge(source, element);
|
||||||
|
}
|
||||||
|
element.put("referenced", referenced);
|
||||||
|
String environmentType = scenario.getEnvironmentType();
|
||||||
|
String environmentGroupId = scenario.getEnvironmentGroupId();
|
||||||
|
String environmentJson = scenario.getEnvironmentJson();
|
||||||
if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) {
|
if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) {
|
||||||
environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId);
|
environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId);
|
||||||
} else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) {
|
} else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) {
|
||||||
|
@ -727,7 +762,6 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ParameterConfig config = new ParameterConfig();
|
ParameterConfig config = new ParameterConfig();
|
||||||
apiScenarioEnvService.setEnvConfig(environmentMap, config);
|
apiScenarioEnvService.setEnvConfig(environmentMap, config);
|
||||||
if (config.getConfig() != null && !config.getConfig().isEmpty()) {
|
if (config.getConfig() != null && !config.getConfig().isEmpty()) {
|
||||||
|
@ -1376,7 +1410,7 @@ public class ApiAutomationService {
|
||||||
if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) {
|
if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
|
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||||
JSONArray hashTree = element.getJSONArray("hashTree");
|
JSONArray hashTree = element.getJSONArray("hashTree");
|
||||||
ApiScenarioImportUtil.formatHashTree(hashTree);
|
ApiScenarioImportUtil.formatHashTree(hashTree);
|
||||||
setHashTree(hashTree);
|
setHashTree(hashTree);
|
||||||
|
@ -1400,7 +1434,7 @@ public class ApiAutomationService {
|
||||||
if (CollectionUtils.isEmpty(object.getJSONArray("hashTree"))) {
|
if (CollectionUtils.isEmpty(object.getJSONArray("hashTree"))) {
|
||||||
ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.getString("id"));
|
ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.getString("id"));
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
JSONObject element = JSON.parseObject(model.getRequest(),Feature.DisableSpecialKeyDetect);
|
JSONObject element = JSON.parseObject(model.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||||
object.put("hashTree", element.getJSONArray("hashTree"));
|
object.put("hashTree", element.getJSONArray("hashTree"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1556,8 +1590,8 @@ public class ApiAutomationService {
|
||||||
|
|
||||||
int containsCount = 0;
|
int containsCount = 0;
|
||||||
for (ApiDefinition model : allEffectiveApiList) {
|
for (ApiDefinition model : allEffectiveApiList) {
|
||||||
if(refIdList.contains(model.getId())){
|
if (refIdList.contains(model.getId())) {
|
||||||
containsCount ++;
|
containsCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class MsHashTreeService {
|
||||||
public static final String AUTH_MANAGER = "authManager";
|
public static final String AUTH_MANAGER = "authManager";
|
||||||
public static final String PROJECT_ID = "projectId";
|
public static final String PROJECT_ID = "projectId";
|
||||||
public static final String ACTIVE = "active";
|
public static final String ACTIVE = "active";
|
||||||
|
public static final String ENV_MAP = "environmentMap";
|
||||||
|
|
||||||
public void setHashTree(JSONArray hashTree) {
|
public void setHashTree(JSONArray hashTree) {
|
||||||
// 将引用转成复制
|
// 将引用转成复制
|
||||||
|
@ -86,14 +87,14 @@ public class MsHashTreeService {
|
||||||
} else {
|
} else {
|
||||||
ApiScenarioWithBLOBs bloBs = apiScenarioMapper.selectByPrimaryKey(object.getString(ID));
|
ApiScenarioWithBLOBs bloBs = apiScenarioMapper.selectByPrimaryKey(object.getString(ID));
|
||||||
if (bloBs != null) {
|
if (bloBs != null) {
|
||||||
object = JSON.parseObject(bloBs.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
|
object = JSON.parseObject(bloBs.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||||
hashTree.set(i, object);
|
hashTree.set(i, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (SCENARIO.equals(object.getString(TYPE))) {
|
} else if (SCENARIO.equals(object.getString(TYPE))) {
|
||||||
ApiScenarioWithBLOBs bloBs = apiScenarioMapper.selectByPrimaryKey(object.getString(ID));
|
ApiScenarioWithBLOBs bloBs = apiScenarioMapper.selectByPrimaryKey(object.getString(ID));
|
||||||
if (bloBs != null) {
|
if (bloBs != null) {
|
||||||
object = JSON.parseObject(bloBs.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
|
object = JSON.parseObject(bloBs.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||||
hashTree.set(i, object);
|
hashTree.set(i, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +184,7 @@ public class MsHashTreeService {
|
||||||
ApiTestCaseInfo apiTestCase = apiTestCaseService.get(element.getString(ID));
|
ApiTestCaseInfo apiTestCase = apiTestCaseService.get(element.getString(ID));
|
||||||
if (apiTestCase != null) {
|
if (apiTestCase != null) {
|
||||||
if (StringUtils.equalsIgnoreCase(element.getString(REFERENCED), REF)) {
|
if (StringUtils.equalsIgnoreCase(element.getString(REFERENCED), REF)) {
|
||||||
JSONObject refElement = JSON.parseObject(apiTestCase.getRequest(),Feature.DisableSpecialKeyDetect);
|
JSONObject refElement = JSON.parseObject(apiTestCase.getRequest(), Feature.DisableSpecialKeyDetect);
|
||||||
ElementUtil.dataFormatting(refElement);
|
ElementUtil.dataFormatting(refElement);
|
||||||
JSONArray array = refElement.getJSONArray(HASH_TREE);
|
JSONArray array = refElement.getJSONArray(HASH_TREE);
|
||||||
ElementUtil.copyBean(element, refElement);
|
ElementUtil.copyBean(element, refElement);
|
||||||
|
@ -255,8 +256,11 @@ public class MsHashTreeService {
|
||||||
boolean variableEnable = element.containsKey(VARIABLE_ENABLE)
|
boolean variableEnable = element.containsKey(VARIABLE_ENABLE)
|
||||||
? element.getBoolean(VARIABLE_ENABLE) : true;
|
? element.getBoolean(VARIABLE_ENABLE) : true;
|
||||||
|
|
||||||
|
if (environmentEnable && StringUtils.isNotEmpty(scenarioWithBLOBs.getEnvironmentJson())) {
|
||||||
|
element.put(ENV_MAP, JSON.parseObject(scenarioWithBLOBs.getEnvironmentJson(), Map.class));
|
||||||
|
}
|
||||||
if (StringUtils.equalsIgnoreCase(element.getString(REFERENCED), REF)) {
|
if (StringUtils.equalsIgnoreCase(element.getString(REFERENCED), REF)) {
|
||||||
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
|
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||||
element.put(REFERENCED, REF);
|
element.put(REFERENCED, REF);
|
||||||
element.put(NAME, scenarioWithBLOBs.getName());
|
element.put(NAME, scenarioWithBLOBs.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1550,7 +1550,7 @@ export default {
|
||||||
if (!this.currentScenario.headers) {
|
if (!this.currentScenario.headers) {
|
||||||
this.currentScenario.headers = [];
|
this.currentScenario.headers = [];
|
||||||
}
|
}
|
||||||
if (this.currentScenario.id) {
|
if (this.currentScenario && this.currentScenario.id) {
|
||||||
this.result = this.$get("/api/automation/getApiScenario/" + this.currentScenario.id, response => {
|
this.result = this.$get("/api/automation/getApiScenario/" + this.currentScenario.id, response => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
this.path = "/api/automation/update";
|
this.path = "/api/automation/update";
|
||||||
|
@ -1818,19 +1818,15 @@ export default {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
checkALevelChecked() {
|
checkALevelChecked() {
|
||||||
if (this.$refs.stepTree) {
|
|
||||||
let resourceIds = [];
|
let resourceIds = [];
|
||||||
|
if (this.$refs.stepTree) {
|
||||||
this.$refs.stepTree.root.childNodes.forEach(item => {
|
this.$refs.stepTree.root.childNodes.forEach(item => {
|
||||||
if (item.checked) {
|
if (item.checked) {
|
||||||
resourceIds.push(item.data.resourceId);
|
resourceIds.push(item.data.resourceId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (resourceIds.length > 20) {
|
|
||||||
this.$warning(this.$t('api_test.automation.open_check_message'));
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
return resourceIds;
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
recursionExpansion(resourceIds, array) {
|
recursionExpansion(resourceIds, array) {
|
||||||
if (array) {
|
if (array) {
|
||||||
|
@ -1850,11 +1846,15 @@ export default {
|
||||||
},
|
},
|
||||||
openExpansion() {
|
openExpansion() {
|
||||||
this.expandedStatus = true;
|
this.expandedStatus = true;
|
||||||
if (this.checkALevelChecked()) {
|
let resourceIds = [];
|
||||||
let resourceIds = this.getAllResourceIds();
|
let openResourceIds = this.checkALevelChecked();
|
||||||
|
if (openResourceIds.length > 20) {
|
||||||
|
resourceIds = openResourceIds.slice(0, 20);
|
||||||
|
} else {
|
||||||
|
resourceIds = this.getAllResourceIds();
|
||||||
|
}
|
||||||
this.changeNodeStatus(resourceIds, this.scenarioDefinition);
|
this.changeNodeStatus(resourceIds, this.scenarioDefinition);
|
||||||
this.recursionExpansion(resourceIds, this.$refs.stepTree.root.childNodes);
|
this.recursionExpansion(resourceIds, this.$refs.stepTree.root.childNodes);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
closeExpansion() {
|
closeExpansion() {
|
||||||
this.expandedStatus = false;
|
this.expandedStatus = false;
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
:environmentType="environmentType"
|
:environmentType="environmentType"
|
||||||
:environmentGroupId="environmentGroupId"
|
:environmentGroupId="environmentGroupId"
|
||||||
:envMap="envMap"
|
:envMap="envMap"
|
||||||
|
:is-scenario="true"
|
||||||
@enable="enable"
|
@enable="enable"
|
||||||
@copy="copyRow"
|
@copy="copyRow"
|
||||||
@remove="remove"
|
@remove="remove"
|
||||||
|
|
|
@ -82,7 +82,7 @@ import {createComponent} from "@/business/components/api/definition/components/j
|
||||||
import {Assertions, Extract} from "@/business/components/api/definition/model/ApiTestModel";
|
import {Assertions, Extract} from "@/business/components/api/definition/model/ApiTestModel";
|
||||||
import {parseEnvironment} from "@/business/components/api/definition/model/EnvironmentModel";
|
import {parseEnvironment} from "@/business/components/api/definition/model/EnvironmentModel";
|
||||||
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
|
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
|
||||||
import {getCurrentProjectID} from "@/common/js/utils";
|
import {getCurrentProjectID, objToStrMap} from "@/common/js/utils";
|
||||||
import {getUUID} from "@/common/js/utils";
|
import {getUUID} from "@/common/js/utils";
|
||||||
import MsJsr233Processor from "@/business/components/api/automation/scenario/component/Jsr233Processor";
|
import MsJsr233Processor from "@/business/components/api/automation/scenario/component/Jsr233Processor";
|
||||||
|
|
||||||
|
@ -102,6 +102,10 @@ export default {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
isScenario: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
isReadOnly: {
|
isReadOnly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
@ -133,8 +137,14 @@ export default {
|
||||||
this.getEnvironments();
|
this.getEnvironments();
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
|
},
|
||||||
|
'$store.state.useEnvironment': function () {
|
||||||
|
if (!this.isScenario) {
|
||||||
|
this.request.environmentId = this.$store.state.useEnvironment;
|
||||||
|
this.getEnvironments();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
remove(row) {
|
remove(row) {
|
||||||
let index = this.request.hashTree.indexOf(row);
|
let index = this.request.hashTree.indexOf(row);
|
||||||
|
@ -167,13 +177,42 @@ export default {
|
||||||
runTest() {
|
runTest() {
|
||||||
|
|
||||||
},
|
},
|
||||||
getEnvironments() {
|
itselfEnvironment() {
|
||||||
this.environments = [];
|
|
||||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||||
|
this.result = this.$get('/api/environment/list/' + id, response => {
|
||||||
|
this.environments = response.data;
|
||||||
|
this.environments.forEach(environment => {
|
||||||
|
parseEnvironment(environment);
|
||||||
|
})
|
||||||
|
this.initDataSource();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getEnvironments() {
|
||||||
let envId = "";
|
let envId = "";
|
||||||
|
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||||
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
|
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
|
||||||
&& this.$store.state.scenarioEnvMap.has(this.projectId)) {
|
&& this.$store.state.scenarioEnvMap.has(id)) {
|
||||||
envId = this.$store.state.scenarioEnvMap.get(this.projectId);
|
envId = this.$store.state.scenarioEnvMap.get(id);
|
||||||
|
}
|
||||||
|
if (this.request.referenced === 'Created' && this.isScenario && !this.request.isRefEnvironment) {
|
||||||
|
this.itselfEnvironment();
|
||||||
|
return;
|
||||||
|
} else if (!this.isScenario && !this.request.customizeReq) {
|
||||||
|
this.itselfEnvironment();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.environments = [];
|
||||||
|
// 场景开启自身环境
|
||||||
|
if (this.request.environmentEnable && this.request.refEevMap) {
|
||||||
|
let obj = Object.prototype.toString.call(this.request.refEevMap).match(/\[object (\w+)\]/)[1].toLowerCase();
|
||||||
|
if (obj !== 'object' && obj !== "map") {
|
||||||
|
this.request.refEevMap = objToStrMap(JSON.parse(this.request.refEevMap));
|
||||||
|
} else if (obj === 'object' && obj !== "map") {
|
||||||
|
this.request.refEevMap = objToStrMap(this.request.refEevMap);
|
||||||
|
}
|
||||||
|
if (this.request.refEevMap instanceof Map && this.request.refEevMap.has(id)) {
|
||||||
|
envId = this.request.refEevMap.get(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let targetDataSourceName = "";
|
let targetDataSourceName = "";
|
||||||
let currentEnvironment = {};
|
let currentEnvironment = {};
|
||||||
|
@ -215,7 +254,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let flag = false;
|
let flag = false;
|
||||||
if (currentEnvironment.config && currentEnvironment.config.databaseConfigs) {
|
if (currentEnvironment && currentEnvironment.config && currentEnvironment.config.databaseConfigs) {
|
||||||
currentEnvironment.config.databaseConfigs.forEach(item => {
|
currentEnvironment.config.databaseConfigs.forEach(item => {
|
||||||
if (item.id === this.request.dataSourceId) {
|
if (item.id === this.request.dataSourceId) {
|
||||||
flag = true;
|
flag = true;
|
||||||
|
|
|
@ -125,6 +125,7 @@ export default {
|
||||||
if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded && this.scenario.hashTree) {
|
if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded && this.scenario.hashTree) {
|
||||||
this.setDisabled(this.scenario.hashTree, this.scenario.projectId);
|
this.setDisabled(this.scenario.hashTree, this.scenario.projectId);
|
||||||
}
|
}
|
||||||
|
this.setOwnEnvironment(this.scenario.hashTree);
|
||||||
},
|
},
|
||||||
components: {ApiBaseComponent, MsSqlBasisParameters, MsTcpBasisParameters, MsDubboBasisParameters, MsApiRequestForm},
|
components: {ApiBaseComponent, MsSqlBasisParameters, MsTcpBasisParameters, MsDubboBasisParameters, MsApiRequestForm},
|
||||||
data() {
|
data() {
|
||||||
|
@ -138,7 +139,6 @@ export default {
|
||||||
computed: {
|
computed: {
|
||||||
isDeletedOrRef() {
|
isDeletedOrRef() {
|
||||||
return this.scenario.referenced !== undefined && this.scenario.referenced === 'Deleted' || this.scenario.referenced === 'REF';
|
return this.scenario.referenced !== undefined && this.scenario.referenced === 'Deleted' || this.scenario.referenced === 'REF';
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -237,6 +237,21 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setOwnEnvironment(scenarioDefinition) {
|
||||||
|
for (let i in scenarioDefinition) {
|
||||||
|
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||||
|
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||||
|
scenarioDefinition[i].refEevMap = new Map();
|
||||||
|
scenarioDefinition[i].environmentEnable = this.scenario.environmentEnable;
|
||||||
|
if (this.scenario.environmentEnable && this.scenario.environmentMap) {
|
||||||
|
scenarioDefinition[i].refEevMap = this.scenario.environmentMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||||
|
this.setOwnEnvironment(scenarioDefinition[i].hashTree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
calcProjectId(projectId, parentId) {
|
calcProjectId(projectId, parentId) {
|
||||||
if (!projectId) {
|
if (!projectId) {
|
||||||
return parentId ? parentId : getCurrentProjectID();
|
return parentId ? parentId : getCurrentProjectID();
|
||||||
|
@ -258,36 +273,36 @@ export default {
|
||||||
clickResource(resource) {
|
clickResource(resource) {
|
||||||
let workspaceId = getCurrentWorkspaceId();
|
let workspaceId = getCurrentWorkspaceId();
|
||||||
let isTurnSpace = true
|
let isTurnSpace = true
|
||||||
if(resource.projectId!==getCurrentProjectID()){
|
if (resource.projectId !== getCurrentProjectID()) {
|
||||||
isTurnSpace = false;
|
isTurnSpace = false;
|
||||||
this.$get("/project/get/" + resource.projectId, response => {
|
this.$get("/project/get/" + resource.projectId, response => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
workspaceId = response.data.workspaceId;
|
workspaceId = response.data.workspaceId;
|
||||||
isTurnSpace = true;
|
isTurnSpace = true;
|
||||||
this.checkPermission(resource,workspaceId,isTurnSpace);
|
this.checkPermission(resource, workspaceId, isTurnSpace);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else {
|
} else {
|
||||||
this.checkPermission(resource,workspaceId,isTurnSpace);
|
this.checkPermission(resource, workspaceId, isTurnSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
gotoTurn(resource,workspaceId,isTurnSpace){
|
gotoTurn(resource, workspaceId, isTurnSpace) {
|
||||||
let automationData = this.$router.resolve({
|
let automationData = this.$router.resolve({
|
||||||
name: 'ApiAutomation',
|
name: 'ApiAutomation',
|
||||||
params: {redirectID: getUUID(), dataType: "scenario", dataSelectRange: 'edit:' + resource.id, projectId: resource.projectId, workspaceId: workspaceId}
|
params: {redirectID: getUUID(), dataType: "scenario", dataSelectRange: 'edit:' + resource.id, projectId: resource.projectId, workspaceId: workspaceId}
|
||||||
});
|
});
|
||||||
if(isTurnSpace){
|
if (isTurnSpace) {
|
||||||
window.open(automationData.href, '_blank');
|
window.open(automationData.href, '_blank');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
checkPermission(resource,workspaceId,isTurnSpace){
|
checkPermission(resource, workspaceId, isTurnSpace) {
|
||||||
this.$get('/project/getOwnerProjectIds', res => {
|
this.$get('/project/getOwnerProjectIds', res => {
|
||||||
const project = res.data.find(p => p === resource.projectId);
|
const project = res.data.find(p => p === resource.projectId);
|
||||||
if(!project){
|
if (!project) {
|
||||||
this.$warning(this.$t('commons.no_permission'));
|
this.$warning(this.$t('commons.no_permission'));
|
||||||
}else{
|
} else {
|
||||||
this.gotoTurn(resource,workspaceId,isTurnSpace)
|
this.gotoTurn(resource, workspaceId, isTurnSpace)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<el-dropdown-item command="enable" v-if="data.command && data.enable">{{ this.$t('ui.disable') }}</el-dropdown-item>
|
<el-dropdown-item command="enable" v-if="data.command && data.enable">{{ this.$t('ui.disable') }}</el-dropdown-item>
|
||||||
<el-dropdown-item command="enable" v-if="data.command && !data.enable">{{ this.$t('ui.enable') }}</el-dropdown-item>
|
<el-dropdown-item command="enable" v-if="data.command && !data.enable">{{ this.$t('ui.enable') }}</el-dropdown-item>
|
||||||
<el-dropdown-item command="remove">{{ this.$t('api_test.automation.delete_step') }}</el-dropdown-item>
|
<el-dropdown-item command="remove">{{ this.$t('api_test.automation.delete_step') }}</el-dropdown-item>
|
||||||
<el-dropdown-item command="rename">{{ this.$t('test_track.module.rename') }}</el-dropdown-item>
|
<el-dropdown-item command="rename" v-if="!isScenario">{{ this.$t('test_track.module.rename') }}</el-dropdown-item>
|
||||||
<el-dropdown-item command="scenarioVar" v-if="data.type==='scenario'">
|
<el-dropdown-item command="scenarioVar" v-if="data.type==='scenario'">
|
||||||
{{ this.$t("api_test.automation.view_scene_variables") }}
|
{{ this.$t("api_test.automation.view_scene_variables") }}
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
|
@ -56,6 +56,12 @@ export default {
|
||||||
name: "StepExtendBtns",
|
name: "StepExtendBtns",
|
||||||
components: {STEP, MsVariableList, MsAddBasisApi},
|
components: {STEP, MsVariableList, MsAddBasisApi},
|
||||||
props: {
|
props: {
|
||||||
|
isScenario: {
|
||||||
|
type: Boolean,
|
||||||
|
default() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
data: Object,
|
data: Object,
|
||||||
environmentType: String,
|
environmentType: String,
|
||||||
environmentGroupId: String,
|
environmentGroupId: String,
|
||||||
|
@ -147,9 +153,25 @@ export default {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
let data = JSON.parse(res.data);
|
let data = JSON.parse(res.data);
|
||||||
this.data.hashTree = data.hashTree;
|
this.data.hashTree = data.hashTree;
|
||||||
|
this.setOwnEnvironment(this.data.hashTree);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
setOwnEnvironment(scenarioDefinition) {
|
||||||
|
for (let i in scenarioDefinition) {
|
||||||
|
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||||
|
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||||
|
scenarioDefinition[i].environmentEnable = this.data.environmentEnable;
|
||||||
|
scenarioDefinition[i].refEevMap = new Map();
|
||||||
|
if (this.data.environmentEnable && this.data.environmentMap) {
|
||||||
|
scenarioDefinition[i].refEevMap = this.data.environmentMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||||
|
this.setOwnEnvironment(scenarioDefinition[i].hashTree);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
saveAsApi() {
|
saveAsApi() {
|
||||||
this.currentProtocol = this.data.protocol;
|
this.currentProtocol = this.data.protocol;
|
||||||
this.data.customizeReq = false;
|
this.data.customizeReq = false;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
:project-id="projectId"
|
:project-id="projectId"
|
||||||
:is-read-only="isReadOnly"
|
:is-read-only="isReadOnly"
|
||||||
:useEnvironment='useEnvironment'
|
:useEnvironment='useEnvironment'
|
||||||
@setEnvironment="setEnvironment" ref="environmentSelect"/>
|
@setEnvironment="setEnvironment" ref="environmentSelect" v-if="api.protocol==='HTTP'"/>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="2">
|
<el-col :span="2">
|
||||||
<!-- 保存操作 -->
|
<!-- 保存操作 -->
|
||||||
|
|
|
@ -144,7 +144,6 @@
|
||||||
v-if="isXpack&&api.method==='ESB'" ref="esbDefinition"/>
|
v-if="isXpack&&api.method==='ESB'" ref="esbDefinition"/>
|
||||||
<ms-sql-basis-parameters
|
<ms-sql-basis-parameters
|
||||||
:showScript="true"
|
:showScript="true"
|
||||||
:is-scenario="true"
|
|
||||||
:request="apiCase.request"
|
:request="apiCase.request"
|
||||||
:response="apiCase.responseData"
|
:response="apiCase.responseData"
|
||||||
v-if="api.protocol==='SQL'"/>
|
v-if="api.protocol==='SQL'"/>
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
<div class="el-step__icon-inner">{{ request.ruleSize }}</div>
|
<div class="el-step__icon-inner">{{ request.ruleSize }}</div>
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
<ms-jmx-step :request="request" :apiId="request.id" :response="response" @reload="reloadBody"
|
<ms-jmx-step :request="request" :apiId="request.id" :response="response" :isScenario="isScenario" @reload="reloadBody"
|
||||||
:tab-type="'assertionsRule'" ref="assertionsRule"/>
|
:tab-type="'assertionsRule'" ref="assertionsRule"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ import MsCodeEdit from "../../../../../common/components/MsCodeEdit";
|
||||||
import MsApiScenarioVariables from "../../ApiScenarioVariables";
|
import MsApiScenarioVariables from "../../ApiScenarioVariables";
|
||||||
import {parseEnvironment} from "../../../model/EnvironmentModel";
|
import {parseEnvironment} from "../../../model/EnvironmentModel";
|
||||||
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
|
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
|
||||||
import {getCurrentProjectID} from "@/common/js/utils";
|
import {getCurrentProjectID, objToStrMap} from "@/common/js/utils";
|
||||||
import {getUUID} from "@/common/js/utils";
|
import {getUUID} from "@/common/js/utils";
|
||||||
import MsJsr233Processor from "../../../../automation/scenario/component/Jsr233Processor";
|
import MsJsr233Processor from "../../../../automation/scenario/component/Jsr233Processor";
|
||||||
import MsJmxStep from "../../step/JmxStep";
|
import MsJmxStep from "../../step/JmxStep";
|
||||||
|
@ -148,6 +148,10 @@ export default {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
isCase: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
isScenario: {
|
isScenario: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
|
@ -177,12 +181,24 @@ export default {
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
},
|
},
|
||||||
|
'$store.state.useEnvironment': function () {
|
||||||
|
if (!this.isScenario) {
|
||||||
|
this.request.environmentId = this.$store.state.useEnvironment;
|
||||||
|
this.getEnvironments();
|
||||||
|
}
|
||||||
|
},
|
||||||
'$store.state.scenarioEnvMap': {
|
'$store.state.scenarioEnvMap': {
|
||||||
handler(v) {
|
handler(v) {
|
||||||
this.getEnvironments();
|
this.getEnvironments();
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
}
|
},
|
||||||
|
'request.refEevMap': {
|
||||||
|
handler(v) {
|
||||||
|
this.getEnvironments();
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getEnvironments();
|
this.getEnvironments();
|
||||||
|
@ -265,9 +281,10 @@ export default {
|
||||||
},
|
},
|
||||||
getEnvironments() {
|
getEnvironments() {
|
||||||
let envId = "";
|
let envId = "";
|
||||||
|
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||||
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
|
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
|
||||||
&& this.$store.state.scenarioEnvMap.has(this.projectId)) {
|
&& this.$store.state.scenarioEnvMap.has(id)) {
|
||||||
envId = this.$store.state.scenarioEnvMap.get(this.projectId);
|
envId = this.$store.state.scenarioEnvMap.get(id);
|
||||||
}
|
}
|
||||||
if (this.request.referenced === 'Created' && this.isScenario && !this.request.isRefEnvironment) {
|
if (this.request.referenced === 'Created' && this.isScenario && !this.request.isRefEnvironment) {
|
||||||
this.itselfEnvironment();
|
this.itselfEnvironment();
|
||||||
|
@ -277,8 +294,18 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.environments = [];
|
this.environments = [];
|
||||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
// 场景开启自身环境
|
||||||
|
if (this.request.environmentEnable && this.request.refEevMap) {
|
||||||
|
let obj = Object.prototype.toString.call(this.request.refEevMap).match(/\[object (\w+)\]/)[1].toLowerCase();
|
||||||
|
if (obj !== 'object' && obj !== "map") {
|
||||||
|
this.request.refEevMap = objToStrMap(JSON.parse(this.request.refEevMap));
|
||||||
|
} else if (obj === 'object' && obj !== "map") {
|
||||||
|
this.request.refEevMap = objToStrMap(this.request.refEevMap);
|
||||||
|
}
|
||||||
|
if (this.request.refEevMap instanceof Map && this.request.refEevMap.has(id)) {
|
||||||
|
envId = this.request.refEevMap.get(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
let targetDataSourceName = "";
|
let targetDataSourceName = "";
|
||||||
let currentEnvironment = {};
|
let currentEnvironment = {};
|
||||||
this.result = this.$get('/api/environment/list/' + id, response => {
|
this.result = this.$get('/api/environment/list/' + id, response => {
|
||||||
|
@ -297,8 +324,10 @@ export default {
|
||||||
}
|
}
|
||||||
if (envId && environment.id === envId) {
|
if (envId && environment.id === envId) {
|
||||||
currentEnvironment = environment;
|
currentEnvironment = environment;
|
||||||
|
if (!this.isCase) {
|
||||||
this.environments = [currentEnvironment];
|
this.environments = [currentEnvironment];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.initDataSource(envId, currentEnvironment, targetDataSourceName);
|
this.initDataSource(envId, currentEnvironment, targetDataSourceName);
|
||||||
});
|
});
|
||||||
|
@ -319,7 +348,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let flag = false;
|
let flag = false;
|
||||||
if (currentEnvironment.config && currentEnvironment.config.databaseConfigs) {
|
if (currentEnvironment && currentEnvironment.config && currentEnvironment.config.databaseConfigs) {
|
||||||
currentEnvironment.config.databaseConfigs.forEach(item => {
|
currentEnvironment.config.databaseConfigs.forEach(item => {
|
||||||
if (item.id === this.request.dataSourceId) {
|
if (item.id === this.request.dataSourceId) {
|
||||||
flag = true;
|
flag = true;
|
||||||
|
|
|
@ -137,6 +137,10 @@ export default {
|
||||||
tabType: String,
|
tabType: String,
|
||||||
response: {},
|
response: {},
|
||||||
apiId: String,
|
apiId: String,
|
||||||
|
isScenario: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
showScript: {
|
showScript: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
|
|
Loading…
Reference in New Issue