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/dto/scenario/Scenario.java b/backend/src/main/java/io/metersphere/api/dto/scenario/Scenario.java index 0d33151293..654689f7ff 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/Scenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/Scenario.java @@ -10,6 +10,7 @@ public class Scenario { private String name; private String url; private String environmentId; + private Boolean enableCookieShare; private List variables; private List headers; private List requests; 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 a886c9ed3a..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; @@ -299,8 +300,8 @@ public class APITestService { if (info.length > 1) { provider.setVersion(info[1]); } - provider.setService(info[0]); - provider.setServiceInterface(p); + provider.setService(p); + provider.setServiceInterface(info[0]); Map services = providerService.findByService(p); if (services != null && !services.isEmpty()) { String[] methods = services.values().stream().findFirst().get().getParameter(CommonConstants.METHODS_KEY).split(","); @@ -314,6 +315,7 @@ public class APITestService { } public List listSchedule(QueryScheduleRequest request) { + request.setEnable(true); List schedules = scheduleService.list(request); List resourceIds = schedules.stream() .map(Schedule::getResourceId) @@ -327,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/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml index 8738fdf285..5cb36cffce 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml @@ -10,6 +10,9 @@ and schedule.workspace_id = #{request.workspaceId} + + and schedule.enable = #{request.enable} + diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 6625dc899b..a52187115d 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -420,6 +420,7 @@ public class PerformanceTestService { } public List listSchedule(QueryScheduleRequest request) { + request.setEnable(true); List schedules = scheduleService.list(request); List resourceIds = schedules.stream() .map(Schedule::getResourceId) diff --git a/frontend/src/business/components/api/head/ApiHeaderMenus.vue b/frontend/src/business/components/api/head/ApiHeaderMenus.vue index 2fdd1e8bd3..96b83dcca5 100644 --- a/frontend/src/business/components/api/head/ApiHeaderMenus.vue +++ b/frontend/src/business/components/api/head/ApiHeaderMenus.vue @@ -11,7 +11,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -29,7 +29,7 @@ - + @@ -60,7 +60,7 @@ title: this.$t('project.recent'), url: "/project/recent/5", index: function (item) { - return '/api/' + item.id; + return '/api/test/list/' + item.id; }, router: function (item) { return {name: 'ApiTestList', params: {projectId: item.id, projectName: item.name}} diff --git a/frontend/src/business/components/api/home/ApiTestHome.vue b/frontend/src/business/components/api/home/ApiTestHome.vue index 431568988b..69919d5c8a 100644 --- a/frontend/src/business/components/api/home/ApiTestHome.vue +++ b/frontend/src/business/components/api/home/ApiTestHome.vue @@ -14,7 +14,7 @@ - + @@ -28,13 +28,13 @@ import MsApiTestRecentList from "./ApiTestRecentList"; import MsApiReportRecentList from "./ApiReportRecentList"; import MsTestHeatmap from "../../common/components/MsTestHeatmap"; - import MsApiTestScheduleList from "./ApiTestScheduleList"; + import MsScheduleList from "./ScheduleList"; export default { name: "ApiTestHome", components: { - MsApiTestScheduleList, + MsScheduleList, MsTestHeatmap, MsApiReportRecentList, MsApiTestRecentList, MsMainContainer, MsContainer }, diff --git a/frontend/src/business/components/api/home/ApiTestScheduleList.vue b/frontend/src/business/components/api/home/ScheduleList.vue similarity index 96% rename from frontend/src/business/components/api/home/ApiTestScheduleList.vue rename to frontend/src/business/components/api/home/ScheduleList.vue index 1495f1e11a..d0cdfcf42d 100644 --- a/frontend/src/business/components/api/home/ApiTestScheduleList.vue +++ b/frontend/src/business/components/api/home/ScheduleList.vue @@ -1,7 +1,7 @@ @@ -59,9 +63,6 @@ scheduleChange() { this.$emit('scheduleChange'); }, - resultListChange(resultList) { - this.recentList = resultList; - }, flashResultList() { this.$refs.crontabResult.expressionChange(); } diff --git a/frontend/src/business/components/common/cron/CrontabResult.vue b/frontend/src/business/components/common/cron/CrontabResult.vue index fa7f206531..a1f4c74e6a 100644 --- a/frontend/src/business/components/common/cron/CrontabResult.vue +++ b/frontend/src/business/components/common/cron/CrontabResult.vue @@ -1,5 +1,5 @@ - +