fix(接口自动化): 跨项目添加场景兼容历史数据

This commit is contained in:
shiziyuan9527 2021-02-25 14:37:08 +08:00
parent 6417a131b0
commit c9e4e32fca
2 changed files with 15 additions and 2 deletions

View File

@ -15,6 +15,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiScenarioWithBLOBs; import io.metersphere.base.domain.ApiScenarioWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.SessionUtils;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -93,7 +94,14 @@ public class MsScenario extends MsTestElement {
config.setStep(this.getName()); config.setStep(this.getName());
config.setStepType("SCENARIO"); config.setStepType("SCENARIO");
config.setEnableCookieShare(enableCookieShare); config.setEnableCookieShare(enableCookieShare);
Map<String,EnvironmentConfig> envConfig = new HashMap<>(); Map<String,EnvironmentConfig> envConfig = new HashMap<>(16);
// 兼容历史数据
if (environmentMap == null || environmentMap.isEmpty()) {
environmentMap = new HashMap<>(16);
if (StringUtils.isNotBlank(environmentId)) {
environmentMap.put(SessionUtils.getCurrentProjectId(), environmentId);
}
}
if (environmentMap != null && !environmentMap.isEmpty()) { if (environmentMap != null && !environmentMap.isEmpty()) {
environmentMap.keySet().forEach(projectId -> { environmentMap.keySet().forEach(projectId -> {
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);

View File

@ -922,7 +922,12 @@ export default {
let obj = JSON.parse(response.data.scenarioDefinition); let obj = JSON.parse(response.data.scenarioDefinition);
if (obj) { if (obj) {
this.currentEnvironmentId = obj.environmentId; this.currentEnvironmentId = obj.environmentId;
if (obj.environmentMap) {
this.projectEnvMap = this.objToStrMap(obj.environmentMap); this.projectEnvMap = this.objToStrMap(obj.environmentMap);
} else {
//
this.projectEnvMap.set(getCurrentProjectID(), obj.environmentId);
}
this.currentScenario.variables = []; this.currentScenario.variables = [];
let index = 1; let index = 1;
if (obj.variables) { if (obj.variables) {