fix(接口测试): 修复接口测试时引用文件库文件的版本不会随着更新的问题
--bug=1017029 --user=宋天阳 【项目设置】文件管理-关联用例-选择接口用例-PULL GitHub文件-执行用例-文件内容未更新 https://www.tapd.cn/55049933/s/1247712
This commit is contained in:
parent
6b1bcb1614
commit
ac35936db9
|
@ -12,6 +12,7 @@ import io.metersphere.api.dto.definition.request.controller.MsLoopController;
|
|||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||
import io.metersphere.api.dto.scenario.request.BodyFile;
|
||||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||
|
@ -892,4 +893,25 @@ public class ElementUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void replaceFileMetadataId(MsTestElement testElement, String newFileMetadataId, String oldFileMetadataId) {
|
||||
if (testElement != null && testElement instanceof MsHTTPSamplerProxy) {
|
||||
if (((MsHTTPSamplerProxy) testElement).getBody() != null && CollectionUtils.isNotEmpty(((MsHTTPSamplerProxy) testElement).getBody().getKvs())) {
|
||||
for (KeyValue keyValue : ((MsHTTPSamplerProxy) testElement).getBody().getKvs()) {
|
||||
if (CollectionUtils.isNotEmpty(keyValue.getFiles())) {
|
||||
for (BodyFile bodyFile : keyValue.getFiles()) {
|
||||
if (StringUtils.equals(bodyFile.getFileId(), oldFileMetadataId)) {
|
||||
bodyFile.setFileId(newFileMetadataId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(testElement.getHashTree())) {
|
||||
for (MsTestElement childElement : testElement.getHashTree()) {
|
||||
replaceFileMetadataId(childElement, newFileMetadataId, oldFileMetadataId);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2435,4 +2435,14 @@ public class ApiAutomationService {
|
|||
List<ApiScenario> apiScenarioList = extApiScenarioMapper.selectBaseInfoByProjectIdAndStatus(projectId, status);
|
||||
return apiScenarioList.stream().collect(Collectors.groupingBy(ApiScenario::getApiScenarioModuleId));
|
||||
}
|
||||
|
||||
public ApiScenarioWithBLOBs getById(String id) {
|
||||
return apiScenarioMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void update(ApiScenarioWithBLOBs apiScenarioWithBLOBs) {
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
apiScenarioMapper.updateByPrimaryKeySelective(apiScenarioWithBLOBs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -412,6 +412,12 @@ public class ApiDefinitionService {
|
|||
return createTest(request);
|
||||
}
|
||||
|
||||
public void update(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs) {
|
||||
if (apiDefinitionWithBLOBs != null) {
|
||||
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinitionWithBLOBs);
|
||||
}
|
||||
}
|
||||
|
||||
public ApiDefinitionResult update(SaveApiDefinitionRequest request, List<MultipartFile> bodyFiles) {
|
||||
if (request.getRequest() != null && StringUtils.isNotEmpty(request.getRequest().getId())) {
|
||||
deleteFileByTestId(request.getRequest().getId());
|
||||
|
|
|
@ -460,7 +460,7 @@ public class ApiTestCaseService {
|
|||
test.setTags(request.getTags());
|
||||
}
|
||||
ApiTestCaseSyncService apiTestCaseSyncService = CommonBeanFactory.getBean(ApiTestCaseSyncService.class);
|
||||
if(apiTestCaseSyncService != null){
|
||||
if (apiTestCaseSyncService != null) {
|
||||
apiTestCaseSyncService.setCaseUpdateValue(test);
|
||||
}
|
||||
|
||||
|
@ -1322,4 +1322,14 @@ public class ApiTestCaseService {
|
|||
List<ApiScenarioReferenceId> apiScenarioReferenceIds = apiScenarioReferenceIdMapper.selectByExample(apiScenarioReferenceIdExample);
|
||||
return apiScenarioReferenceIds.size();
|
||||
}
|
||||
|
||||
public ApiTestCaseWithBLOBs getById(String id) {
|
||||
return apiTestCaseMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void update(ApiTestCaseWithBLOBs apiTestCaseWithBLOBs) {
|
||||
if (apiTestCaseWithBLOBs != null) {
|
||||
apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCaseWithBLOBs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.alibaba.nacos.common.utils.ByteUtils;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.api.service.ApiAutomationService;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.api.service.ApiTestCaseService;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.ExtFileMetadataMapper;
|
||||
|
@ -701,7 +704,7 @@ public class FileMetadataService {
|
|||
for (LoadTestFile loadTestFile : loadTestFileList) {
|
||||
LoadTest loadTest = loadTestMapper.selectByPrimaryKey(loadTestFile.getTestId());
|
||||
if (loadTest != null) {
|
||||
FileRelevanceCaseDTO dto = new FileRelevanceCaseDTO(loadTestFile.getFileId(), loadTest.getId(), loadTest.getName(), "LOAD_CASE"
|
||||
FileRelevanceCaseDTO dto = new FileRelevanceCaseDTO(loadTestFile.getFileId(), loadTest.getNum() + "", loadTest.getName(), "LOAD_CASE"
|
||||
, fileCommitIdMap.get(loadTestFile.getFileId()));
|
||||
list.add(dto);
|
||||
}
|
||||
|
@ -729,6 +732,9 @@ public class FileMetadataService {
|
|||
if (CollectionUtils.isNotEmpty(request.getIds())) {
|
||||
FileAssociationExample associationExample = new FileAssociationExample();
|
||||
associationExample.createCriteria().andIdIn(request.getIds());
|
||||
List<FileAssociation> fileAssociationList = fileAssociationMapper.selectByExample(associationExample);
|
||||
//同步更新具体的场景/用例/接口的hashTree
|
||||
this.updateResource(latestId, fileAssociationList);
|
||||
FileAssociation fileAssociation = new FileAssociation();
|
||||
fileAssociation.setFileMetadataId(latestId);
|
||||
updateCount = fileAssociationMapper.updateByExampleSelective(fileAssociation, associationExample);
|
||||
|
@ -745,4 +751,39 @@ public class FileMetadataService {
|
|||
returnString = String.valueOf(updateCount);
|
||||
return returnString;
|
||||
}
|
||||
|
||||
private void updateResource(String newFileMetadataId, List<FileAssociation> fileAssociationList) {
|
||||
if (CollectionUtils.isNotEmpty(fileAssociationList)) {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||
ApiAutomationService apiAutomationService = CommonBeanFactory.getBean(ApiAutomationService.class);
|
||||
fileAssociationList.forEach(item -> {
|
||||
if (StringUtils.equals(item.getType(), FileAssociationType.API.name()) && apiDefinitionService != null) {
|
||||
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionService.getBLOBs(item.getSourceId());
|
||||
if (apiDefinitionWithBLOBs != null && StringUtils.isNotBlank(apiDefinitionWithBLOBs.getRequest())) {
|
||||
String requestStr = apiDefinitionWithBLOBs.getRequest();
|
||||
requestStr = StringUtils.replace(requestStr, item.getFileMetadataId(), newFileMetadataId);
|
||||
apiDefinitionWithBLOBs.setRequest(requestStr);
|
||||
apiDefinitionService.update(apiDefinitionWithBLOBs);
|
||||
}
|
||||
} else if (StringUtils.equals(item.getType(), FileAssociationType.SCENARIO.name()) && apiAutomationService != null) {
|
||||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = apiAutomationService.getById(item.getSourceId());
|
||||
if (apiScenarioWithBLOBs != null && StringUtils.isNotBlank(apiScenarioWithBLOBs.getScenarioDefinition())) {
|
||||
String requestStr = apiScenarioWithBLOBs.getScenarioDefinition();
|
||||
requestStr = StringUtils.replace(requestStr, item.getFileMetadataId(), newFileMetadataId);
|
||||
apiScenarioWithBLOBs.setScenarioDefinition(requestStr);
|
||||
apiAutomationService.update(apiScenarioWithBLOBs);
|
||||
}
|
||||
} else if (StringUtils.equals(item.getType(), FileAssociationType.CASE.name()) && apiTestCaseService != null) {
|
||||
ApiTestCaseWithBLOBs testCaseWithBLOBs = apiTestCaseService.getById(item.getSourceId());
|
||||
if (testCaseWithBLOBs != null && StringUtils.isNotBlank(testCaseWithBLOBs.getRequest())) {
|
||||
String requestStr = testCaseWithBLOBs.getRequest();
|
||||
requestStr = StringUtils.replace(requestStr, item.getFileMetadataId(), newFileMetadataId);
|
||||
testCaseWithBLOBs.setRequest(requestStr);
|
||||
apiTestCaseService.update(testCaseWithBLOBs);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
prop="caseType">
|
||||
<template v-slot="scope">
|
||||
<span v-if="scope.row.caseType === 'API'">
|
||||
{{ $t('api_test.home_page.api_details_card.title') }}
|
||||
{{ $t('workstation.table_name.api_definition') }}
|
||||
</span>
|
||||
<span v-else-if="scope.row.caseType === 'CASE'">
|
||||
{{ $t('commons.api_case') }}
|
||||
|
|
Loading…
Reference in New Issue