fix(接口自动化): 修复多层启用环境问题
--bug=1007851 --user=赵勇 【接口测试】引用的场景,启用场景环境 功能没有生效 https://www.tapd.cn/55049933/s/1068272
This commit is contained in:
parent
4fefff7d11
commit
f17a37e6e9
|
@ -103,7 +103,7 @@ public class MsScenario extends MsTestElement {
|
|||
ElementUtil.dataFormatting(element.getJSONArray("hashTree"));
|
||||
this.setName(scenario.getName());
|
||||
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"))) {
|
||||
|
@ -119,7 +119,10 @@ public class MsScenario extends MsTestElement {
|
|||
});
|
||||
this.setHeaders(headers);
|
||||
}
|
||||
|
||||
if (element.get("environmentMap") != null) {
|
||||
this.setEnvironmentMap((Map) element.get("environmentMap"));
|
||||
}
|
||||
this.setHashTree(sourceHashTree);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
@ -139,18 +142,7 @@ public class MsScenario extends MsTestElement {
|
|||
}
|
||||
}
|
||||
if (this.environmentMap != null && !this.environmentMap.isEmpty()) {
|
||||
this.environmentMap.keySet().forEach(projectId -> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.setEnv(this.environmentMap, envConfig);
|
||||
config.setConfig(envConfig);
|
||||
}
|
||||
} else {
|
||||
|
@ -173,28 +165,15 @@ public class MsScenario extends MsTestElement {
|
|||
ElementUtil.addCounter(tree, variables);
|
||||
ElementUtil.addRandom(tree, variables);
|
||||
if (CollectionUtils.isNotEmpty(this.headers)) {
|
||||
//setHeader(tree, this.headers);
|
||||
config.setHeaders(this.headers);
|
||||
}
|
||||
ParameterConfig newConfig = new ParameterConfig();
|
||||
if (this.isEnvironmentEnable() && this.environmentMap != null && !this.environmentMap.isEmpty()) {
|
||||
environmentMap.keySet().forEach(projectId -> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.setEnv(this.environmentMap, envConfig);
|
||||
newConfig.setConfig(envConfig);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
for (MsTestElement el : hashTree) {
|
||||
// 给所有孩子加一个父亲标志
|
||||
el.setParent(this);
|
||||
el.setMockEnvironment(this.isMockEnvironment());
|
||||
if (this.isEnvironmentEnable()) {
|
||||
|
@ -263,5 +242,18 @@ public class MsScenario extends MsTestElement {
|
|||
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) {
|
||||
targetHashTree.forEach(item => {
|
||||
item.disabled = true;
|
||||
})
|
||||
});
|
||||
this.request.hashTree = targetHashTree;
|
||||
}
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue