fix(接口测试): 修复tcp协议批量执行环境选择错误问题

--bug=1013593 --user=赵勇 【接口测试】TCP请求CASE,批量执行,没有带上环境信息 https://www.tapd.cn/55049933/s/1170150
This commit is contained in:
fit2-zhao 2022-05-31 16:19:39 +08:00 committed by f2c-ci-robot[bot]
parent cda010f76f
commit d9773faeed
2 changed files with 8 additions and 3 deletions

View File

@ -159,7 +159,9 @@ public class MsTCPSampler extends MsTestElement {
} }
if (config.getConfig() == null) { if (config.getConfig() == null) {
// 单独接口执行 // 单独接口执行
this.setProjectId(config.getProjectId()); if(StringUtils.isNotEmpty(config.getProjectId())) {
this.setProjectId(config.getProjectId());
}
config.setConfig(ElementUtil.getEnvironmentConfig(StringUtils.isNotEmpty(this.getEnvironmentId()) ? this.getEnvironmentId() : useEnvironment, this.getProjectId(), this.isMockEnvironment())); config.setConfig(ElementUtil.getEnvironmentConfig(StringUtils.isNotEmpty(this.getEnvironmentId()) ? this.getEnvironmentId() : useEnvironment, this.getProjectId(), this.isMockEnvironment()));
} }
EnvironmentConfig envConfig = null; EnvironmentConfig envConfig = null;

View File

@ -215,7 +215,7 @@ public class ApiScenarioSerialService {
group.setName(runRequest.getReportId()); group.setName(runRequest.getReportId());
group.setProjectId(caseWithBLOBs.getProjectId()); group.setProjectId(caseWithBLOBs.getProjectId());
MsTestElement testElement = parse(data, testId, envId); MsTestElement testElement = parse(data, testId, envId, caseWithBLOBs.getProjectId());
group.setHashTree(new LinkedList<>()); group.setHashTree(new LinkedList<>());
group.getHashTree().add(testElement); group.getHashTree().add(testElement);
testPlan.getHashTree().add(group); testPlan.getHashTree().add(group);
@ -235,7 +235,7 @@ public class ApiScenarioSerialService {
return null; return null;
} }
private MsTestElement parse(String api, String planId, String envId) { private MsTestElement parse(String api, String planId, String envId, String projectId) {
try { try {
JSONObject element = JSON.parseObject(api, Feature.DisableSpecialKeyDetect); JSONObject element = JSON.parseObject(api, Feature.DisableSpecialKeyDetect);
ElementUtil.dataFormatting(element); ElementUtil.dataFormatting(element);
@ -258,6 +258,9 @@ public class ApiScenarioSerialService {
} }
if (element.getString("type").equals("TCPSampler")) { if (element.getString("type").equals("TCPSampler")) {
MsTCPSampler msTCPSampler = JSON.parseObject(api, MsTCPSampler.class, Feature.DisableSpecialKeyDetect); MsTCPSampler msTCPSampler = JSON.parseObject(api, MsTCPSampler.class, Feature.DisableSpecialKeyDetect);
if (StringUtils.isEmpty(msTCPSampler.getProjectId())) {
msTCPSampler.setProjectId(projectId);
}
if (StringUtils.isNotEmpty(envId)) { if (StringUtils.isNotEmpty(envId)) {
msTCPSampler.setUseEnvironment(envId); msTCPSampler.setUseEnvironment(envId);
} }