fix(接口定义): 修复新功能导致执行问题

This commit is contained in:
fit2-zhao 2021-02-25 18:25:38 +08:00
parent 46bff0e294
commit 9b2b7e7f63
5 changed files with 22 additions and 12 deletions

View File

@ -49,7 +49,6 @@ import org.apache.jorphan.collections.ListedHashTree;
import java.io.ByteArrayOutputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@ -167,7 +166,7 @@ public abstract class MsTestElement {
}
public Arguments addArguments(ParameterConfig config) {
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) {
Arguments arguments = new Arguments();
arguments.setEnabled(true);

View File

@ -12,7 +12,7 @@ public class ParameterConfig {
/**
* 环境配置
*/
private Map<String,EnvironmentConfig> config;
private Map<String, EnvironmentConfig> config;
/**
* 公共场景参数
*/
@ -26,4 +26,8 @@ public class ParameterConfig {
* 是否是导入/导出操作
*/
private boolean isOperating;
/**
* 项目ID支持单接口执行
*/
private String projectId;
}

View File

@ -8,6 +8,7 @@ import io.metersphere.api.dto.definition.request.auth.MsAuthManager;
import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager;
import io.metersphere.api.dto.scenario.Body;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.ScriptEngineUtils;
@ -116,7 +117,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (config != null && config.getConfig() != null) {
config.setConfig(config.getConfig());
} else {
// config.setConfig(getEnvironmentConfig(useEnvironment));
// 单独接口执行
this.setProjectId(config.getProjectId());
Map<String, EnvironmentConfig> map = new HashMap<>();
map.put(this.getProjectId(), getEnvironmentConfig(useEnvironment));
config.setConfig(map);
}
// 添加环境中的公共变量
@ -125,7 +130,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
tree.add(arguments);
}
try {
if (config != null && config.getConfig() != null) {
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null) {
String url = config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol() + "://" + config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket();
// 补充如果是完整URL 则用自身URL
boolean isUrl = false;
@ -214,13 +219,13 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
// 通用请求Headers
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()).getHttpConfig() != null
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getHttpConfig() != null
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getHttpConfig().getHeaders())) {
setHeader(httpSamplerTree, config.getConfig().get(this.getProjectId()).getHttpConfig().getHeaders());
}
//判断是否要开启DNS
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
&& config.getConfig().get(this.getProjectId()).getCommonConfig().isEnableHost()) {
MsDNSCacheManager.addEnvironmentVariables(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId()));
MsDNSCacheManager.addEnvironmentDNS(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId()));

View File

@ -9,6 +9,8 @@ import io.metersphere.api.dto.automation.ReferenceDTO;
import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.definition.parse.ApiDefinitionImport;
import io.metersphere.api.dto.definition.parse.ApiDefinitionImportParserFactory;
import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.definition.request.ScheduleInfoSwaggerUrlRequest;
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
import io.metersphere.api.dto.scenario.request.RequestType;
@ -18,7 +20,6 @@ import io.metersphere.api.jmeter.JMeterService;
import io.metersphere.api.jmeter.RequestResult;
import io.metersphere.api.jmeter.TestResult;
import io.metersphere.api.parse.ApiImportParser;
import io.metersphere.api.dto.definition.parse.ApiDefinitionImportParserFactory;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.*;
@ -426,8 +427,9 @@ public class ApiDefinitionService {
public String run(RunDefinitionRequest request, List<MultipartFile> bodyFiles) {
List<String> bodyUploadIds = new ArrayList<>(request.getBodyUploadIds());
FileUtils.createBodyFiles(bodyUploadIds, bodyFiles);
HashTree hashTree = request.getTestElement().generateHashTree();
ParameterConfig config = new ParameterConfig();
config.setProjectId(request.getProjectId());
HashTree hashTree = request.getTestElement().generateHashTree(config);
String runMode = ApiRunMode.DEFINITION.name();
if (StringUtils.isNotBlank(request.getType()) && StringUtils.equals(request.getType(), ApiRunMode.API_PLAN.name())) {
runMode = ApiRunMode.API_PLAN.name();

View File

@ -2,7 +2,7 @@
<span></span>
</template>
<script>
import {getUUID, getBodyUploadFiles} from "@/common/js/utils";
import {getUUID, getBodyUploadFiles,getCurrentProjectID} from "@/common/js/utils";
import ThreadGroup from "./jmeter/components/thread-group";
import TestPlan from "./jmeter/components/test-plan";
@ -64,7 +64,7 @@
this.runData.forEach(item => {
threadGroup.hashTree.push(item);
})
let reqObj = {id: this.reportId, testElement: testPlan, type: this.type};
let reqObj = {id: this.reportId, testElement: testPlan, type: this.type,projectId:getCurrentProjectID()};
let bodyFiles = getBodyUploadFiles(reqObj, this.runData);
let url = "";
if (this.debug) {