Merge branch 'master' into v1.7

This commit is contained in:
BugKing 2021-01-28 15:06:03 +08:00
commit a3aa640e11
11 changed files with 82 additions and 44 deletions

View File

@ -71,6 +71,7 @@ public class MsScenario extends MsTestElement {
ex.printStackTrace();
}
}
config.setStep(this.name);
config.setStepType("SCENARIO");
config.setEnableCookieShare(enableCookieShare);
@ -91,6 +92,8 @@ public class MsScenario extends MsTestElement {
this.addRandom(tree, variables);
if (CollectionUtils.isNotEmpty(hashTree)) {
for (MsTestElement el : hashTree) {
// 给所有孩子加一个父亲标志
el.setParent(this);
el.toHashTree(tree, el.getHashTree(), config);
}
}

View File

@ -29,10 +29,13 @@ import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.LoopConstants;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.config.CSVDataSet;
import org.apache.jmeter.config.RandomVariableConfig;
@ -96,7 +99,10 @@ public abstract class MsTestElement {
@JSONField(ordinal = 10)
private LinkedList<MsTestElement> hashTree;
private MsTestElement parent;
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
// 公共环境逐层传递如果自身有环境 以自身引用环境为准否则以公共环境作为请求环境
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
for (MsTestElement el : hashTree) {
@ -173,7 +179,7 @@ public abstract class MsTestElement {
return null;
}
protected void addCsvDataSet(HashTree tree,List<ScenarioVariable> variables) {
protected void addCsvDataSet(HashTree tree, List<ScenarioVariable> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
@ -197,7 +203,7 @@ public abstract class MsTestElement {
}
}
protected void addCounter(HashTree tree,List<ScenarioVariable> variables) {
protected void addCounter(HashTree tree, List<ScenarioVariable> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCounterValid).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
@ -219,7 +225,7 @@ public abstract class MsTestElement {
}
}
protected void addRandom(HashTree tree,List<ScenarioVariable> variables) {
protected void addRandom(HashTree tree, List<ScenarioVariable> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isRandom).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
@ -240,6 +246,44 @@ public abstract class MsTestElement {
}
}
public MsTestElement getRootParent(MsTestElement element) {
if (element.getParent() == null) {
return element;
}
if (MsTestElementConstants.LoopController.name().equals(element.getType())) {
return element;
}
return getRootParent(element.getParent());
}
protected String getParentName(MsTestElement element, ParameterConfig config) {
if (element != null) {
MsTestElement parent = this.getRootParent(element);
if (parent != null) {
if (MsTestElementConstants.LoopController.name().equals(parent.getType())) {
MsLoopController loopController = (MsLoopController) parent;
if (StringUtils.equals(loopController.getLoopType(), LoopConstants.WHILE.name()) && loopController.getWhileController() != null) {
return "While 循环-" + "${LoopCounterConfigXXX}";
}
if (StringUtils.equals(loopController.getLoopType(), LoopConstants.FOREACH.name()) && loopController.getForEachController() != null) {
return "ForEach 循环-" + "${LoopCounterConfigXXX}";
}
if (StringUtils.equals(loopController.getLoopType(), LoopConstants.LOOP_COUNT.name()) && loopController.getCountController() != null) {
return "次数循环-" + "${LoopCounterConfigXXX}";
}
}
return parent.getName();
}
return element.getName();
} else if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if (MsTestElementConstants.SCENARIO.name().equals(config.getStepType())) {
return config.getStep();
} else {
return config.getStep() + "-" + "${LoopCounterConfigXXX}";
}
}
return "";
}
}

View File

@ -32,6 +32,8 @@ public class MsIfController extends MsTestElement {
final HashTree groupTree = tree.add(ifController());
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {
// 给所有孩子加一个父亲标志
el.setParent(this);
el.toHashTree(groupTree, el.getHashTree(), config);
});
}

View File

@ -83,6 +83,8 @@ public class MsLoopController extends MsTestElement {
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {
// 给所有孩子加一个父亲标志
el.setParent(this);
el.toHashTree(groupTree, el.getHashTree(), config);
});
}

View File

@ -39,12 +39,9 @@ public class MsJSR223Processor extends MsTestElement {
} else {
processor.setName("JSR223Processor");
}
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
processor.setName(this.getName() + "<->" + config.getStep());
} else {
processor.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}");
}
String name = this.getParentName(this.getParent(), config);
if (StringUtils.isNotEmpty(name)) {
processor.setName(this.getName() + "<->" + name);
}
processor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName());
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));

View File

@ -12,6 +12,7 @@ import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConfigCenter;
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConsumerAndService;
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.commons.constants.MsTestElementConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
@ -62,7 +63,7 @@ public class MsDubboSampler extends MsTestElement {
if (this.getReferenced() != null && "Deleted".equals(this.getReferenced())) {
return;
}
if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
this.getRefElement(this);
}
@ -77,12 +78,9 @@ public class MsDubboSampler extends MsTestElement {
private DubboSample dubboSample(ParameterConfig config) {
DubboSample sampler = new DubboSample();
sampler.setName(this.getName());
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
sampler.setName(this.getName() + "<->" + config.getStep());
} else {
sampler.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}");
}
String name = this.getParentName(this.getParent(), config);
if (StringUtils.isNotEmpty(name)) {
sampler.setName(this.getName() + "<->" + name);
}
sampler.setProperty(TestElement.TEST_CLASS, DubboSample.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));

View File

@ -7,6 +7,7 @@ import io.metersphere.api.dto.definition.request.ParameterConfig;
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.commons.constants.MsTestElementConstants;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.ScriptEngineUtils;
import lombok.Data;
@ -91,20 +92,16 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (!this.isEnable()) {
return;
}
if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
this.getRefElement(this);
}
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
sampler.setEnabled(true);
sampler.setName(this.getName());
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
sampler.setName(this.getName() + "<->" + config.getStep());
} else {
sampler.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}");
}
String name = this.getParentName(this.getParent(), config);
if (StringUtils.isNotEmpty(name)) {
sampler.setName(this.getName() + "<->" + name);
}
sampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
sampler.setMethod(this.getMethod());

View File

@ -10,6 +10,7 @@ import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
import lombok.Data;
@ -57,7 +58,7 @@ public class MsJDBCSampler extends MsTestElement {
if (!this.isEnable()) {
return;
}
if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
this.getRefElement(this);
}
if (StringUtils.isNotEmpty(dataSourceId)) {
@ -110,12 +111,9 @@ public class MsJDBCSampler extends MsTestElement {
private JDBCSampler jdbcSampler(ParameterConfig config) {
JDBCSampler sampler = new JDBCSampler();
sampler.setName(this.getName());
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
sampler.setName(this.getName() + "<->" + config.getStep());
} else {
sampler.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}");
}
String name = this.getParentName(this.getParent(), config);
if (StringUtils.isNotEmpty(name)) {
sampler.setName(this.getName() + "<->" + name);
}
sampler.setProperty(TestElement.TEST_CLASS, JDBCSampler.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));

View File

@ -7,6 +7,7 @@ import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.commons.constants.MsTestElementConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
@ -73,7 +74,7 @@ public class MsTCPSampler extends MsTestElement {
if (!this.isEnable()) {
return;
}
if (this.getReferenced() != null && this.getReferenced().equals("REF")) {
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
this.getRefElement(this);
}
config.setConfig(getEnvironmentConfig(useEnvironment));
@ -102,12 +103,9 @@ public class MsTCPSampler extends MsTestElement {
private TCPSampler tcpSampler(ParameterConfig config) {
TCPSampler tcpSampler = new TCPSampler();
tcpSampler.setName(this.getName());
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
tcpSampler.setName(this.getName() + "<->" + config.getStep());
} else {
tcpSampler.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}");
}
String name = this.getParentName(this.getParent(), config);
if (StringUtils.isNotEmpty(name)) {
tcpSampler.setName(this.getName() + "<->" + name);
}
tcpSampler.setProperty(TestElement.TEST_CLASS, TCPSampler.class.getName());

View File

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

View File

@ -8,7 +8,6 @@
<img :src="'/display/file/loginLogo'" alt="">
</div>
<div class="welcome">
<span>Metersphere</span>
<span>{{ $t('commons.welcome') }}</span>
</div>
</div>
@ -283,11 +282,6 @@ export default {
margin: 165px 0px;
}
.welcome span:first-child {
font-weight: bold;
margin-right: 3px;
}
</style>
<style>