fix(接口测试): 修复下载JMX文件及ZIP包名称问题处理

This commit is contained in:
fit2-zhao 2021-12-23 19:08:21 +08:00 committed by xiaomeinvG
parent 7ac223d42e
commit fc598de402
2 changed files with 8 additions and 6 deletions

View File

@ -49,9 +49,10 @@ public class ApiJmeterFileController {
@GetMapping("download")
public ResponseEntity<byte[]> downloadJmeterFiles(@RequestParam("testId") String testId, @RequestParam("reportId") String reportId, @RequestParam("runMode") String runMode, @RequestParam("testPlanScenarioId") String testPlanScenarioId) {
byte[] bytes = apiJmeterFileService.downloadJmeterFiles(runMode, testId, reportId, testPlanScenarioId);
String zipName = reportId + "_" + testId;
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + testId + ".zip\"")
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + zipName + ".zip\"")
.body(bytes);
}

View File

@ -68,7 +68,7 @@ public class ApiJmeterFileService {
}
}
HashTree hashTree;
if (StringUtils.equalsAnyIgnoreCase(runMode, ApiRunMode.DEFINITION.name(), ApiRunMode.JENKINS_API_PLAN.name(),ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) {
if (StringUtils.equalsAnyIgnoreCase(runMode, ApiRunMode.DEFINITION.name(), ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) {
String testId = remoteTestId;
if (remoteTestId.contains(":")) {
//执行测试计划案例时会有拼接ID,ID为 planTestCaseId:测试计划报告ID
@ -82,9 +82,11 @@ public class ApiJmeterFileService {
}
hashTree = apiAutomationService.generateHashTree(item, reportId, planEnvMap);
}
return zipFilesToByteArray(reportId, hashTree);
String jmxName = reportId + "_" + remoteTestId + ".jmx";
return zipFilesToByteArray(jmxName, hashTree);
}
public byte[] downloadJmx(String runMode, String testId, String reportId, String testPlanScenarioId) {
Map<String, String> planEnvMap = new HashMap<>();
if (StringUtils.isNotEmpty(testPlanScenarioId)) {
@ -222,12 +224,11 @@ public class ApiJmeterFileService {
return multipartFiles;
}
private byte[] zipFilesToByteArray(String testId, HashTree hashTree) {
String fileName = testId + ".jmx";
private byte[] zipFilesToByteArray(String jmxName, HashTree hashTree) {
String jmx = new MsTestPlan().getJmx(hashTree);
Map<String, byte[]> files = new HashMap<>();
// 每个测试生成一个文件夹
files.put(fileName, jmx.getBytes(StandardCharsets.UTF_8));
files.put(jmxName, jmx.getBytes(StandardCharsets.UTF_8));
// 获取JMX使用到的附件
Map<String, byte[]> multipartFiles = this.getMultipartFiles(hashTree);
if (!com.alibaba.excel.util.CollectionUtils.isEmpty(multipartFiles)) {