Merge branch 'main' of https://github.com/metersphere/metersphere
This commit is contained in:
commit
a463c879e7
|
@ -1,6 +1,7 @@
|
||||||
package io.metersphere.api.dto.definition.request;
|
package io.metersphere.api.dto.definition.request;
|
||||||
|
|
||||||
import io.metersphere.api.dto.EnvironmentType;
|
import io.metersphere.api.dto.EnvironmentType;
|
||||||
|
import io.metersphere.api.dto.RunningParamKeys;
|
||||||
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
|
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
|
||||||
import io.metersphere.api.dto.definition.request.auth.MsAuthManager;
|
import io.metersphere.api.dto.definition.request.auth.MsAuthManager;
|
||||||
import io.metersphere.api.dto.definition.request.controller.MsIfController;
|
import io.metersphere.api.dto.definition.request.controller.MsIfController;
|
||||||
|
@ -18,16 +19,21 @@ import io.metersphere.api.dto.definition.request.timer.MsConstantTimer;
|
||||||
import io.metersphere.api.dto.definition.request.unknown.MsJmeterElement;
|
import io.metersphere.api.dto.definition.request.unknown.MsJmeterElement;
|
||||||
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||||
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||||
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.api.dto.scenario.environment.item.EnvAssertions;
|
import io.metersphere.api.dto.scenario.environment.item.EnvAssertions;
|
||||||
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.base.domain.FileMetadata;
|
import io.metersphere.base.domain.FileMetadata;
|
||||||
import io.metersphere.base.mapper.ApiScenarioMapper;
|
import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||||
import io.metersphere.commons.constants.*;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
|
import io.metersphere.commons.constants.PropertyConstant;
|
||||||
|
import io.metersphere.commons.constants.StorageConstants;
|
||||||
import io.metersphere.commons.enums.StorageEnums;
|
import io.metersphere.commons.enums.StorageEnums;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.*;
|
import io.metersphere.commons.utils.*;
|
||||||
|
import io.metersphere.commons.vo.JDBCProcessorVO;
|
||||||
|
import io.metersphere.commons.vo.ScriptProcessorVO;
|
||||||
import io.metersphere.constants.RunModeConstants;
|
import io.metersphere.constants.RunModeConstants;
|
||||||
import io.metersphere.environment.service.BaseEnvGroupProjectService;
|
import io.metersphere.environment.service.BaseEnvGroupProjectService;
|
||||||
import io.metersphere.environment.service.BaseEnvironmentService;
|
import io.metersphere.environment.service.BaseEnvironmentService;
|
||||||
|
@ -46,8 +52,10 @@ import org.apache.jmeter.config.RandomVariableConfig;
|
||||||
import org.apache.jmeter.modifiers.CounterConfig;
|
import org.apache.jmeter.modifiers.CounterConfig;
|
||||||
import org.apache.jmeter.modifiers.UserParameters;
|
import org.apache.jmeter.modifiers.UserParameters;
|
||||||
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
|
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
|
||||||
|
import org.apache.jmeter.protocol.java.sampler.BeanShellSampler;
|
||||||
|
import org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement;
|
||||||
|
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
|
||||||
import org.apache.jmeter.save.SaveService;
|
import org.apache.jmeter.save.SaveService;
|
||||||
import org.apache.jmeter.testelement.AbstractTestElement;
|
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jmeter.testelement.TestPlan;
|
import org.apache.jmeter.testelement.TestPlan;
|
||||||
import org.apache.jmeter.threads.ThreadGroup;
|
import org.apache.jmeter.threads.ThreadGroup;
|
||||||
|
@ -67,6 +75,7 @@ public class ElementUtil {
|
||||||
private static final String POST = "POST";
|
private static final String POST = "POST";
|
||||||
private static final String ASSERTIONS = ElementConstants.ASSERTIONS;
|
private static final String ASSERTIONS = ElementConstants.ASSERTIONS;
|
||||||
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
|
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
|
||||||
|
private static final String TEST_BEAN_GUI = "TestBeanGUI";
|
||||||
|
|
||||||
|
|
||||||
public static Map<String, EnvironmentConfig> getEnvironmentConfig(String environmentId, String projectId) {
|
public static Map<String, EnvironmentConfig> getEnvironmentConfig(String environmentId, String projectId) {
|
||||||
|
@ -101,7 +110,7 @@ public class ElementUtil {
|
||||||
CSVDataSet csvDataSet = new CSVDataSet();
|
CSVDataSet csvDataSet = new CSVDataSet();
|
||||||
csvDataSet.setEnabled(true);
|
csvDataSet.setEnabled(true);
|
||||||
csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName());
|
csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName());
|
||||||
csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
||||||
csvDataSet.setName(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName());
|
csvDataSet.setName(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName());
|
||||||
csvDataSet.setProperty("fileEncoding", StringUtils.isEmpty(item.getEncoding()) ? StandardCharsets.UTF_8.name() : item.getEncoding());
|
csvDataSet.setProperty("fileEncoding", StringUtils.isEmpty(item.getEncoding()) ? StandardCharsets.UTF_8.name() : item.getEncoding());
|
||||||
if (CollectionUtils.isEmpty(item.getFiles())) {
|
if (CollectionUtils.isEmpty(item.getFiles())) {
|
||||||
|
@ -150,7 +159,7 @@ public class ElementUtil {
|
||||||
CSVDataSet csvDataSet = new CSVDataSet();
|
CSVDataSet csvDataSet = new CSVDataSet();
|
||||||
csvDataSet.setEnabled(true);
|
csvDataSet.setEnabled(true);
|
||||||
csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName());
|
csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName());
|
||||||
csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
||||||
csvDataSet.setName(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName());
|
csvDataSet.setName(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName());
|
||||||
csvDataSet.setProperty("fileEncoding", StringUtils.isEmpty(item.getEncoding()) ? StandardCharsets.UTF_8.name() : item.getEncoding());
|
csvDataSet.setProperty("fileEncoding", StringUtils.isEmpty(item.getEncoding()) ? StandardCharsets.UTF_8.name() : item.getEncoding());
|
||||||
if (CollectionUtils.isEmpty(item.getFiles())) {
|
if (CollectionUtils.isEmpty(item.getFiles())) {
|
||||||
|
@ -219,7 +228,7 @@ public class ElementUtil {
|
||||||
RandomVariableConfig randomVariableConfig = new RandomVariableConfig();
|
RandomVariableConfig randomVariableConfig = new RandomVariableConfig();
|
||||||
randomVariableConfig.setEnabled(true);
|
randomVariableConfig.setEnabled(true);
|
||||||
randomVariableConfig.setProperty(TestElement.TEST_CLASS, RandomVariableConfig.class.getName());
|
randomVariableConfig.setProperty(TestElement.TEST_CLASS, RandomVariableConfig.class.getName());
|
||||||
randomVariableConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
randomVariableConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
||||||
randomVariableConfig.setName(item.getName());
|
randomVariableConfig.setName(item.getName());
|
||||||
randomVariableConfig.setProperty("variableName", item.getName());
|
randomVariableConfig.setProperty("variableName", item.getName());
|
||||||
randomVariableConfig.setProperty("outputFormat", item.getValue());
|
randomVariableConfig.setProperty("outputFormat", item.getValue());
|
||||||
|
@ -590,7 +599,7 @@ public class ElementUtil {
|
||||||
return processor;
|
return processor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBaseParams(AbstractTestElement sampler, MsTestElement parent, ParameterConfig config, String id, String indexPath) {
|
public static void setBaseParams(TestElement sampler, MsTestElement parent, ParameterConfig config, String id, String indexPath) {
|
||||||
sampler.setProperty("MS-ID", id);
|
sampler.setProperty("MS-ID", id);
|
||||||
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(id, config, parent, indexPath));
|
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(id, config, parent, indexPath));
|
||||||
}
|
}
|
||||||
|
@ -866,4 +875,127 @@ public class ElementUtil {
|
||||||
public static String getDataSourceName(String name) {
|
public static String getDataSourceName(String name) {
|
||||||
return StringUtils.join(name, "-", UUID.randomUUID().toString());
|
return StringUtils.join(name, "-", UUID.randomUUID().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void initScript(TestElement testElement, ScriptProcessorVO vo) {
|
||||||
|
testElement.setEnabled(vo.isEnabled());
|
||||||
|
if (StringUtils.isNotEmpty(vo.getName())) {
|
||||||
|
testElement.setName(vo.getName());
|
||||||
|
} else {
|
||||||
|
testElement.setName(testElement.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
//替换环境变量
|
||||||
|
if (StringUtils.isNotEmpty(vo.getScript())) {
|
||||||
|
vo.setScript(StringUtils.replace(vo.getScript(), RunningParamKeys.API_ENVIRONMENT_ID, "\"" + RunningParamKeys.RUNNING_PARAMS_PREFIX + vo.getEnvironmentId() + ".\""));
|
||||||
|
}
|
||||||
|
testElement.setProperty(TestElement.TEST_CLASS, testElement.getClass().getSimpleName());
|
||||||
|
testElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
||||||
|
String scriptLanguage = vo.getScriptLanguage();
|
||||||
|
if (StringUtils.equals(scriptLanguage, "nashornScript")) {
|
||||||
|
scriptLanguage = "nashorn";
|
||||||
|
}
|
||||||
|
if (StringUtils.equalsAny(scriptLanguage, "rhinoScript", "javascript")) {
|
||||||
|
scriptLanguage = "rhino";
|
||||||
|
}
|
||||||
|
testElement.setProperty("scriptLanguage", scriptLanguage);
|
||||||
|
|
||||||
|
if (testElement instanceof BeanShellSampler) {
|
||||||
|
testElement.setProperty("BeanShellSampler.query", vo.getScript());
|
||||||
|
testElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("BeanShellSamplerGui"));
|
||||||
|
} else {
|
||||||
|
testElement.setProperty("scriptLanguage", vo.getScriptLanguage());
|
||||||
|
testElement.setProperty("script", vo.getScript());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getScriptEnv(String environmentId, ParameterConfig config) {
|
||||||
|
if (StringUtils.isEmpty(environmentId)) {
|
||||||
|
if (config.getConfig() != null) {
|
||||||
|
if (config.getProjectId() != null && config.getConfig().containsKey(config.getProjectId())) {
|
||||||
|
return config.getConfig().get(config.getProjectId()).getEnvironmentId();
|
||||||
|
} else {
|
||||||
|
if (CollectionUtils.isNotEmpty(config.getConfig().values())) {
|
||||||
|
Optional<EnvironmentConfig> values = config.getConfig().entrySet().stream().findFirst().map(Map.Entry::getValue);
|
||||||
|
return values.get().getEnvironmentId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return environmentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void jdbcArguments(String name, List<KeyValue> variables, HashTree tree) {
|
||||||
|
if (CollectionUtils.isNotEmpty(variables)) {
|
||||||
|
Arguments arguments = new Arguments();
|
||||||
|
arguments.setEnabled(true);
|
||||||
|
name = StringUtils.isNotEmpty(name) ? name : "Arguments";
|
||||||
|
arguments.setName(name + "JDBC_Argument");
|
||||||
|
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
|
||||||
|
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
|
||||||
|
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
|
||||||
|
arguments.addArgument(keyValue.getName(), ElementUtil.getEvlValue(keyValue.getValue()), "=")
|
||||||
|
);
|
||||||
|
if (!arguments.getArguments().isEmpty()) {
|
||||||
|
tree.add(arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void jdbcProcessor(AbstractJDBCTestElement jdbcProcessor, ParameterConfig config, JDBCProcessorVO vo) {
|
||||||
|
jdbcProcessor.setEnabled(vo.isEnable());
|
||||||
|
jdbcProcessor.setName(vo.getName() == null ? jdbcProcessor.getClass().getSimpleName() : vo.getName());
|
||||||
|
jdbcProcessor.setProperty(TestElement.TEST_CLASS, jdbcProcessor.getClass().getSimpleName());
|
||||||
|
jdbcProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
||||||
|
|
||||||
|
ElementUtil.setBaseParams(jdbcProcessor, vo.getParent(), config, vo.getId(), vo.getIndex());
|
||||||
|
jdbcProcessor.setDataSource(ElementUtil.getDataSourceName(vo.getDataSource().getName()));
|
||||||
|
jdbcProcessor.setProperty("dataSource", jdbcProcessor.getDataSource());
|
||||||
|
jdbcProcessor.setProperty("query", vo.getQuery());
|
||||||
|
jdbcProcessor.setProperty("queryTimeout", String.valueOf(vo.getQueryTimeout()));
|
||||||
|
jdbcProcessor.setProperty("resultVariable", vo.getResultVariable());
|
||||||
|
jdbcProcessor.setProperty("variableNames", vo.getVariableNames());
|
||||||
|
jdbcProcessor.setProperty("resultSetHandler", "Store as String");
|
||||||
|
jdbcProcessor.setProperty("queryType", "Callable Statement");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DataSourceElement jdbcDataSource(String sourceName, DatabaseConfig dataSource) {
|
||||||
|
DataSourceElement dataSourceElement = new DataSourceElement();
|
||||||
|
dataSourceElement.setEnabled(true);
|
||||||
|
dataSourceElement.setName(sourceName + " JDBCDataSource");
|
||||||
|
dataSourceElement.setProperty(TestElement.TEST_CLASS, DataSourceElement.class.getName());
|
||||||
|
dataSourceElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
||||||
|
dataSourceElement.setProperty("autocommit", true);
|
||||||
|
dataSourceElement.setProperty("keepAlive", true);
|
||||||
|
dataSourceElement.setProperty("preinit", false);
|
||||||
|
dataSourceElement.setProperty("dataSource", sourceName);
|
||||||
|
dataSourceElement.setProperty("dbUrl", dataSource.getDbUrl());
|
||||||
|
dataSourceElement.setProperty("driver", dataSource.getDriver());
|
||||||
|
dataSourceElement.setProperty("username", dataSource.getUsername());
|
||||||
|
dataSourceElement.setProperty("password", dataSource.getPassword());
|
||||||
|
dataSourceElement.setProperty("poolMax", dataSource.getPoolMax());
|
||||||
|
dataSourceElement.setProperty("timeout", String.valueOf(dataSource.getTimeout()));
|
||||||
|
dataSourceElement.setProperty("connectionAge", 5000);
|
||||||
|
dataSourceElement.setProperty("trimInterval", 6000);
|
||||||
|
dataSourceElement.setProperty("transactionIsolation", "DEFAULT");
|
||||||
|
return dataSourceElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static DatabaseConfig initDataSource(String environmentId, String dataSourceId) {
|
||||||
|
if (StringUtils.isNotBlank(environmentId) && StringUtils.isNotBlank(dataSourceId)) {
|
||||||
|
BaseEnvironmentService service = CommonBeanFactory.getBean(BaseEnvironmentService.class);
|
||||||
|
ApiTestEnvironmentWithBLOBs environment = service.get(environmentId);
|
||||||
|
if (environment != null && environment.getConfig() != null) {
|
||||||
|
EnvironmentConfig envConfig = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
||||||
|
if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) {
|
||||||
|
List<DatabaseConfig> configs = envConfig.getDatabaseConfigs().stream().filter(item ->
|
||||||
|
StringUtils.equals(item.getId(), dataSourceId)).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(configs)) {
|
||||||
|
return configs.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class MsAssertionJSR223 extends MsAssertionType {
|
||||||
private String name;
|
private String name;
|
||||||
private String script;
|
private String script;
|
||||||
private String scriptLanguage;
|
private String scriptLanguage;
|
||||||
|
private Boolean jsrEnable;
|
||||||
|
|
||||||
public MsAssertionJSR223() {
|
public MsAssertionJSR223() {
|
||||||
setType(MsAssertionType.JSR223);
|
setType(MsAssertionType.JSR223);
|
||||||
|
|
|
@ -2,16 +2,17 @@ package io.metersphere.api.dto.definition.request.assertions;
|
||||||
|
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.definition.request.assertions.document.MsAssertionDocument;
|
import io.metersphere.api.dto.definition.request.assertions.document.MsAssertionDocument;
|
||||||
import io.metersphere.service.definition.ApiDefinitionService;
|
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
import io.metersphere.commons.constants.PropertyConstant;
|
import io.metersphere.commons.constants.PropertyConstant;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
|
import io.metersphere.commons.utils.ErrorReportLibraryUtil;
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
import io.metersphere.commons.utils.ErrorReportLibraryUtil;
|
import io.metersphere.service.definition.ApiDefinitionService;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.assertions.*;
|
import org.apache.jmeter.assertions.*;
|
||||||
import org.apache.jmeter.save.SaveService;
|
import org.apache.jmeter.save.SaveService;
|
||||||
|
@ -196,8 +197,11 @@ public class MsAssertions extends MsTestElement {
|
||||||
return assertion;
|
return assertion;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSR223Assertion jsr223Assertion(MsAssertionJSR223 assertionJSR223) {
|
private TestElement jsr223Assertion(MsAssertionJSR223 assertionJSR223) {
|
||||||
JSR223Assertion assertion = new JSR223Assertion();
|
TestElement assertion = new BeanShellAssertion();
|
||||||
|
if (assertionJSR223.getJsrEnable() == null || BooleanUtils.isTrue(assertionJSR223.getJsrEnable())) {
|
||||||
|
assertion = new JSR223Assertion();
|
||||||
|
}
|
||||||
assertion.setEnabled(this.isEnable());
|
assertion.setEnabled(this.isEnable());
|
||||||
if (StringUtils.isNotEmpty(assertionJSR223.getDesc())) {
|
if (StringUtils.isNotEmpty(assertionJSR223.getDesc())) {
|
||||||
assertion.setName("JSR223" + delimiter + this.getName() + delimiter + assertionJSR223.getDesc() + delimiterScript + assertionJSR223.getScript());
|
assertion.setName("JSR223" + delimiter + this.getName() + delimiter + assertionJSR223.getDesc() + delimiterScript + assertionJSR223.getScript());
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
package io.metersphere.api.dto.definition.request.processors;
|
package io.metersphere.api.dto.definition.request.processors;
|
||||||
|
|
||||||
import io.metersphere.api.dto.RunningParamKeys;
|
|
||||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
|
||||||
import io.metersphere.api.dto.shell.filter.ScriptFilter;
|
import io.metersphere.api.dto.shell.filter.ScriptFilter;
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
|
import io.metersphere.commons.vo.ScriptProcessorVO;
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
|
import io.metersphere.utils.JMeterVars;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.jmeter.protocol.java.sampler.BeanShellSampler;
|
||||||
import org.apache.jmeter.protocol.java.sampler.JSR223Sampler;
|
import org.apache.jmeter.protocol.java.sampler.JSR223Sampler;
|
||||||
import org.apache.jmeter.save.SaveService;
|
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -27,32 +28,15 @@ public class MsJSR223Processor extends MsTestElement {
|
||||||
private String clazzName = MsJSR223Processor.class.getCanonicalName();
|
private String clazzName = MsJSR223Processor.class.getCanonicalName();
|
||||||
private String script;
|
private String script;
|
||||||
private String scriptLanguage;
|
private String scriptLanguage;
|
||||||
|
private Boolean jsrEnable;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
||||||
ScriptFilter.verify(this.getScriptLanguage(), this.getName(), script);
|
ScriptFilter.verify(this.getScriptLanguage(), this.getName(), script);
|
||||||
ParameterConfig config = (ParameterConfig) msParameter;
|
ParameterConfig config = (ParameterConfig) msParameter;
|
||||||
//替换Metersphere环境变量
|
|
||||||
if (StringUtils.isEmpty(this.getEnvironmentId())) {
|
|
||||||
if (config.getConfig() != null) {
|
|
||||||
if (config.getProjectId() != null) {
|
|
||||||
String evnId = config.getConfig().get(config.getProjectId()).getEnvironmentId();
|
|
||||||
this.setEnvironmentId(evnId);
|
|
||||||
} else {
|
|
||||||
Collection<EnvironmentConfig> evnConfigList = config.getConfig().values();
|
|
||||||
if (evnConfigList != null && !evnConfigList.isEmpty()) {
|
|
||||||
for (EnvironmentConfig configItem : evnConfigList) {
|
|
||||||
String evnId = configItem.getEnvironmentId();
|
|
||||||
this.setEnvironmentId(evnId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID, "\"" + RunningParamKeys.RUNNING_PARAMS_PREFIX + this.getEnvironmentId() + ".\"");
|
|
||||||
if (config.isOperating()) {
|
if (config.isOperating()) {
|
||||||
if (StringUtils.isNotEmpty(script) && script.startsWith("io.metersphere.utils.JMeterVars.addVars")) {
|
if (StringUtils.isNotEmpty(script) && script.startsWith(JMeterVars.class.getCanonicalName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,28 +44,20 @@ public class MsJSR223Processor extends MsTestElement {
|
||||||
if (!config.isOperating() && !this.isEnable()) {
|
if (!config.isOperating() && !this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSR223Sampler processor = new JSR223Sampler();
|
this.setEnvironmentId(ElementUtil.getScriptEnv(this.getEnvironmentId(), config));
|
||||||
processor.setEnabled(this.isEnable());
|
|
||||||
if (StringUtils.isNotEmpty(this.getName())) {
|
TestElement processor = new BeanShellSampler();
|
||||||
processor.setName(this.getName());
|
if (jsrEnable == null || BooleanUtils.isTrue(jsrEnable)) {
|
||||||
} else {
|
processor = new JSR223Sampler();
|
||||||
processor.setName(ElementConstants.JSR223);
|
|
||||||
}
|
}
|
||||||
|
ScriptProcessorVO vo = new ScriptProcessorVO();
|
||||||
|
BeanUtils.copyBean(vo, this);
|
||||||
|
vo.setEnabled(this.isEnable());
|
||||||
|
ElementUtil.initScript(processor, vo);
|
||||||
|
|
||||||
String resourceId = StringUtils.isNotEmpty(this.getId()) ? this.getId() : this.getResourceId();
|
String resourceId = StringUtils.isNotEmpty(this.getId()) ? this.getId() : this.getResourceId();
|
||||||
ElementUtil.setBaseParams(processor, this.getParent(), config, resourceId, this.getIndex());
|
ElementUtil.setBaseParams(processor, this.getParent(), config, resourceId, this.getIndex());
|
||||||
processor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName());
|
|
||||||
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
|
||||||
processor.setProperty("scriptLanguage", this.getScriptLanguage());
|
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("nashornScript")) {
|
|
||||||
processor.setProperty("scriptLanguage", "nashorn");
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("rhinoScript")) {
|
|
||||||
processor.setProperty("scriptLanguage", "rhino");
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("javascript")) {
|
|
||||||
processor.setProperty("scriptLanguage", "rhino");
|
|
||||||
}
|
|
||||||
processor.setProperty("script", this.getScript());
|
|
||||||
final HashTree jsr223PreTree = tree.add(processor);
|
final HashTree jsr223PreTree = tree.add(processor);
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
hashTree.forEach(el -> {
|
hashTree.forEach(el -> {
|
||||||
|
|
|
@ -1,40 +1,23 @@
|
||||||
package io.metersphere.api.dto.definition.request.processors.post;
|
package io.metersphere.api.dto.definition.request.processors.post;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
|
||||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
|
||||||
import io.metersphere.commons.constants.CommonConstants;
|
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
import io.metersphere.commons.utils.JSONUtil;
|
import io.metersphere.commons.vo.JDBCProcessorVO;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
|
||||||
import io.metersphere.environment.service.BaseEnvironmentService;
|
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
import io.metersphere.service.definition.ApiDefinitionService;
|
|
||||||
import io.metersphere.service.definition.ApiTestCaseService;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.config.Arguments;
|
|
||||||
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
|
|
||||||
import org.apache.jmeter.protocol.jdbc.processor.JDBCPostProcessor;
|
import org.apache.jmeter.protocol.jdbc.processor.JDBCPostProcessor;
|
||||||
import org.apache.jmeter.save.SaveService;
|
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -70,42 +53,35 @@ public class MsJDBCPostProcessor extends MsTestElement {
|
||||||
if (!config.isOperating() && !this.isEnable()) {
|
if (!config.isOperating() && !this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
|
||||||
this.setRefElement();
|
|
||||||
}
|
|
||||||
if (config.getConfig() == null) {
|
if (config.getConfig() == null) {
|
||||||
// 单独接口执行
|
// 单独接口执行
|
||||||
this.setProjectId(config.getProjectId());
|
this.setProjectId(config.getProjectId());
|
||||||
config.setConfig(ElementUtil.getEnvironmentConfig(StringUtils.isNotEmpty(useEnvironment) ? useEnvironment : environmentId, this.getProjectId()));
|
config.setConfig(ElementUtil.getEnvironmentConfig(StringUtils.isNotEmpty(useEnvironment) ? useEnvironment : environmentId, this.getProjectId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果当前数据源为null,则获取已选环境的数据源
|
// 自选了数据源
|
||||||
if (this.dataSource == null) {
|
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
|
||||||
// 自选了数据源
|
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
||||||
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
|
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
|
||||||
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) {
|
||||||
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
|
this.environmentId = environmentConfig.getEnvironmentId();
|
||||||
if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) {
|
}
|
||||||
this.environmentId = environmentConfig.getEnvironmentId();
|
this.dataSource = ElementUtil.initDataSource(this.environmentId, this.dataSourceId);
|
||||||
}
|
} else {
|
||||||
this.initDataSource();
|
// 取当前环境下默认的一个数据源
|
||||||
} else {
|
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
||||||
// 取当前环境下默认的一个数据源
|
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, config.getConfig().get(this.getProjectId()));
|
||||||
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
if (dataSourceOrg != null) {
|
||||||
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, config.getConfig().get(this.getProjectId()));
|
this.dataSource = dataSourceOrg;
|
||||||
if (dataSourceOrg != null) {
|
} else {
|
||||||
this.dataSource = dataSourceOrg;
|
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
|
||||||
} else {
|
|
||||||
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.dataSource == null) {
|
if (this.dataSource == null) {
|
||||||
// 用自身的数据
|
// 用自身的数据
|
||||||
if (StringUtils.isNotEmpty(dataSourceId)) {
|
if (StringUtils.isNotEmpty(dataSourceId)) {
|
||||||
this.dataSource = null;
|
this.dataSource = ElementUtil.initDataSource(this.environmentId, this.dataSourceId);
|
||||||
this.initDataSource();
|
|
||||||
}
|
}
|
||||||
if (this.dataSource == null) {
|
if (this.dataSource == null) {
|
||||||
String message = "数据源为空请选择数据源";
|
String message = "数据源为空请选择数据源";
|
||||||
|
@ -114,11 +90,9 @@ public class MsJDBCPostProcessor extends MsTestElement {
|
||||||
}
|
}
|
||||||
JDBCPostProcessor jdbcPostProcessor = jdbcPostProcessor(config);
|
JDBCPostProcessor jdbcPostProcessor = jdbcPostProcessor(config);
|
||||||
final HashTree samplerHashTree = tree.add(jdbcPostProcessor);
|
final HashTree samplerHashTree = tree.add(jdbcPostProcessor);
|
||||||
tree.add(jdbcDataSource(jdbcPostProcessor.getDataSource()));
|
|
||||||
Arguments arguments = arguments(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Arguments", this.getVariables());
|
tree.add(ElementUtil.jdbcDataSource(jdbcPostProcessor.getDataSource(), this.dataSource));
|
||||||
if (arguments != null) {
|
ElementUtil.jdbcArguments(this.getName(), this.getVariables(), tree);
|
||||||
tree.add(arguments);
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
hashTree.forEach(el -> {
|
hashTree.forEach(el -> {
|
||||||
el.toHashTree(samplerHashTree, el.getHashTree(), config);
|
el.toHashTree(samplerHashTree, el.getHashTree(), config);
|
||||||
|
@ -134,117 +108,11 @@ public class MsJDBCPostProcessor extends MsTestElement {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRefElement() {
|
|
||||||
try {
|
|
||||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
MsJDBCPostProcessor proxy = null;
|
|
||||||
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
|
||||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
|
||||||
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
|
|
||||||
if (bloBs != null) {
|
|
||||||
this.setName(bloBs.getName());
|
|
||||||
this.setProjectId(bloBs.getProjectId());
|
|
||||||
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
|
||||||
ElementUtil.dataFormatting(element);
|
|
||||||
proxy = mapper.readValue(element.toString(), new TypeReference<MsJDBCPostProcessor>() {
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
|
||||||
if (apiDefinition != null) {
|
|
||||||
this.setProjectId(apiDefinition.getProjectId());
|
|
||||||
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsJDBCPostProcessor>() {
|
|
||||||
});
|
|
||||||
this.setName(apiDefinition.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (proxy != null) {
|
|
||||||
this.setHashTree(proxy.getHashTree());
|
|
||||||
this.setDataSource(proxy.getDataSource());
|
|
||||||
this.setDataSourceId(proxy.getDataSourceId());
|
|
||||||
this.setQuery(proxy.getQuery());
|
|
||||||
this.setVariables(proxy.getVariables());
|
|
||||||
this.setVariableNames(proxy.getVariableNames());
|
|
||||||
this.setResultVariable(proxy.getResultVariable());
|
|
||||||
this.setQueryTimeout(proxy.getQueryTimeout());
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
LogUtil.error(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initDataSource() {
|
|
||||||
BaseEnvironmentService apiTestEnvironmentService = CommonBeanFactory.getBean(BaseEnvironmentService.class);
|
|
||||||
ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(environmentId);
|
|
||||||
if (environment != null && environment.getConfig() != null) {
|
|
||||||
EnvironmentConfig envConfig = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
|
||||||
if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) {
|
|
||||||
envConfig.getDatabaseConfigs().forEach(item -> {
|
|
||||||
if (item.getId().equals(this.dataSourceId)) {
|
|
||||||
this.dataSource = item;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Arguments arguments(String name, List<KeyValue> variables) {
|
|
||||||
if (CollectionUtils.isNotEmpty(variables)) {
|
|
||||||
Arguments arguments = new Arguments();
|
|
||||||
arguments.setEnabled(true);
|
|
||||||
arguments.setName(name + "JDBC_Argument");
|
|
||||||
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
|
|
||||||
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
|
|
||||||
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
|
|
||||||
arguments.addArgument(keyValue.getName(), ElementUtil.getEvlValue(keyValue.getValue()), "=")
|
|
||||||
);
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JDBCPostProcessor jdbcPostProcessor(ParameterConfig config) {
|
private JDBCPostProcessor jdbcPostProcessor(ParameterConfig config) {
|
||||||
JDBCPostProcessor jdbcPostProcessor = new JDBCPostProcessor();
|
JDBCPostProcessor jdbcPostProcessor = new JDBCPostProcessor();
|
||||||
jdbcPostProcessor.setEnabled(this.isEnable());
|
JDBCProcessorVO vo = new JDBCProcessorVO();
|
||||||
jdbcPostProcessor.setName(this.getName() == null ? ElementConstants.JDBC_POST : this.getName());
|
BeanUtils.copyBean(vo, this);
|
||||||
jdbcPostProcessor.setProperty(TestElement.TEST_CLASS, JDBCPostProcessor.class.getName());
|
ElementUtil.jdbcProcessor(jdbcPostProcessor, config, vo);
|
||||||
jdbcPostProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
|
||||||
|
|
||||||
ElementUtil.setBaseParams(jdbcPostProcessor, this.getParent(), config, this.getId(), this.getIndex());
|
|
||||||
// request.getDataSource() 是ID,需要转换为Name
|
|
||||||
jdbcPostProcessor.setDataSource(ElementUtil.getDataSourceName(this.dataSource.getName()));
|
|
||||||
jdbcPostProcessor.setProperty("dataSource", jdbcPostProcessor.getDataSource());
|
|
||||||
jdbcPostProcessor.setProperty("query", this.getQuery());
|
|
||||||
jdbcPostProcessor.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
|
|
||||||
jdbcPostProcessor.setProperty("resultVariable", this.getResultVariable());
|
|
||||||
jdbcPostProcessor.setProperty("variableNames", this.getVariableNames());
|
|
||||||
jdbcPostProcessor.setProperty("resultSetHandler", "Store as String");
|
|
||||||
jdbcPostProcessor.setProperty("queryType", "Callable Statement");
|
|
||||||
return jdbcPostProcessor;
|
return jdbcPostProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSourceElement jdbcDataSource(String sourceName) {
|
|
||||||
DataSourceElement dataSourceElement = new DataSourceElement();
|
|
||||||
dataSourceElement.setEnabled(true);
|
|
||||||
dataSourceElement.setName(this.getName() + " JDBCDataSource");
|
|
||||||
dataSourceElement.setProperty(TestElement.TEST_CLASS, DataSourceElement.class.getName());
|
|
||||||
dataSourceElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
|
||||||
dataSourceElement.setProperty("autocommit", true);
|
|
||||||
dataSourceElement.setProperty("keepAlive", true);
|
|
||||||
dataSourceElement.setProperty("preinit", false);
|
|
||||||
dataSourceElement.setProperty("dataSource", sourceName);
|
|
||||||
dataSourceElement.setProperty("dbUrl", dataSource.getDbUrl());
|
|
||||||
dataSourceElement.setProperty("driver", dataSource.getDriver());
|
|
||||||
dataSourceElement.setProperty("username", dataSource.getUsername());
|
|
||||||
dataSourceElement.setProperty("password", dataSource.getPassword());
|
|
||||||
dataSourceElement.setProperty("poolMax", dataSource.getPoolMax());
|
|
||||||
dataSourceElement.setProperty("timeout", String.valueOf(dataSource.getTimeout()));
|
|
||||||
dataSourceElement.setProperty("connectionAge", 5000);
|
|
||||||
dataSourceElement.setProperty("trimInterval", 6000);
|
|
||||||
dataSourceElement.setProperty("transactionIsolation", "DEFAULT");
|
|
||||||
return dataSourceElement;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
package io.metersphere.api.dto.definition.request.processors.post;
|
package io.metersphere.api.dto.definition.request.processors.post;
|
||||||
|
|
||||||
import io.metersphere.api.dto.RunningParamKeys;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
|
||||||
import io.metersphere.api.dto.shell.filter.ScriptFilter;
|
import io.metersphere.api.dto.shell.filter.ScriptFilter;
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
|
import io.metersphere.commons.vo.ScriptProcessorVO;
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
|
import io.metersphere.utils.JMeterVars;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.jmeter.extractor.BeanShellPostProcessor;
|
||||||
import org.apache.jmeter.extractor.JSR223PostProcessor;
|
import org.apache.jmeter.extractor.JSR223PostProcessor;
|
||||||
import org.apache.jmeter.save.SaveService;
|
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -26,31 +28,14 @@ public class MsJSR223PostProcessor extends MsTestElement {
|
||||||
private String clazzName = MsJSR223PostProcessor.class.getCanonicalName();
|
private String clazzName = MsJSR223PostProcessor.class.getCanonicalName();
|
||||||
private String script;
|
private String script;
|
||||||
private String scriptLanguage;
|
private String scriptLanguage;
|
||||||
|
private Boolean jsrEnable;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
||||||
ScriptFilter.verify(this.getScriptLanguage(), this.getName(), script);
|
|
||||||
ParameterConfig config = (ParameterConfig) msParameter;
|
ParameterConfig config = (ParameterConfig) msParameter;
|
||||||
if (StringUtils.isEmpty(this.getEnvironmentId())) {
|
ScriptFilter.verify(this.getScriptLanguage(), this.getName(), script);
|
||||||
if (config.getConfig() != null) {
|
|
||||||
if (config.getProjectId() != null && config.getConfig().containsKey(config.getProjectId())) {
|
|
||||||
String evnId = config.getConfig().get(config.getProjectId()).getEnvironmentId();
|
|
||||||
this.setEnvironmentId(evnId);
|
|
||||||
} else {
|
|
||||||
Collection<EnvironmentConfig> evnConfigList = config.getConfig().values();
|
|
||||||
if (evnConfigList != null && !evnConfigList.isEmpty()) {
|
|
||||||
for (EnvironmentConfig configItem : evnConfigList) {
|
|
||||||
String evnId = configItem.getEnvironmentId();
|
|
||||||
this.setEnvironmentId(evnId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID, "\"" + RunningParamKeys.RUNNING_PARAMS_PREFIX + this.getEnvironmentId() + ".\"");
|
|
||||||
if (config.isOperating()) {
|
if (config.isOperating()) {
|
||||||
if (StringUtils.isNotEmpty(script) && script.startsWith("io.metersphere.utils.JMeterVars.addVars")) {
|
if (StringUtils.isNotEmpty(script) && script.startsWith(JMeterVars.class.getCanonicalName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,26 +43,17 @@ public class MsJSR223PostProcessor extends MsTestElement {
|
||||||
if (!config.isOperating() && !this.isEnable()) {
|
if (!config.isOperating() && !this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSR223PostProcessor processor = new JSR223PostProcessor();
|
this.setEnvironmentId(ElementUtil.getScriptEnv(this.getEnvironmentId(), config));
|
||||||
processor.setEnabled(this.isEnable());
|
|
||||||
if (StringUtils.isNotEmpty(this.getName())) {
|
TestElement processor = new BeanShellPostProcessor();
|
||||||
processor.setName(this.getName());
|
if (jsrEnable == null || BooleanUtils.isTrue(jsrEnable)) {
|
||||||
} else {
|
processor = new JSR223PostProcessor();
|
||||||
processor.setName(ElementConstants.JSR223_POST);
|
|
||||||
}
|
}
|
||||||
processor.setProperty(TestElement.TEST_CLASS, JSR223PostProcessor.class.getName());
|
ScriptProcessorVO vo = new ScriptProcessorVO();
|
||||||
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
BeanUtils.copyBean(vo, this);
|
||||||
processor.setProperty("scriptLanguage", this.getScriptLanguage());
|
vo.setEnabled(this.isEnable());
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("nashornScript")) {
|
ElementUtil.initScript(processor, vo);
|
||||||
processor.setProperty("scriptLanguage", "nashorn");
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("rhinoScript")) {
|
|
||||||
processor.setProperty("scriptLanguage", "rhino");
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("javascript")) {
|
|
||||||
processor.setProperty("scriptLanguage", "rhino");
|
|
||||||
}
|
|
||||||
processor.setProperty("script", this.getScript());
|
|
||||||
final HashTree jsr223PostTree = tree.add(processor);
|
final HashTree jsr223PostTree = tree.add(processor);
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
hashTree.forEach(el -> {
|
hashTree.forEach(el -> {
|
||||||
|
|
|
@ -1,41 +1,24 @@
|
||||||
package io.metersphere.api.dto.definition.request.processors.pre;
|
package io.metersphere.api.dto.definition.request.processors.pre;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
|
||||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
|
||||||
import io.metersphere.commons.constants.CommonConstants;
|
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
|
||||||
import io.metersphere.commons.constants.RequestTypeConstants;
|
import io.metersphere.commons.constants.RequestTypeConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
import io.metersphere.commons.utils.JSONUtil;
|
import io.metersphere.commons.vo.JDBCProcessorVO;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
|
||||||
import io.metersphere.environment.service.BaseEnvironmentService;
|
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
import io.metersphere.service.definition.ApiDefinitionService;
|
|
||||||
import io.metersphere.service.definition.ApiTestCaseService;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.config.Arguments;
|
|
||||||
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
|
|
||||||
import org.apache.jmeter.protocol.jdbc.processor.JDBCPreProcessor;
|
import org.apache.jmeter.protocol.jdbc.processor.JDBCPreProcessor;
|
||||||
import org.apache.jmeter.save.SaveService;
|
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -70,55 +53,48 @@ public class MsJDBCPreProcessor extends MsTestElement {
|
||||||
if (!config.isOperating() && !this.isEnable()) {
|
if (!config.isOperating() && !this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
|
||||||
this.setRefElement();
|
|
||||||
}
|
|
||||||
if (config.getConfig() == null) {
|
if (config.getConfig() == null) {
|
||||||
// 单独接口执行
|
// 单独接口执行
|
||||||
this.setProjectId(config.getProjectId());
|
this.setProjectId(config.getProjectId());
|
||||||
config.setConfig(ElementUtil.getEnvironmentConfig(StringUtils.isNotEmpty(useEnvironment) ? useEnvironment : environmentId, this.getProjectId()));
|
config.setConfig(ElementUtil.getEnvironmentConfig(StringUtils.isNotEmpty(useEnvironment) ? useEnvironment : environmentId, this.getProjectId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果当前数据源为null,则获取已选环境的数据源
|
// 自选了数据源
|
||||||
if (this.dataSource == null) {
|
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
|
||||||
// 自选了数据源
|
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
||||||
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
|
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
|
||||||
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) {
|
||||||
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
|
this.environmentId = environmentConfig.getEnvironmentId();
|
||||||
if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) {
|
}
|
||||||
this.environmentId = environmentConfig.getEnvironmentId();
|
this.dataSource = ElementUtil.initDataSource(this.environmentId, this.dataSourceId);
|
||||||
}
|
} else {
|
||||||
this.initDataSource();
|
// 取当前环境下默认的一个数据源
|
||||||
} else {
|
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
||||||
// 取当前环境下默认的一个数据源
|
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, config.getConfig().get(this.getProjectId()));
|
||||||
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
if (dataSourceOrg != null) {
|
||||||
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, config.getConfig().get(this.getProjectId()));
|
this.dataSource = dataSourceOrg;
|
||||||
if (dataSourceOrg != null) {
|
} else {
|
||||||
this.dataSource = dataSourceOrg;
|
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
|
||||||
} else {
|
|
||||||
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.dataSource == null) {
|
if (this.dataSource == null) {
|
||||||
// 用自身的数据
|
// 用自身的数据
|
||||||
if (StringUtils.isNotEmpty(dataSourceId)) {
|
if (StringUtils.isNotEmpty(dataSourceId)) {
|
||||||
this.dataSource = null;
|
this.dataSource = ElementUtil.initDataSource(this.environmentId, this.dataSourceId);
|
||||||
this.initDataSource();
|
|
||||||
}
|
}
|
||||||
if (this.dataSource == null) {
|
if (this.dataSource == null) {
|
||||||
String message = "数据源为空请选择数据源";
|
String message = "数据源为空请选择数据源";
|
||||||
MSException.throwException(StringUtils.isNotEmpty(this.getName()) ? this.getName() + ":" + message : message);
|
MSException.throwException(StringUtils.isNotEmpty(this.getName()) ? this.getName() + ":" + message : message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JDBCPreProcessor jdbcPreProcessor = jdbcPreProcessor(config);
|
JDBCPreProcessor jdbcPreProcessor = jdbcPreProcessor(config);
|
||||||
final HashTree samplerHashTree = tree.add(jdbcPreProcessor);
|
final HashTree samplerHashTree = tree.add(jdbcPreProcessor);
|
||||||
tree.add(jdbcDataSource(jdbcPreProcessor.getDataSource()));
|
// 数据源
|
||||||
Arguments arguments = arguments(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Arguments", this.getVariables());
|
tree.add(ElementUtil.jdbcDataSource(jdbcPreProcessor.getDataSource(), this.dataSource));
|
||||||
if (arguments != null) {
|
// 参数
|
||||||
tree.add(arguments);
|
ElementUtil.jdbcArguments(this.getName(), this.getVariables(), tree);
|
||||||
}
|
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
hashTree.forEach(el -> {
|
hashTree.forEach(el -> {
|
||||||
el.toHashTree(samplerHashTree, el.getHashTree(), config);
|
el.toHashTree(samplerHashTree, el.getHashTree(), config);
|
||||||
|
@ -134,117 +110,11 @@ public class MsJDBCPreProcessor extends MsTestElement {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRefElement() {
|
|
||||||
try {
|
|
||||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
MsJDBCPreProcessor proxy = null;
|
|
||||||
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
|
||||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
|
||||||
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
|
|
||||||
if (bloBs != null) {
|
|
||||||
this.setName(bloBs.getName());
|
|
||||||
this.setProjectId(bloBs.getProjectId());
|
|
||||||
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
|
||||||
ElementUtil.dataFormatting(element);
|
|
||||||
proxy = mapper.readValue(element.toString(), new TypeReference<MsJDBCPreProcessor>() {
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
|
||||||
if (apiDefinition != null) {
|
|
||||||
this.setProjectId(apiDefinition.getProjectId());
|
|
||||||
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsJDBCPreProcessor>() {
|
|
||||||
});
|
|
||||||
this.setName(apiDefinition.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (proxy != null) {
|
|
||||||
this.setHashTree(proxy.getHashTree());
|
|
||||||
this.setDataSource(proxy.getDataSource());
|
|
||||||
this.setDataSourceId(proxy.getDataSourceId());
|
|
||||||
this.setQuery(proxy.getQuery());
|
|
||||||
this.setVariables(proxy.getVariables());
|
|
||||||
this.setVariableNames(proxy.getVariableNames());
|
|
||||||
this.setResultVariable(proxy.getResultVariable());
|
|
||||||
this.setQueryTimeout(proxy.getQueryTimeout());
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
LogUtil.error(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initDataSource() {
|
|
||||||
BaseEnvironmentService apiTestEnvironmentService = CommonBeanFactory.getBean(BaseEnvironmentService.class);
|
|
||||||
ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(environmentId);
|
|
||||||
if (environment != null && environment.getConfig() != null) {
|
|
||||||
EnvironmentConfig envConfig = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
|
||||||
if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) {
|
|
||||||
envConfig.getDatabaseConfigs().forEach(item -> {
|
|
||||||
if (item.getId().equals(this.dataSourceId)) {
|
|
||||||
this.dataSource = item;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Arguments arguments(String name, List<KeyValue> variables) {
|
|
||||||
if (CollectionUtils.isNotEmpty(variables)) {
|
|
||||||
Arguments arguments = new Arguments();
|
|
||||||
arguments.setEnabled(true);
|
|
||||||
arguments.setName(name + "JDBC_Argument");
|
|
||||||
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
|
|
||||||
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
|
|
||||||
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
|
|
||||||
arguments.addArgument(keyValue.getName(), ElementUtil.getEvlValue(keyValue.getValue()), "=")
|
|
||||||
);
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JDBCPreProcessor jdbcPreProcessor(ParameterConfig config) {
|
private JDBCPreProcessor jdbcPreProcessor(ParameterConfig config) {
|
||||||
JDBCPreProcessor jdbcPreProcessor = new JDBCPreProcessor();
|
JDBCPreProcessor jdbcPreProcessor = new JDBCPreProcessor();
|
||||||
jdbcPreProcessor.setEnabled(this.isEnable());
|
JDBCProcessorVO vo = new JDBCProcessorVO();
|
||||||
jdbcPreProcessor.setName(this.getName() == null ? ElementConstants.JDBC_PRE : this.getName());
|
BeanUtils.copyBean(vo, this);
|
||||||
jdbcPreProcessor.setProperty(TestElement.TEST_CLASS, JDBCPreProcessor.class.getName());
|
ElementUtil.jdbcProcessor(jdbcPreProcessor, config, vo);
|
||||||
jdbcPreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
|
||||||
|
|
||||||
ElementUtil.setBaseParams(jdbcPreProcessor, this.getParent(), config, this.getId(), this.getIndex());
|
|
||||||
jdbcPreProcessor.setDataSource(ElementUtil.getDataSourceName(this.dataSource.getName()));
|
|
||||||
jdbcPreProcessor.setProperty("dataSource", jdbcPreProcessor.getDataSource());
|
|
||||||
jdbcPreProcessor.setProperty("query", this.getQuery());
|
|
||||||
jdbcPreProcessor.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
|
|
||||||
jdbcPreProcessor.setProperty("resultVariable", this.getResultVariable());
|
|
||||||
jdbcPreProcessor.setProperty("variableNames", this.getVariableNames());
|
|
||||||
jdbcPreProcessor.setProperty("resultSetHandler", "Store as String");
|
|
||||||
jdbcPreProcessor.setProperty("queryType", "Callable Statement");
|
|
||||||
return jdbcPreProcessor;
|
return jdbcPreProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSourceElement jdbcDataSource(String sourceName) {
|
|
||||||
DataSourceElement dataSourceElement = new DataSourceElement();
|
|
||||||
dataSourceElement.setEnabled(true);
|
|
||||||
dataSourceElement.setName(this.getName() + " JDBCDataSource");
|
|
||||||
dataSourceElement.setProperty(TestElement.TEST_CLASS, DataSourceElement.class.getName());
|
|
||||||
dataSourceElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
|
||||||
dataSourceElement.setProperty("autocommit", true);
|
|
||||||
dataSourceElement.setProperty("keepAlive", true);
|
|
||||||
dataSourceElement.setProperty("preinit", false);
|
|
||||||
dataSourceElement.setProperty("dataSource", sourceName);
|
|
||||||
dataSourceElement.setProperty("dbUrl", dataSource.getDbUrl());
|
|
||||||
dataSourceElement.setProperty("driver", dataSource.getDriver());
|
|
||||||
dataSourceElement.setProperty("username", dataSource.getUsername());
|
|
||||||
dataSourceElement.setProperty("password", dataSource.getPassword());
|
|
||||||
dataSourceElement.setProperty("poolMax", dataSource.getPoolMax());
|
|
||||||
dataSourceElement.setProperty("timeout", String.valueOf(dataSource.getTimeout()));
|
|
||||||
dataSourceElement.setProperty("connectionAge", 5000);
|
|
||||||
dataSourceElement.setProperty("trimInterval", 6000);
|
|
||||||
dataSourceElement.setProperty("transactionIsolation", "DEFAULT");
|
|
||||||
return dataSourceElement;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
package io.metersphere.api.dto.definition.request.processors.pre;
|
package io.metersphere.api.dto.definition.request.processors.pre;
|
||||||
|
|
||||||
import io.metersphere.api.dto.RunningParamKeys;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
|
||||||
import io.metersphere.api.dto.shell.filter.ScriptFilter;
|
import io.metersphere.api.dto.shell.filter.ScriptFilter;
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
|
import io.metersphere.commons.vo.ScriptProcessorVO;
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
import io.metersphere.utils.JMeterVars;
|
import io.metersphere.utils.JMeterVars;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.jmeter.modifiers.BeanShellPreProcessor;
|
||||||
import org.apache.jmeter.modifiers.JSR223PreProcessor;
|
import org.apache.jmeter.modifiers.JSR223PreProcessor;
|
||||||
import org.apache.jmeter.save.SaveService;
|
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -27,6 +28,7 @@ public class MsJSR223PreProcessor extends MsTestElement {
|
||||||
private String clazzName = MsJSR223PreProcessor.class.getCanonicalName();
|
private String clazzName = MsJSR223PreProcessor.class.getCanonicalName();
|
||||||
private String script;
|
private String script;
|
||||||
private String scriptLanguage;
|
private String scriptLanguage;
|
||||||
|
private Boolean jsrEnable;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
||||||
|
@ -35,34 +37,15 @@ public class MsJSR223PreProcessor extends MsTestElement {
|
||||||
if (!config.isOperating() && !this.isEnable()) {
|
if (!config.isOperating() && !this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ScriptFilter.verify(this.getScriptLanguage(), this.getName(), script);
|
|
||||||
if (StringUtils.isEmpty(this.getEnvironmentId())) {
|
|
||||||
if (config.getConfig() != null) {
|
|
||||||
if (config.getProjectId() != null) {
|
|
||||||
String evnId = config.getConfig().get(config.getProjectId()).getEnvironmentId();
|
|
||||||
this.setEnvironmentId(evnId);
|
|
||||||
} else {
|
|
||||||
Collection<EnvironmentConfig> evnConfigList = config.getConfig().values();
|
|
||||||
if (evnConfigList != null && !evnConfigList.isEmpty()) {
|
|
||||||
for (EnvironmentConfig configItem : evnConfigList) {
|
|
||||||
String evnId = configItem.getEnvironmentId();
|
|
||||||
this.setEnvironmentId(evnId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//替换环境变量
|
|
||||||
if (StringUtils.isNotEmpty(script)) {
|
|
||||||
script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID, "\"" + RunningParamKeys.RUNNING_PARAMS_PREFIX + this.getEnvironmentId() + ".\"");
|
|
||||||
}
|
|
||||||
if (config.isOperating()) {
|
if (config.isOperating()) {
|
||||||
if (StringUtils.isNotEmpty(script) && script.startsWith(JMeterVars.class.getCanonicalName())) {
|
if (StringUtils.isNotEmpty(script) && script.startsWith(JMeterVars.class.getCanonicalName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final HashTree jsr223PreTree = tree.add(getJSR223PreProcessor());
|
ScriptFilter.verify(this.getScriptLanguage(), this.getName(), script);
|
||||||
|
this.setEnvironmentId(ElementUtil.getScriptEnv(this.getEnvironmentId(), config));
|
||||||
|
|
||||||
|
final HashTree jsr223PreTree = tree.add(getShellProcessor());
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
hashTree.forEach(el -> {
|
hashTree.forEach(el -> {
|
||||||
el.toHashTree(jsr223PreTree, el.getHashTree(), config);
|
el.toHashTree(jsr223PreTree, el.getHashTree(), config);
|
||||||
|
@ -70,28 +53,15 @@ public class MsJSR223PreProcessor extends MsTestElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSR223PreProcessor getJSR223PreProcessor() {
|
public TestElement getShellProcessor() {
|
||||||
JSR223PreProcessor processor = new JSR223PreProcessor();
|
TestElement processor = new BeanShellPreProcessor();
|
||||||
processor.setEnabled(this.isEnable());
|
if (jsrEnable == null || BooleanUtils.isTrue(jsrEnable)) {
|
||||||
if (StringUtils.isNotEmpty(this.getName())) {
|
processor = new JSR223PreProcessor();
|
||||||
processor.setName(this.getName());
|
|
||||||
} else {
|
|
||||||
processor.setName(ElementConstants.JSR223_PRE);
|
|
||||||
}
|
}
|
||||||
processor.setProperty(TestElement.TEST_CLASS, JSR223PreProcessor.class.getName());
|
ScriptProcessorVO vo = new ScriptProcessorVO();
|
||||||
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
BeanUtils.copyBean(vo, this);
|
||||||
/*processor.setProperty("cacheKey", "true");*/
|
vo.setEnabled(this.isEnable());
|
||||||
processor.setProperty("scriptLanguage", this.getScriptLanguage());
|
ElementUtil.initScript(processor, vo);
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("nashornScript")) {
|
|
||||||
processor.setProperty("scriptLanguage", "nashorn");
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("rhinoScript")) {
|
|
||||||
processor.setProperty("scriptLanguage", "rhino");
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("javascript")) {
|
|
||||||
processor.setProperty("scriptLanguage", "rhino");
|
|
||||||
}
|
|
||||||
processor.setProperty("script", this.getScript());
|
|
||||||
return processor;
|
return processor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,6 @@ package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample;
|
import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample;
|
||||||
import io.github.ningyu.jmeter.plugin.dubbo.sample.MethodArgument;
|
import io.github.ningyu.jmeter.plugin.dubbo.sample.MethodArgument;
|
||||||
import io.github.ningyu.jmeter.plugin.util.Constants;
|
import io.github.ningyu.jmeter.plugin.util.Constants;
|
||||||
|
@ -113,9 +110,6 @@ public class MsDubboSampler extends MsTestElement {
|
||||||
|
|
||||||
private boolean setRefElement() {
|
private boolean setRefElement() {
|
||||||
try {
|
try {
|
||||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
MsDubboSampler proxy = null;
|
MsDubboSampler proxy = null;
|
||||||
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
||||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||||
|
@ -124,16 +118,15 @@ public class MsDubboSampler extends MsTestElement {
|
||||||
this.setProjectId(bloBs.getProjectId());
|
this.setProjectId(bloBs.getProjectId());
|
||||||
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
||||||
ElementUtil.dataFormatting(element);
|
ElementUtil.dataFormatting(element);
|
||||||
proxy = mapper.readValue(element.toString(), new TypeReference<MsDubboSampler>() {
|
proxy = JSONUtil.parseObject(element.toString(), MsDubboSampler.class);
|
||||||
});
|
|
||||||
this.setName(bloBs.getName());
|
this.setName(bloBs.getName());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
||||||
if (apiDefinition != null) {
|
if (apiDefinition != null) {
|
||||||
this.setProjectId(apiDefinition.getProjectId());
|
this.setProjectId(apiDefinition.getProjectId());
|
||||||
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsDubboSampler>() {
|
proxy = JSONUtil.parseObject(apiDefinition.getRequest(), MsDubboSampler.class);
|
||||||
});
|
|
||||||
this.setName(apiDefinition.getName());
|
this.setName(apiDefinition.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package io.metersphere.api.dto.definition.request.sampler;
|
package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
|
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
|
||||||
|
@ -85,6 +82,8 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
private String alias;
|
private String alias;
|
||||||
private boolean customizeReq;
|
private boolean customizeReq;
|
||||||
private final static String DEF_TIME_OUT = "60000";
|
private final static String DEF_TIME_OUT = "60000";
|
||||||
|
//客户端实现
|
||||||
|
private String implementation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
||||||
|
@ -125,6 +124,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
sampler.setContentEncoding(StandardCharsets.UTF_8.name());
|
sampler.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||||
sampler.setFollowRedirects(this.isFollowRedirects());
|
sampler.setFollowRedirects(this.isFollowRedirects());
|
||||||
sampler.setAutoRedirects(this.isAutoRedirects());
|
sampler.setAutoRedirects(this.isAutoRedirects());
|
||||||
|
sampler.setImplementation(this.getImplementation());
|
||||||
sampler.setUseKeepAlive(true);
|
sampler.setUseKeepAlive(true);
|
||||||
sampler.setDoMultipart(this.isDoMultipartPost());
|
sampler.setDoMultipart(this.isDoMultipartPost());
|
||||||
if (config.getConfig() == null) {
|
if (config.getConfig() == null) {
|
||||||
|
@ -247,8 +247,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
|
|
||||||
private boolean setRefElement() {
|
private boolean setRefElement() {
|
||||||
try {
|
try {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
MsHTTPSamplerProxy proxy = null;
|
MsHTTPSamplerProxy proxy = null;
|
||||||
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
||||||
ApiTestCaseWithBLOBs bloBs = CommonBeanFactory.getBean(ApiTestCaseService.class).get(this.getId());
|
ApiTestCaseWithBLOBs bloBs = CommonBeanFactory.getBean(ApiTestCaseService.class).get(this.getId());
|
||||||
|
@ -256,8 +254,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
this.setProjectId(bloBs.getProjectId());
|
this.setProjectId(bloBs.getProjectId());
|
||||||
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
||||||
ElementUtil.dataFormatting(element);
|
ElementUtil.dataFormatting(element);
|
||||||
proxy = mapper.readValue(element.toString(), new TypeReference<MsHTTPSamplerProxy>() {
|
proxy = JSONUtil.parseObject(element.toString(), MsHTTPSamplerProxy.class);
|
||||||
});
|
|
||||||
this.setName(bloBs.getName());
|
this.setName(bloBs.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package io.metersphere.api.dto.definition.request.sampler;
|
package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||||
|
@ -17,10 +14,8 @@ import io.metersphere.commons.constants.CommonConstants;
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.commons.utils.HashTreeUtil;
|
import io.metersphere.commons.vo.JDBCProcessorVO;
|
||||||
import io.metersphere.commons.utils.JSONUtil;
|
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
|
||||||
import io.metersphere.environment.service.BaseEnvironmentService;
|
import io.metersphere.environment.service.BaseEnvironmentService;
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
|
@ -32,10 +27,7 @@ import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.config.Arguments;
|
import org.apache.jmeter.config.Arguments;
|
||||||
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
|
|
||||||
import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
|
import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
|
||||||
import org.apache.jmeter.save.SaveService;
|
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
@ -123,11 +115,9 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
}
|
}
|
||||||
JDBCSampler jdbcSampler = jdbcSampler(config);
|
JDBCSampler jdbcSampler = jdbcSampler(config);
|
||||||
final HashTree samplerHashTree = tree.add(jdbcSampler);
|
final HashTree samplerHashTree = tree.add(jdbcSampler);
|
||||||
tree.add(jdbcDataSource(jdbcSampler.getDataSource()));
|
tree.add(ElementUtil.jdbcDataSource(jdbcSampler.getDataSource(), this.dataSource));
|
||||||
Arguments arguments = arguments(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Arguments", this.getVariables());
|
ElementUtil.jdbcArguments(this.getName(), this.getVariables(), tree);
|
||||||
if (arguments != null) {
|
|
||||||
tree.add(arguments);
|
|
||||||
}
|
|
||||||
// 环境通用请求头
|
// 环境通用请求头
|
||||||
Arguments envArguments = ElementUtil.getConfigArguments(config, this.getName(), this.getProjectId(), null);
|
Arguments envArguments = ElementUtil.getConfigArguments(config, this.getName(), this.getProjectId(), null);
|
||||||
if (envArguments != null) {
|
if (envArguments != null) {
|
||||||
|
@ -162,22 +152,8 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getParentProjectId() {
|
|
||||||
MsTestElement parent = this.getParent();
|
|
||||||
while (parent != null) {
|
|
||||||
if (StringUtils.isNotBlank(parent.getProjectId())) {
|
|
||||||
return parent.getProjectId();
|
|
||||||
}
|
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean setRefElement() {
|
private boolean setRefElement() {
|
||||||
try {
|
try {
|
||||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
MsJDBCSampler proxy = null;
|
MsJDBCSampler proxy = null;
|
||||||
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
||||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||||
|
@ -187,15 +163,14 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
this.setProjectId(bloBs.getProjectId());
|
this.setProjectId(bloBs.getProjectId());
|
||||||
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
||||||
ElementUtil.dataFormatting(element);
|
ElementUtil.dataFormatting(element);
|
||||||
proxy = mapper.readValue(element.toString(), new TypeReference<MsJDBCSampler>() {
|
proxy = JSONUtil.parseObject(element.toString(), MsJDBCSampler.class);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
||||||
if (apiDefinition != null) {
|
if (apiDefinition != null) {
|
||||||
this.setProjectId(apiDefinition.getProjectId());
|
this.setProjectId(apiDefinition.getProjectId());
|
||||||
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsJDBCSampler>() {
|
proxy = JSONUtil.parseObject(apiDefinition.getRequest(), MsJDBCSampler.class);
|
||||||
});
|
|
||||||
this.setName(apiDefinition.getName());
|
this.setName(apiDefinition.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,7 +205,6 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
envConfig.getDatabaseConfigs().forEach(item -> {
|
envConfig.getDatabaseConfigs().forEach(item -> {
|
||||||
if (item.getId().equals(this.dataSourceId)) {
|
if (item.getId().equals(this.dataSourceId)) {
|
||||||
this.dataSource = item;
|
this.dataSource = item;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -238,23 +212,12 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
return envConfig;
|
return envConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Arguments arguments(String name, List<KeyValue> variables) {
|
|
||||||
if (CollectionUtils.isNotEmpty(variables)) {
|
|
||||||
Arguments arguments = new Arguments();
|
|
||||||
arguments.setEnabled(true);
|
|
||||||
arguments.setName(name + "JDBC_Argument");
|
|
||||||
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
|
|
||||||
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
|
|
||||||
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
|
|
||||||
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
|
|
||||||
);
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JDBCSampler jdbcSampler(ParameterConfig config) {
|
private JDBCSampler jdbcSampler(ParameterConfig config) {
|
||||||
JDBCSampler sampler = new JDBCSampler();
|
JDBCSampler sampler = new JDBCSampler();
|
||||||
|
JDBCProcessorVO vo = new JDBCProcessorVO();
|
||||||
|
BeanUtils.copyBean(vo, this);
|
||||||
|
ElementUtil.jdbcProcessor(sampler, config, vo);
|
||||||
sampler.setEnabled(this.isEnable());
|
sampler.setEnabled(this.isEnable());
|
||||||
sampler.setName(this.getName());
|
sampler.setName(this.getName());
|
||||||
if (config.isOperating()) {
|
if (config.isOperating()) {
|
||||||
|
@ -264,39 +227,6 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
sampler.setName(testName);
|
sampler.setName(testName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sampler.setProperty(TestElement.TEST_CLASS, JDBCSampler.class.getName());
|
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
|
||||||
ElementUtil.setBaseParams(sampler, this.getParent(), config, this.getId(), this.getIndex());
|
|
||||||
sampler.setDataSource(ElementUtil.getDataSourceName(this.dataSource.getName()));
|
|
||||||
sampler.setProperty("dataSource", sampler.getDataSource());
|
|
||||||
sampler.setProperty("query", this.getQuery());
|
|
||||||
sampler.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
|
|
||||||
sampler.setProperty("resultVariable", this.getResultVariable());
|
|
||||||
sampler.setProperty("variableNames", this.getVariableNames());
|
|
||||||
sampler.setProperty("resultSetHandler", "Store as String");
|
|
||||||
sampler.setProperty("queryType", "Callable Statement");
|
|
||||||
return sampler;
|
return sampler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSourceElement jdbcDataSource(String dataSourceName) {
|
|
||||||
DataSourceElement dataSourceElement = new DataSourceElement();
|
|
||||||
dataSourceElement.setEnabled(true);
|
|
||||||
dataSourceElement.setName(this.getName() + " JDBCDataSource");
|
|
||||||
dataSourceElement.setProperty(TestElement.TEST_CLASS, DataSourceElement.class.getName());
|
|
||||||
dataSourceElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
|
||||||
dataSourceElement.setProperty("autocommit", true);
|
|
||||||
dataSourceElement.setProperty("keepAlive", true);
|
|
||||||
dataSourceElement.setProperty("preinit", false);
|
|
||||||
dataSourceElement.setProperty("dataSource", dataSourceName);
|
|
||||||
dataSourceElement.setProperty("dbUrl", dataSource.getDbUrl());
|
|
||||||
dataSourceElement.setProperty("driver", dataSource.getDriver());
|
|
||||||
dataSourceElement.setProperty("username", dataSource.getUsername());
|
|
||||||
dataSourceElement.setProperty("password", dataSource.getPassword());
|
|
||||||
dataSourceElement.setProperty("poolMax", dataSource.getPoolMax());
|
|
||||||
dataSourceElement.setProperty("timeout", String.valueOf(dataSource.getTimeout()));
|
|
||||||
dataSourceElement.setProperty("connectionAge", 5000);
|
|
||||||
dataSourceElement.setProperty("trimInterval", 6000);
|
|
||||||
dataSourceElement.setProperty("transactionIsolation", "DEFAULT");
|
|
||||||
return dataSourceElement;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package io.metersphere.api.dto.definition.request.sampler;
|
package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||||
import io.metersphere.api.dto.automation.TcpTreeTableDataStruct;
|
import io.metersphere.api.dto.automation.TcpTreeTableDataStruct;
|
||||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
|
@ -151,7 +148,7 @@ public class MsTCPSampler extends MsTestElement {
|
||||||
tree.set(tcpSampler(config), samplerHashTree);
|
tree.set(tcpSampler(config), samplerHashTree);
|
||||||
setUserParameters(samplerHashTree);
|
setUserParameters(samplerHashTree);
|
||||||
if (tcpPreProcessor != null && StringUtils.isNotBlank(tcpPreProcessor.getScript())) {
|
if (tcpPreProcessor != null && StringUtils.isNotBlank(tcpPreProcessor.getScript())) {
|
||||||
samplerHashTree.add(tcpPreProcessor.getJSR223PreProcessor());
|
samplerHashTree.add(tcpPreProcessor.getShellProcessor());
|
||||||
}
|
}
|
||||||
//增加误报、全局断言
|
//增加误报、全局断言
|
||||||
HashTreeUtil.addPositive(envConfig, samplerHashTree, config, this.getProjectId());
|
HashTreeUtil.addPositive(envConfig, samplerHashTree, config, this.getProjectId());
|
||||||
|
@ -180,9 +177,6 @@ public class MsTCPSampler extends MsTestElement {
|
||||||
|
|
||||||
private boolean setRefElement() {
|
private boolean setRefElement() {
|
||||||
try {
|
try {
|
||||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
MsTCPSampler proxy = null;
|
MsTCPSampler proxy = null;
|
||||||
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) {
|
||||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||||
|
@ -192,16 +186,15 @@ public class MsTCPSampler extends MsTestElement {
|
||||||
this.setProjectId(bloBs.getProjectId());
|
this.setProjectId(bloBs.getProjectId());
|
||||||
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
JSONObject element = JSONUtil.parseObject(bloBs.getRequest());
|
||||||
ElementUtil.dataFormatting(element);
|
ElementUtil.dataFormatting(element);
|
||||||
proxy = mapper.readValue(element.toString(), new TypeReference<MsTCPSampler>() {
|
proxy = JSONUtil.parseObject(element.toString(), MsTCPSampler.class);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
||||||
if (apiDefinition != null) {
|
if (apiDefinition != null) {
|
||||||
this.setName(apiDefinition.getName());
|
this.setName(apiDefinition.getName());
|
||||||
this.setProjectId(apiDefinition.getProjectId());
|
this.setProjectId(apiDefinition.getProjectId());
|
||||||
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsTCPSampler>() {
|
proxy = JSONUtil.parseObject(apiDefinition.getRequest(), MsTCPSampler.class);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (proxy != null) {
|
if (proxy != null) {
|
||||||
|
|
|
@ -55,4 +55,6 @@ public class BaseEnvElement {
|
||||||
|
|
||||||
// 步骤别名
|
// 步骤别名
|
||||||
private String stepName;
|
private String stepName;
|
||||||
|
|
||||||
|
private Boolean jsrEnable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package io.metersphere.api.exec.api;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.metersphere.api.dto.definition.RunCaseRequest;
|
import io.metersphere.api.dto.definition.RunCaseRequest;
|
||||||
import io.metersphere.api.dto.definition.RunDefinitionRequest;
|
import io.metersphere.api.dto.definition.RunDefinitionRequest;
|
||||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
|
@ -68,8 +67,6 @@ public class ApiExecuteService {
|
||||||
@Resource
|
@Resource
|
||||||
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
private ExtApiTestCaseMapper extApiTestCaseMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ObjectMapper mapper;
|
|
||||||
@Resource
|
|
||||||
private TestPlanApiCaseMapper testPlanApiCaseMapper;
|
private TestPlanApiCaseMapper testPlanApiCaseMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private SystemParameterService systemParameterService;
|
private SystemParameterService systemParameterService;
|
||||||
|
@ -276,8 +273,7 @@ public class ApiExecuteService {
|
||||||
JSONObject elementObj = JSONUtil.parseObject(testCaseWithBLOBs.getRequest());
|
JSONObject elementObj = JSONUtil.parseObject(testCaseWithBLOBs.getRequest());
|
||||||
ElementUtil.dataFormatting(elementObj);
|
ElementUtil.dataFormatting(elementObj);
|
||||||
|
|
||||||
MsTestElement element = mapper.readValue(elementObj.toString(), new TypeReference<MsTestElement>() {
|
MsTestElement element = JSON.parseObject(elementObj.toString(), new TypeReference<MsTestElement>() {});
|
||||||
});
|
|
||||||
element.setProjectId(testCaseWithBLOBs.getProjectId());
|
element.setProjectId(testCaseWithBLOBs.getProjectId());
|
||||||
if (StringUtils.isBlank(request.getEnvironmentId())) {
|
if (StringUtils.isBlank(request.getEnvironmentId())) {
|
||||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package io.metersphere.api.jmeter;
|
package io.metersphere.api.jmeter;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.metersphere.api.exec.queue.PoolExecBlockingQueueUtil;
|
import io.metersphere.api.exec.queue.PoolExecBlockingQueueUtil;
|
||||||
import io.metersphere.commons.constants.ApiRunMode;
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
import io.metersphere.commons.constants.ExtendedParameter;
|
import io.metersphere.commons.constants.ExtendedParameter;
|
||||||
|
import io.metersphere.commons.utils.JSON;
|
||||||
import io.metersphere.dto.ResultDTO;
|
import io.metersphere.dto.ResultDTO;
|
||||||
import io.metersphere.service.ApiExecutionQueueService;
|
import io.metersphere.service.ApiExecutionQueueService;
|
||||||
import io.metersphere.service.TestResultService;
|
import io.metersphere.service.TestResultService;
|
||||||
|
@ -22,8 +22,6 @@ public class KafkaListenerTask implements Runnable {
|
||||||
private ConsumerRecord<?, String> record;
|
private ConsumerRecord<?, String> record;
|
||||||
private ApiExecutionQueueService apiExecutionQueueService;
|
private ApiExecutionQueueService apiExecutionQueueService;
|
||||||
private TestResultService testResultService;
|
private TestResultService testResultService;
|
||||||
private ObjectMapper mapper;
|
|
||||||
|
|
||||||
private static final Map<String, String> RUN_MODE_MAP = new HashMap<String, String>() {{
|
private static final Map<String, String> RUN_MODE_MAP = new HashMap<String, String>() {{
|
||||||
this.put(ApiRunMode.SCHEDULE_API_PLAN.name(), "schedule-task");
|
this.put(ApiRunMode.SCHEDULE_API_PLAN.name(), "schedule-task");
|
||||||
this.put(ApiRunMode.JENKINS_API_PLAN.name(), "schedule-task");
|
this.put(ApiRunMode.JENKINS_API_PLAN.name(), "schedule-task");
|
||||||
|
@ -99,9 +97,8 @@ public class KafkaListenerTask implements Runnable {
|
||||||
|
|
||||||
private ResultDTO formatResult() {
|
private ResultDTO formatResult() {
|
||||||
try {
|
try {
|
||||||
// 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取
|
|
||||||
if (StringUtils.isNotEmpty(record.value())) {
|
if (StringUtils.isNotEmpty(record.value())) {
|
||||||
return mapper.readValue(record.value(), new TypeReference<ResultDTO>() {
|
return JSON.parseObject(record.value(), new TypeReference<ResultDTO>() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package io.metersphere.api.jmeter;
|
package io.metersphere.api.jmeter;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.metersphere.api.dto.MsgDTO;
|
import io.metersphere.api.dto.MsgDTO;
|
||||||
import io.metersphere.commons.constants.KafkaTopicConstants;
|
import io.metersphere.commons.constants.KafkaTopicConstants;
|
||||||
import io.metersphere.commons.utils.JSONUtil;
|
import io.metersphere.commons.utils.JSONUtil;
|
||||||
|
@ -30,8 +29,6 @@ public class MsKafkaListener {
|
||||||
private ApiExecutionQueueService apiExecutionQueueService;
|
private ApiExecutionQueueService apiExecutionQueueService;
|
||||||
@Resource
|
@Resource
|
||||||
private TestResultService testResultService;
|
private TestResultService testResultService;
|
||||||
@Resource
|
|
||||||
private ObjectMapper mapper;
|
|
||||||
// 线程池维护线程的最少数量
|
// 线程池维护线程的最少数量
|
||||||
private final static int CORE_POOL_SIZE = 20;
|
private final static int CORE_POOL_SIZE = 20;
|
||||||
// 线程池维护线程的最大数量
|
// 线程池维护线程的最大数量
|
||||||
|
@ -57,7 +54,6 @@ public class MsKafkaListener {
|
||||||
KafkaListenerTask task = new KafkaListenerTask();
|
KafkaListenerTask task = new KafkaListenerTask();
|
||||||
task.setApiExecutionQueueService(apiExecutionQueueService);
|
task.setApiExecutionQueueService(apiExecutionQueueService);
|
||||||
task.setTestResultService(testResultService);
|
task.setTestResultService(testResultService);
|
||||||
task.setMapper(mapper);
|
|
||||||
task.setRecord(item);
|
task.setRecord(item);
|
||||||
threadPool.execute(task);
|
threadPool.execute(task);
|
||||||
this.outKafkaPoolLogger();
|
this.outKafkaPoolLogger();
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package io.metersphere.commons.vo;
|
||||||
|
|
||||||
|
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||||
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
|
import io.metersphere.commons.constants.RequestTypeConstants;
|
||||||
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class JDBCProcessorVO {
|
||||||
|
private boolean enable;
|
||||||
|
private String name;
|
||||||
|
private String id;
|
||||||
|
private String index;
|
||||||
|
|
||||||
|
private DatabaseConfig dataSource;
|
||||||
|
private String query;
|
||||||
|
private long queryTimeout;
|
||||||
|
private String resultVariable;
|
||||||
|
private String variableNames;
|
||||||
|
private List<KeyValue> variables;
|
||||||
|
private String environmentId;
|
||||||
|
private String dataSourceId;
|
||||||
|
private String protocol = RequestTypeConstants.SQL;
|
||||||
|
private String useEnvironment;
|
||||||
|
private MsTestElement parent;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package io.metersphere.commons.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ScriptProcessorVO {
|
||||||
|
private String name;
|
||||||
|
private String scriptLanguage;
|
||||||
|
private String script;
|
||||||
|
private Boolean jsrEnable;
|
||||||
|
private boolean enabled;
|
||||||
|
private String environmentId;
|
||||||
|
}
|
|
@ -31,7 +31,6 @@ import io.metersphere.api.parse.scenario.TcpTreeTableDataParser;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.*;
|
import io.metersphere.base.mapper.ext.*;
|
||||||
import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper;
|
|
||||||
import io.metersphere.commons.constants.*;
|
import io.metersphere.commons.constants.*;
|
||||||
import io.metersphere.commons.enums.*;
|
import io.metersphere.commons.enums.*;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
|
@ -158,8 +157,6 @@ public class ApiDefinitionService {
|
||||||
@Resource
|
@Resource
|
||||||
private ExtApiScenarioMapper extApiScenarioMapper;
|
private ExtApiScenarioMapper extApiScenarioMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
|
|
||||||
@Resource
|
|
||||||
private ApiCustomFieldService customFieldApiService;
|
private ApiCustomFieldService customFieldApiService;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiScenarioMapper apiScenarioMapper;
|
private ApiScenarioMapper apiScenarioMapper;
|
||||||
|
@ -298,51 +295,6 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initDefaultModuleId() {
|
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
|
||||||
example.createCriteria().andModuleIdIsNull();
|
|
||||||
List<ApiDefinition> updateApiList = apiDefinitionMapper.selectByExample(example);
|
|
||||||
Map<String, Map<String, List<ApiDefinition>>> projectIdMap = new HashMap<>();
|
|
||||||
for (ApiDefinition api : updateApiList) {
|
|
||||||
String projectId = api.getProjectId();
|
|
||||||
String protocol = api.getProtocol();
|
|
||||||
if (projectIdMap.containsKey(projectId)) {
|
|
||||||
if (projectIdMap.get(projectId).containsKey(protocol)) {
|
|
||||||
projectIdMap.get(projectId).get(protocol).add(api);
|
|
||||||
} else {
|
|
||||||
List<ApiDefinition> list = new ArrayList<>();
|
|
||||||
list.add(api);
|
|
||||||
projectIdMap.get(projectId).put(protocol, list);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
List<ApiDefinition> list = new ArrayList<>();
|
|
||||||
list.add(api);
|
|
||||||
Map<String, List<ApiDefinition>> map = new HashMap<>();
|
|
||||||
map.put(protocol, list);
|
|
||||||
projectIdMap.put(projectId, map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, Map<String, List<ApiDefinition>>> entry : projectIdMap.entrySet()) {
|
|
||||||
String projectId = entry.getKey();
|
|
||||||
Map<String, List<ApiDefinition>> map = entry.getValue();
|
|
||||||
|
|
||||||
for (Map.Entry<String, List<ApiDefinition>> itemEntry : map.entrySet()) {
|
|
||||||
String protocol = itemEntry.getKey();
|
|
||||||
ApiModule node = apiModuleService.getDefaultNodeUnCreateNew(projectId, protocol);
|
|
||||||
if (node != null) {
|
|
||||||
List<ApiDefinition> testCaseList = itemEntry.getValue();
|
|
||||||
for (ApiDefinition apiDefinition : testCaseList) {
|
|
||||||
ApiDefinitionWithBLOBs updateCase = new ApiDefinitionWithBLOBs();
|
|
||||||
updateCase.setId(apiDefinition.getId());
|
|
||||||
updateCase.setModuleId(node.getId());
|
|
||||||
updateCase.setModulePath("/" + node.getName());
|
|
||||||
|
|
||||||
apiDefinitionMapper.updateByPrimaryKeySelective(updateCase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ApiDefinitionResult> listBatch(ApiBatchRequest request) {
|
public List<ApiDefinitionResult> listBatch(ApiBatchRequest request) {
|
||||||
ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiDefinitionMapper.selectIds(query));
|
ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiDefinitionMapper.selectIds(query));
|
||||||
|
@ -2926,27 +2878,6 @@ public class ApiDefinitionService {
|
||||||
return envIdList;
|
return envIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<String>> getProjectEnvNameByEnvConfig(String projectId, String envConfig) {
|
|
||||||
Map<String, List<String>> returnMap = new HashMap<>();
|
|
||||||
RunModeConfigDTO runModeConfigDTO = null;
|
|
||||||
try {
|
|
||||||
runModeConfigDTO = JSON.parseObject(envConfig, RunModeConfigDTO.class);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败!", e);
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) {
|
|
||||||
String envId = runModeConfigDTO.getEnvMap().get(projectId);
|
|
||||||
String envName = apiTestEnvironmentService.selectNameById(envId);
|
|
||||||
Project project = baseProjectService.getProjectById(projectId);
|
|
||||||
String projectName = project == null ? null : project.getName();
|
|
||||||
if (StringUtils.isNoneEmpty(envName, projectName)) {
|
|
||||||
returnMap.put(projectName, new ArrayList<>() {{
|
|
||||||
this.add(envName);
|
|
||||||
}});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return returnMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, List<String>> getProjectEnvNameByEnvConfig(Map<String, List<String>> projectEnvConfigMap) {
|
public Map<String, List<String>> getProjectEnvNameByEnvConfig(Map<String, List<String>> projectEnvConfigMap) {
|
||||||
Map<String, List<String>> returnMap = new HashMap<>();
|
Map<String, List<String>> returnMap = new HashMap<>();
|
||||||
|
|
|
@ -2332,6 +2332,12 @@ export default {
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
getAllCheckedNodes() {
|
||||||
|
if (this.$refs.stepTree) {
|
||||||
|
return this.$refs.stepTree.getCheckedNodes();
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
},
|
||||||
checkALevelChecked() {
|
checkALevelChecked() {
|
||||||
let resourceIds = [];
|
let resourceIds = [];
|
||||||
if (this.$refs.stepTree) {
|
if (this.$refs.stepTree) {
|
||||||
|
@ -2404,7 +2410,7 @@ export default {
|
||||||
confirmButtonText: this.$t('commons.confirm'),
|
confirmButtonText: this.$t('commons.confirm'),
|
||||||
callback: (action) => {
|
callback: (action) => {
|
||||||
if (action === 'confirm') {
|
if (action === 'confirm') {
|
||||||
this.getAllResourceIds().forEach((item) => {
|
this.getAllCheckedNodes().forEach((item) => {
|
||||||
this.recursionDelete(item, this.scenarioDefinition);
|
this.recursionDelete(item, this.scenarioDefinition);
|
||||||
});
|
});
|
||||||
this.sort();
|
this.sort();
|
||||||
|
@ -2417,14 +2423,15 @@ export default {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
recursionDelete(resourceId, nodes) {
|
recursionDelete(item, nodes) {
|
||||||
for (let i in nodes) {
|
for (let i in nodes) {
|
||||||
if (nodes[i]) {
|
if (nodes[i]) {
|
||||||
if (resourceId === nodes[i].resourceId) {
|
//复制的case的断言的resourceId是一样的,所以要加上parentIndex做唯一标识
|
||||||
|
if (item.resourceId === nodes[i].resourceId && item.parentIndex === nodes[i].parentIndex) {
|
||||||
nodes.splice(i, 1);
|
nodes.splice(i, 1);
|
||||||
} else {
|
} else {
|
||||||
if (nodes[i].hashTree != undefined && nodes[i].hashTree.length > 0) {
|
if (nodes[i].hashTree != undefined && nodes[i].hashTree.length > 0) {
|
||||||
this.recursionDelete(resourceId, nodes[i].hashTree);
|
this.recursionDelete(item, nodes[i].hashTree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,12 @@
|
||||||
:commands="languages"
|
:commands="languages"
|
||||||
style="margin-bottom: 5px; margin-left: 15px"
|
style="margin-bottom: 5px; margin-left: 15px"
|
||||||
@command="languageChange" />
|
@command="languageChange" />
|
||||||
|
<el-checkbox
|
||||||
|
v-model="jsr223ProcessorData.jsrEnable"
|
||||||
|
style="padding-left: 10px"
|
||||||
|
:disabled="jsr223ProcessorData.scriptLanguage !== 'beanshell'">
|
||||||
|
JSR223
|
||||||
|
</el-checkbox>
|
||||||
<script-nav-menu
|
<script-nav-menu
|
||||||
ref="scriptNavMenu"
|
ref="scriptNavMenu"
|
||||||
:language="jsr223ProcessorData.scriptLanguage"
|
:language="jsr223ProcessorData.scriptLanguage"
|
||||||
|
@ -164,6 +170,9 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
if (this.jsr223Processor.jsrEnable === null || this.jsr223Processor.jsrEnable === undefined) {
|
||||||
|
this.$set(this.jsr223Processor, 'jsrEnable', true);
|
||||||
|
}
|
||||||
this.jsr223ProcessorData = this.jsr223Processor;
|
this.jsr223ProcessorData = this.jsr223Processor;
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
@ -206,6 +215,9 @@ export default {
|
||||||
},
|
},
|
||||||
languageChange(language) {
|
languageChange(language) {
|
||||||
this.jsr223ProcessorData.scriptLanguage = language;
|
this.jsr223ProcessorData.scriptLanguage = language;
|
||||||
|
if (language !== 'beanshell') {
|
||||||
|
this.jsr223ProcessorData.jsrEnable = true;
|
||||||
|
}
|
||||||
this.$emit('languageChange');
|
this.$emit('languageChange');
|
||||||
},
|
},
|
||||||
addCustomFuncScript(script) {
|
addCustomFuncScript(script) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<mavon-editor :id="id" :editable="!disabled" @imgAdd="imgAdd" :default-open="defaultOpenValue"
|
<mavon-editor v-loading="loading" :id="id" :editable="!disabled" @imgAdd="imgAdd" :default-open="defaultOpenValue"
|
||||||
:xss-options="xssOptions" :style="{'min-height': customMinHeight + 'px', 'min-width': '100px'}"
|
:xss-options="xssOptions" :style="{'min-height': customMinHeight + 'px', 'min-width': '100px'}"
|
||||||
@change="change" :image-click="imageClick"
|
@change="change" :image-click="imageClick"
|
||||||
:subfield="false" :toolbars="toolbars" :language="language" :toolbarsFlag="!disabled"
|
:subfield="false" :toolbars="toolbars" :language="language" :toolbarsFlag="!disabled"
|
||||||
|
@ -80,7 +80,7 @@ export default {
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
result: {loading: false},
|
loading: false,
|
||||||
id: getUUID(),
|
id: getUUID(),
|
||||||
xssOptions: {
|
xssOptions: {
|
||||||
whiteList: {
|
whiteList: {
|
||||||
|
@ -183,13 +183,13 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
imgAdd(pos, file) {
|
imgAdd(pos, file) {
|
||||||
this.result.loading = true;
|
this.loading = true;
|
||||||
uploadMarkDownImg(file)
|
uploadMarkDownImg(file)
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
this.$success(this.$t('commons.save_success'));
|
this.$success(this.$t('commons.save_success'));
|
||||||
let url = '/resource/md/get?fileName=' + r.data;
|
let url = '/resource/md/get?fileName=' + r.data;
|
||||||
this.$refs.md.$img2Url(pos, url);
|
this.$refs.md.$img2Url(pos, url);
|
||||||
this.result.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
this.$emit('imgAdd', file);
|
this.$emit('imgAdd', file);
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,24 +2,52 @@
|
||||||
<div>
|
<div>
|
||||||
<el-row type="flex" :gutter="10">
|
<el-row type="flex" :gutter="10">
|
||||||
<el-col :span="codeSpan" class="script-content">
|
<el-col :span="codeSpan" class="script-content">
|
||||||
<ms-code-edit v-if="isCodeEditAlive" :mode="codeEditModeMap[jsr223ProcessorData.scriptLanguage]"
|
<ms-code-edit
|
||||||
:read-only="isReadOnly"
|
v-if="isCodeEditAlive"
|
||||||
:data.sync="jsr223ProcessorData.script" theme="eclipse" :modes="['java','python']"
|
:mode="codeEditModeMap[jsr223ProcessorData.scriptLanguage]"
|
||||||
ref="codeEdit"/>
|
:read-only="isReadOnly"
|
||||||
|
:data.sync="jsr223ProcessorData.script"
|
||||||
|
theme="eclipse"
|
||||||
|
:modes="['java', 'python']"
|
||||||
|
ref="codeEdit"
|
||||||
|
/>
|
||||||
</el-col>
|
</el-col>
|
||||||
<div style="width: 14px;margin-right: 5px;">
|
<div style="width: 14px; margin-right: 5px">
|
||||||
<div style="height: 12px;width: 12px; line-height:12px;">
|
<div style="height: 12px; width: 12px; line-height: 12px">
|
||||||
<i :class="showMenu ? 'el-icon-remove-outline' : 'el-icon-circle-plus-outline'"
|
<i
|
||||||
class="show-menu"
|
:class="
|
||||||
@click="switchMenu"></i>
|
showMenu
|
||||||
|
? 'el-icon-remove-outline'
|
||||||
|
: 'el-icon-circle-plus-outline'
|
||||||
|
"
|
||||||
|
class="show-menu"
|
||||||
|
@click="switchMenu"
|
||||||
|
></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<el-col :span="menuSpan" class="script-index" v-if="isReadOnly !== true">
|
<el-col :span="menuSpan" class="script-index" v-if="isReadOnly !== true">
|
||||||
<ms-dropdown :default-command="jsr223ProcessorData.scriptLanguage" :commands="languages"
|
<ms-dropdown
|
||||||
style="margin-bottom: 5px;margin-left: 15px;"
|
:default-command="jsr223ProcessorData.scriptLanguage"
|
||||||
@command="languageChange"/>
|
:commands="languages"
|
||||||
<script-nav-menu ref="scriptNavMenu" :language="jsr223ProcessorData.scriptLanguage" :menus="codeTemplates"
|
style="margin-bottom: 5px; margin-left: 15px"
|
||||||
@handleCode="handleCodeTemplate"/>
|
@command="languageChange"
|
||||||
|
/>
|
||||||
|
<el-checkbox
|
||||||
|
v-model="jsr223ProcessorData.jsrEnable"
|
||||||
|
style="padding-left: 10px"
|
||||||
|
:disabled="
|
||||||
|
jsr223ProcessorData.scriptLanguage &&
|
||||||
|
jsr223ProcessorData.scriptLanguage !== 'beanshell'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
JSR223
|
||||||
|
</el-checkbox>
|
||||||
|
<script-nav-menu
|
||||||
|
ref="scriptNavMenu"
|
||||||
|
:language="jsr223ProcessorData.scriptLanguage"
|
||||||
|
:menus="codeTemplates"
|
||||||
|
@handleCode="handleCodeTemplate"
|
||||||
|
/>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,135 +60,165 @@ import ScriptNavMenu from "../snippet/ScriptNavMenu";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Jsr233ProcessorContent",
|
name: "Jsr233ProcessorContent",
|
||||||
components: {MsDropdown, MsCodeEdit, ScriptNavMenu},
|
components: { MsDropdown, MsCodeEdit, ScriptNavMenu },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
jsr223ProcessorData: {},
|
jsr223ProcessorData: {},
|
||||||
codeTemplates: [
|
codeTemplates: [
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.api_test'),
|
title: this.$t("project.code_segment.api_test"),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.import_api_test'),
|
title: this.$t("project.code_segment.import_api_test"),
|
||||||
command: "api_definition",
|
command: "api_definition",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.new_api_test'),
|
title: this.$t("project.code_segment.new_api_test"),
|
||||||
command: "new_api_request",
|
command: "new_api_request",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.custom_value'),
|
title: this.$t("project.code_segment.custom_value"),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: this.$t('api_test.request.processor.code_template_get_variable'),
|
title: this.$t(
|
||||||
|
"api_test.request.processor.code_template_get_variable"
|
||||||
|
),
|
||||||
value: 'vars.get("variable_name")',
|
value: 'vars.get("variable_name")',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('api_test.request.processor.code_template_set_variable'),
|
title: this.$t(
|
||||||
|
"api_test.request.processor.code_template_set_variable"
|
||||||
|
),
|
||||||
value: 'vars.put("variable_name", "variable_value")',
|
value: 'vars.put("variable_name", "variable_value")',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('api_test.request.processor.code_template_get_response_header'),
|
title: this.$t(
|
||||||
value: 'prev.getResponseHeaders()',
|
"api_test.request.processor.code_template_get_response_header"
|
||||||
disabled: this.isPreProcessor
|
),
|
||||||
|
value: "prev.getResponseHeaders()",
|
||||||
|
disabled: this.isPreProcessor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('api_test.request.processor.code_template_get_response_code'),
|
title: this.$t(
|
||||||
value: 'prev.getResponseCode()',
|
"api_test.request.processor.code_template_get_response_code"
|
||||||
disabled: this.isPreProcessor
|
),
|
||||||
|
value: "prev.getResponseCode()",
|
||||||
|
disabled: this.isPreProcessor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('api_test.request.processor.code_template_get_response_result'),
|
title: this.$t(
|
||||||
value: 'prev.getResponseDataAsString()',
|
"api_test.request.processor.code_template_get_response_result"
|
||||||
disabled: this.isPreProcessor
|
),
|
||||||
|
value: "prev.getResponseDataAsString()",
|
||||||
|
disabled: this.isPreProcessor,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.project_env'),
|
title: this.$t("project.code_segment.project_env"),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: this.$t('api_test.request.processor.param_environment_set_global_variable'),
|
title: this.$t(
|
||||||
value: 'vars.put(${__metersphere_env_id}+"key","value");\n' + 'vars.put("key","value")',
|
"api_test.request.processor.param_environment_set_global_variable"
|
||||||
|
),
|
||||||
|
value:
|
||||||
|
'vars.put(${__metersphere_env_id}+"key","value");\n' +
|
||||||
|
'vars.put("key","value")',
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.code_segment'),
|
title: this.$t("project.code_segment.code_segment"),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.insert_segment'),
|
title: this.$t("project.code_segment.insert_segment"),
|
||||||
command: "custom_function",
|
command: "custom_function",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.exception_handle'),
|
title: this.$t("project.code_segment.exception_handle"),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.stop_test'),
|
title: this.$t("project.code_segment.stop_test"),
|
||||||
value: 'ctx.getEngine().stopThreadNow(ctx.getThread().getThreadName());'
|
value:
|
||||||
|
"ctx.getEngine().stopThreadNow(ctx.getThread().getThreadName());",
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('project.code_segment.report_handle'),
|
title: this.$t("project.code_segment.report_handle"),
|
||||||
hideScript: this.isHideScript(),
|
hideScript: this.isHideScript(),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: this.$t('api_test.request.processor.code_add_report_length'),
|
title: this.$t(
|
||||||
value: 'String report = ctx.getCurrentSampler().getRequestData();\n' +
|
"api_test.request.processor.code_add_report_length"
|
||||||
'if(report!=null){\n' +
|
),
|
||||||
' //补足8位长度,前置补0\n' +
|
value:
|
||||||
|
"String report = ctx.getCurrentSampler().getRequestData();\n" +
|
||||||
|
"if(report!=null){\n" +
|
||||||
|
" //补足8位长度,前置补0\n" +
|
||||||
' String reportlengthStr = String.format("%08d",report.length());\n' +
|
' String reportlengthStr = String.format("%08d",report.length());\n' +
|
||||||
' report = reportlengthStr+report;\n' +
|
" report = reportlengthStr+report;\n" +
|
||||||
' ctx.getCurrentSampler().setRequestData(report);\n' +
|
" ctx.getCurrentSampler().setRequestData(report);\n" +
|
||||||
'}',
|
"}",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: this.$t('api_test.request.processor.code_hide_report_length'),
|
title: this.$t(
|
||||||
value: '//Get response data\n' +
|
"api_test.request.processor.code_hide_report_length"
|
||||||
'String returnData = prev.getResponseDataAsString();\n' +
|
),
|
||||||
'if(returnData!=null&&returnData.length()>8){\n' +
|
value:
|
||||||
'//remove 8 report length \n' +
|
"//Get response data\n" +
|
||||||
' String subStringData = returnData.substring(8,returnData.length());\n' +
|
"String returnData = prev.getResponseDataAsString();\n" +
|
||||||
|
"if(returnData!=null&&returnData.length()>8){\n" +
|
||||||
|
"//remove 8 report length \n" +
|
||||||
|
" String subStringData = returnData.substring(8,returnData.length());\n" +
|
||||||
' if(subStringData.startsWith("<")){\n' +
|
' if(subStringData.startsWith("<")){\n' +
|
||||||
' returnData = subStringData;\n' +
|
" returnData = subStringData;\n" +
|
||||||
' prev.setResponseData(returnData);\n' +
|
" prev.setResponseData(returnData);\n" +
|
||||||
' }\n' +
|
" }\n" +
|
||||||
'}',
|
"}",
|
||||||
disabled: this.isPreProcessor,
|
disabled: this.isPreProcessor,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
isCodeEditAlive: true,
|
isCodeEditAlive: true,
|
||||||
languages: [
|
languages: ["beanshell", "python", "groovy", "javascript"],
|
||||||
'beanshell', "python", "groovy", "javascript"
|
|
||||||
],
|
|
||||||
codeEditModeMap: {
|
codeEditModeMap: {
|
||||||
beanshell: 'java',
|
beanshell: "java",
|
||||||
python: 'python',
|
python: "python",
|
||||||
groovy: 'java',
|
groovy: "java",
|
||||||
nashornScript: 'javascript',
|
nashornScript: "javascript",
|
||||||
rhinoScript: 'javascript',
|
rhinoScript: "javascript",
|
||||||
javascript: 'javascript',
|
javascript: "javascript",
|
||||||
},
|
},
|
||||||
codeSpan: 20,
|
codeSpan: 20,
|
||||||
menuSpan: 4,
|
menuSpan: 4,
|
||||||
showMenu: true,
|
showMenu: true,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
if (
|
||||||
|
this.jsr223Processor.jsrEnable === null ||
|
||||||
|
this.jsr223Processor.jsrEnable === undefined
|
||||||
|
) {
|
||||||
|
this.$set(this.jsr223Processor, "jsrEnable", true);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
this.jsr223Processor.scriptLanguage === null ||
|
||||||
|
this.jsr223Processor.scriptLanguage === undefined
|
||||||
|
) {
|
||||||
|
this.$set(this.jsr223Processor, "scriptLanguage", "beanshell");
|
||||||
|
}
|
||||||
this.jsr223ProcessorData = this.jsr223Processor;
|
this.jsr223ProcessorData = this.jsr223Processor;
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
isReadOnly: {
|
isReadOnly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default:
|
default: false,
|
||||||
false
|
|
||||||
},
|
},
|
||||||
jsr223Processor: {
|
jsr223Processor: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
@ -168,15 +226,14 @@ export default {
|
||||||
protocol: String,
|
protocol: String,
|
||||||
isPreProcessor: {
|
isPreProcessor: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default:
|
default: false,
|
||||||
false
|
|
||||||
},
|
},
|
||||||
node: {},
|
node: {},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
jsr223Processor() {
|
jsr223Processor() {
|
||||||
this.reload();
|
this.reload();
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addTemplate(template) {
|
addTemplate(template) {
|
||||||
|
@ -184,25 +241,29 @@ export default {
|
||||||
this.jsr223ProcessorData.script = "";
|
this.jsr223ProcessorData.script = "";
|
||||||
}
|
}
|
||||||
this.jsr223ProcessorData.script += template.value;
|
this.jsr223ProcessorData.script += template.value;
|
||||||
if (this.jsr223ProcessorData.scriptLanguage === 'beanshell') {
|
if (this.jsr223ProcessorData.scriptLanguage === "beanshell") {
|
||||||
this.jsr223ProcessorData.script += ';';
|
this.jsr223ProcessorData.script += ";";
|
||||||
}
|
}
|
||||||
this.reload();
|
this.reload();
|
||||||
},
|
},
|
||||||
isHideScript() {
|
isHideScript() {
|
||||||
return this.protocol !== 'TCP';
|
return this.protocol !== "TCP";
|
||||||
},
|
},
|
||||||
reload() {
|
reload() {
|
||||||
this.isCodeEditAlive = false;
|
this.isCodeEditAlive = false;
|
||||||
this.$nextTick(() => (this.isCodeEditAlive = true));
|
this.$nextTick(() => (this.isCodeEditAlive = true));
|
||||||
},
|
},
|
||||||
languageChange(language) {
|
languageChange(language) {
|
||||||
|
if (language !== "beanshell") {
|
||||||
|
this.jsr223ProcessorData.jsrEnable = true;
|
||||||
|
}
|
||||||
this.jsr223ProcessorData.scriptLanguage = language;
|
this.jsr223ProcessorData.scriptLanguage = language;
|
||||||
this.$emit("languageChange");
|
this.$emit("languageChange");
|
||||||
},
|
},
|
||||||
addCustomFuncScript(script) {
|
addCustomFuncScript(script) {
|
||||||
this.jsr223ProcessorData.script = this.jsr223ProcessorData.script ?
|
this.jsr223ProcessorData.script = this.jsr223ProcessorData.script
|
||||||
this.jsr223ProcessorData.script + '\n\n' + script : script;
|
? this.jsr223ProcessorData.script + "\n\n" + script
|
||||||
|
: script;
|
||||||
this.reload();
|
this.reload();
|
||||||
},
|
},
|
||||||
switchMenu() {
|
switchMenu() {
|
||||||
|
@ -220,8 +281,8 @@ export default {
|
||||||
this.$refs.codeEdit.insert(code);
|
this.$refs.codeEdit.insert(code);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
@ -268,5 +329,4 @@ export default {
|
||||||
.show-menu:hover {
|
.show-menu:hover {
|
||||||
color: #935aa1;
|
color: #935aa1;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1078,7 +1078,8 @@ const message = {
|
||||||
avg_response_time: 'Average Response Time',
|
avg_response_time: 'Average Response Time',
|
||||||
tps: 'Transactions Per Second',
|
tps: 'Transactions Per Second',
|
||||||
plan_share_url: 'Whether the link jump is logged in',
|
plan_share_url: 'Whether the link jump is logged in',
|
||||||
rename_report: 'Rename report'
|
rename_report: 'Rename report',
|
||||||
|
run_model: 'Run model'
|
||||||
},
|
},
|
||||||
load_test: {
|
load_test: {
|
||||||
exist_related_file: 'Existed Relate Files',
|
exist_related_file: 'Existed Relate Files',
|
||||||
|
|
|
@ -1086,7 +1086,8 @@ const message = {
|
||||||
avg_response_time: '平均响应时间',
|
avg_response_time: '平均响应时间',
|
||||||
tps: '每秒传输的事物处理个数',
|
tps: '每秒传输的事物处理个数',
|
||||||
plan_share_url: '链接跳转是否登陆',
|
plan_share_url: '链接跳转是否登陆',
|
||||||
rename_report: '重命名报告'
|
rename_report: '重命名报告',
|
||||||
|
run_model: '运行模式'
|
||||||
},
|
},
|
||||||
load_test: {
|
load_test: {
|
||||||
exist_related_file: '已存在的关联文件',
|
exist_related_file: '已存在的关联文件',
|
||||||
|
|
|
@ -1083,7 +1083,8 @@ const message = {
|
||||||
avg_response_time: '平均響應時間',
|
avg_response_time: '平均響應時間',
|
||||||
tps: '每秒傳輸的事物處理個數',
|
tps: '每秒傳輸的事物處理個數',
|
||||||
plan_share_url: '鏈接跳轉是否登陸',
|
plan_share_url: '鏈接跳轉是否登陸',
|
||||||
rename_report: '重命名報告'
|
rename_report: '重命名報告',
|
||||||
|
run_model: '運行模式'
|
||||||
},
|
},
|
||||||
load_test: {
|
load_test: {
|
||||||
exist_related_file: '已存在的關聯文件',
|
exist_related_file: '已存在的關聯文件',
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class IssueProxyResourceController {
|
||||||
|
|
||||||
@GetMapping(value = "/md/get/url")
|
@GetMapping(value = "/md/get/url")
|
||||||
public ResponseEntity<byte[]> getFileByUrl(@RequestParam ("url") String url, @RequestParam (value = "platform", required = false) String platform,
|
public ResponseEntity<byte[]> getFileByUrl(@RequestParam ("url") String url, @RequestParam (value = "platform", required = false) String platform,
|
||||||
@RequestParam ("project_id") String projectId, @RequestParam ("workspace_id") String workspaceId) {
|
@RequestParam (value = "workspace_id", required = false) String workspaceId) {
|
||||||
return issueProxyResourceService.getMdImageByUrl(url, platform, projectId, workspaceId);
|
return issueProxyResourceService.getMdImageByUrl(url, platform, workspaceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class IssueProxyResourceService {
|
||||||
* @param platform
|
* @param platform
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ResponseEntity<byte[]> getMdImageByUrl(String url, String platform, String projectId, String workspaceId) {
|
public ResponseEntity<byte[]> getMdImageByUrl(String url, String platform, String workspaceId) {
|
||||||
if (url.contains("md/get/url")) {
|
if (url.contains("md/get/url")) {
|
||||||
MSException.throwException(Translator.get("invalid_parameter"));
|
MSException.throwException(Translator.get("invalid_parameter"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,10 @@ export function testCasePublicBatchDeleteToGc(param) {
|
||||||
return post(BASE_URL + 'batch/movePublic/deleteToGc', param);
|
return post(BASE_URL + 'batch/movePublic/deleteToGc', param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function testCaseBatchRelateDemand(param) {
|
||||||
|
return post(BASE_URL + 'batch/relate/demand', param);
|
||||||
|
}
|
||||||
|
|
||||||
export function getTestCaseFollow(id) {
|
export function getTestCaseFollow(id) {
|
||||||
return get(BASE_URL + `follow/${id}`);
|
return get(BASE_URL + `follow/${id}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,9 +246,9 @@ import {
|
||||||
getTestCaseStep,
|
getTestCaseStep,
|
||||||
getTestCaseVersions, testCaseBatchCopy,
|
getTestCaseVersions, testCaseBatchCopy,
|
||||||
testCaseBatchDelete,
|
testCaseBatchDelete,
|
||||||
testCaseBatchDeleteToGc, testCaseBatchEdit,
|
testCaseBatchDeleteToGc, testCaseBatchEdit, testCaseBatchRelateDemand,
|
||||||
testCaseDelete,
|
testCaseDelete,
|
||||||
testCaseDeleteToGc, testCaseList, testCasePublicBatchDeleteToGc,
|
testCaseDeleteToGc, testCaseList,
|
||||||
testCaseReduction
|
testCaseReduction
|
||||||
} from "@/api/testCase";
|
} from "@/api/testCase";
|
||||||
import {getGraphByCondition} from "@/api/graph";
|
import {getGraphByCondition} from "@/api/graph";
|
||||||
|
@ -993,7 +993,7 @@ export default {
|
||||||
param.condition = this.condition;
|
param.condition = this.condition;
|
||||||
param.demandId = form.demandId;
|
param.demandId = form.demandId;
|
||||||
param.demandName = form.demandName;
|
param.demandName = form.demandName;
|
||||||
testCasePublicBatchDeleteToGc(param)
|
testCaseBatchRelateDemand(param)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$success(this.$t('commons.save_success'));
|
this.$success(this.$t('commons.save_success'));
|
||||||
this.refresh();
|
this.refresh();
|
||||||
|
|
|
@ -80,6 +80,11 @@
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<ms-review-table-item
|
||||||
|
v-else-if="item.id === 'description'"
|
||||||
|
:data="scope.row"
|
||||||
|
prop="description"/>
|
||||||
|
|
||||||
<span v-else-if="item.id === 'resourceName'">
|
<span v-else-if="item.id === 'resourceName'">
|
||||||
<el-link v-if="scope.row.resourceName"
|
<el-link v-if="scope.row.resourceName"
|
||||||
@click="$router.push('/track/plan/view/' + scope.row.resourceId)">
|
@click="$router.push('/track/plan/view/' + scope.row.resourceId)">
|
||||||
|
@ -103,21 +108,12 @@
|
||||||
|
|
||||||
<!-- 自定义字段 -->
|
<!-- 自定义字段 -->
|
||||||
<span v-else-if="item.isCustom">
|
<span v-else-if="item.isCustom">
|
||||||
<span v-if="item.type === 'richText' && scope.row.displayValueMap.get(item.id)">
|
<span v-if="item.type === 'richText' && scope.row.displayValueMap[item.id]">
|
||||||
<el-popover
|
<ms-review-table-item
|
||||||
placement="right"
|
:data="scope.row.displayValueMap" :prop="item.id"/>
|
||||||
width="500"
|
|
||||||
trigger="hover"
|
|
||||||
popper-class="issues-popover">
|
|
||||||
<ms-mark-down-text
|
|
||||||
prop="value"
|
|
||||||
:disabled="true"
|
|
||||||
:data="{value: scope.row.displayValueMap.get(item.id)}"/>
|
|
||||||
<el-button slot="reference" type="text">{{ $t('test_track.issue.preview') }}</el-button>
|
|
||||||
</el-popover>
|
|
||||||
</span>
|
</span>
|
||||||
<span v-else>
|
<span v-else>
|
||||||
{{ scope.row.displayValueMap.get(item.id) }}
|
{{ scope.row.displayValueMap[item.id] }}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
@ -185,10 +181,12 @@ import {
|
||||||
} from "metersphere-frontend/src/components/search/custom-component";
|
} from "metersphere-frontend/src/components/search/custom-component";
|
||||||
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
|
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
|
||||||
import {hasLicense} from "metersphere-frontend/src/utils/permission";
|
import {hasLicense} from "metersphere-frontend/src/utils/permission";
|
||||||
|
import MsReviewTableItem from "@/business/issue/MsReviewTableItem";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "IssueList",
|
name: "IssueList",
|
||||||
components: {
|
components: {
|
||||||
|
MsReviewTableItem,
|
||||||
MsMarkDownText,
|
MsMarkDownText,
|
||||||
MsMainContainer,
|
MsMainContainer,
|
||||||
MsContainer,
|
MsContainer,
|
||||||
|
@ -418,7 +416,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.page.data.forEach(item => {
|
this.page.data.forEach(item => {
|
||||||
let displayValueMap = new Map();
|
let displayValueMap = {};
|
||||||
let fieldIdSet = new Set(this.fields.map(i => i.id));
|
let fieldIdSet = new Set(this.fields.map(i => i.id));
|
||||||
this.issueTemplate.customFields.forEach(field => {
|
this.issueTemplate.customFields.forEach(field => {
|
||||||
let displayValue;
|
let displayValue;
|
||||||
|
@ -430,7 +428,7 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
displayValue = this.getCustomFieldValue(item, field);
|
displayValue = this.getCustomFieldValue(item, field);
|
||||||
}
|
}
|
||||||
displayValueMap.set(field.name, displayValue);
|
displayValueMap[field.name] = displayValue;
|
||||||
});
|
});
|
||||||
item.displayValueMap = displayValueMap;
|
item.displayValueMap = displayValueMap;
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<template>
|
||||||
|
<el-popover
|
||||||
|
placement="right"
|
||||||
|
width="500"
|
||||||
|
trigger="hover"
|
||||||
|
popper-class="issues-popover">
|
||||||
|
<ms-mark-down-text :prop="prop" :data="data" :disabled="true"/>
|
||||||
|
<el-button slot="reference" type="text">{{ $t('test_track.issue.preview') }}</el-button>
|
||||||
|
</el-popover>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import MsTableColumn from "metersphere-frontend/src/components/table/MsTableColumn";
|
||||||
|
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
|
||||||
|
export default {
|
||||||
|
name: "MsReviewTableItem",
|
||||||
|
components: {MsMarkDownText, MsTableColumn},
|
||||||
|
props: {
|
||||||
|
data: Object,
|
||||||
|
prop: String,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
Loading…
Reference in New Issue