fix(接口自动化): 场景数据迁移问题修改
This commit is contained in:
parent
06686e573d
commit
fb0af088c5
|
@ -65,6 +65,15 @@ public class HistoricalDataUpgradeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MsScenario createScenarioByTest(ApiTest test) {
|
||||||
|
MsScenario scenario = new MsScenario();
|
||||||
|
scenario.setName(test.getName());
|
||||||
|
scenario.setReferenced("Upgrade");
|
||||||
|
scenario.setResourceId(UUID.randomUUID().toString());
|
||||||
|
scenario.setId(test.getId());
|
||||||
|
return scenario;
|
||||||
|
}
|
||||||
|
|
||||||
private MsScenario createScenario(Scenario oldScenario) {
|
private MsScenario createScenario(Scenario oldScenario) {
|
||||||
MsScenario scenario = new MsScenario();
|
MsScenario scenario = new MsScenario();
|
||||||
scenario.setOldVariables(oldScenario.getVariables());
|
scenario.setOldVariables(oldScenario.getVariables());
|
||||||
|
@ -147,6 +156,9 @@ public class HistoricalDataUpgradeService {
|
||||||
BeanUtils.copyBean(element, request1);
|
BeanUtils.copyBean(element, request1);
|
||||||
((MsHTTPSamplerProxy) element).setProtocol(RequestType.HTTP);
|
((MsHTTPSamplerProxy) element).setProtocol(RequestType.HTTP);
|
||||||
((MsHTTPSamplerProxy) element).setArguments(request1.getParameters());
|
((MsHTTPSamplerProxy) element).setArguments(request1.getParameters());
|
||||||
|
List<KeyValue> keyValues = new LinkedList<>();
|
||||||
|
keyValues.add(new KeyValue("", ""));
|
||||||
|
((MsHTTPSamplerProxy) element).setRest(keyValues);
|
||||||
if (StringUtils.isEmpty(element.getName())) {
|
if (StringUtils.isEmpty(element.getName())) {
|
||||||
element.setName(request1.getPath());
|
element.setName(request1.getPath());
|
||||||
}
|
}
|
||||||
|
@ -251,9 +263,9 @@ public class HistoricalDataUpgradeService {
|
||||||
return scenario;
|
return scenario;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiScenarioWithBLOBs checkNameExist(Scenario oldScenario, String projectId, ApiScenarioMapper mapper) {
|
private ApiScenarioWithBLOBs getScenario(String oldScenarioId, ApiScenarioMapper mapper) {
|
||||||
ApiScenarioExample example = new ApiScenarioExample();
|
ApiScenarioExample example = new ApiScenarioExample();
|
||||||
example.createCriteria().andIdEqualTo(oldScenario.getId());
|
example.createCriteria().andIdEqualTo(oldScenarioId);
|
||||||
List<ApiScenarioWithBLOBs> list = mapper.selectByExampleWithBLOBs(example);
|
List<ApiScenarioWithBLOBs> list = mapper.selectByExampleWithBLOBs(example);
|
||||||
if (list.size() > 0) {
|
if (list.size() > 0) {
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
|
@ -333,20 +345,20 @@ public class HistoricalDataUpgradeService {
|
||||||
copyDir(dir, BODY_FILE_DIR);
|
copyDir(dir, BODY_FILE_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createApiScenarioWithBLOBs(SaveHistoricalDataUpgrade saveHistoricalDataUpgrade, Scenario oldScenario, String scenarioDefinition, ApiScenarioMapper mapper, int num) {
|
private void createApiScenarioWithBLOBs(SaveHistoricalDataUpgrade saveHistoricalDataUpgrade, String id, String name, int total, String scenarioDefinition, ApiScenarioMapper mapper, int num) {
|
||||||
if (StringUtils.isEmpty(oldScenario.getName())) {
|
if (StringUtils.isEmpty(name)) {
|
||||||
oldScenario.setName("默认名称-" + DateUtils.getTimeStr(System.currentTimeMillis()));
|
name = "默认名称-" + DateUtils.getTimeStr(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
ApiScenarioWithBLOBs scenario = checkNameExist(oldScenario, saveHistoricalDataUpgrade.getProjectId(), mapper);
|
ApiScenarioWithBLOBs scenario = getScenario(id, mapper);
|
||||||
if (scenario != null) {
|
if (scenario != null) {
|
||||||
scenario.setName(oldScenario.getName());
|
scenario.setName(name);
|
||||||
scenario.setProjectId(saveHistoricalDataUpgrade.getProjectId());
|
scenario.setProjectId(saveHistoricalDataUpgrade.getProjectId());
|
||||||
scenario.setTags(scenario.getTags());
|
scenario.setTags(scenario.getTags());
|
||||||
scenario.setLevel("P0");
|
scenario.setLevel("P0");
|
||||||
scenario.setModulePath(saveHistoricalDataUpgrade.getModulePath());
|
scenario.setModulePath(saveHistoricalDataUpgrade.getModulePath());
|
||||||
scenario.setApiScenarioModuleId(saveHistoricalDataUpgrade.getModuleId());
|
scenario.setApiScenarioModuleId(saveHistoricalDataUpgrade.getModuleId());
|
||||||
scenario.setPrincipal(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
scenario.setPrincipal(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||||
scenario.setStepTotal(oldScenario.getRequests().size());
|
scenario.setStepTotal(total);
|
||||||
scenario.setScenarioDefinition(scenarioDefinition);
|
scenario.setScenarioDefinition(scenarioDefinition);
|
||||||
scenario.setUpdateTime(System.currentTimeMillis());
|
scenario.setUpdateTime(System.currentTimeMillis());
|
||||||
scenario.setStatus(ScenarioStatus.Underway.name());
|
scenario.setStatus(ScenarioStatus.Underway.name());
|
||||||
|
@ -354,15 +366,15 @@ public class HistoricalDataUpgradeService {
|
||||||
mapper.updateByPrimaryKeySelective(scenario);
|
mapper.updateByPrimaryKeySelective(scenario);
|
||||||
} else {
|
} else {
|
||||||
scenario = new ApiScenarioWithBLOBs();
|
scenario = new ApiScenarioWithBLOBs();
|
||||||
scenario.setId(oldScenario.getId());
|
scenario.setId(id);
|
||||||
scenario.setName(oldScenario.getName());
|
scenario.setName(name);
|
||||||
scenario.setProjectId(saveHistoricalDataUpgrade.getProjectId());
|
scenario.setProjectId(saveHistoricalDataUpgrade.getProjectId());
|
||||||
scenario.setTags(scenario.getTags());
|
scenario.setTags(scenario.getTags());
|
||||||
scenario.setLevel("P0");
|
scenario.setLevel("P0");
|
||||||
scenario.setModulePath(saveHistoricalDataUpgrade.getModulePath());
|
scenario.setModulePath(saveHistoricalDataUpgrade.getModulePath());
|
||||||
scenario.setApiScenarioModuleId(saveHistoricalDataUpgrade.getModuleId());
|
scenario.setApiScenarioModuleId(saveHistoricalDataUpgrade.getModuleId());
|
||||||
scenario.setPrincipal(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
scenario.setPrincipal(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||||
scenario.setStepTotal(oldScenario.getRequests().size());
|
scenario.setStepTotal(total);
|
||||||
scenario.setScenarioDefinition(scenarioDefinition);
|
scenario.setScenarioDefinition(scenarioDefinition);
|
||||||
scenario.setCreateTime(System.currentTimeMillis());
|
scenario.setCreateTime(System.currentTimeMillis());
|
||||||
scenario.setUpdateTime(System.currentTimeMillis());
|
scenario.setUpdateTime(System.currentTimeMillis());
|
||||||
|
@ -386,7 +398,9 @@ public class HistoricalDataUpgradeService {
|
||||||
for (ApiTest test : blobs) {
|
for (ApiTest test : blobs) {
|
||||||
// 附件迁移
|
// 附件迁移
|
||||||
createBodyFiles(test.getId());
|
createBodyFiles(test.getId());
|
||||||
|
// 把test 生成一个场景,旧场景数据变成引用步骤
|
||||||
|
MsScenario scenarioTest = createScenarioByTest(test);
|
||||||
|
LinkedList<MsTestElement> listSteps = new LinkedList<>();
|
||||||
List<Scenario> scenarios = JSON.parseArray(test.getScenarioDefinition(), Scenario.class);
|
List<Scenario> scenarios = JSON.parseArray(test.getScenarioDefinition(), Scenario.class);
|
||||||
if (CollectionUtils.isNotEmpty(scenarios)) {
|
if (CollectionUtils.isNotEmpty(scenarios)) {
|
||||||
// 批量处理
|
// 批量处理
|
||||||
|
@ -394,9 +408,20 @@ public class HistoricalDataUpgradeService {
|
||||||
MsScenario scenario1 = createScenario(scenario);
|
MsScenario scenario1 = createScenario(scenario);
|
||||||
String scenarioDefinition = JSON.toJSONString(scenario1);
|
String scenarioDefinition = JSON.toJSONString(scenario1);
|
||||||
num++;
|
num++;
|
||||||
createApiScenarioWithBLOBs(saveHistoricalDataUpgrade, scenario, scenarioDefinition, mapper, num);
|
createApiScenarioWithBLOBs(saveHistoricalDataUpgrade, scenario.getId(), scenario.getName(), scenario.getRequests().size(), scenarioDefinition, mapper, num);
|
||||||
|
MsScenario step = new MsScenario();
|
||||||
|
step.setId(scenario1.getId());
|
||||||
|
step.setName(scenario1.getName());
|
||||||
|
step.setType("scenario");
|
||||||
|
step.setResourceId(UUID.randomUUID().toString());
|
||||||
|
step.setReferenced("REF");
|
||||||
|
listSteps.add(step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
num++;
|
||||||
|
scenarioTest.setHashTree(listSteps);
|
||||||
|
String scenarioDefinition = JSON.toJSONString(scenarioTest);
|
||||||
|
createApiScenarioWithBLOBs(saveHistoricalDataUpgrade, scenarioTest.getId(), scenarioTest.getName(), listSteps.size(), scenarioDefinition, mapper, num);
|
||||||
}
|
}
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue