Merge branch 'v1.8' of github.com:metersphere/metersphere into v1.8

This commit is contained in:
chenjianxing 2021-03-31 13:44:02 +08:00
commit 5dd39b60e5
6 changed files with 127 additions and 147 deletions

View File

@ -214,6 +214,8 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
samplerProxy.getBody().setKvs(keyValues); samplerProxy.getBody().setKvs(keyValues);
} }
samplerProxy.setProtocol(RequestType.HTTP); samplerProxy.setProtocol(RequestType.HTTP);
samplerProxy.setConnectTimeout(source.getConnectTimeout()+"");
samplerProxy.setResponseTimeout(source.getResponseTimeout()+"");
samplerProxy.setPort(source.getPropertyAsString("HTTPSampler.port")); samplerProxy.setPort(source.getPropertyAsString("HTTPSampler.port"));
samplerProxy.setDomain(source.getDomain()); samplerProxy.setDomain(source.getDomain());
if (source.getArguments() != null) { if (source.getArguments() != null) {
@ -239,6 +241,7 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
samplerProxy.setMethod(source.getMethod()); samplerProxy.setMethod(source.getMethod());
if (this.getUrl(source) != null) { if (this.getUrl(source) != null) {
samplerProxy.setUrl(this.getUrl(source)); samplerProxy.setUrl(this.getUrl(source));
samplerProxy.setPath(null);
} }
samplerProxy.setId(UUID.randomUUID().toString()); samplerProxy.setId(UUID.randomUUID().toString());
samplerProxy.setType("HTTPSamplerProxy"); samplerProxy.setType("HTTPSamplerProxy");

View File

@ -91,9 +91,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
@JSONField(ordinal = 36) @JSONField(ordinal = 36)
private MsAuthManager authManager; private MsAuthManager authManager;
@JSONField(ordinal = 37)
private boolean urlOrPath;
@Override @Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
// 非导出操作且不是启用状态则跳过执行 // 非导出操作且不是启用状态则跳过执行
@ -198,10 +195,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
URL urlObject = new URL(url); URL urlObject = new URL(url);
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), "UTF-8")); sampler.setDomain(URLDecoder.decode(urlObject.getHost(), "UTF-8"));
if (urlObject.getPort() > 0 && urlObject.getPort() != 10990 && StringUtils.isNotEmpty(this.getPort()) && this.getPort().startsWith("${")) { if (urlObject.getPort() > 0 && urlObject.getPort() == 10990 && StringUtils.isNotEmpty(this.getPort()) && this.getPort().startsWith("${")) {
sampler.setPort(urlObject.getPort());
} else {
sampler.setProperty("HTTPSampler.port", this.getPort()); sampler.setProperty("HTTPSampler.port", this.getPort());
} else {
sampler.setPort(urlObject.getPort());
} }
sampler.setProtocol(urlObject.getProtocol()); sampler.setProtocol(urlObject.getProtocol());
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();

View File

@ -1,30 +1,20 @@
/* //
* Licensed to the Apache Software Foundation (ASF) under one or more // Source code recreated from a .class file by IntelliJ IDEA
* contributor license agreements. See the NOTICE file distributed with // (powered by Fernflower decompiler)
* this work for additional information regarding copyright ownership. //
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter.assertions; package org.apache.jmeter.assertions;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Predicate;
import java.io.Serializable; import java.io.Serializable;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import com.alibaba.fastjson.JSONArray; import net.minidev.json.JSONArray;
import com.alibaba.fastjson.JSONObject; import net.minidev.json.JSONObject;
import com.jayway.jsonpath.JsonPath;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.AbstractTestElement; import org.apache.jmeter.testelement.AbstractTestElement;
@ -34,12 +24,6 @@ import org.apache.oro.text.regex.Pattern;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/**
* This is main class for JSONPath Assertion which verifies assertion on
* previous sample result using JSON path expression
*
* @since 4.0
*/
public class JSONPathAssertion extends AbstractTestElement implements Serializable, Assertion, ThreadListener { public class JSONPathAssertion extends AbstractTestElement implements Serializable, Assertion, ThreadListener {
private static final Logger log = LoggerFactory.getLogger(JSONPathAssertion.class); private static final Logger log = LoggerFactory.getLogger(JSONPathAssertion.class);
private static final long serialVersionUID = 2L; private static final long serialVersionUID = 2L;
@ -49,119 +33,118 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
public static final String EXPECT_NULL = "EXPECT_NULL"; public static final String EXPECT_NULL = "EXPECT_NULL";
public static final String INVERT = "INVERT"; public static final String INVERT = "INVERT";
public static final String ISREGEX = "ISREGEX"; public static final String ISREGEX = "ISREGEX";
private static ThreadLocal<DecimalFormat> decimalFormatter = ThreadLocal.withInitial(JSONPathAssertion::createDecimalFormat);
private static ThreadLocal<DecimalFormat> decimalFormatter = public JSONPathAssertion() {
ThreadLocal.withInitial(JSONPathAssertion::createDecimalFormat); }
private static DecimalFormat createDecimalFormat() {
DecimalFormat decimalFormatter = new DecimalFormat("#.#");
decimalFormatter.setMaximumFractionDigits(340);
decimalFormatter.setMinimumFractionDigits(1);
return decimalFormatter;
}
public String getOption() { public String getOption() {
return getPropertyAsString("ASS_OPTION"); return getPropertyAsString("ASS_OPTION");
} }
private static DecimalFormat createDecimalFormat() {
DecimalFormat decimalFormatter = new DecimalFormat("#.#");
decimalFormatter.setMaximumFractionDigits(340); // java.text.DecimalFormat.DOUBLE_FRACTION_DIGITS == 340
decimalFormatter.setMinimumFractionDigits(1);
return decimalFormatter;
}
public String getJsonPath() { public String getJsonPath() {
return getPropertyAsString(JSONPATH); return this.getPropertyAsString("JSON_PATH");
} }
public void setJsonPath(String jsonPath) { public void setJsonPath(String jsonPath) {
setProperty(JSONPATH, jsonPath); this.setProperty("JSON_PATH", jsonPath);
} }
public String getExpectedValue() { public String getExpectedValue() {
return getPropertyAsString(EXPECTEDVALUE); return this.getPropertyAsString("EXPECTED_VALUE");
} }
public void setExpectedValue(String expectedValue) { public void setExpectedValue(String expectedValue) {
setProperty(EXPECTEDVALUE, expectedValue); this.setProperty("EXPECTED_VALUE", expectedValue);
} }
public void setJsonValidationBool(boolean jsonValidation) { public void setJsonValidationBool(boolean jsonValidation) {
setProperty(JSONVALIDATION, jsonValidation); this.setProperty("JSONVALIDATION", jsonValidation);
} }
public void setExpectNull(boolean val) { public void setExpectNull(boolean val) {
setProperty(EXPECT_NULL, val); this.setProperty("EXPECT_NULL", val);
} }
public boolean isExpectNull() { public boolean isExpectNull() {
return getPropertyAsBoolean(EXPECT_NULL); return this.getPropertyAsBoolean("EXPECT_NULL");
} }
public boolean isJsonValidationBool() { public boolean isJsonValidationBool() {
return getPropertyAsBoolean(JSONVALIDATION); return this.getPropertyAsBoolean("JSONVALIDATION");
} }
public void setInvert(boolean invert) { public void setInvert(boolean invert) {
setProperty(INVERT, invert); this.setProperty("INVERT", invert);
} }
public boolean isInvert() { public boolean isInvert() {
return getPropertyAsBoolean(INVERT); return this.getPropertyAsBoolean("INVERT");
} }
public void setIsRegex(boolean flag) { public void setIsRegex(boolean flag) {
setProperty(ISREGEX, flag); this.setProperty("ISREGEX", flag);
} }
public boolean isUseRegex() { public boolean isUseRegex() {
return getPropertyAsBoolean(ISREGEX, true); return this.getPropertyAsBoolean("ISREGEX", true);
} }
private void doAssert(String jsonString) { private void doAssert(String jsonString) {
Object value = JsonPath.read(jsonString, getJsonPath()); Object value = JsonPath.read(jsonString, this.getJsonPath(), new Predicate[0]);
if (this.isJsonValidationBool()) {
if (!isJsonValidationBool()) { if (value instanceof JSONArray) {
return; if (this.arrayMatched((JSONArray) value)) {
} return;
}
if (value instanceof JSONArray) { } else if (this.isExpectNull() && value == null || this.isEquals(value)) {
if (arrayMatched((JSONArray) value)) {
return; return;
} }
} else {
if ((isExpectNull() && value == null)
|| isEquals(value)) {
return;
}
}
if (isExpectNull()) { if (this.isExpectNull()) {
throw new IllegalStateException(String.format("Value expected to be null, but found '%s'", value)); throw new IllegalStateException(String.format("Value expected to be null, but found '%s'", value));
} else {
String msg;
if (isUseRegex()) {
msg = "Value expected to match regexp '%s', but it did not match: '%s'";
} else { } else {
msg = "Value expected to be '%s', but found '%s'"; String msg;
if (this.isUseRegex()) {
msg = "Value expected to match regexp '%s', but it did not match: '%s'";
} else {
msg = "Value expected to be '%s', but found '%s'";
}
throw new IllegalStateException(String.format(msg, this.getExpectedValue(), objectToString(value)));
} }
throw new IllegalStateException(String.format(msg, getExpectedValue(), objectToString(value)));
} }
} }
private boolean arrayMatched(JSONArray value) { private boolean arrayMatched(JSONArray value) {
if (value.isEmpty() && "[]".equals(getExpectedValue())) { if (value.isEmpty() && "[]".equals(this.getExpectedValue())) {
return true; return true;
} } else {
Object[] var2 = value.toArray();
int var3 = var2.length;
for (Object subj : value.toArray()) { for (int var4 = 0; var4 < var3; ++var4) {
if ((subj == null && isExpectNull()) Object subj = var2[var4];
|| isEquals(subj)) { if (subj == null && this.isExpectNull() || this.isEquals(subj)) {
return true; return true;
}
} }
}
return isEquals(value); return this.isEquals(value);
}
} }
private boolean isEquals(Object subj) { private boolean isEquals(Object subj) {
String str = objectToString(subj); String str = objectToString(subj);
if (isUseRegex()) { if (this.isUseRegex()) {
Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue()); Pattern pattern = JMeterUtils.getPatternCache().getPattern(this.getExpectedValue());
return JMeterUtils.getMatcher().matches(str, pattern); return JMeterUtils.getMatcher().matches(str, pattern);
} else { } else {
if (StringUtils.isNotEmpty(getOption())) { if (StringUtils.isNotEmpty(getOption())) {
@ -182,47 +165,46 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
} }
return refFlag; return refFlag;
} }
return str.equals(getExpectedValue()); return str.equals(this.getExpectedValue());
} }
} }
@Override
public AssertionResult getResult(SampleResult samplerResult) { public AssertionResult getResult(SampleResult samplerResult) {
AssertionResult result = new AssertionResult(getName()); AssertionResult result = new AssertionResult(this.getName());
String responseData = samplerResult.getResponseDataAsString(); String responseData = samplerResult.getResponseDataAsString();
if (responseData.isEmpty()) { if (responseData.isEmpty()) {
return result.setResultForNull(); return result.setResultForNull();
}
result.setFailure(false);
result.setFailureMessage("");
if (!isInvert()) {
try {
doAssert(responseData);
} catch (Exception e) {
log.debug("Assertion failed", e);
result.setFailure(true);
result.setFailureMessage(e.getMessage());
}
} else { } else {
try { result.setFailure(false);
doAssert(responseData); result.setFailureMessage("");
result.setFailure(true); if (!this.isInvert()) {
if (isJsonValidationBool()) { try {
if (isExpectNull()) { this.doAssert(responseData);
result.setFailureMessage("Failed that JSONPath " + getJsonPath() + " not matches null"); } catch (Exception var6) {
} else { log.debug("Assertion failed", var6);
result.setFailureMessage("Failed that JSONPath " + getJsonPath() + " not matches " + getExpectedValue()); result.setFailure(true);
} result.setFailureMessage(var6.getMessage());
} else { }
result.setFailureMessage("Failed that JSONPath not exists: " + getJsonPath()); } else {
try {
this.doAssert(responseData);
result.setFailure(true);
if (this.isJsonValidationBool()) {
if (this.isExpectNull()) {
result.setFailureMessage("Failed that JSONPath " + this.getJsonPath() + " not matches null");
} else {
result.setFailureMessage("Failed that JSONPath " + this.getJsonPath() + " not matches " + this.getExpectedValue());
}
} else {
result.setFailureMessage("Failed that JSONPath not exists: " + this.getJsonPath());
}
} catch (Exception var5) {
log.debug("Assertion failed, as expected", var5);
} }
} catch (Exception e) {
log.debug("Assertion failed, as expected", e);
} }
return result;
} }
return result;
} }
public static String objectToString(Object subj) { public static String objectToString(Object subj) {
@ -230,22 +212,19 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
if (subj == null) { if (subj == null) {
str = "null"; str = "null";
} else if (subj instanceof Map) { } else if (subj instanceof Map) {
//noinspection unchecked str = (new JSONObject((Map) subj)).toJSONString();
str = new JSONObject((Map<String, Object>) subj).toJSONString(); } else if (!(subj instanceof Double) && !(subj instanceof Float)) {
} else if (subj instanceof Double || subj instanceof Float) {
str = decimalFormatter.get().format(subj);
} else {
str = subj.toString(); str = subj.toString();
} else {
str = ((DecimalFormat) decimalFormatter.get()).format(subj);
} }
return str; return str;
} }
@Override
public void threadStarted() { public void threadStarted() {
// nothing to do on thread start
} }
@Override
public void threadFinished() { public void threadFinished() {
decimalFormatter.remove(); decimalFormatter.remove();
} }

View File

@ -54,20 +54,23 @@
methods: { methods: {
init() { init() {
this.projectIds.forEach(id => { this.projectIds.forEach(id => {
let item = {id: id, envs: [], selectEnv: ""}; const project = this.projectList.find(p => p.id === id);
this.data.push(item); if (project) {
this.result = this.$get('/api/environment/list/' + id, res => { let item = {id: id, envs: [], selectEnv: ""};
let envs = res.data; this.data.push(item);
envs.forEach(environment => { this.result = this.$get('/api/environment/list/' + id, res => {
parseEnvironment(environment); let envs = res.data;
}); envs.forEach(environment => {
// parseEnvironment(environment);
let temp = this.data.find(dt => dt.id === id); });
temp.envs = envs; //
let envId = this.envMap.get(id); let temp = this.data.find(dt => dt.id === id);
// temp.envs = envs;
temp.selectEnv = envs.filter(e => e.id === envId).length === 0 ? null : envId; let envId = this.envMap.get(id);
}) //
temp.selectEnv = envs.filter(e => e.id === envId).length === 0 ? null : envId;
})
}
}) })
}, },
open() { open() {
@ -240,13 +243,11 @@
} }
}) })
} else { } else {
// this.checkFullUrl(data);
// sign = this.isFullUrl;
sign = false; sign = false;
} }
// //
//this.checkFullUrl(data);
//sign = this.isFullUrl;
} }
if (!sign) { if (!sign) {

View File

@ -226,7 +226,7 @@
this.headers = headers; this.headers = headers;
} }
this.visible = true; this.visible = true;
this.editData = {type: "CONSTANT"}; this.editData = {type: "CONSTANT", delimiter: ","};
this.addParameters(this.editData); this.addParameters(this.editData);
this.disabled = disabled; this.disabled = disabled;
}, },

View File

@ -173,11 +173,12 @@ export default {
updateTime: row.lastModified, updateTime: row.lastModified,
}); });
} }
//
rows.forEach(row => {
this.fileList.push(row);
})
if (this.loadType === 'resource') { if (this.loadType === 'resource') {
rows.forEach(row => {
this.fileList.push(row);
})
this.$success(this.$t('test_track.case.import.success')); this.$success(this.$t('test_track.case.import.success'));
this.close(); this.close();
return; return;
@ -197,8 +198,6 @@ export default {
tg.options = {}; tg.options = {};
this.scenarios.push(tg); this.scenarios.push(tg);
}); });
let file = new File([d.jmx], d.name);
this.uploadList.push(file);
}); });
this.$emit('fileChange', this.scenarios); this.$emit('fileChange', this.scenarios);