fix(接口测试): 导入的用例和mock现在可以同步发送通知

--bug=1046249 --user=宋天阳 【接口测试】接口导入-MeterSphere格式-接口带用例-消息通知-未发送创建/更新用例的消息(站内信/邮件/企业微信/钉钉/飞书) https://www.tapd.cn/55049933/s/1578213
This commit is contained in:
Jianguo-Genius 2024-09-13 18:41:36 +08:00 committed by 建国
parent cef35278b9
commit 3119807957
4 changed files with 17 additions and 5 deletions

View File

@ -41,19 +41,21 @@ public class JmeterParserApiDefinition implements ApiDefinitionImportParser<ApiI
AbstractMsTestElement msTestElement = parser.parse(hashTree); AbstractMsTestElement msTestElement = parser.parse(hashTree);
List<AbstractMsProtocolTestElement> msElement = parser.getAbstractMsProtocolTestElement(msTestElement); List<AbstractMsProtocolTestElement> msElement = parser.getAbstractMsProtocolTestElement(msTestElement);
LinkedHashMap<ApiDefinitionDetail, List<ApiTestCaseDTO>> allImportDetails = this.parseImportFile(request.getProjectId(), msElement); LinkedHashMap<ApiDefinitionDetail, List<ApiTestCaseDTO>> allImportDetails = this.parseImportFile(request.getProjectId(), msElement);
return this.genApiDefinitionImport(allImportDetails); String moduleName = StringUtils.trim(parser.parseTestPlanName(hashTree));
return this.genApiDefinitionImport(allImportDetails, moduleName);
} catch (Exception e) { } catch (Exception e) {
LogUtils.error(e); LogUtils.error(e);
throw new MSException("当前JMX版本不兼容"); throw new MSException("当前JMX版本不兼容");
} }
} }
private ApiImportFileParseResult genApiDefinitionImport(LinkedHashMap<ApiDefinitionDetail, List<ApiTestCaseDTO>> allImportDetails) { private ApiImportFileParseResult genApiDefinitionImport(LinkedHashMap<ApiDefinitionDetail, List<ApiTestCaseDTO>> allImportDetails, String moduleName) {
Map<ApiDefinitionDetail, List<ApiTestCaseDTO>> groupWithUniqueIdentification = this.mergeApiCaseWithUniqueIdentification(allImportDetails); Map<ApiDefinitionDetail, List<ApiTestCaseDTO>> groupWithUniqueIdentification = this.mergeApiCaseWithUniqueIdentification(allImportDetails);
ApiImportFileParseResult returnDTO = new ApiImportFileParseResult(); ApiImportFileParseResult returnDTO = new ApiImportFileParseResult();
groupWithUniqueIdentification.forEach((definitionImportDetail, caseData) -> { groupWithUniqueIdentification.forEach((definitionImportDetail, caseData) -> {
String apiID = IDGenerator.nextStr(); String apiID = IDGenerator.nextStr();
definitionImportDetail.setId(apiID); definitionImportDetail.setId(apiID);
definitionImportDetail.setModulePath(moduleName);
returnDTO.getData().add(definitionImportDetail); returnDTO.getData().add(definitionImportDetail);
caseData.forEach(item -> { caseData.forEach(item -> {
item.setId(IDGenerator.nextStr()); item.setId(IDGenerator.nextStr());

View File

@ -4,6 +4,7 @@ import io.metersphere.api.dto.request.MsScenario;
import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement; import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement;
import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.HashTree;
import java.util.ArrayList; import java.util.ArrayList;
@ -27,6 +28,15 @@ public class MsTestElementParser {
return msScenario; return msScenario;
} }
public String parseTestPlanName(HashTree hashTree) {
for (Object key : hashTree.keySet()) {
if (key instanceof TestPlan testPlan) {
return testPlan.getName();
}
}
return null;
}
public List<AbstractMsProtocolTestElement> getAbstractMsProtocolTestElement(AbstractMsTestElement msTestElement) { public List<AbstractMsProtocolTestElement> getAbstractMsProtocolTestElement(AbstractMsTestElement msTestElement) {
List<AbstractMsProtocolTestElement> result = new ArrayList<>(); List<AbstractMsProtocolTestElement> result = new ArrayList<>();
if (msTestElement instanceof AbstractMsProtocolTestElement abstractMsProtocolTestElement) { if (msTestElement instanceof AbstractMsProtocolTestElement abstractMsProtocolTestElement) {

View File

@ -351,9 +351,9 @@ public class ApiDefinitionImportService {
private void insertApiTestCase(ImportRequest request, List<ApiTestCaseDTO> insertApiCaseData, ApiTestCaseMapper apiTestCaseMapper, ApiTestCaseBlobMapper apiTestCaseBlobMapper, SqlSession sqlSession) { private void insertApiTestCase(ImportRequest request, List<ApiTestCaseDTO> insertApiCaseData, ApiTestCaseMapper apiTestCaseMapper, ApiTestCaseBlobMapper apiTestCaseBlobMapper, SqlSession sqlSession) {
insertApiCaseData.forEach(t -> { insertApiCaseData.forEach(t -> {
t.setId(IDGenerator.nextStr());
ApiTestCase apiTestCase = new ApiTestCase(); ApiTestCase apiTestCase = new ApiTestCase();
BeanUtils.copyBean(apiTestCase, t); BeanUtils.copyBean(apiTestCase, t);
apiTestCase.setId(IDGenerator.nextStr());
apiTestCase.setProjectId(request.getProjectId()); apiTestCase.setProjectId(request.getProjectId());
apiTestCase.setPos(getImportNextOrder(request.getProjectId())); apiTestCase.setPos(getImportNextOrder(request.getProjectId()));
apiTestCase.setNum(NumGenerator.nextNum(request.getProjectId(), ApplicationNumScope.API_DEFINITION)); apiTestCase.setNum(NumGenerator.nextNum(request.getProjectId(), ApplicationNumScope.API_DEFINITION));
@ -383,9 +383,9 @@ public class ApiDefinitionImportService {
api = batchApiMapper.selectByPrimaryKey(t.getApiDefinitionId()); api = batchApiMapper.selectByPrimaryKey(t.getApiDefinitionId());
apiDefinitionIdMap.put(t.getApiDefinitionId(), api); apiDefinitionIdMap.put(t.getApiDefinitionId(), api);
} }
t.setId(IDGenerator.nextStr());
ApiDefinitionMock apiMock = new ApiDefinitionMock(); ApiDefinitionMock apiMock = new ApiDefinitionMock();
BeanUtils.copyBean(apiMock, t); BeanUtils.copyBean(apiMock, t);
apiMock.setId(IDGenerator.nextStr());
apiMock.setProjectId(request.getProjectId()); apiMock.setProjectId(request.getProjectId());
apiMock.setExpectNum(String.valueOf(NumGenerator.nextNum(request.getProjectId() + "_" + api.getNum(), ApplicationNumScope.API_MOCK))); apiMock.setExpectNum(String.valueOf(NumGenerator.nextNum(request.getProjectId() + "_" + api.getNum(), ApplicationNumScope.API_MOCK)));
apiMock.setVersionId(request.getVersionId()); apiMock.setVersionId(request.getVersionId());

View File

@ -2036,7 +2036,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
paramMap.add("file", file); paramMap.add("file", file);
this.requestMultipartWithOkAndReturn(IMPORT, paramMap); this.requestMultipartWithOkAndReturn(IMPORT, paramMap);
List<ApiDefinitionModule> apiDefinitionModuleList = apiDefinitionModuleMapper.selectByExample(moduleExample); List<ApiDefinitionModule> apiDefinitionModuleList = apiDefinitionModuleMapper.selectByExample(moduleExample);
Assertions.assertEquals(0, apiDefinitionModuleList.size()); Assertions.assertEquals(1, apiDefinitionModuleList.size());
List<ApiDefinitionBlob> apiDefinitionBlobs = apiDefinitionImportTestService.selectBlobByProjectId(importProject.getId()); List<ApiDefinitionBlob> apiDefinitionBlobs = apiDefinitionImportTestService.selectBlobByProjectId(importProject.getId());
Assertions.assertEquals(2, apiDefinitionBlobs.size()); Assertions.assertEquals(2, apiDefinitionBlobs.size());