diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java index c237e2349a..07f92a927d 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java @@ -100,7 +100,7 @@ public class ApiTestCaseController { } @PostMapping(value = "/jenkins/run") - public String jenkinsRun(@RequestPart("request") RunCaseRequest request) { + public String jenkinsRun(@RequestBody RunCaseRequest request) { return apiTestCaseService.run(request); } } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 0f9b5cc1cd..03f5b37b56 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -8,6 +8,9 @@ import io.metersphere.api.dto.ApiCaseBatchRequest; import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.definition.request.MsTestElement; +import io.metersphere.api.dto.definition.request.MsTestPlan; +import io.metersphere.api.dto.definition.request.MsThreadGroup; +import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiDefinitionMapper; @@ -30,6 +33,7 @@ import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.jorphan.collections.HashTree; +import org.apache.jorphan.collections.ListedHashTree; import org.aspectj.util.FileUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -400,11 +404,28 @@ public class ApiTestCaseService { try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - MsTestElement elements = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference() { }); - HashTree hashTree = elements.generateHashTree(); + MsTestElement element = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference() { + }); + // 测试计划 + MsTestPlan testPlan = new MsTestPlan(); + testPlan.setHashTree(new LinkedList<>()); + HashTree jmeterHashTree = new ListedHashTree(); + + // 线程组 + MsThreadGroup group = new MsThreadGroup(); + group.setLabel(testCaseWithBLOBs.getName()); + group.setName(testCaseWithBLOBs.getId()); + + LinkedList hashTrees = new LinkedList<>(); + hashTrees.add(element); + group.setHashTree(hashTrees); + testPlan.getHashTree().add(group); + + testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig()); + String runMode = ApiRunMode.DELIMIT.name(); // 调用执行方法 - jMeterService.runDefinition(request.getReportId(), hashTree, request.getReportId(), runMode); + jMeterService.runDefinition(request.getReportId(), jmeterHashTree, request.getReportId(), runMode); } catch (Exception ex) { LogUtil.error(ex.getMessage());