fix(接口测试): csv部分配置不生效
This commit is contained in:
parent
8647152be3
commit
58f9137cec
|
@ -67,9 +67,11 @@ public class MsCsvChildPreConverter extends AbstractJmeterElementConverter<Abstr
|
|||
csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI));
|
||||
csvDataSet.setName(StringUtils.isEmpty(csvVariable.getName()) ? CSVDataSet.class.getSimpleName() : csvVariable.getName());
|
||||
csvDataSet.setProperty(JmeterProperty.FILE_ENCODING, StringUtils.isEmpty(csvVariable.getEncoding()) ? StandardCharsets.UTF_8.name() : csvVariable.getEncoding());
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.IGNORE_FIRST_LINE, csvVariable.getIgnoreFirstLine());
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.STOP_THREAD, csvVariable.getStopThreadOnEof());
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.FILE_NAME, path);
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.SHARE_MODE, shareMode);
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.RECYCLE, true);
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.RECYCLE, csvVariable.getRecycleOnEof());
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.VARIABLE_NAMES, csvVariable.getVariableNames());
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.DELIMITER, csvVariable.getDelimiter());
|
||||
csvDataSet.setProperty(JmeterProperty.CSVDataSetProperty.QUOTED_DATA, csvVariable.getAllowQuotedData());
|
||||
|
|
|
@ -14,6 +14,8 @@ public class JmeterProperty {
|
|||
public final static String FILE_ENCODING = "fileEncoding";
|
||||
|
||||
public class CSVDataSetProperty {
|
||||
public static final String IGNORE_FIRST_LINE = "ignoreFirstLine";
|
||||
public static final String STOP_THREAD = "stopThread";
|
||||
public static final String FILE_NAME = "filename";
|
||||
public static final String SHARE_MODE = "shareMode";
|
||||
public static final String RECYCLE = "recycle";
|
||||
|
|
|
@ -527,15 +527,31 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
}
|
||||
|
||||
csvSteps.forEach(step -> step.setScenarioId(scenario.getId()));
|
||||
saveStepCsv(scenario.getId(), steps, csvSteps);
|
||||
|
||||
csvSteps = filterNotExistCsv(request.getScenarioConfig(), csvSteps);
|
||||
saveStepCsv(scenario.getId(), csvSteps);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ApiScenarioCsvStep> filterNotExistCsv(ScenarioConfig scenarioConfig, List<ApiScenarioCsvStep> csvSteps) {
|
||||
Set<String> csvIdSet =
|
||||
getCsvVariables(scenarioConfig)
|
||||
.stream()
|
||||
.map(CsvVariable::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
csvSteps = csvSteps.stream()
|
||||
.filter(step -> csvIdSet.contains(step.getFileId()))
|
||||
.collect(Collectors.toList());
|
||||
return csvSteps;
|
||||
}
|
||||
|
||||
private void handCsvFilesAdd(ApiScenarioAddRequest request, String creator, ApiScenario scenario) {
|
||||
if (request.getScenarioConfig() == null || request.getScenarioConfig().getVariable() == null || request.getScenarioConfig().getVariable().getCsvVariables() == null) {
|
||||
List<CsvVariable> csvVariables = getCsvVariables(request.getScenarioConfig());
|
||||
|
||||
if (CollectionUtils.isEmpty(csvVariables)) {
|
||||
return;
|
||||
}
|
||||
List<CsvVariable> csvVariables = request.getScenarioConfig().getVariable().getCsvVariables();
|
||||
|
||||
// 处理 csv 相关数据表
|
||||
handleCsvDataUpdate(csvVariables, scenario, List.of());
|
||||
|
@ -544,6 +560,13 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
handleCsvFileUpdate(csvVariables, List.of(), scenario, creator);
|
||||
}
|
||||
|
||||
private List<CsvVariable> getCsvVariables(ScenarioConfig scenarioConfig) {
|
||||
if (scenarioConfig == null ||scenarioConfig.getVariable() == null || scenarioConfig.getVariable().getCsvVariables() == null) {
|
||||
return List.of();
|
||||
}
|
||||
return scenarioConfig.getVariable().getCsvVariables();
|
||||
}
|
||||
|
||||
private void handleStepFilesAdd(ApiScenarioAddRequest request, String creator, ApiScenario scenario) {
|
||||
Map<String, ResourceAddFileParam> stepFileParam = request.getStepFileParam();
|
||||
if (MapUtils.isNotEmpty(stepFileParam)) {
|
||||
|
@ -576,7 +599,7 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
return resourceUpdateRequest;
|
||||
}
|
||||
|
||||
private void saveStepCsv(String scenarioId, List<ApiScenarioStep> steps, List<ApiScenarioCsvStep> csvSteps) {
|
||||
private void saveStepCsv(String scenarioId, List<ApiScenarioCsvStep> csvSteps) {
|
||||
// 先删除
|
||||
ApiScenarioCsvStepExample csvStepExample = new ApiScenarioCsvStepExample();
|
||||
csvStepExample.createCriteria().andScenarioIdEqualTo(scenarioId);
|
||||
|
@ -589,10 +612,11 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
}
|
||||
|
||||
private void handleCsvUpdate(ScenarioConfig scenarioConfig, ApiScenario scenario, String userId) {
|
||||
if (scenarioConfig == null || scenarioConfig.getVariable() == null || scenarioConfig.getVariable().getCsvVariables() == null) {
|
||||
if (scenarioConfig == null) {
|
||||
return;
|
||||
}
|
||||
List<CsvVariable> csvVariables = scenarioConfig.getVariable().getCsvVariables();
|
||||
|
||||
List<CsvVariable> csvVariables = getCsvVariables(scenarioConfig);
|
||||
List<ApiScenarioCsv> dbCsv = getApiScenarioCsv(scenario.getId());
|
||||
|
||||
// 更新 csv 相关数据表
|
||||
|
@ -782,7 +806,8 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
apiScenarioSteps.forEach(step -> step.setScenarioId(scenario.getId()));
|
||||
scenarioCsvSteps.forEach(step -> step.setScenarioId(scenario.getId()));
|
||||
|
||||
saveStepCsv(scenario.getId(), apiScenarioSteps, scenarioCsvSteps);
|
||||
scenarioCsvSteps = filterNotExistCsv(request.getScenarioConfig(), scenarioCsvSteps);
|
||||
saveStepCsv(scenario.getId(), scenarioCsvSteps);
|
||||
// 获取待更新的步骤详情
|
||||
addSpecialStepDetails(steps, request.getStepDetails());
|
||||
List<ApiScenarioStepBlob> updateStepBlobs = getUpdateStepBlobs(apiScenarioSteps, request.getStepDetails());
|
||||
|
@ -960,11 +985,11 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
|
||||
if (CollectionUtils.isNotEmpty(step.getCsvIds())) {
|
||||
//如果是csv文件 需要保存到apiScenarioCsvStep表中
|
||||
step.getCsvIds().forEach(fileId -> {
|
||||
step.getCsvIds().forEach(csvId -> {
|
||||
ApiScenarioCsvStep csvStep = new ApiScenarioCsvStep();
|
||||
csvStep.setId(IDGenerator.nextStr());
|
||||
csvStep.setStepId(apiScenarioStep.getId());
|
||||
csvStep.setFileId(fileId);
|
||||
csvStep.setFileId(csvId);
|
||||
csvSteps.add(csvStep);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -175,6 +175,8 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ApiScenarioReportService scenarioReportService;
|
||||
@Resource
|
||||
private ApiScenarioCsvStepMapper apiScenarioCsvStepMapper;
|
||||
|
||||
private static String fileMetadataId;
|
||||
private static String fileMetadataStepId;
|
||||
|
@ -1235,6 +1237,7 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
Assertions.assertEquals(apiScenarioDetail.getCreateUserName(), userMapper.selectByPrimaryKey(apiScenarioDetail.getCreateUser()).getName());
|
||||
Assertions.assertEquals(apiScenarioDetail.getUpdateUserName(), userMapper.selectByPrimaryKey(apiScenarioDetail.getUpdateUser()).getName());
|
||||
Assertions.assertFalse(apiScenarioDetail.getFollow());
|
||||
|
||||
// 验证数据
|
||||
assertGetApiScenarioSteps(this.addApiScenarioSteps, apiScenarioDetail.getSteps());
|
||||
|
||||
|
@ -1327,6 +1330,13 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
for (int i = 0; i < addApiScenarioSteps.size(); i++) {
|
||||
ApiScenarioStepRequest stepRequest = (ApiScenarioStepRequest) addApiScenarioSteps.get(i);
|
||||
ApiScenarioStepDTO stepDTO = (ApiScenarioStepDTO) steps.get(i);
|
||||
ApiScenarioCsvStepExample example = new ApiScenarioCsvStepExample();
|
||||
example.createCriteria().andStepIdEqualTo(stepDTO.getId());
|
||||
List<String> csvIds = apiScenarioCsvStepMapper.selectByExample(example).stream().map(ApiScenarioCsvStep::getFileId).collect(Collectors.toList());
|
||||
stepRequest.setCsvIds(csvIds);
|
||||
if (stepDTO.getCsvIds() == null) {
|
||||
stepDTO.setCsvIds(List.of());
|
||||
}
|
||||
Assertions.assertEquals(BeanUtils.copyBean(new ApiScenarioStepCommonDTO(), stepRequest), BeanUtils.copyBean(new ApiScenarioStepCommonDTO(), stepDTO));
|
||||
assertGetApiScenarioSteps(stepRequest.getChildren(), stepDTO.getChildren());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue