refactor(接口测试): 引用逻辑优化

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2023-06-29 15:40:53 +08:00 committed by fit2-zhao
parent 8eb82df44d
commit 0795ef896c
24 changed files with 91 additions and 248 deletions

View File

@ -1171,19 +1171,4 @@ public class ElementUtil {
}
return false;
}
public static boolean isEnable(MsTestElement element, ParameterConfig config) {
if (MapUtils.isEmpty(config.getKeyMap())) {
return true;
}
String path = ElementUtil.getFullIndexPath(element, "");
if (StringUtils.isNotBlank(path) && path.endsWith("_")) {
path = path.substring(0, path.length() - 1);
}
String key = StringUtils.join(element.getId(), "_", path);
if (config.getKeyMap().containsKey(key)) {
return config.getKeyMap().get(key);
}
return true;
}
}

View File

@ -19,12 +19,10 @@ import io.metersphere.environment.service.BaseEnvGroupProjectService;
import io.metersphere.environment.service.BaseEnvironmentService;
import io.metersphere.plugin.core.MsParameter;
import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.service.MsHashTreeService;
import io.metersphere.utils.LoggerUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
@ -67,18 +65,16 @@ public class MsScenario extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
if (!config.isOperating() && !this.isEnable()) {
return;
}
if (this.getReferenced() != null && this.getReferenced().equals(MsTestElementConstants.Deleted.name())) {
return;
} else if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())
&& !this.setRefScenario(hashTree, config)) {
return;
}
if (!ElementUtil.isEnable(this, config)) {
&& !this.setRefScenario(hashTree)) {
return;
}
// 设置共享cookie
config.setEnableCookieShare(enableCookieShare);
Map<String, EnvironmentConfig> envConfig = new HashMap<>(16);
@ -141,7 +137,6 @@ public class MsScenario extends MsTestElement {
}
if ((this.variableEnable == null && this.mixEnable == null)
|| BooleanUtils.isTrue(this.variableEnable) || BooleanUtils.isTrue(this.mixEnable)) {
newConfig.setKeyMap(config.getKeyMap());
ElementUtil.addCsvDataSet(scenarioTree, variables, this.isEnvironmentEnable() ? newConfig : config, "shareMode.group");
ElementUtil.addCounter(scenarioTree, variables);
ElementUtil.addRandom(scenarioTree, variables);
@ -210,23 +205,12 @@ public class MsScenario extends MsTestElement {
}
}
private boolean setRefScenario(List<MsTestElement> hashTree, ParameterConfig config) {
private boolean setRefScenario(List<MsTestElement> hashTree) {
try {
ApiScenarioMapper apiAutomationService = CommonBeanFactory.getBean(ApiScenarioMapper.class);
ApiScenarioWithBLOBs scenario = apiAutomationService.selectByPrimaryKey(this.getId());
if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
JSONObject element = JSONUtil.parseObject(scenario.getScenarioDefinition());
if (MapUtils.isNotEmpty(config.getKeyMap())) {
String path = ElementUtil.getFullIndexPath(this, "");
if (path.endsWith("_")) {
path = path.substring(0, path.length() - 1);
}
element.put(MsHashTreeService.INDEX, path);
boolean enable = config.getKeyMap().get(this.getId() + "_" + path);
if (!enable) {
return false;
}
}
// 历史数据处理
ElementUtil.dataFormatting(element.optJSONArray(ElementConstants.HASH_TREE));
this.setName(scenario.getName());

View File

@ -102,11 +102,6 @@ public class ParameterConfig extends MsParameter {
private List<String> excludeScenarioIds = new ArrayList<>();
private List<String> csvFilePaths = new ArrayList<>();
/**
* 启用或禁用记录
*/
private Map<String, Boolean> keyMap = new HashMap<>();
public boolean isEffective(String projectId) {
if (this.config != null && this.config.get(projectId) != null) {

View File

@ -35,12 +35,10 @@ public class MsIfController extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
return;
}
if (!ElementUtil.isEnable(this, config)) {
if (!config.isOperating() && !this.isEnable()) {
return;
}
final HashTree groupTree = tree.add(ifController());
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {

View File

@ -47,12 +47,10 @@ public class MsLoopController extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
return;
}
if (!ElementUtil.isEnable(this, config)) {
if (!config.isOperating() && !this.isEnable()) {
return;
}
final HashTree groupTree = controller(tree);
// 自身场景
if (CollectionUtils.isNotEmpty(config.getVariables())) {

View File

@ -34,12 +34,10 @@ public class MsTransactionController extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
return;
}
if (!ElementUtil.isEnable(this, config)) {
if (!config.isOperating() && !this.isEnable()) {
return;
}
TransactionController transactionController = transactionController();
final HashTree groupTree = tree.add(transactionController);
if (CollectionUtils.isNotEmpty(hashTree)) {

View File

@ -12,7 +12,6 @@ import io.metersphere.utils.JMeterVars;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.protocol.java.sampler.BeanShellSampler;
@ -41,11 +40,9 @@ public class MsJSR223Processor extends MsTestElement {
return;
}
}
if (!ElementUtil.isEnable(this, config)) {
return;
}
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
if (!config.isOperating() && !this.isEnable()) {
return;
}
this.setEnvironmentId(ElementUtil.getScriptEnv(this.getEnvironmentId(), config, this.getProjectId()));

View File

@ -1,6 +1,5 @@
package io.metersphere.api.dto.definition.request.sampler;
import io.metersphere.api.dto.definition.request.ElementUtil;
import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.commons.constants.ElementConstants;
import io.metersphere.plugin.core.MsParameter;
@ -8,7 +7,6 @@ import io.metersphere.plugin.core.MsTestElement;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.sampler.DebugSampler;
import org.apache.jmeter.save.SaveService;
@ -36,12 +34,10 @@ public class MsDebugSampler extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
return;
}
if (!ElementUtil.isEnable(this, config)) {
if (!config.isOperating() && !this.isEnable()) {
return;
}
final HashTree groupTree = tree.add(debugSampler());
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {

View File

@ -29,7 +29,6 @@ import io.metersphere.service.definition.ApiTestCaseService;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.save.SaveService;
@ -64,7 +63,7 @@ public class MsDubboSampler extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
if (!config.isOperating() && !this.isEnable()) {
return;
} else if (config.isOperating() && StringUtils.isNotEmpty(config.getOperatingSampleTestName())) {
this.setName(config.getOperatingSampleTestName());
@ -72,9 +71,7 @@ public class MsDubboSampler extends MsTestElement {
if (this.getReferenced() != null && "Deleted".equals(this.getReferenced())) {
return;
}
if (!ElementUtil.isEnable(this, config)) {
return;
}
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
boolean ref = this.setRefElement();
if (!ref) {

View File

@ -34,7 +34,6 @@ import io.metersphere.service.definition.ApiTestCaseService;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
@ -99,14 +98,12 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
// 非导出操作且不是启用状态则跳过执行Ms
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
if (!config.isOperating() && !this.isEnable()) {
return;
} else if (config.isOperating() && StringUtils.isNotEmpty(config.getOperatingSampleTestName())) {
this.setName(config.getOperatingSampleTestName());
}
if (!ElementUtil.isEnable(this, config)) {
return;
}
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
boolean ref = this.setRefElement();
if (!ref) {

View File

@ -62,14 +62,12 @@ public class MsJDBCSampler extends MsTestElement {
// 清理掉历史遗留数据
this.dataSource = null;
// 非导出操作且不是启用状态则跳过执行
if (config != null && !config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
if (config != null && !config.isOperating() && !this.isEnable()) {
return;
} else if (config.isOperating() && StringUtils.isNotEmpty(config.getOperatingSampleTestName())) {
this.setName(config.getOperatingSampleTestName());
}
if (!ElementUtil.isEnable(this, config)) {
return;
}
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
boolean ref = this.setRefElement();
if (!ref) {

View File

@ -86,14 +86,12 @@ public class MsTCPSampler extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
if (!config.isOperating() && !this.isEnable()) {
return;
} else if (config.isOperating() && StringUtils.isNotEmpty(config.getOperatingSampleTestName())) {
this.setName(config.getOperatingSampleTestName());
}
if (!ElementUtil.isEnable(this, config)) {
return;
}
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
boolean ref = this.setRefElement();
if (!ref) {

View File

@ -28,12 +28,10 @@ public class MsConstantTimer extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
return;
}
if (!ElementUtil.isEnable(this, config)) {
if (!config.isOperating() && !this.isEnable()) {
return;
}
final HashTree groupTree = tree.add(constantTimer());
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {

View File

@ -1,6 +1,5 @@
package io.metersphere.api.dto.definition.request.unknown;
import io.metersphere.api.dto.definition.request.ElementUtil;
import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
import io.metersphere.commons.constants.ElementConstants;
@ -13,7 +12,6 @@ import io.metersphere.request.BodyFile;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.CSVDataSet;
import org.apache.jmeter.save.SaveService;
@ -44,10 +42,7 @@ public class MsJmeterElement extends MsTestElement {
try {
ParameterConfig config = (ParameterConfig) msParameter;
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable() && MapUtils.isEmpty(config.getKeyMap())) {
return;
}
if (!ElementUtil.isEnable(this, config)) {
if (!config.isOperating() && !this.isEnable()) {
return;
}
InputStream inputSource = getStrToStream(jmeterElement);

View File

@ -428,7 +428,7 @@ public class ApiScenarioExecuteService {
report.setVersionId(scenario.getVersionId());
String scenarioDefinition = JSON.toJSONString(request.getTestElement().getHashTree().get(0).getHashTree().get(0));
scenario.setScenarioDefinition(scenarioDefinition);
apiScenarioReportStructureService.save(scenario, report.getId(), request.getConfig().getReportType(), true);
apiScenarioReportStructureService.save(scenario, report.getId(), request.getConfig().getReportType());
} else {
if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) {
ApiScenarioWithBLOBs apiScenario = new ApiScenarioWithBLOBs();
@ -437,7 +437,7 @@ public class ApiScenarioExecuteService {
if (testElement != null) {
apiScenario.setName(testElement.getName());
apiScenario.setScenarioDefinition(JSON.toJSONString(testElement));
apiScenarioReportStructureService.save(apiScenario, report.getId(), request.getConfig().getReportType(), true);
apiScenarioReportStructureService.save(apiScenario, report.getId(), request.getConfig().getReportType());
}
}
}
@ -448,8 +448,6 @@ public class ApiScenarioExecuteService {
uploadBodyFiles(request.getBodyFileRequestIds(), bodyFiles);
FileUtils.createBodyFiles(request.getScenarioFileIds(), scenarioFiles);
this.testElement(request);
Map<String, Boolean> keyMap = MsHashTreeService.getIndexKeyMap(request.getTestElement(), "");
config.setKeyMap(keyMap);
HashTree hashTree = request.getTestElement().generateHashTree(config);
String runMode = StringUtils.isEmpty(request.getRunMode()) ? ApiRunMode.SCENARIO.name() : request.getRunMode();

View File

@ -19,19 +19,16 @@ import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.JSONUtil;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.ProjectConfig;
import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.service.definition.ApiDefinitionService;
import io.metersphere.service.definition.ApiTestCaseService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -101,7 +98,6 @@ public class MsHashTreeService {
private static final String DATASOURCEID = "dataSourceId";
private static final String RESULT_VARIABLE = "resultVariable";
private static final String ENV_Id = "environmentId";
private static final String PARENT_INDEX = "parentIndex";
private final static String JSON_PATH = "jsonPath";
@ -316,7 +312,7 @@ public class MsHashTreeService {
}
}
private JSONObject setRefScenario(JSONObject element, Map<String, Boolean> keyMap) {
private JSONObject setRefScenario(JSONObject element) {
boolean enable = element.has(ENABLE) ? element.optBoolean(ENABLE) : true;
if (!element.has(MIX_ENABLE)) {
element.put(MIX_ENABLE, false);
@ -334,19 +330,7 @@ public class MsHashTreeService {
}
if (StringUtils.equalsIgnoreCase(element.optString(REFERENCED), REF)) {
JSONObject object = JSONUtil.parseObject(scenarioWithBLOBs.getScenarioDefinition());
object.put(PARENT_INDEX, element.optString(PARENT_INDEX));
object.put(INDEX, element.optString(INDEX));
if (object.has(ENABLE) && BooleanUtils.isFalse(object.optBoolean(ENABLE))) {
enable = false;
object.put(REF_ENABLE, true);
} else {
String indexStr = object.has(PARENT_INDEX) && StringUtils.isNotBlank(object.optString(PARENT_INDEX)) ?
StringUtils.join(object.optString(PARENT_INDEX), "_", object.optString(INDEX)) : object.optString(INDEX);
if (MapUtils.isNotEmpty(keyMap) && keyMap.containsKey(element.optString(ID) + indexStr)) {
enable = keyMap.get(element.optString(ID) + indexStr);
object.put(ENABLE, enable);
}
}
element = object;
element.put(REFERENCED, REF);
element.put(NAME, scenarioWithBLOBs.getName());
@ -371,88 +355,41 @@ public class MsHashTreeService {
}
if (element.has(ENABLE) && BooleanUtils.isFalse(element.optBoolean(ENABLE))) {
element.put(REF_ENABLE, true);
} else {
String indexStr = element.has(PARENT_INDEX) && StringUtils.isNotBlank(element.optString(PARENT_INDEX)) ?
StringUtils.join(element.optString(PARENT_INDEX), "_", element.optString(INDEX)) : element.optString(INDEX);
if (MapUtils.isNotEmpty(keyMap) && keyMap.containsKey(element.optString(ID) + indexStr)) {
enable = keyMap.get(element.optString(ID) + indexStr);
element.put(ENABLE, enable);
}
}
element.put(NUM, StringUtils.EMPTY);
}
return element;
}
public static Map<String, Boolean> getIndexKeyMap(JSONObject element, String parentIndex) {
Map<String, Boolean> indexKeyMap = new HashMap<>();
StringBuilder builder = new StringBuilder(parentIndex);
if (element.has(ENABLE) && element.has(ID) && element.has(INDEX)) {
builder.append("_").append(element.optString(INDEX));
String key = StringUtils.join(element.optString(ID), builder.toString());
indexKeyMap.put(key, element.optBoolean(ENABLE));
}
if (element.has(HASH_TREE)) {
element.getJSONArray(HASH_TREE).forEach(item -> {
JSONObject obj = (JSONObject) item;
indexKeyMap.putAll(getIndexKeyMap(obj, builder.toString()));
});
}
return indexKeyMap;
}
public void dataFormatting(JSONArray hashTree, List<String> caseIds, Map<String, Boolean> keyMap, String parentIndex) {
public void dataFormatting(JSONArray hashTree, List<String> caseIds) {
for (int i = 0; i < hashTree.length(); i++) {
JSONObject element = hashTree.optJSONObject(i);
// 设置父级索引
element.put(PARENT_INDEX, parentIndex);
if (element != null && StringUtils.equalsIgnoreCase(element.optString(TYPE), SCENARIO)) {
element = this.setRefScenario(element, keyMap);
element = this.setRefScenario(element);
hashTree.put(i, element);
} else if (element != null && ElementConstants.REQUESTS.contains(element.optString(TYPE))) {
setCaseEnable(element, keyMap, parentIndex);
this.getCaseIds(element, caseIds);
hashTree.put(i, element);
} else {
setCaseEnable(element, keyMap, parentIndex);
}
if (element.has(HASH_TREE)) {
JSONArray elementJSONArray = element.optJSONArray(HASH_TREE);
String indexStr = StringUtils.join(parentIndex, "_", element.optString(INDEX));
dataFormatting(elementJSONArray, caseIds, keyMap, indexStr);
dataFormatting(elementJSONArray, caseIds);
}
}
}
public void dataFormatting(JSONObject element, List<String> caseIds, Map<String, Boolean> keyMap) {
public void dataFormatting(JSONObject element, List<String> caseIds) {
if (element == null) {
return;
}
// 设置父级索引
String parentIndex = element.has(PARENT_INDEX) ?
StringUtils.join(element.optString(PARENT_INDEX), "_", element.optString(INDEX))
: element.optString(INDEX);
element.put(PARENT_INDEX, parentIndex);
if (StringUtils.equalsIgnoreCase(element.optString(TYPE), SCENARIO)) {
element = this.setRefScenario(element, keyMap);
element = this.setRefScenario(element);
} else if (ElementConstants.REQUESTS.contains(element.optString(TYPE))) {
setCaseEnable(element, keyMap, parentIndex);
this.getCaseIds(element, caseIds);
} else {
setCaseEnable(element, keyMap, parentIndex);
}
if (element.has(HASH_TREE)) {
JSONArray elementJSONArray = element.optJSONArray(HASH_TREE);
dataFormatting(elementJSONArray, caseIds, keyMap, parentIndex);
}
}
private void setCaseEnable(JSONObject element, Map<String, Boolean> keyMap, String parentIndex) {
String indexStr = StringUtils.join(element.optString(ID), parentIndex, "_", element.optString(INDEX));
if (MapUtils.isNotEmpty(keyMap) && keyMap.containsKey(indexStr)) {
element.put(ENABLE, keyMap.get(indexStr));
dataFormatting(elementJSONArray, caseIds);
}
}
@ -482,20 +419,4 @@ public class MsHashTreeService {
caseFormatting(elementJSONArray, caseMap, msParameter);
}
}
public static Map<String, Boolean> getIndexKeyMap(MsTestElement element, String parentIndex) {
Map<String, Boolean> indexKeyMap = new HashMap<>();
StringBuilder builder = new StringBuilder(parentIndex);
if (StringUtils.isNotBlank(element.getId()) && StringUtils.isNotBlank(element.getIndex())) {
builder.append("_").append(element.getIndex());
String key = StringUtils.join(element.getId(), builder.toString());
indexKeyMap.put(key, element.isEnable());
}
if (CollectionUtils.isNotEmpty(element.getHashTree())) {
element.getHashTree().forEach(item -> {
indexKeyMap.putAll(getIndexKeyMap(item, builder.toString()));
});
}
return indexKeyMap;
}
}

View File

@ -82,7 +82,7 @@ public class ApiScenarioReportStructureService {
public void save(List<ApiScenarioWithBLOBs> apiScenarios, String reportId, String reportType) {
List<StepTreeDTO> dtoList = new LinkedList<>();
for (ApiScenarioWithBLOBs bos : apiScenarios) {
StepTreeDTO dto = dataFormatting(bos, reportType, false);
StepTreeDTO dto = dataFormatting(bos, reportType);
dtoList.add(dto);
}
this.save(reportId, dtoList);
@ -91,22 +91,15 @@ public class ApiScenarioReportStructureService {
public List<StepTreeDTO> get(List<ApiScenarioWithBLOBs> apiScenarios, String reportType) {
List<StepTreeDTO> dtoList = new LinkedList<>();
for (ApiScenarioWithBLOBs bos : apiScenarios) {
StepTreeDTO dto = dataFormatting(bos, reportType, false);
StepTreeDTO dto = dataFormatting(bos, reportType);
dtoList.add(dto);
}
return dtoList;
}
public void save(ApiScenarioWithBLOBs apiScenario, String reportId, String reportType, boolean isDebug) {
List<StepTreeDTO> dtoList = new LinkedList<>();
StepTreeDTO dto = dataFormatting(apiScenario, reportType, isDebug);
dtoList.add(dto);
this.save(reportId, dtoList);
}
public void save(ApiScenarioWithBLOBs apiScenario, String reportId, String reportType) {
List<StepTreeDTO> dtoList = new LinkedList<>();
StepTreeDTO dto = dataFormatting(apiScenario, reportType, false);
StepTreeDTO dto = dataFormatting(apiScenario, reportType);
dtoList.add(dto);
this.save(reportId, dtoList);
}
@ -149,12 +142,12 @@ public class ApiScenarioReportStructureService {
}
}
public static StepTreeDTO dataFormatting(ApiScenarioWithBLOBs apiScenario, String reportType, boolean isDebug) {
return dataFormatting(apiScenario.getId(), apiScenario.getName(), apiScenario.getScenarioDefinition(), reportType, isDebug);
public static StepTreeDTO dataFormatting(ApiScenarioWithBLOBs apiScenario, String reportType) {
return dataFormatting(apiScenario.getId(), apiScenario.getName(), apiScenario.getScenarioDefinition(), reportType);
}
public static StepTreeDTO dataFormatting(UiScenarioWithBLOBs uiScenario, String reportType, boolean isDebug) {
return dataFormatting(null, uiScenario.getName(), uiScenario.getScenarioDefinition(), reportType, isDebug);
public static StepTreeDTO dataFormatting(UiScenarioWithBLOBs uiScenario, String reportType) {
return dataFormatting(null, uiScenario.getName(), uiScenario.getScenarioDefinition(), reportType);
}
private static String combinationResourceId(JSONObject element, String reportType, String id) {
@ -170,18 +163,14 @@ public class ApiScenarioReportStructureService {
return resourceId;
}
public static StepTreeDTO dataFormatting(String id, String name, String scenarioDefinition, String reportType, boolean isDebug) {
public static StepTreeDTO dataFormatting(String id, String name, String scenarioDefinition, String reportType) {
JSONObject element = JSONUtil.parseObject(scenarioDefinition);
if (element != null && element.getBoolean(ENABLE)) {
//保证场景的步骤是最新的比如场景中包含引用场景
MsHashTreeService hashTreeService = CommonBeanFactory.getBean(MsHashTreeService.class);
assert hashTreeService != null;
List<String> caseIds = new ArrayList<>();
Map<String, Boolean> keyMap = new HashMap<>();
if (isDebug) {
keyMap = MsHashTreeService.getIndexKeyMap(element, element.optString(ElementConstants.INDEX));
}
hashTreeService.dataFormatting(element, caseIds, keyMap);
hashTreeService.dataFormatting(element, caseIds);
// 处理用例
hashTreeService.caseFormatting(element, caseIds, null);

View File

@ -757,7 +757,7 @@ public class ApiScenarioService {
if (StringUtils.isNotEmpty(scenarioWithBLOBs.getScenarioDefinition())) {
JSONObject element = JSONUtil.parseObject(scenarioWithBLOBs.getScenarioDefinition());
List<String> caseIds = new ArrayList<>();
hashTreeService.dataFormatting(element, caseIds, null);
hashTreeService.dataFormatting(element, caseIds);
// 处理用例
hashTreeService.caseFormatting(element, caseIds, getConfig(scenarioWithBLOBs));
ElementUtil.dataFormatting(element);
@ -885,8 +885,7 @@ public class ApiScenarioService {
JSONObject element = JSONUtil.parseObject(dto.getScenarioDefinition());
// 获取所有case
List<String> caseIds = new ArrayList<>();
Map<String, Boolean> keyMap = MsHashTreeService.getIndexKeyMap(element, element.optString(ElementConstants.INDEX));
hashTreeService.dataFormatting(element, caseIds, keyMap);
hashTreeService.dataFormatting(element, caseIds);
// 处理用例
hashTreeService.caseFormatting(element, caseIds, null);

View File

@ -1756,6 +1756,11 @@ export default {
if (this.pluginDelStep) {
this.debugLoading = false;
this.$error('场景包含插件步骤,对应场景已经删除不能调试!');
this.clearResult(this.scenarioDefinition);
this.clearNodeStatus(this.$refs.stepTree.root.childNodes);
runScenario.run = false;
this.message = "STOP";
return;
}
let hasRequest = runScenario && runScenario.hasRequest;

View File

@ -81,7 +81,7 @@
v-model="data.enable"
class="enable-switch"
size="mini"
:disabled="!showVersion || isDeleted || isEnabled()" />
:disabled="isEnabled()" />
</el-tooltip>
<el-button
@ -96,7 +96,7 @@
'PROJECT_API_SCENARIO:READ+CREATE',
'PROJECT_API_SCENARIO:READ+COPY',
]"
:disabled="(data.disabled && !data.root && !data.isCopy) || !showVersion || isDeleted" />
:disabled="isEnabled()" />
<el-button
v-show="isSingleButton"
@ -106,7 +106,7 @@
style="padding: 5px"
circle
@click="remove"
:disabled="(data.disabled && !data.root && !data.isCopy) || !showVersion || isDeleted"
:disabled="isEnabled()"
v-permission="[
'PROJECT_API_SCENARIO:READ+EDIT',
'PROJECT_API_SCENARIO:READ+CREATE',
@ -285,7 +285,7 @@ export default {
},
isMoreButton() {
if (this.data.type === 'ConstantTimer' || this.data.type === 'Assertions') {
return (
return !this.data.caseEnable && (
!this.innerStep ||
(this.showBtn &&
(!this.data.disabled || this.data.root || this.data.isCopy || this.data.showExtend) &&
@ -303,7 +303,7 @@ export default {
},
methods: {
isEnabled() {
return this.stepFilter.get("ALlSamplerStep").indexOf(this.data.type) !== -1 && this.data.caseEnable;
return !this.showVersion || this.isDeleted || this.data.caseEnable;
},
active() {
this.$emit('active');

View File

@ -29,7 +29,7 @@
</span>
<span v-else>
<el-tooltip class="ms-num" effect="dark" :content="$t('api_test.automation.scenario.num_none')" placement="top">
<i class="el-icon-warning"/>
<i class="el-icon-warning" />
</el-tooltip>
</span>
<span v-xpack v-if="scenario.versionEnable">{{ $t('project.version.name') }}: {{ scenario.versionName }}</span>
@ -41,7 +41,7 @@
</el-tag>
<el-tag size="small" class="ms-tag" v-if="scenario.referenced === 'Copy'"> {{ $t('commons.copy') }}</el-tag>
<el-tag size="small" class="ms-tag" v-if="scenario.referenced === 'REF'"
>{{ $t('api_test.scenario.reference') }}
>{{ $t('api_test.scenario.reference') }}
</el-tag>
<span class="ms-tag ms-step-name-api">{{ getProjectName(scenario.projectId) }}</span>
<el-tooltip
@ -51,23 +51,20 @@
:content="$t('api_test.scenario.base_scenario_step_is_empty')"
placement="top"
style="margin-left: 5px">
<i class="el-icon-warning"/>
<i class="el-icon-warning" />
</el-tooltip>
</template>
<template v-slot:debugStepCode>
<span v-if="node.data.testing" class="ms-test-running">
<i class="el-icon-loading" style="font-size: 16px"/>
<i class="el-icon-loading" style="font-size: 16px" />
{{ $t('commons.testing') }}
</span>
<span
class="ms-step-debug-code"
:class="'ms-req-error-report'"
v-if="
!loading && !node.data.testing && node.data.debug &&
node.data.code === 'FAKE_ERROR'
">
FakeError
</span>
v-if="!loading && !node.data.testing && node.data.debug && node.data.code === 'FAKE_ERROR'">
FakeError
</span>
<span
class="ms-step-debug-code"
:class="node.data.code === 'ERROR' ? 'ms-req-error' : 'ms-req-success'"
@ -85,10 +82,7 @@
class="ms-btn"
size="mini"
circle
v-permission="[
'PROJECT_API_SCENARIO:READ+DEBUG',
'PROJECT_API_SCENARIO:READ+RUN'
]"/>
v-permission="['PROJECT_API_SCENARIO:READ+DEBUG', 'PROJECT_API_SCENARIO:READ+RUN']" />
</el-tooltip>
<el-tooltip :content="$t('report.stop_btn')" placement="top" :enterable="false" v-else>
<el-button
@ -98,10 +92,7 @@
style="color: white; padding: 0 0.1px; width: 24px; height: 24px"
class="stop-btn"
circle
v-permission="[
'PROJECT_API_SCENARIO:READ+DEBUG',
'PROJECT_API_SCENARIO:READ+RUN'
]">
v-permission="['PROJECT_API_SCENARIO:READ+DEBUG', 'PROJECT_API_SCENARIO:READ+RUN']">
<div style="transform: scale(0.66)">
<span style="margin-left: -4.5px; font-weight: bold">STOP</span>
</div>
@ -117,11 +108,11 @@ import MsTcpBasisParameters from '../../../definition/components/request/tcp/Tcp
import MsDubboBasisParameters from '../../../definition/components/request/dubbo/BasisParameters';
import MsApiRequestForm from '../../../definition/components/request/http/ApiHttpRequestForm';
import ApiBaseComponent from '../common/ApiBaseComponent';
import {getCurrentProjectID, getCurrentWorkspaceId} from 'metersphere-frontend/src/utils/token';
import {getUUID, strMapToObj} from 'metersphere-frontend/src/utils';
import {STEP} from '@/business/automation/scenario/Setting';
import {getOwnerProjectIds, getProject} from '@/api/project';
import {checkScenarioEnv, getScenarioById, setScenarioDomain} from '@/api/scenario';
import { getCurrentProjectID, getCurrentWorkspaceId } from 'metersphere-frontend/src/utils/token';
import { getUUID, strMapToObj } from 'metersphere-frontend/src/utils';
import { STEP } from '@/business/automation/scenario/Setting';
import { getOwnerProjectIds, getProject } from '@/api/project';
import { checkScenarioEnv, getScenarioById, setScenarioDomain } from '@/api/scenario';
export default {
name: 'ApiScenarioComponent',
@ -171,11 +162,10 @@ export default {
created() {
this.isShowNum = this.scenario.num ? true : false;
if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded && this.scenario.hashTree) {
this.scenario.root = this.node.parent.parent ? false : true;
this.scenario.disabled = true;
this.scenario.showExtend =
this.node.parent && this.node.parent.data && this.node.parent.data.disabled ? false : true;
this.recursive(this.scenario.hashTree, this.scenario.projectId, true);
this.recursiveEnable(this.scenario.hashTree);
}
if (this.scenario.id && this.scenario.referenced === 'Copy' && !this.scenario.isCopy && !this.scenario.disabled) {
this.scenario.isCopy = true;
@ -281,14 +271,7 @@ export default {
this.node.expanded = !this.node.expanded;
}
}
if (this.scenario && this.scenario.hashTree && this.node.expanded) {
this.scenario.disabled = this.scenario.id && this.scenario.referenced === 'REF';
this.recursive(
this.scenario.hashTree,
this.scenario.projectId,
this.scenario.id && this.scenario.referenced === 'REF'
);
}
this.recursive(this.scenario.hashTree, this.scenario.projectId);
this.reload();
},
copyRow() {
@ -303,12 +286,20 @@ export default {
this.loading = false;
});
},
recursive(arr, id, disabled) {
recursiveEnable(arr) {
for (let i in arr) {
arr[i].disabled = true;
arr[i].caseEnable = true;
if (arr[i].hashTree && arr[i].hashTree.length > 0) {
this.recursiveEnable(arr[i].hashTree);
}
}
},
recursive(arr, id) {
for (let i in arr) {
arr[i].disabled = disabled;
arr[i].isCopy = false;
arr[i].projectId = this.calcProjectId(arr[i].projectId, id);
arr[i].caseEnable = disabled;
//
let typeArray = ['JDBCPostProcessor', 'JDBCSampler', 'JDBCPreProcessor'];
if (typeArray.indexOf(arr[i].type) !== -1) {
@ -319,7 +310,7 @@ export default {
}
}
if (arr[i].hashTree && arr[i].hashTree.length > 0) {
this.recursive(arr[i].hashTree, arr[i].projectId, disabled);
this.recursive(arr[i].hashTree, arr[i].projectId);
}
}
},

View File

@ -17,12 +17,14 @@
draggable
size="mini"
v-model="controller.variable"
:disabled="controller.caseEnable"
style="width: 12%"
:placeholder="$t('api_test.request.condition_variable')" />
<el-select
v-model="controller.operator"
:placeholder="$t('commons.please_select')"
:disabled="controller.caseEnable"
size="mini"
@change="change"
class="ms-select">
@ -34,6 +36,7 @@
size="mini"
v-model="controller.value"
:placeholder="$t('api_test.value')"
:disabled="controller.caseEnable"
v-if="!hasEmptyOperator"
class="ms-btn" />
@ -42,6 +45,7 @@
size="mini"
v-model="controller.remark"
:placeholder="$t('commons.remark')"
:disabled="controller.caseEnable"
v-if="!hasEmptyOperator && !isMax"
class="ms-btn" />
</template>

View File

@ -40,15 +40,16 @@
size="mini"
v-model="controller.name"
style="width: 20%"
:disabled="controller.caseEnable"
:placeholder="$t('api_test.automation.transaction_controller')" />
<el-checkbox
v-model="controller.generateParentSample"
@change="changeGenerateParantSample"
:disabled="controller.disabled"
:disabled="controller.caseEnable"
class="ms-btn">
Generate Parent Sample
</el-checkbox>
<el-checkbox v-model="controller.includeTimers" @change="changeIncludeTimers" :disabled="controller.disabled">
<el-checkbox v-model="controller.includeTimers" @change="changeIncludeTimers" :disabled="controller.caseEnable">
Include Timers
</el-checkbox>
</template>

View File

@ -567,6 +567,7 @@ export default {
let index = 1;
for (let i in this.request.hashTree) {
let step = this.request.hashTree[i];
step.caseEnable = step.disabled;
if (
this.tabType === 'pre' &&
(step.type === 'JSR223PreProcessor' || step.type === 'JDBCPreProcessor' || step.type === 'ConstantTimer')