fix(测试跟踪): 测试计划关联场景时环境设置问题

This commit is contained in:
shiziyuan9527 2021-04-09 16:11:05 +08:00 committed by 刘瑞斌
parent 611aa96b81
commit 65a21d5719
6 changed files with 54 additions and 18 deletions

View File

@ -97,7 +97,7 @@ public class ApiAutomationController {
} }
@GetMapping("/getApiScenario/{id}") @GetMapping("/getApiScenario/{id}")
public ApiScenarioDTO getScenarioDefinition(@PathVariable String id) { public ApiScenarioWithBLOBs getScenarioDefinition(@PathVariable String id) {
return apiAutomationService.getApiScenario(id); return apiAutomationService.getApiScenario(id);
} }
@ -106,6 +106,11 @@ public class ApiAutomationController {
return apiAutomationService.getApiScenarioEnv(request.getDefinition()); return apiAutomationService.getApiScenarioEnv(request.getDefinition());
} }
@GetMapping("/getApiScenarioProjectId/{id}")
public ScenarioEnv getApiScenarioProjectId(@PathVariable String id) {
return apiAutomationService.getApiScenarioProjectId(id);
}
@PostMapping("/getApiScenarios") @PostMapping("/getApiScenarios")
public List<ApiScenarioWithBLOBs> getApiScenarios(@RequestBody List<String> ids) { public List<ApiScenarioWithBLOBs> getApiScenarios(@RequestBody List<String> ids) {
return apiAutomationService.getApiScenarios(ids); return apiAutomationService.getApiScenarios(ids);

View File

@ -28,6 +28,7 @@ import org.apache.jorphan.collections.HashTree;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -134,7 +135,17 @@ public class MsHTTPSamplerProxy extends MsTestElement {
this.setProjectId(getParentProjectId()); this.setProjectId(getParentProjectId());
} else { } else {
// 1.8 之前 数据 // 1.8 之前 数据
if (config.getConfig() != null) {
if (config.getConfig().containsKey("historyProjectID")) {
this.setProjectId("historyProjectID"); this.setProjectId("historyProjectID");
} else {
// 测试计划执行
Iterator<String> it = config.getConfig().keySet().iterator();
if (it.hasNext()) {
this.setProjectId(it.next());
}
}
}
} }
// 添加环境中的公共变量 // 添加环境中的公共变量

View File

@ -361,15 +361,8 @@ public class ApiAutomationService {
} }
} }
public ApiScenarioDTO getApiScenario(String id) { public ApiScenarioWithBLOBs getApiScenario(String id) {
ApiScenarioDTO apiScenarioDTO = new ApiScenarioDTO(); return apiScenarioMapper.selectByPrimaryKey(id);
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(id);
if (scenarioWithBLOBs != null) {
BeanUtils.copyBean(apiScenarioDTO, scenarioWithBLOBs);
setApiScenarioProjectIds(apiScenarioDTO);
return apiScenarioDTO;
}
return null;
} }
public ScenarioEnv getApiScenarioEnv(String definition) { public ScenarioEnv getApiScenarioEnv(String definition) {
@ -408,7 +401,7 @@ public class ApiAutomationService {
} }
} else if (StringUtils.equals(tr.getType(), "scenario")) { } else if (StringUtils.equals(tr.getType(), "scenario")) {
if (tr.isEnable()) { if (tr.isEnable()) {
ApiScenarioDTO apiScenario = getApiScenario(tr.getId()); ApiScenarioWithBLOBs apiScenario = getApiScenario(tr.getId());
env.getProjectIds().add(apiScenario.getProjectId()); env.getProjectIds().add(apiScenario.getProjectId());
String scenarioDefinition = apiScenario.getScenarioDefinition(); String scenarioDefinition = apiScenario.getScenarioDefinition();
JSONObject element1 = JSON.parseObject(scenarioDefinition); JSONObject element1 = JSON.parseObject(scenarioDefinition);
@ -433,7 +426,9 @@ public class ApiAutomationService {
if (!tr.isEnable()) { if (!tr.isEnable()) {
continue; continue;
} }
if (StringUtils.equals(tr.getType(), "scenario")) {
env.getProjectIds().add(tr.getProjectId()); env.getProjectIds().add(tr.getProjectId());
}
if (CollectionUtils.isNotEmpty(tr.getHashTree())) { if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
getHashTree(tr.getHashTree(), env); getHashTree(tr.getHashTree(), env);
} }
@ -477,7 +472,7 @@ public class ApiAutomationService {
} }
} else if (StringUtils.equals(tr.getType(), "scenario")) { } else if (StringUtils.equals(tr.getType(), "scenario")) {
if (tr.isEnable()) { if (tr.isEnable()) {
ApiScenarioDTO apiScenario = getApiScenario(tr.getId()); ApiScenarioWithBLOBs apiScenario = getApiScenario(tr.getId());
env.getProjectIds().add(apiScenario.getProjectId()); env.getProjectIds().add(apiScenario.getProjectId());
String scenarioDefinition = apiScenario.getScenarioDefinition(); String scenarioDefinition = apiScenario.getScenarioDefinition();
JSONObject element1 = JSON.parseObject(scenarioDefinition); JSONObject element1 = JSON.parseObject(scenarioDefinition);
@ -502,7 +497,9 @@ public class ApiAutomationService {
if (!tr.isEnable()) { if (!tr.isEnable()) {
continue; continue;
} }
if (StringUtils.equals(tr.getType(), "scenario")) {
env.getProjectIds().add(tr.getProjectId()); env.getProjectIds().add(tr.getProjectId());
}
if (CollectionUtils.isNotEmpty(tr.getHashTree())) { if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
getHashTree(tr.getHashTree(), env); getHashTree(tr.getHashTree(), env);
} }
@ -1330,4 +1327,24 @@ public class ApiAutomationService {
}catch (Exception e){ }catch (Exception e){
} }
} }
public ScenarioEnv getApiScenarioProjectId(String id) {
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id);
ScenarioEnv scenarioEnv = new ScenarioEnv();
if (scenario == null) {
return scenarioEnv;
}
String definition = scenario.getScenarioDefinition();
if (StringUtils.isBlank(definition)) {
return scenarioEnv;
}
scenarioEnv = getApiScenarioEnv(definition);
scenarioEnv.getProjectIds().remove(null);
if (scenarioEnv.getProjectIds().isEmpty()) {
scenarioEnv.getProjectIds().add(scenario.getProjectId());
}
return scenarioEnv;
}
} }

View File

@ -235,8 +235,9 @@ export default {
}, },
setScenarioSelectRows(rows) { setScenarioSelectRows(rows) {
this.projectIds.clear(); this.projectIds.clear();
this.map.clear();
rows.forEach(row => { rows.forEach(row => {
this.result = this.$get('/api/automation/getApiScenario/' + row.id, res => { this.result = this.$get('/api/automation/getApiScenarioProjectId/' + row.id, res => {
let data = res.data; let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d)); data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds); this.map.set(row.id, data.projectIds);

View File

@ -130,9 +130,10 @@
this.$set(this.form, "value", ""); this.$set(this.form, "value", "");
if (val === 'projectEnv' && this.isScenario !== '') { if (val === 'projectEnv' && this.isScenario !== '') {
this.projectIds.clear(); this.projectIds.clear();
this.map.clear();
this.selectRows.forEach(row => { this.selectRows.forEach(row => {
let id = this.isScenario === 'scenario' ? row.id : row.caseId; let id = this.isScenario === 'scenario' ? row.id : row.caseId;
this.result = this.$get('/api/automation/getApiScenario/' + id, res => { this.result = this.$get('/api/automation/getApiScenarioProjectId/' + id, res => {
let data = res.data; let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d)); data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds); this.map.set(row.id, data.projectIds);

View File

@ -168,8 +168,9 @@
}, },
initProjectIds() { initProjectIds() {
this.projectIds.clear(); this.projectIds.clear();
this.map.clear();
this.selectRows.forEach(row => { this.selectRows.forEach(row => {
this.result = this.$get('/api/automation/getApiScenario/' + row.id, res => { this.result = this.$get('/api/automation/getApiScenarioProjectId/' + row.id, res => {
let data = res.data; let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d)); data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds); this.map.set(row.id, data.projectIds);