fix(接口测试): 修复导出jmx报错
--bug=1013228 --user=王孝刚 【接口测试】github#13619,[企业客户] 导出场景用例为metersphere格式或jmeter格式报错 https://www.tapd.cn/55049933/s/1160362
This commit is contained in:
parent
1b3152f8aa
commit
4ea8291d30
|
@ -1411,10 +1411,12 @@ public class ApiAutomationService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
|
||||||
JSONArray hashTree = element.getJSONArray("hashTree");
|
if (element != null) {
|
||||||
ApiScenarioImportUtil.formatHashTree(hashTree);
|
JSONArray hashTree = element.getJSONArray("hashTree");
|
||||||
setHashTree(hashTree);
|
ApiScenarioImportUtil.formatHashTree(hashTree);
|
||||||
scenario.setScenarioDefinition(JSONObject.toJSONString(element));
|
setHashTree(hashTree);
|
||||||
|
scenario.setScenarioDefinition(JSONObject.toJSONString(element));
|
||||||
|
}
|
||||||
names.add(scenario.getName());
|
names.add(scenario.getName());
|
||||||
ids.add(scenario.getId());
|
ids.add(scenario.getId());
|
||||||
}
|
}
|
||||||
|
@ -1456,6 +1458,8 @@ public class ApiAutomationService {
|
||||||
|
|
||||||
public List<ApiScenarioExportJmxDTO> exportJmx(ApiScenarioBatchRequest request) {
|
public List<ApiScenarioExportJmxDTO> exportJmx(ApiScenarioBatchRequest request) {
|
||||||
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBs = getExportResult(request);
|
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBs = getExportResult(request);
|
||||||
|
//检查运行环境
|
||||||
|
checkExportEnv(apiScenarioWithBLOBs);
|
||||||
// 生成jmx
|
// 生成jmx
|
||||||
List<ApiScenarioExportJmxDTO> resList = new ArrayList<>();
|
List<ApiScenarioExportJmxDTO> resList = new ArrayList<>();
|
||||||
apiScenarioWithBLOBs.forEach(item -> {
|
apiScenarioWithBLOBs.forEach(item -> {
|
||||||
|
@ -1483,6 +1487,8 @@ public class ApiAutomationService {
|
||||||
|
|
||||||
public byte[] exportZip(ApiScenarioBatchRequest request) {
|
public byte[] exportZip(ApiScenarioBatchRequest request) {
|
||||||
List<ApiScenarioWithBLOBs> scenarios = getExportResult(request);
|
List<ApiScenarioWithBLOBs> scenarios = getExportResult(request);
|
||||||
|
//环境检查
|
||||||
|
checkExportEnv(scenarios);
|
||||||
// 生成jmx
|
// 生成jmx
|
||||||
Map<String, byte[]> files = new LinkedHashMap<>();
|
Map<String, byte[]> files = new LinkedHashMap<>();
|
||||||
scenarios.forEach(item -> {
|
scenarios.forEach(item -> {
|
||||||
|
@ -1505,6 +1511,23 @@ public class ApiAutomationService {
|
||||||
return FileUtils.listBytesToZip(files);
|
return FileUtils.listBytesToZip(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkExportEnv(List<ApiScenarioWithBLOBs> scenarios) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (ApiScenarioWithBLOBs apiScenarioWithBLOBs : scenarios) {
|
||||||
|
try {
|
||||||
|
boolean haveEnv = apiScenarioEnvService.checkScenarioEnv(apiScenarioWithBLOBs, null);
|
||||||
|
if (!haveEnv) {
|
||||||
|
builder.append(apiScenarioWithBLOBs.getName()).append("; ");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
MSException.throwException("场景:" + builder.toString() + "运行环境未配置,请检查!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (builder.length() > 0) {
|
||||||
|
MSException.throwException("场景:" + builder.toString() + "运行环境未配置,请检查!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void batchUpdateEnv(ApiScenarioBatchRequest request) {
|
public void batchUpdateEnv(ApiScenarioBatchRequest request) {
|
||||||
Map<String, String> envMap = request.getEnvMap();
|
Map<String, String> envMap = request.getEnvMap();
|
||||||
String envType = request.getEnvironmentType();
|
String envType = request.getEnvironmentType();
|
||||||
|
|
Loading…
Reference in New Issue