refactor(接口自动化): 代码规范修改

This commit is contained in:
fit2-zhao 2021-09-15 14:19:28 +08:00 committed by fit2-zhao
parent 3fbea438c6
commit 09b0693187
1 changed files with 4 additions and 16 deletions

View File

@ -892,7 +892,6 @@ public class ApiAutomationService {
group.setName(reportId); group.setName(reportId);
MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class); MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class);
group.setOnSampleError(scenario.getOnSampleError()); group.setOnSampleError(scenario.getOnSampleError());
this.preduceMsScenario(scenario);
if (planEnvMap.size() > 0) { if (planEnvMap.size() > 0) {
scenario.setEnvironmentMap(planEnvMap); scenario.setEnvironmentMap(planEnvMap);
} }
@ -1142,7 +1141,7 @@ public class ApiAutomationService {
public void run() { public void run() {
List<String> reportIds = new LinkedList<>(); List<String> reportIds = new LinkedList<>();
//记录串行执行中的环境参数供下一个场景执行时使用 <envId,<key,data>> //记录串行执行中的环境参数供下一个场景执行时使用 <envId,<key,data>>
Map<String, Map<String, String>> execute_env_param_datas = new LinkedHashMap<>(); Map<String, Map<String, String>> executeEnvParams = new LinkedHashMap<>();
ApiTestEnvironmentService apiTestEnvironmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); ApiTestEnvironmentService apiTestEnvironmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
HashTreeUtil hashTreeUtil = new HashTreeUtil(); HashTreeUtil hashTreeUtil = new HashTreeUtil();
for (String key : executeQueue.keySet()) { for (String key : executeQueue.keySet()) {
@ -1158,9 +1157,9 @@ public class ApiAutomationService {
apiScenarioReportMapper.updateByPrimaryKey(report); apiScenarioReportMapper.updateByPrimaryKey(report);
} }
try { try {
if (!execute_env_param_datas.isEmpty()) { if (!executeEnvParams.isEmpty()) {
HashTree hashTree = executeQueue.get(key).getHashTree(); HashTree hashTree = executeQueue.get(key).getHashTree();
hashTreeUtil.setEnvParamsMapToHashTree(hashTree, execute_env_param_datas); hashTreeUtil.setEnvParamsMapToHashTree(hashTree, executeEnvParams);
executeQueue.get(key).setHashTree(hashTree); executeQueue.get(key).setHashTree(hashTree);
} }
Future<ApiScenarioReport> future = executorService.submit(new SerialScenarioExecTask(jMeterService, apiScenarioReportMapper, executeQueue.get(key), request)); Future<ApiScenarioReport> future = executorService.submit(new SerialScenarioExecTask(jMeterService, apiScenarioReportMapper, executeQueue.get(key), request));
@ -1174,7 +1173,7 @@ public class ApiAutomationService {
} }
Map<String, Map<String, String>> envParamsMap = hashTreeUtil.getEnvParamsDataByHashTree(executeQueue.get(key).getHashTree(), apiTestEnvironmentService); Map<String, Map<String, String>> envParamsMap = hashTreeUtil.getEnvParamsDataByHashTree(executeQueue.get(key).getHashTree(), apiTestEnvironmentService);
execute_env_param_datas = hashTreeUtil.mergeParamDataMap(execute_env_param_datas, envParamsMap); executeEnvParams = hashTreeUtil.mergeParamDataMap(executeEnvParams, envParamsMap);
} catch (Exception e) { } catch (Exception e) {
reportIds.remove(key); reportIds.remove(key);
LogUtil.error("执行终止:" + e.getMessage()); LogUtil.error("执行终止:" + e.getMessage());
@ -1269,7 +1268,6 @@ public class ApiAutomationService {
MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class); MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class);
group.setOnSampleError(scenario.getOnSampleError()); group.setOnSampleError(scenario.getOnSampleError());
this.preduceMsScenario(scenario);
// 多态JSON普通转换会丢失内容需要通过 ObjectMapper 获取 // 多态JSON普通转换会丢失内容需要通过 ObjectMapper 获取
if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) {
LinkedList<MsTestElement> elements = mapper.readValue(element.getString("hashTree"), LinkedList<MsTestElement> elements = mapper.readValue(element.getString("hashTree"),
@ -1336,16 +1334,6 @@ public class ApiAutomationService {
return jmeterHashTree; return jmeterHashTree;
} }
private void preduceMsScenario(MsScenario scenario) {
if (scenario.getHashTree() != null) {
for (MsTestElement itemElement : scenario.getHashTree()) {
if (itemElement instanceof MsScenario) {
itemElement.setId(UUID.randomUUID().toString());
}
}
}
}
private boolean checkScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs, TestPlanApiScenario testPlanApiScenarios) { private boolean checkScenarioEnv(ApiScenarioWithBLOBs apiScenarioWithBLOBs, TestPlanApiScenario testPlanApiScenarios) {
String definition = apiScenarioWithBLOBs.getScenarioDefinition(); String definition = apiScenarioWithBLOBs.getScenarioDefinition();
MsScenario scenario = JSONObject.parseObject(definition, MsScenario.class); MsScenario scenario = JSONObject.parseObject(definition, MsScenario.class);