From 3155af90f5f86fbc00378ee62ab2ae922f0c255d Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Thu, 31 Dec 2020 15:11:08 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20jenkins=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApiAutomationController.java | 8 +++--- .../base/mapper/ext/ExtTestCaseMapper.xml | 7 +++++ .../mapper/ext/ExtTestPlanTestCaseMapper.java | 2 ++ .../mapper/ext/ExtTestPlanTestCaseMapper.xml | 28 +++++++++++++++++++ .../commons/constants/ApiRunMode.java | 2 +- .../track/controller/TestCaseController.java | 2 +- .../TestPlanTestCaseController.java | 4 +-- .../service/TestPlanTestCaseService.java | 5 ++++ 8 files changed, 50 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index fb49ac9127..2f8fbdbc06 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -85,15 +85,15 @@ public class ApiAutomationController { } @PostMapping(value = "/run") - public void run(@RequestBody RunScenarioRequest request) { + public String run(@RequestBody RunScenarioRequest request) { request.setExecuteType(ExecuteType.Completed.name()); - apiAutomationService.run(request); + return apiAutomationService.run(request); } @PostMapping(value = "/run/batch") - public void runBatch(@RequestBody RunScenarioRequest request) { + public String runBatch(@RequestBody RunScenarioRequest request) { request.setExecuteType(ExecuteType.Saved.name()); - apiAutomationService.run(request); + return apiAutomationService.run(request); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index 832e1ffd44..709dffae63 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -333,6 +333,13 @@ and project_id= #{request.projectId} + UNION ALL + select id,name,status,project_id,"scenario" as type from api_scenario + + + and project_id= #{request.projectId} + + + update test_plan_test_case diff --git a/backend/src/main/java/io/metersphere/commons/constants/ApiRunMode.java b/backend/src/main/java/io/metersphere/commons/constants/ApiRunMode.java index 469c3d698b..5dd7a0e5c3 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ApiRunMode.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ApiRunMode.java @@ -1,5 +1,5 @@ package io.metersphere.commons.constants; public enum ApiRunMode { - RUN, DEBUG,DELIMIT,SCENARIO, API_PLAN, SCENARIO_PLAN + RUN, DEBUG,DELIMIT,SCENARIO, API_PLAN, SCENARIO_PLAN,API } diff --git a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java index e87d9cd916..ecf8290d04 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java @@ -57,7 +57,7 @@ public class TestCaseController { return testCaseService.listTestCase(request); } - + /*jenkins项目下所有接口和性能测试用例*/ @GetMapping("/list/method/{projectId}") public List listByMethod(@PathVariable String projectId) { QueryTestCaseRequest request = new QueryTestCaseRequest(); diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanTestCaseController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanTestCaseController.java index cedcf7eeda..0d2d38cbad 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanTestCaseController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanTestCaseController.java @@ -30,13 +30,13 @@ public class TestPlanTestCaseController { Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, testPlanTestCaseService.list(request)); } - + /*jenkins测试计划下全部用例*/ @GetMapping("/list/{planId}") public List getTestPlanCaseByPlanId(@PathVariable String planId) { QueryTestPlanCaseRequest request = new QueryTestPlanCaseRequest(); request.setPlanId(planId); request.setMethod("auto"); - return testPlanTestCaseService.list(request); + return testPlanTestCaseService.listByPlanId(request); } @GetMapping("/list/node/{planId}/{nodePaths}") diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java index cd21abb1e5..a5c3202b41 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java @@ -55,6 +55,11 @@ public class TestPlanTestCaseService { }); return list; } + public List listByPlanId(QueryTestPlanCaseRequest request) { + List list = extTestPlanTestCaseMapper.listByPlanId(request); + + return list; + } public List listByNode(QueryTestPlanCaseRequest request) { List list = extTestPlanTestCaseMapper.listByNode(request); From 515f524f3e26ea64eb2002b3bcd0f6f789214b3b Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 31 Dec 2020 15:23:45 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0Jenkins=20=E8=B0=83=E7=94=A8=20=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=94=A8=E4=BE=8B=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/ApiTestCaseController.java | 5 ++ .../api/dto/definition/RunCaseRequest.java | 13 +++++ .../api/service/ApiTestCaseService.java | 58 ++++++++++++++----- 3 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/dto/definition/RunCaseRequest.java 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 40ab590b92..c237e2349a 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java @@ -98,4 +98,9 @@ public class ApiTestCaseController { public void testPlanRelevance(@RequestBody ApiCaseRelevanceRequest request) { apiTestCaseService.relevanceByCase(request); } + + @PostMapping(value = "/jenkins/run") + public String jenkinsRun(@RequestPart("request") RunCaseRequest request) { + return apiTestCaseService.run(request); + } } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/RunCaseRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/RunCaseRequest.java new file mode 100644 index 0000000000..993509e950 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/definition/RunCaseRequest.java @@ -0,0 +1,13 @@ +package io.metersphere.api.dto.definition; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class RunCaseRequest { + + private String caseId; + + private String reportId; +} 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 6219e5e609..0f9b5cc1cd 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -1,11 +1,14 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSONObject; -import io.metersphere.api.dto.automation.ApiScenarioDTO; -import io.metersphere.api.dto.automation.ApiScenarioRequest; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.metersphere.api.dto.ApiCaseBatchRequest; import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.definition.*; -import io.metersphere.api.dto.ApiCaseBatchRequest; +import io.metersphere.api.dto.definition.request.MsTestElement; +import io.metersphere.api.jmeter.JMeterService; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiDefinitionMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; @@ -14,6 +17,7 @@ import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; +import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.i18n.Translator; @@ -21,11 +25,12 @@ import io.metersphere.service.FileService; import io.metersphere.service.QuotaService; import io.metersphere.service.UserService; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; +import org.apache.commons.lang3.StringUtils; 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.aspectj.util.FileUtil; -import org.python.antlr.ast.Str; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -57,6 +62,8 @@ public class ApiTestCaseService { private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper; @Resource private ApiDefinitionMapper apiDefinitionMapper; + @Resource + private JMeterService jMeterService; private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; @@ -271,7 +278,7 @@ public class ApiTestCaseService { } public void deleteBatch(List ids) { - for (String testId:ids) { + for (String testId : ids) { extTestPlanTestCaseMapper.deleteByTestCaseID(testId); } ApiTestCaseExample example = new ApiTestCaseExample(); @@ -331,10 +338,10 @@ public class ApiTestCaseService { Date firstTime = startAndEndDateInWeek.get("firstTime"); Date lastTime = startAndEndDateInWeek.get("lastTime"); - if(firstTime==null || lastTime == null){ - return 0; - }else { - return extApiTestCaseMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime()); + if (firstTime == null || lastTime == null) { + return 0; + } else { + return extApiTestCaseMapper.countByProjectIDAndCreateInThisWeek(projectId, firstTime.getTime(), lastTime.getTime()); } } @@ -351,16 +358,16 @@ public class ApiTestCaseService { public void deleteBatchByParam(ApiTestBatchRequest request) { List ids = request.getIds(); - if(request.isSelectAllDate()){ - ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(),request.getModuleIds(),request.getName(),request.getProjectId(),request.getProtocol(),request.getUnSelectIds(),request.getStatus()); + if (request.isSelectAllDate()) { + ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(), request.getModuleIds(), request.getName(), request.getProjectId(), request.getProtocol(), request.getUnSelectIds(), request.getStatus()); } this.deleteBatch(ids); } public void editApiBathByParam(ApiTestBatchRequest request) { List ids = request.getIds(); - if(request.isSelectAllDate()){ - ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(),request.getModuleIds(),request.getName(),request.getProjectId(),request.getProtocol(),request.getUnSelectIds(),request.getStatus()); + if (request.isSelectAllDate()) { + ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(), request.getModuleIds(), request.getName(), request.getProjectId(), request.getProtocol(), request.getUnSelectIds(), request.getStatus()); } request.cleanSelectParam(); ApiTestCaseExample apiDefinitionExample = new ApiTestCaseExample(); @@ -371,7 +378,7 @@ public class ApiTestCaseService { apiTestCaseMapper.updateByExampleSelective(apiDefinitionWithBLOBs, apiDefinitionExample); } - private List getAllApiCaseIdsByFontedSelect(Map> filters,ListmoduleIds, String name, String projectId, String protocol,List unSelectIds,String status) { + private List getAllApiCaseIdsByFontedSelect(Map> filters, List moduleIds, String name, String projectId, String protocol, List unSelectIds, String status) { ApiTestCaseRequest selectRequest = new ApiTestCaseRequest(); selectRequest.setFilters(filters); selectRequest.setModuleIds(moduleIds); @@ -383,6 +390,27 @@ public class ApiTestCaseService { List list = extApiTestCaseMapper.list(selectRequest); List allIds = list.stream().map(ApiTestCaseResult::getId).collect(Collectors.toList()); List ids = allIds.stream().filter(id -> !unSelectIds.contains(id)).collect(Collectors.toList()); - return ids; + return ids; } + + public String run(RunCaseRequest request) { + ApiTestCaseWithBLOBs testCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(request.getCaseId()); + // 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取 + if (testCaseWithBLOBs != null && StringUtils.isNotEmpty(testCaseWithBLOBs.getRequest())) { + 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(); + String runMode = ApiRunMode.DELIMIT.name(); + // 调用执行方法 + jMeterService.runDefinition(request.getReportId(), hashTree, request.getReportId(), runMode); + + } catch (Exception ex) { + LogUtil.error(ex.getMessage()); + } + } + return request.getReportId(); + } + } From cd14c9667d56eac4cb3f6675a32a8d64086500f4 Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Thu, 31 Dec 2020 15:27:55 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= =?UTF-8?q?-=E6=A1=88=E4=BE=8B=E5=88=97=E8=A1=A8-=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E6=98=BE=E7=A4=BA=E6=80=BB=E6=9D=A1?= =?UTF-8?q?=E6=95=B0=E9=94=99=E6=88=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复接口定义-案例列表-批量修改时显示总条数错误的问题 --- .../components/api/definition/components/basis/BatchEdit.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/business/components/api/definition/components/basis/BatchEdit.vue b/frontend/src/business/components/api/definition/components/basis/BatchEdit.vue index b00fadf98d..75f7d70de9 100644 --- a/frontend/src/business/components/api/definition/components/basis/BatchEdit.vue +++ b/frontend/src/business/components/api/definition/components/basis/BatchEdit.vue @@ -78,7 +78,7 @@ }, open() { this.dialogVisible = true; - this.size = this.$parent.selectRows.size; + this.size = this.$parent.selectDataCounts; listenGoBack(this.handleClose); }, handleClose() { From 221f0e204812d9d411f9ab9c9abdbb741fc8dcaf Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 31 Dec 2020 15:41:07 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8Dsql=E7=B1=BB=E5=9E=8B=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/api/automation/scenario/ApiComponent.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/business/components/api/automation/scenario/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/ApiComponent.vue index afd426524b..1763c431fa 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiComponent.vue @@ -56,10 +56,10 @@

{{$t('api_test.definition.request.req_param')}}

- - - - + + + +

{{$t('api_test.definition.request.res_param')}}

From ec8265b4be68fb49c5ca68065fa474ea8aa096e4 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 31 Dec 2020 16:35:07 +0800 Subject: [PATCH 5/5] chore: Sync --- backend/src/main/java/io/metersphere/xpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index f27d1609d7..068127ce59 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit f27d1609d77f7d6c988d37d709466e844d350e17 +Subproject commit 068127ce59ea8b016434ed52a9de4a7a4b13bdb4