fix(接口自动化): 修复多层启用环境问题
--bug=1007851 --user=赵勇 【接口测试】引用的场景,启用场景环境 功能没有生效 https://www.tapd.cn/55049933/s/1068272
This commit is contained in:
parent
b96b57afd6
commit
905c3ad909
|
@ -103,7 +103,7 @@ public class MsScenario extends MsTestElement {
|
||||||
ElementUtil.dataFormatting(element.getJSONArray("hashTree"));
|
ElementUtil.dataFormatting(element.getJSONArray("hashTree"));
|
||||||
this.setName(scenario.getName());
|
this.setName(scenario.getName());
|
||||||
this.setProjectId(scenario.getProjectId());
|
this.setProjectId(scenario.getProjectId());
|
||||||
hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {
|
LinkedList<MsTestElement> sourceHashTree = mapper.readValue(element.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {
|
||||||
});
|
});
|
||||||
// 场景变量
|
// 场景变量
|
||||||
if (StringUtils.isNotEmpty(element.getString("variables"))) {
|
if (StringUtils.isNotEmpty(element.getString("variables"))) {
|
||||||
|
@ -119,7 +119,10 @@ public class MsScenario extends MsTestElement {
|
||||||
});
|
});
|
||||||
this.setHeaders(headers);
|
this.setHeaders(headers);
|
||||||
}
|
}
|
||||||
|
if (element.get("environmentMap") != null) {
|
||||||
|
this.setEnvironmentMap((Map) element.get("environmentMap"));
|
||||||
|
}
|
||||||
|
this.setHashTree(sourceHashTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -139,18 +142,7 @@ public class MsScenario extends MsTestElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.environmentMap != null && !this.environmentMap.isEmpty()) {
|
if (this.environmentMap != null && !this.environmentMap.isEmpty()) {
|
||||||
this.environmentMap.keySet().forEach(projectId -> {
|
this.setEnv(this.environmentMap, envConfig);
|
||||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
|
||||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(this.environmentMap.get(projectId));
|
|
||||||
if (environment != null && environment.getConfig() != null) {
|
|
||||||
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
|
||||||
env.setApiEnvironmentid(environment.getId());
|
|
||||||
envConfig.put(projectId, env);
|
|
||||||
if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) {
|
|
||||||
this.setMockEnvironment(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
config.setConfig(envConfig);
|
config.setConfig(envConfig);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -173,28 +165,15 @@ public class MsScenario extends MsTestElement {
|
||||||
ElementUtil.addCounter(tree, variables);
|
ElementUtil.addCounter(tree, variables);
|
||||||
ElementUtil.addRandom(tree, variables);
|
ElementUtil.addRandom(tree, variables);
|
||||||
if (CollectionUtils.isNotEmpty(this.headers)) {
|
if (CollectionUtils.isNotEmpty(this.headers)) {
|
||||||
//setHeader(tree, this.headers);
|
|
||||||
config.setHeaders(this.headers);
|
config.setHeaders(this.headers);
|
||||||
}
|
}
|
||||||
ParameterConfig newConfig = new ParameterConfig();
|
ParameterConfig newConfig = new ParameterConfig();
|
||||||
if (this.isEnvironmentEnable() && this.environmentMap != null && !this.environmentMap.isEmpty()) {
|
if (this.isEnvironmentEnable() && this.environmentMap != null && !this.environmentMap.isEmpty()) {
|
||||||
environmentMap.keySet().forEach(projectId -> {
|
this.setEnv(this.environmentMap, envConfig);
|
||||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
|
||||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(this.environmentMap.get(projectId));
|
|
||||||
if (environment != null && environment.getConfig() != null) {
|
|
||||||
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
|
||||||
env.setApiEnvironmentid(environment.getId());
|
|
||||||
envConfig.put(projectId, env);
|
|
||||||
if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) {
|
|
||||||
this.setMockEnvironment(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
newConfig.setConfig(envConfig);
|
newConfig.setConfig(envConfig);
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
for (MsTestElement el : hashTree) {
|
for (MsTestElement el : hashTree) {
|
||||||
// 给所有孩子加一个父亲标志
|
|
||||||
el.setParent(this);
|
el.setParent(this);
|
||||||
el.setMockEnvironment(this.isMockEnvironment());
|
el.setMockEnvironment(this.isMockEnvironment());
|
||||||
if (this.isEnvironmentEnable()) {
|
if (this.isEnvironmentEnable()) {
|
||||||
|
@ -263,5 +242,18 @@ public class MsScenario extends MsTestElement {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setEnv(Map<String, String> environmentMap, Map<String, EnvironmentConfig> envConfig) {
|
||||||
|
for (String projectId : environmentMap.keySet()) {
|
||||||
|
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||||
|
ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentMap.get(projectId));
|
||||||
|
if (environment != null && StringUtils.isNotEmpty(environment.getConfig())) {
|
||||||
|
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
||||||
|
env.setApiEnvironmentid(environment.getId());
|
||||||
|
envConfig.put(projectId, env);
|
||||||
|
if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) {
|
||||||
|
this.setMockEnvironment(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -425,7 +425,7 @@ export default {
|
||||||
if (targetHashTree) {
|
if (targetHashTree) {
|
||||||
targetHashTree.forEach(item => {
|
targetHashTree.forEach(item => {
|
||||||
item.disabled = true;
|
item.disabled = true;
|
||||||
})
|
});
|
||||||
this.request.hashTree = targetHashTree;
|
this.request.hashTree = targetHashTree;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue