diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index 8238f27752..55fdb3b511 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -32,6 +32,7 @@ import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.constants.LoopConstants; import io.metersphere.commons.constants.MsTestElementConstants; +import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.LogUtil; @@ -48,6 +49,7 @@ import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; import java.io.ByteArrayOutputStream; +import java.io.File; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -211,6 +213,9 @@ public abstract class MsTestElement { csvDataSet.setName(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName()); csvDataSet.setProperty("fileEncoding", StringUtils.isEmpty(item.getEncoding()) ? "UTF-8" : item.getEncoding()); if (CollectionUtils.isNotEmpty(item.getFiles())) { + if (new File(BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName()).exists()) { + MSException.throwException(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName() + ":[ CSV文件不存在 ]"); + } csvDataSet.setProperty("filename", BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName()); } csvDataSet.setIgnoreFirstLine(false); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/unknown/MsJmeterElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/unknown/MsJmeterElement.java index 38237e19f9..710ab4b672 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/unknown/MsJmeterElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/unknown/MsJmeterElement.java @@ -3,11 +3,14 @@ package io.metersphere.api.dto.definition.request.unknown; import com.alibaba.fastjson.annotation.JSONType; import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.LogUtil; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.config.CSVDataSet; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.testelement.TestPlan; @@ -15,6 +18,7 @@ import org.apache.jmeter.threads.ThreadGroup; import org.apache.jorphan.collections.HashTree; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.InputStream; import java.util.List; @@ -53,6 +57,13 @@ public class MsJmeterElement extends MsTestElement { if (!config.isOperating() && scriptWrapper instanceof ThreadGroup && !((ThreadGroup) scriptWrapper).isEnabled()) { LogUtil.info(((ThreadGroup) scriptWrapper).getName() + "是被禁用线程组不加入执行"); } else { + // CSV数据检查文件路径是否还存在 + if (scriptWrapper instanceof CSVDataSet) { + String path = ((CSVDataSet) scriptWrapper).getPropertyAsString("filename"); + if (!new File(path).exists()) { + MSException.throwException(StringUtils.isEmpty(((CSVDataSet) scriptWrapper).getName()) ? "CSVDataSet" : ((CSVDataSet) scriptWrapper).getName() + ":[ CSV文件不存在 ]"); + } + } if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { el.toHashTree(elementTree, el.getHashTree(), config); @@ -62,6 +73,7 @@ public class MsJmeterElement extends MsTestElement { } } catch (Exception ex) { ex.printStackTrace(); + MSException.throwException(ex.getMessage()); } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 8096f1e974..4b4abebdb6 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -535,8 +535,12 @@ public class ApiAutomationService { } // 生成报告和HashTree - HashTree hashTree = generateHashTree(item, reportId, planEnvMap); - + HashTree hashTree = null; + try { + hashTree = generateHashTree(item, reportId, planEnvMap); + } catch (Exception ex) { + MSException.throwException(ex.getMessage()); + } //存储报告 batchMapper.insert(report); @@ -602,7 +606,12 @@ public class ApiAutomationService { } ParameterConfig config = new ParameterConfig(); config.setConfig(envConfig); - HashTree hashTree = request.getTestElement().generateHashTree(config); + HashTree hashTree = null; + try { + hashTree = request.getTestElement().generateHashTree(config); + } catch (Exception e) { + MSException.throwException(e.getMessage()); + } // 调用执行方法 APIScenarioReportResult reportResult = createScenarioReport(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(), SessionUtils.getUserId()); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java index c95006f3b8..a6c67b6c5b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java @@ -3,6 +3,7 @@ package io.metersphere.base.mapper.ext; import io.metersphere.base.domain.FileMetadata; import io.metersphere.base.domain.LoadTest; import io.metersphere.dto.LoadTestDTO; +import io.metersphere.performance.request.QueryProjectFileRequest; import io.metersphere.performance.request.QueryTestPlanRequest; import org.apache.ibatis.annotations.Param; @@ -18,6 +19,7 @@ public interface ExtLoadTestMapper { LoadTest getNextNum(@Param("projectId") String projectId); - List getProjectFiles(@Param("projectId") String projectId, @Param("loadTypes") List loadType); + List getProjectFiles(@Param("projectId") String projectId, @Param("loadTypes") List loadType, + @Param("request") QueryProjectFileRequest request); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml index 6e77469707..8580002eff 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml @@ -145,5 +145,8 @@ #{id} AND project_id = #{projectId,jdbcType=VARCHAR} + + AND file_metadata.name LIKE CONCAT('%', #{request.name}, '%') + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java index d196782bf1..d144342a68 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java @@ -1,6 +1,7 @@ package io.metersphere.base.mapper.ext; import io.metersphere.track.dto.TestCaseReportStatusResultDTO; +import io.metersphere.track.dto.TestCaseTestDTO; import io.metersphere.track.dto.TestPlanCaseDTO; import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest; import org.apache.ibatis.annotations.Param; @@ -47,4 +48,6 @@ public interface ExtTestPlanTestCaseMapper { List getExecResultByPlanId(String planId); List listForMinder(@Param("planId") String planId); + + List listTestCaseTest(@Param("caseId") String caseId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml index 80c68f3fbc..495d5ed733 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml @@ -421,6 +421,9 @@ pc.plan_id = #{planId} + update test_plan_test_case diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java index da19e2da3c..21f845385d 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java @@ -120,12 +120,13 @@ public class PerformanceTestController { return performanceTestService.exportJmx(fileIds); } - @GetMapping("/project/{loadType}/{projectId}/{goPage}/{pageSize}") + @PostMapping("/project/{loadType}/{projectId}/{goPage}/{pageSize}") public Pager> getProjectFiles(@PathVariable String projectId, @PathVariable String loadType, - @PathVariable int goPage, @PathVariable int pageSize) { + @PathVariable int goPage, @PathVariable int pageSize, + @RequestBody QueryProjectFileRequest request) { checkPermissionService.checkProjectOwner(projectId); Page page = PageHelper.startPage(goPage, pageSize, true); - return PageUtils.setPageInfo(page, performanceTestService.getProjectFiles(projectId, loadType)); + return PageUtils.setPageInfo(page, performanceTestService.getProjectFiles(projectId, loadType, request)); } @PostMapping("/delete") diff --git a/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java b/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java index 5c5e9d88fb..f67454fa1a 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java +++ b/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java @@ -19,8 +19,8 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import java.util.List; -import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; public abstract class AbstractEngine implements Engine { protected String JMETER_IMAGE; @@ -106,17 +106,20 @@ public abstract class AbstractEngine implements Engine { String loadConfiguration = t.getLoadConfiguration(); JSONArray jsonArray = JSON.parseArray(loadConfiguration); for (int i = 0; i < jsonArray.size(); i++) { - if (jsonArray.get(i) instanceof Map) { - JSONObject o = jsonArray.getJSONObject(i); - if (StringUtils.equals(o.getString("key"), "TargetLevel")) { - s = o.getInteger("value"); - break; - } - } if (jsonArray.get(i) instanceof List) { JSONArray o = jsonArray.getJSONArray(i); - for (int j = 0; j < o.size(); j++) { - JSONObject b = o.getJSONObject(j); + List enabledConfig = o.stream() + .filter(b -> { + JSONObject c = JSON.parseObject(b.toString()); + if (StringUtils.equals(c.getString("deleted"), "true")) { + return false; + } + return !StringUtils.equals(c.getString("enabled"), "false"); + }) + .map(b -> JSON.parseObject(b.toString())) + .collect(Collectors.toList()); + + for (JSONObject b : enabledConfig) { if (StringUtils.equals(b.getString("key"), "TargetLevel")) { s += b.getInteger("value"); break; diff --git a/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java b/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java index 90c71dcb8a..a8808c1c8c 100644 --- a/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java +++ b/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java @@ -4,5 +4,5 @@ import lombok.Data; @Data public class QueryProjectFileRequest { - private String filename; + private String name; } 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 6a73af82b5..8e33726a6f 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -561,19 +561,23 @@ public class PerformanceTestService { } } - public List getProjectFiles(String projectId, String loadType) { + public List getProjectFiles(String projectId, String loadType, QueryProjectFileRequest request) { List loadTypes = new ArrayList<>(); loadTypes.add(StringUtils.upperCase(loadType)); if (StringUtils.equalsIgnoreCase(loadType, "resource")) { - loadTypes.add(FileType.CSV.name()); - loadTypes.add(FileType.JAR.name()); + List fileTypes = Arrays.stream(FileType.values()) + .filter(fileType -> !fileType.equals(FileType.JMX)) + .map(FileType::name) + .collect(Collectors.toList()); + loadTypes.addAll(fileTypes); } if (StringUtils.equalsIgnoreCase(loadType, "all")) { - loadTypes.add(FileType.CSV.name()); - loadTypes.add(FileType.JAR.name()); - loadTypes.add(FileType.JMX.name()); + List fileTypes = Arrays.stream(FileType.values()) + .map(FileType::name) + .collect(Collectors.toList()); + loadTypes.addAll(fileTypes); } - return extLoadTestMapper.getProjectFiles(projectId, loadTypes); + return extLoadTestMapper.getProjectFiles(projectId, loadTypes, request); } public List exportJmx(List fileIds) { diff --git a/backend/src/main/java/io/metersphere/service/FileService.java b/backend/src/main/java/io/metersphere/service/FileService.java index e1d7b3ffd1..cc2aa106c2 100644 --- a/backend/src/main/java/io/metersphere/service/FileService.java +++ b/backend/src/main/java/io/metersphere/service/FileService.java @@ -202,8 +202,8 @@ public class FileService { FileMetadataExample example = new FileMetadataExample(); FileMetadataExample.Criteria criteria = example.createCriteria(); criteria.andProjectIdEqualTo(projectId); - if (!StringUtils.isEmpty(request.getFilename())) { - criteria.andNameEqualTo(request.getFilename()); + if (!StringUtils.isEmpty(request.getName())) { + criteria.andNameEqualTo(request.getName()); } return fileMetadataMapper.selectByExample(example); } diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index 77a218d37e..d0b601c31c 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -173,7 +173,7 @@ public class ProjectService { if (files != null) { for (MultipartFile file : files) { QueryProjectFileRequest request = new QueryProjectFileRequest(); - request.setFilename(file.getOriginalFilename()); + request.setName(file.getOriginalFilename()); if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) { fileService.saveFile(file, projectId); } else { diff --git a/backend/src/main/java/io/metersphere/track/dto/TestCaseTestDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestCaseTestDTO.java new file mode 100644 index 0000000000..042bc04368 --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/dto/TestCaseTestDTO.java @@ -0,0 +1,11 @@ +package io.metersphere.track.dto; + +import io.metersphere.base.domain.TestCaseTest; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class TestCaseTestDTO extends TestCaseTest { + private String testName; +} diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanCaseDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanCaseDTO.java index d677de4b0b..3540c43f19 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanCaseDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanCaseDTO.java @@ -3,6 +3,8 @@ package io.metersphere.track.dto; import io.metersphere.base.domain.TestCaseWithBLOBs; import lombok.Getter; import lombok.Setter; +import java.util.List; + @Getter @Setter @@ -18,4 +20,6 @@ public class TestPlanCaseDTO extends TestCaseWithBLOBs { private String reportId; private String model; private String projectName; + + private List list; } 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 3b103d1aaf..221fdae702 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanTestCaseService.java @@ -1,11 +1,8 @@ package io.metersphere.track.service; import com.github.pagehelper.PageHelper; -import io.metersphere.base.domain.TestPlan; -import io.metersphere.base.domain.TestPlanTestCaseExample; -import io.metersphere.base.domain.TestPlanTestCaseWithBLOBs; -import io.metersphere.base.domain.User; -import io.metersphere.base.mapper.TestPlanTestCaseMapper; +import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; import io.metersphere.commons.constants.TestPlanTestCaseStatus; import io.metersphere.commons.user.SessionUser; @@ -14,6 +11,7 @@ import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.service.UserService; +import io.metersphere.track.dto.TestCaseTestDTO; import io.metersphere.track.dto.TestPlanCaseDTO; import io.metersphere.track.request.testcase.TestPlanCaseBatchRequest; import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest; @@ -42,6 +40,14 @@ public class TestPlanTestCaseService { @Resource ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; + @Resource + private TestCaseTestMapper testCaseTestMapper; + @Resource + private LoadTestMapper loadTestMapper; + @Resource + private ApiTestCaseMapper apiTestCaseMapper; + @Resource + private ApiScenarioMapper apiScenarioMapper; public List list(QueryTestPlanCaseRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); @@ -134,7 +140,40 @@ public class TestPlanTestCaseService { } public TestPlanCaseDTO get(String testplanTestCaseId) { - return extTestPlanTestCaseMapper.get(testplanTestCaseId); + TestPlanCaseDTO testPlanCaseDTO = extTestPlanTestCaseMapper.get(testplanTestCaseId); + List testCaseTestDTOS = extTestPlanTestCaseMapper.listTestCaseTest(testPlanCaseDTO.getCaseId()); + testCaseTestDTOS.forEach(dto -> { + setTestName(dto); + }); + testPlanCaseDTO.setList(testCaseTestDTOS); + return testPlanCaseDTO; + } + + private void setTestName(TestCaseTestDTO dto) { + String type = dto.getTestType(); + String id = dto.getTestId(); + switch (type) { + case "performance": + LoadTest loadTest = loadTestMapper.selectByPrimaryKey(id); + if (loadTest != null) { + dto.setTestName(loadTest.getName()); + } + break; + case "testcase": + ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(id); + if (apiTestCaseWithBLOBs != null) { + dto.setTestName(apiTestCaseWithBLOBs.getName()); + } + break; + case "automation": + ApiScenarioWithBLOBs apiScenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(id); + if (apiScenarioWithBLOBs != null) { + dto.setTestName(apiScenarioWithBLOBs.getName()); + } + break; + default: + break; + } } public void deleteTestCaseBath(TestPlanCaseBatchRequest request) { diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 2fb883803f..e20541d8c8 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 2fb883803fa9909162ce9f6fab8a15b63af66923 +Subproject commit e20541d8c864216ebdaade01226b795efeb10c48 diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index b035cc76b2..141b314e7f 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -69,7 +69,7 @@ - + - + diff --git a/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue b/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue index 5b00d2fc71..12700397ca 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue @@ -219,8 +219,12 @@ return this.selection.includes(row.id) }, open: function (variables, headers, disabled) { - this.variables = variables; - this.headers = headers; + if(variables){ + this.variables = variables; + } + if(headers){ + this.headers = headers; + } this.visible = true; this.editData = {type: "CONSTANT"}; this.addParameters(this.editData); diff --git a/frontend/src/business/components/api/definition/components/list/ApiList.vue b/frontend/src/business/components/api/definition/components/list/ApiList.vue index 823a797568..6069e06e71 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiList.vue @@ -45,7 +45,7 @@ {{ scope.row.num }} {{ scope.row.num }} - + @@ -211,548 +211,548 @@