fix(接口测试): 修复历史数据导致请求路径错误问题

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2023-12-27 15:50:55 +08:00 committed by Craftsman
parent 7ab9c9d628
commit 4befeadbcf
2 changed files with 18 additions and 10 deletions

View File

@ -36,6 +36,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
@ -114,6 +115,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
hashTree = this.getHashTree();
}
if (StringUtils.equalsAnyIgnoreCase(this.getReferenced(),
MsTestElementConstants.REF.name(), MsTestElementConstants.COPY.name())
|| BooleanUtils.isTrue(this.isRefEnvironment)) {
this.setUrl(null);
}
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
sampler.setEnabled(this.isEnable());
sampler.setName(this.getName());
@ -397,17 +403,19 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setProperty(HTTPSamplerBase.PATH, path);
}
} else {
String envPath;
String envPath = this.path;
try {
URL urlObject = new URL(url);
if (url.contains("${")) {
envPath = url;
} else {
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8));
envPath = urlObject.getPath();
sampler.setPort(urlObject.getPort());
if (StringUtils.isNotBlank(url)) {
URL urlObject = new URL(url);
if (url.contains("${")) {
envPath = url;
} else {
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8));
envPath = urlObject.getPath();
sampler.setPort(urlObject.getPort());
}
sampler.setProtocol(urlObject.getProtocol());
}
sampler.setProtocol(urlObject.getProtocol());
} catch (Exception e) {
envPath = url == null ? "" : url;
}

View File

@ -1,5 +1,5 @@
package io.metersphere.commons.constants;
public enum MsTestElementConstants {
LoopController, SCENARIO, REF, Deleted, TransactionController
LoopController, SCENARIO, REF, COPY, Deleted, TransactionController
}