fix(接口测试): 导入的用例和mock现在可以同步发送通知
--bug=1046249 --user=宋天阳 【接口测试】接口导入-MeterSphere格式-接口带用例-消息通知-未发送创建/更新用例的消息(站内信/邮件/企业微信/钉钉/飞书) https://www.tapd.cn/55049933/s/1578213
This commit is contained in:
parent
cef35278b9
commit
3119807957
|
@ -41,19 +41,21 @@ public class JmeterParserApiDefinition implements ApiDefinitionImportParser<ApiI
|
|||
AbstractMsTestElement msTestElement = parser.parse(hashTree);
|
||||
List<AbstractMsProtocolTestElement> msElement = parser.getAbstractMsProtocolTestElement(msTestElement);
|
||||
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) {
|
||||
LogUtils.error(e);
|
||||
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);
|
||||
ApiImportFileParseResult returnDTO = new ApiImportFileParseResult();
|
||||
groupWithUniqueIdentification.forEach((definitionImportDetail, caseData) -> {
|
||||
String apiID = IDGenerator.nextStr();
|
||||
definitionImportDetail.setId(apiID);
|
||||
definitionImportDetail.setModulePath(moduleName);
|
||||
returnDTO.getData().add(definitionImportDetail);
|
||||
caseData.forEach(item -> {
|
||||
item.setId(IDGenerator.nextStr());
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.metersphere.api.dto.request.MsScenario;
|
|||
import io.metersphere.plugin.api.spi.AbstractMsProtocolTestElement;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jmeter.testelement.TestPlan;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -27,6 +28,15 @@ public class MsTestElementParser {
|
|||
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) {
|
||||
List<AbstractMsProtocolTestElement> result = new ArrayList<>();
|
||||
if (msTestElement instanceof AbstractMsProtocolTestElement abstractMsProtocolTestElement) {
|
||||
|
|
|
@ -351,9 +351,9 @@ public class ApiDefinitionImportService {
|
|||
|
||||
private void insertApiTestCase(ImportRequest request, List<ApiTestCaseDTO> insertApiCaseData, ApiTestCaseMapper apiTestCaseMapper, ApiTestCaseBlobMapper apiTestCaseBlobMapper, SqlSession sqlSession) {
|
||||
insertApiCaseData.forEach(t -> {
|
||||
t.setId(IDGenerator.nextStr());
|
||||
ApiTestCase apiTestCase = new ApiTestCase();
|
||||
BeanUtils.copyBean(apiTestCase, t);
|
||||
apiTestCase.setId(IDGenerator.nextStr());
|
||||
apiTestCase.setProjectId(request.getProjectId());
|
||||
apiTestCase.setPos(getImportNextOrder(request.getProjectId()));
|
||||
apiTestCase.setNum(NumGenerator.nextNum(request.getProjectId(), ApplicationNumScope.API_DEFINITION));
|
||||
|
@ -383,9 +383,9 @@ public class ApiDefinitionImportService {
|
|||
api = batchApiMapper.selectByPrimaryKey(t.getApiDefinitionId());
|
||||
apiDefinitionIdMap.put(t.getApiDefinitionId(), api);
|
||||
}
|
||||
t.setId(IDGenerator.nextStr());
|
||||
ApiDefinitionMock apiMock = new ApiDefinitionMock();
|
||||
BeanUtils.copyBean(apiMock, t);
|
||||
apiMock.setId(IDGenerator.nextStr());
|
||||
apiMock.setProjectId(request.getProjectId());
|
||||
apiMock.setExpectNum(String.valueOf(NumGenerator.nextNum(request.getProjectId() + "_" + api.getNum(), ApplicationNumScope.API_MOCK)));
|
||||
apiMock.setVersionId(request.getVersionId());
|
||||
|
|
|
@ -2036,7 +2036,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
|||
paramMap.add("file", file);
|
||||
this.requestMultipartWithOkAndReturn(IMPORT, paramMap);
|
||||
List<ApiDefinitionModule> apiDefinitionModuleList = apiDefinitionModuleMapper.selectByExample(moduleExample);
|
||||
Assertions.assertEquals(0, apiDefinitionModuleList.size());
|
||||
Assertions.assertEquals(1, apiDefinitionModuleList.size());
|
||||
List<ApiDefinitionBlob> apiDefinitionBlobs = apiDefinitionImportTestService.selectBlobByProjectId(importProject.getId());
|
||||
Assertions.assertEquals(2, apiDefinitionBlobs.size());
|
||||
|
||||
|
|
Loading…
Reference in New Issue