From 683fed8ec9b059e5e75fb232b303c6eb44396258 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 7 Aug 2020 17:16:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/APITestController.java | 6 ++- .../api/service/APIReportService.java | 11 ++-- .../api/service/APITestService.java | 26 ++++++++++ .../api/report/components/ScenarioResults.vue | 2 +- .../components/request/ApiRequestForm.vue | 50 ++++++++++++++++++- 5 files changed, 87 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/APITestController.java b/backend/src/main/java/io/metersphere/api/controller/APITestController.java index 69d82379c1..6667d1648b 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -49,7 +49,6 @@ public class APITestController { return apiTestService.getApiTestByProjectId(projectId); } - @PostMapping(value = "/schedule/update") public void updateSchedule(@RequestBody Schedule request) { apiTestService.updateSchedule(request); @@ -90,6 +89,11 @@ public class APITestController { return apiTestService.run(request); } + @PostMapping(value = "/run/independent", consumes = {"multipart/form-data"}) + public String runIndependent(@RequestBody SaveAPITestRequest request, @RequestPart(value = "files") List files) { + return apiTestService.runIndependent(request, files); + } + @PostMapping(value = "/import", consumes = {"multipart/form-data"}) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) public ApiTest testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) { diff --git a/backend/src/main/java/io/metersphere/api/service/APIReportService.java b/backend/src/main/java/io/metersphere/api/service/APIReportService.java index beba5891e5..e7107995ca 100644 --- a/backend/src/main/java/io/metersphere/api/service/APIReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/APIReportService.java @@ -101,7 +101,12 @@ public class APIReportService { if (running != null) { return running.getId(); } + ApiTestReport report = buildReport(test, triggerMode, APITestStatus.Running.name()); + apiTestReportMapper.insert(report); + return report.getId(); + } + public ApiTestReport buildReport(ApiTest test, String triggerMode, String status) { ApiTestReport report = new ApiTestReport(); report.setId(UUID.randomUUID().toString()); report.setTestId(test.getId()); @@ -110,11 +115,9 @@ public class APIReportService { report.setDescription(test.getDescription()); report.setCreateTime(System.currentTimeMillis()); report.setUpdateTime(System.currentTimeMillis()); - report.setStatus(APITestStatus.Running.name()); + report.setStatus(status); report.setUserId(test.getUserId()); - apiTestReportMapper.insert(report); - - return report.getId(); + return report; } public ApiTestReport getRunningReport(String testId) { diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index cc43c6b390..42ac2dd1e9 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -37,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; @@ -328,4 +329,29 @@ public class APITestService { } return schedules; } + + public String runIndependent(SaveAPITestRequest request, List files) { + if (files == null || files.isEmpty()) { + throw new IllegalArgumentException(Translator.get("file_cannot_be_null")); + } +// ApiTest test = createTest(request); +// saveFile(test.getId(), files); + MultipartFile file = files.get(0); + InputStream is = null; + try { + is = new ByteArrayInputStream(file.getBytes()); + } catch (IOException e) { + LogUtil.error(e); + } + + APITestResult apiTest = get(request.getId()); + if (SessionUtils.getUser() == null) { + apiTest.setUserId(request.getUserId()); + } + String reportId = apiReportService.create(apiTest, request.getTriggerMode()); + changeStatus(request.getId(), APITestStatus.Running); + + jMeterService.run(request.getId(), is); + return reportId; + } } diff --git a/frontend/src/business/components/api/report/components/ScenarioResults.vue b/frontend/src/business/components/api/report/components/ScenarioResults.vue index 6d311f7c70..8400d44184 100644 --- a/frontend/src/business/components/api/report/components/ScenarioResults.vue +++ b/frontend/src/business/components/api/report/components/ScenarioResults.vue @@ -1,5 +1,5 @@