fix(接口测试): 步骤级csv作用域有误

This commit is contained in:
AgAngle 2024-05-17 16:24:41 +08:00 committed by Craftsman
parent f2dc234103
commit 6d9f017a90
4 changed files with 13 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package io.metersphere.api.dto;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
/**
* 接口执行所需要的文件
@ -33,4 +34,8 @@ public class ApiFile {
* 引用的文件被删除需要标识
*/
private Boolean delete = false;
public boolean isValid() {
return StringUtils.isNotBlank(fileId) && StringUtils.isNotBlank(fileName) ;
}
}

View File

@ -79,7 +79,7 @@ public class CsvVariable {
private Boolean stopThreadOnEof = false;
public boolean isValid() {
return StringUtils.isNotBlank(name) && file != null;
return StringUtils.isNotBlank(name) && file != null && file.isValid();
}
public boolean isEnable() {

View File

@ -18,6 +18,7 @@ import org.apache.jorphan.collections.HashTree;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.UUID;
/**
* 解析 csv 文件
@ -37,7 +38,10 @@ public class MsCsvChildPreConverter extends AbstractJmeterElementConverter<Abstr
csvIds.forEach(csvId -> {
CsvVariable csvVariable = apiParamConfig.getCsvVariable(csvId);
if (csvVariable != null) {
addCsvDataSet(tree, JmeterProperty.CSVDataSetProperty.SHARE_MODE_THREAD, csvVariable);
// 场景级的线程共享步骤级的私有
String shareMode = StringUtils.equals(csvVariable.getScope(), CsvVariable.CsvVariableScope.SCENARIO.name()) ?
JmeterProperty.CSVDataSetProperty.SHARE_MODE_THREAD : UUID.randomUUID().toString();
addCsvDataSet(tree, shareMode, csvVariable);
}
});
}
@ -66,6 +70,7 @@ public class MsCsvChildPreConverter extends AbstractJmeterElementConverter<Abstr
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.FILE_NAME, path);
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.SHARE_MODE, shareMode);
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.RECYCLE, true);
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.VARIABLE_NAMES, csvVariable.getVariableNames());
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.DELIMITER, csvVariable.getDelimiter());
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.QUOTED_DATA, csvVariable.getAllowQuotedData());
tree.add(csvDataSet);

View File

@ -21,6 +21,7 @@ public class JmeterProperty {
public static final String QUOTED_DATA = "quotedData";
public static final String SHARE_MODE_GROUP = "shareMode.group";
public static final String SHARE_MODE_THREAD = "shareMode.thread";
public static final String VARIABLE_NAMES = "variableNames";
}
}