refactor(接口测试): 重构接口测试文件相关参数

This commit is contained in:
AgAngle 2024-02-21 20:44:58 +08:00 committed by Craftsman
parent ed47fba038
commit 193aa7032c
41 changed files with 907 additions and 180 deletions

View File

@ -14,6 +14,10 @@ public enum ApiScenarioStepType {
* 接口用例
*/
API_CASE,
/**
* 自定义请求
*/
CUSTOM_REQUEST,
/**
* 场景
*/

View File

@ -20,6 +20,21 @@ public class ApiFile {
* 文件名
*/
@NotBlank
@Size(max = 200)
@Size(max = 255)
private String fileName;
/**
* 是否是本地上传的文件
*/
private Boolean local = true;
/**
* 文件别名引用的文件需要展示别名
* 查询时获取最新的
*/
@Size(max = 255)
private String fileAlias;
/**
* 文件是否别删除
* 引用的文件被删除需要标识
*/
private Boolean delete = false;
}

View File

@ -29,11 +29,11 @@ public class ApiDebugAddRequest implements Serializable {
private String protocol;
@Schema(description = "http协议类型post/get/其它协议则是协议名(mqtt)")
@Size(max = 20, message = "{api_debug.method.length_range}")
@Size(min = 1, max = 20, message = "{api_debug.method.length_range}")
private String method;
@Schema(description = "http协议url/其它协议则为空")
@Size(max = 500, message = "{api_debug.protocol.length_range}")
@Size(min = 1, max = 500, message = "{api_debug.protocol.length_range}")
private String path;
@Schema(description = "项目fk", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -15,8 +15,17 @@ public class ApiDebugRunRequest {
@Schema(description = "报告ID")
@NotNull
private String reportId;
@Schema(description = "点击调试时尚未保存的文件ID列表")
private List<String> tempFileIds;
/**
* 新上传的文件ID
* 创建时先按ID创建目录再把文件放入目录
*/
@Schema(description = "新上传的文件ID")
private List<String> uploadFileIds;
/**
* 新关联的文件ID
*/
@Schema(description = "关联文件ID")
private List<String> linkFileIds;
@NotNull
@Schema(description = "请求内容")
private Object request;

View File

@ -23,19 +23,19 @@ public class ApiDebugUpdateRequest implements Serializable {
private String id;
@Schema(description = "接口名称", requiredMode = Schema.RequiredMode.REQUIRED)
@Size(max = 255, message = "{api_debug.name.length_range}")
@Size(min = 1, max = 255, message = "{api_debug.name.length_range}")
private String name;
@Schema(description = "http协议类型post/get/其它协议则是协议名(mqtt)")
@Size(max = 20, message = "{api_debug.method.length_range}")
@Size(min = 1, max = 20, message = "{api_debug.method.length_range}")
private String method;
@Schema(description = "http协议路径/其它协议则为空")
@Size(max = 500, message = "{api_debug.protocol.length_range}")
@Size(min = 1, max = 500, message = "{api_debug.protocol.length_range}")
private String path;
@Schema(description = "模块fk", requiredMode = Schema.RequiredMode.REQUIRED)
@Size(max = 50, message = "{api_debug.module_id.length_range}")
@Size(min = 1, max = 50, message = "{api_debug.module_id.length_range}")
private String moduleId;
@Schema(description = "请求内容")
@ -64,5 +64,5 @@ public class ApiDebugUpdateRequest implements Serializable {
* 删除关联的文件ID
*/
@Schema(description = "取消关联文件ID")
private List<String> unLinkRefIds;
private List<String> unLinkFileIds;
}

View File

@ -49,7 +49,7 @@ public class ApiFileResourceUpdateRequest implements Serializable {
/**
* 删除关联的文件ID
*/
private List<String> unLinkRefIds;
private List<String> unLinkFileIds;
/**
* 文件关联的sourceType
* @see io.metersphere.sdk.util.FileAssociationSourceUtil

View File

@ -1,6 +1,7 @@
package io.metersphere.api.dto.debug;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@ -38,7 +39,14 @@ public class ApiResourceRunRequest {
*/
private AbstractMsTestElement testElement;
/**
* 点击调试时尚未保存的文件列表
* 新上传的文件ID
* 创建时先按ID创建目录再把文件放入目录
*/
private List<String> tempFileIds;
@Schema(description = "新上传的文件ID")
private List<String> uploadFileIds;
/**
* 新关联的文件ID
*/
@Schema(description = "关联文件ID")
private List<String> linkFileIds;
}

View File

@ -34,5 +34,5 @@ public class ApiDefinitionUpdateRequest extends ApiDefinitionAddRequest {
* 删除关联的文件ID
*/
@Schema(description = "取消关联文件ID")
private List<String> unLinkRefIds;
private List<String> unLinkFileIds;
}

View File

@ -72,7 +72,7 @@ public class ApiTestCaseUpdateRequest implements Serializable {
* 删除关联的文件ID
*/
@Schema(description = "取消关联文件ID")
private List<String> unLinkRefIds;
private List<String> unLinkFileIds;
public List<String> getTags() {
if (tags == null) {

View File

@ -1,10 +1,16 @@
package io.metersphere.api.dto.definition;
import io.metersphere.api.dto.ApiFile;
import jakarta.validation.Valid;
import lombok.Data;
@Data
public class ResponseBinaryBody extends ApiFile {
public class ResponseBinaryBody {
private boolean sendAsBody;
private String description;
/**
* 文件对象
*/
@Valid
private ApiFile file;
}

View File

@ -34,6 +34,6 @@ public class ApiDefinitionMockUpdateRequest extends ApiDefinitionMockAddRequest
* 删除关联的文件ID
*/
@Schema(description = "取消关联文件ID")
private List<String> unLinkRefIds;
private List<String> unLinkFileIds;
}

View File

@ -1,11 +1,15 @@
package io.metersphere.api.dto.request.http.body;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* @Author: jianxing
* @CreateTime: 2023-11-06 18:25
*/
// 避免空的bean序列化报错
@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"})
@Data
public class NoneBody {
}

View File

@ -2,7 +2,6 @@ package io.metersphere.api.dto.request.http.body;
import io.metersphere.project.api.KeyValueEnableParam;
import io.metersphere.system.valid.EnumValue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
@ -17,10 +16,9 @@ public class WWWFormKV extends KeyValueEnableParam {
* 参数类型
* 取值参考 {@link BodyParamType} 中的 value 属性
*/
@NotBlank
@Size(max = 20)
@EnumValue(enumClass = BodyParamType.class)
private String paramType;
private String paramType = BodyParamType.STRING.getValue();
/**
* 是否必填
* 默认为 false

View File

@ -51,6 +51,15 @@ public class ApiScenarioDebugRequest {
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank
private String projectId;
@Schema(description = "点击调试时尚未保存的文件ID列表")
private List<String> tempFileIds;
/**
* 新上传的文件ID
* 创建时先按ID创建目录再把文件放入目录
*/
@Schema(description = "新上传的文件ID")
private List<String> uploadFileIds;
/**
* 新关联的文件ID
*/
@Schema(description = "关联文件ID")
private List<String> linkFileIds;
}

View File

@ -91,5 +91,5 @@ public class ApiScenarioUpdateRequest {
/**
* 删除关联的文件ID
*/
private List<String> unLinkRefIds;
private List<String> unLinkFileIds;
}

View File

@ -19,4 +19,13 @@ public interface ExtApiScenarioStepMapper {
List<CsvVariable> getCsvVariableByScenarioId(@Param("id") String id);
List<ApiScenarioCsvStep> getCsvStepByStepIds(@Param("ids") List<String> stepIds);
/**
* 查询有步骤详情的请求类型的步骤
* 包括 接口定义接口用例自定义请求
* 类型是 COPY 或者 DIRECT
* @param scenarioId
* @return
*/
List<String> getHasBlobRequestStepIds(@Param("scenarioId") String scenarioId);
}

View File

@ -26,4 +26,11 @@
#{id}
</foreach>
</select>
<select id="getHasBlobRequestStepIds" resultType="java.lang.String">
select id
from api_scenario_step
where scenario_id = #{scenarioId}
and step_type in ('API', 'API_CASE', 'CUSTOM_REQUEST')
and ref_type in ('COPY', 'DIRECT')
</select>
</mapper>

View File

@ -0,0 +1,162 @@
package io.metersphere.api.service;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.definition.ResponseBinaryBody;
import io.metersphere.api.dto.definition.ResponseBody;
import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.dto.request.http.body.BinaryBody;
import io.metersphere.api.dto.request.http.body.Body;
import io.metersphere.api.dto.request.http.body.FormDataBody;
import io.metersphere.api.dto.request.http.body.FormDataKV;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileMetadata;
import io.metersphere.project.service.FileAssociationService;
import io.metersphere.project.service.FileMetadataService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Author: jianxing
* @CreateTime: 2024-02-20 21:04
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ApiCommonService {
@Resource
private FileAssociationService fileAssociationService;
@Resource
private FileMetadataService fileMetadataService;
/**
* 根据 fileId 查找 MsHTTPElement 中的 ApiFile
* @param fileId
* @param msTestElement
* @return
*/
public List<ApiFile> getApiFilesByFileId(String fileId, AbstractMsTestElement msTestElement) {
if (msTestElement instanceof MsHTTPElement httpElement) {
List<ApiFile> apiFiles = getApiBodyFiles(httpElement.getBody());
return apiFiles.stream()
.filter(file -> StringUtils.equals(fileId, file.getFileId()))
.collect(Collectors.toList());
} else {
return List.of();
}
}
public List<ApiFile> getApiFiles(AbstractMsTestElement msTestElement) {
if (msTestElement instanceof MsHTTPElement httpElement) {
return getApiBodyFiles(httpElement.getBody());
} else {
return List.of();
}
}
/**
* 设置关联的文件的最新信息
* 包括文件别名和是否被删除
* @param resourceId
* @param msTestElement
*/
public void updateLinkFileInfo(String resourceId, AbstractMsTestElement msTestElement) {
updateLinkFileInfo(resourceId, getApiFiles(msTestElement));
}
/**
* 设置关联的文件的最新信息
* 包括文件别名和是否被删除
* @param resourceId
* @param responseBody
*/
public void updateLinkFileInfo(String resourceId, ResponseBody responseBody) {
updateLinkFileInfo(resourceId, getApiBodyFiles(responseBody));
}
private void updateLinkFileInfo(String resourceId, List<ApiFile> apiFiles) {
List<ApiFile> linkFiles = apiFiles.stream()
.filter(file -> !file.getLocal() && !file.getDelete())
.toList();
List<String> linkFileIds = linkFiles.stream()
.map(ApiFile::getFileId)
.distinct()
.toList();
if (CollectionUtils.isEmpty(linkFileIds)) {
return;
}
Map<String, String> fileNameMap = fileMetadataService.selectByList(linkFileIds)
.stream()
.collect(Collectors.toMap(FileMetadata::getId, FileMetadata::getName));
for (ApiFile linkFile : linkFiles) {
String fileName = fileNameMap.get(linkFile.getFileId());
if (StringUtils.isBlank(fileName)) {
// fileName 为空则文件被删除设置为已删除并且设置文件名
linkFile.setDelete(true);
List<FileAssociation> fileAssociations = fileAssociationService.getByFileIdAndSourceId(resourceId, linkFile.getFileId());
if (CollectionUtils.isNotEmpty(fileAssociations)) {
linkFile.setFileAlias(fileAssociations.get(0).getDeletedFileName());
}
} else {
linkFile.setFileAlias(fileName);
}
}
}
/**
*
* @param body
* @return
*/
public List<ApiFile> getApiBodyFiles(Body body) {
List<ApiFile> updateFiles = new ArrayList<>(0);
if (body != null) {
FormDataBody formDataBody = body.getFormDataBody();
if (formDataBody != null) {
List<FormDataKV> formValues = formDataBody.getFormValues();
if (CollectionUtils.isNotEmpty(formValues)) {
formValues.forEach(formDataKV -> {
List<ApiFile> files = formDataKV.getFiles();
if (CollectionUtils.isNotEmpty(files)) {
updateFiles.addAll(files);
}
});
}
}
BinaryBody binaryBody = body.getBinaryBody();
if (binaryBody != null && binaryBody.getFile() != null) {
updateFiles.add(binaryBody.getFile());
}
}
return updateFiles;
}
public List<ApiFile> getApiBodyFiles(ResponseBody responseBody) {
List<ApiFile> updateFiles = new ArrayList<>(0);
if (responseBody != null) {
ResponseBinaryBody binaryBody = responseBody.getBinaryBody();
if (binaryBody != null && binaryBody.getFile() != null) {
updateFiles.add(binaryBody.getFile());
}
}
return updateFiles;
}
public void replaceApiFileInfo(List<ApiFile> updateFiles, FileMetadata newFileMetadata) {
for (ApiFile updateFile : updateFiles) {
updateFile.setFileId(newFileMetadata.getId());
// todo 重新设置文件名
// updateFile.setFileName();
}
}
}

View File

@ -276,11 +276,23 @@ public class ApiExecuteService {
return refFileInfo;
}).collect(Collectors.toList());
// 处理没有保存的临时文件
List<String> tempFileIds = request.getTempFileIds();
if (CollectionUtils.isNotEmpty(tempFileIds)) {
// 查询这些文件有哪些是关联文件管理的文件
List<ApiExecuteFileInfo> refTempFiles = fileMetadataService.getByFileIds(tempFileIds)
// 没有保存的本地临时文件
List<String> uploadFileIds = request.getUploadFileIds();
if (CollectionUtils.isNotEmpty(uploadFileIds)) {
// 去掉文件管理的文件即通过本地上传的临时文件
List<ApiExecuteFileInfo> localTempFiles = uploadFileIds.stream()
.map(tempFileId -> {
String fileName = apiFileResourceService.getTempFileNameByFileId(tempFileId);
return getApiExecuteFileInfo(tempFileId, fileName, request.getProjectId());
})
.collect(Collectors.toList());
taskRequest.setLocalTempFiles(localTempFiles);
}
List<String> linkFileIds = request.getLinkFileIds();
// 没有保存的文件管理临时文件
if (CollectionUtils.isNotEmpty(linkFileIds)) {
List<ApiExecuteFileInfo> refTempFiles = fileMetadataService.getByFileIds(linkFileIds)
.stream()
.map(file -> {
String fileName = file.getName();
@ -298,17 +310,6 @@ public class ApiExecuteService {
}).toList();
// 添加临时的文件管理的文件
refFiles.addAll(refTempFiles);
Set<String> refTempFileIds = refTempFiles.stream().map(ApiExecuteFileInfo::getFileId).collect(Collectors.toSet());
// 去掉文件管理的文件即通过本地上传的临时文件
List<ApiExecuteFileInfo> localTempFiles = tempFileIds.stream()
.filter(tempFileId -> !refTempFileIds.contains(tempFileId))
.map(tempFileId -> {
String fileName = apiFileResourceService.getTempFileNameByFileId(tempFileId);
return getApiExecuteFileInfo(tempFileId, fileName, request.getProjectId());
})
.collect(Collectors.toList());
taskRequest.setLocalTempFiles(localTempFiles);
}
taskRequest.setRefFiles(refFiles);

View File

@ -0,0 +1,44 @@
package io.metersphere.api.service;
import io.metersphere.api.service.debug.ApiDebugService;
import io.metersphere.api.service.definition.ApiDefinitionService;
import io.metersphere.api.service.definition.ApiTestCaseService;
import io.metersphere.api.service.scenario.ApiScenarioService;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileMetadata;
import io.metersphere.project.invoker.FileAssociationUpdateService;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.FileAssociationSourceUtil;
import org.springframework.stereotype.Service;
/**
* @Author: jianxing
* @CreateTime: 2024-02-06 20:48
*/
@Service
public class ApiFileAssociationUpdateService implements FileAssociationUpdateService {
/**
* 处理接口关联的文件被更新
*
* @param originFileAssociation 原来的文件ID
* @param newFileMetadata 最新文件
*/
@Override
public void handleUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata) {
String sourceType = originFileAssociation.getSourceType();
switch (sourceType) {
case FileAssociationSourceUtil.SOURCE_TYPE_API_DEBUG ->
CommonBeanFactory.getBean(ApiDebugService.class).handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
case FileAssociationSourceUtil.SOURCE_TYPE_API_DEFINITION ->
CommonBeanFactory.getBean(ApiDefinitionService.class).handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
case FileAssociationSourceUtil.SOURCE_TYPE_API_TEST_CASE ->
CommonBeanFactory.getBean(ApiTestCaseService.class).handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
case FileAssociationSourceUtil.SOURCE_TYPE_API_SCENARIO ->
CommonBeanFactory.getBean(ApiScenarioService.class).handleFileAssociationUpgrade(originFileAssociation, newFileMetadata);
default -> {
}
}
}
}

View File

@ -180,9 +180,9 @@ public class ApiFileResourceService {
}
// 处理关联文件
List<String> unLinkRefIds = resourceUpdateRequest.getUnLinkRefIds();
if (CollectionUtils.isNotEmpty(unLinkRefIds)) {
fileAssociationService.deleteBySourceIdAndFileIds(resourceUpdateRequest.getResourceId(), unLinkRefIds,
List<String> unLinkFileIds = resourceUpdateRequest.getUnLinkFileIds();
if (CollectionUtils.isNotEmpty(unLinkFileIds)) {
fileAssociationService.deleteBySourceIdAndFileIds(resourceUpdateRequest.getResourceId(), unLinkFileIds,
createFileLogRecord(resourceUpdateRequest.getOperator(), resourceUpdateRequest.getProjectId(), resourceUpdateRequest.getLogModule()));
}
}

View File

@ -5,6 +5,7 @@ import io.metersphere.api.domain.ApiDebug;
import io.metersphere.api.domain.ApiDebugBlob;
import io.metersphere.api.domain.ApiDebugExample;
import io.metersphere.api.domain.ApiDebugModule;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.ApiParamConfig;
import io.metersphere.api.dto.debug.*;
import io.metersphere.api.dto.request.ApiEditPosRequest;
@ -12,10 +13,13 @@ import io.metersphere.api.mapper.ApiDebugBlobMapper;
import io.metersphere.api.mapper.ApiDebugMapper;
import io.metersphere.api.mapper.ApiDebugModuleMapper;
import io.metersphere.api.mapper.ExtApiDebugMapper;
import io.metersphere.api.service.ApiCommonService;
import io.metersphere.api.service.ApiExecuteService;
import io.metersphere.api.service.ApiFileResourceService;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileMetadata;
import io.metersphere.project.service.ProjectService;
import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.exception.MSException;
@ -58,6 +62,8 @@ public class ApiDebugService {
private ApiPluginService apiPluginService;
@Resource
private ApiDebugModuleMapper apiDebugModuleMapper;
@Resource
private ApiCommonService apiCommonService;
public static final Long ORDER_STEP = 5000L;
@ -71,7 +77,9 @@ public class ApiDebugService {
ApiDebugBlob apiDebugBlob = apiDebugBlobMapper.selectByPrimaryKey(id);
ApiDebugDTO apiDebugDTO = new ApiDebugDTO();
BeanUtils.copyBean(apiDebugDTO, apiDebug);
apiDebugDTO.setRequest(ApiDataUtils.parseObject(new String(apiDebugBlob.getRequest()), AbstractMsTestElement.class));
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiDebugBlob.getRequest()), AbstractMsTestElement.class);
apiCommonService.updateLinkFileInfo(id, msTestElement);
apiDebugDTO.setRequest(msTestElement);
apiDebugDTO.setResponse(apiDebugDTO.getResponse());
return apiDebugDTO;
}
@ -140,7 +148,7 @@ public class ApiDebugService {
ApiFileResourceUpdateRequest resourceUpdateRequest = getApiFileResourceUpdateRequest(originApiDebug.getId(), originApiDebug.getProjectId(), updateUser);
resourceUpdateRequest.setUploadFileIds(request.getUploadFileIds());
resourceUpdateRequest.setLinkFileIds(request.getLinkFileIds());
resourceUpdateRequest.setUnLinkRefIds(request.getUnLinkRefIds());
resourceUpdateRequest.setUnLinkFileIds(request.getUnLinkFileIds());
resourceUpdateRequest.setDeleteFileIds(request.getDeleteFileIds());
apiFileResourceService.updateFileResource(resourceUpdateRequest);
return apiDebug;
@ -245,4 +253,28 @@ public class ApiDebugService {
extApiDebugMapper::getLastPos,
apiDebugMapper::updateByPrimaryKeySelective);
}
/**
* 处理关联的文件被更新
* @param originFileAssociation
* @param newFileMetadata
*/
public void handleFileAssociationUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata) {
ApiDebugBlob apiDebugBlob = apiDebugBlobMapper.selectByPrimaryKey(originFileAssociation.getSourceId());
if (apiDebugBlob == null) {
return;
}
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiDebugBlob.getRequest()), AbstractMsTestElement.class);
// 获取接口中需要更新的文件
List<ApiFile> updateFiles = apiCommonService.getApiFilesByFileId(originFileAssociation.getFileId(), msTestElement);
// 替换文件的Id和name
apiCommonService.replaceApiFileInfo(updateFiles, newFileMetadata);
// 如果有需要更新的文件则更新 request 字段
if (CollectionUtils.isNotEmpty(updateFiles)) {
apiDebugBlob.setRequest(ApiDataUtils.toJSONString(msTestElement).getBytes());
apiDebugBlob.setResponse(null);
apiDebugBlobMapper.updateByPrimaryKeySelective(apiDebugBlob);
}
}
}

View File

@ -1,17 +1,14 @@
package io.metersphere.api.service.definition;
import io.metersphere.api.domain.ApiDefinition;
import io.metersphere.api.domain.ApiDefinitionBlob;
import io.metersphere.api.domain.ApiDefinitionExample;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.mapper.ApiDefinitionBlobMapper;
import io.metersphere.api.mapper.ApiDefinitionMapper;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.domain.Project;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.log.constants.OperationLogModule;
@ -25,7 +22,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
@Transactional(rollbackFor = Exception.class)
@ -34,9 +30,6 @@ public class ApiDefinitionLogService {
@Resource
private ApiDefinitionMapper apiDefinitionMapper;
@Resource
private ApiDefinitionBlobMapper apiDefinitionBlobMapper;
@Resource
private ProjectMapper projectMapper;
@ -256,22 +249,13 @@ public class ApiDefinitionLogService {
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
if (null != apiDefinition) {
// 2. 使用Optional避免空指针异常
handleBlob(id, apiDefinitionDTO);
CommonBeanFactory.getBean(ApiDefinitionService.class).handleBlob(id, apiDefinitionDTO);
BeanUtils.copyBean(apiDefinitionDTO, apiDefinition);
}
return apiDefinitionDTO;
}
public void handleBlob(String id, ApiDefinitionDTO apiDefinitionDTO) {
Optional<ApiDefinitionBlob> apiDefinitionBlobOptional = Optional.ofNullable(apiDefinitionBlobMapper.selectByPrimaryKey(id));
apiDefinitionBlobOptional.ifPresent(blob -> {
apiDefinitionDTO.setRequest(ApiDataUtils.parseObject(new String(blob.getRequest()), AbstractMsTestElement.class));
// blob.getResponse() null 时不进行转换
if (blob.getResponse() != null) {
apiDefinitionDTO.setResponse(ApiDataUtils.parseArray(new String(blob.getResponse()), HttpResponse.class));
}
});
}
private void saveBatchLog(String projectId, List<String> ids, String path, String userId, String operationType, boolean isHistory) {
List<LogDTO> dtoList = new ArrayList<>();
@ -282,7 +266,7 @@ public class ApiDefinitionLogService {
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
apiDefinitions.forEach(item -> {
ApiDefinitionDTO apiDefinitionDTO = new ApiDefinitionDTO();
handleBlob(item.getId(), apiDefinitionDTO);
CommonBeanFactory.getBean(ApiDefinitionService.class).handleBlob(item.getId(), apiDefinitionDTO);
BeanUtils.copyBean(apiDefinitionDTO, item);
LogDTO dto = new LogDTO(
project.getId(),

View File

@ -195,7 +195,7 @@ public class ApiDefinitionMockService {
ApiFileResourceUpdateRequest resourceUpdateRequest = getApiFileResourceRequest(apiDefinitionMock.getId(), apiDefinitionMock.getProjectId(), userId);
resourceUpdateRequest.setUploadFileIds(request.getUploadFileIds());
resourceUpdateRequest.setLinkFileIds(request.getLinkFileIds());
resourceUpdateRequest.setUnLinkRefIds(request.getUnLinkRefIds());
resourceUpdateRequest.setUnLinkFileIds(request.getUnLinkFileIds());
resourceUpdateRequest.setDeleteFileIds(request.getDeleteFileIds());
apiFileResourceService.updateFileResource(resourceUpdateRequest);

View File

@ -4,6 +4,7 @@ import io.metersphere.api.constants.ApiDefinitionDocType;
import io.metersphere.api.constants.ApiResourceType;
import io.metersphere.api.controller.result.ApiResultCode;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.ApiResourceModuleInfo;
import io.metersphere.api.dto.converter.ApiDefinitionImport;
import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest;
@ -13,9 +14,12 @@ import io.metersphere.api.dto.request.ImportRequest;
import io.metersphere.api.mapper.*;
import io.metersphere.api.parser.ImportParser;
import io.metersphere.api.parser.ImportParserFactory;
import io.metersphere.api.service.ApiCommonService;
import io.metersphere.api.service.ApiFileResourceService;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileMetadata;
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.project.service.ProjectService;
import io.metersphere.sdk.constants.ApiReportStatus;
@ -81,6 +85,9 @@ public class ApiDefinitionService {
@Resource
private ApiDefinitionBlobMapper apiDefinitionBlobMapper;
@Resource
private ApiCommonService apiCommonService;
@Resource
private ExtApiTestCaseMapper extApiTestCaseMapper;
@ -273,7 +280,7 @@ public class ApiDefinitionService {
ApiFileResourceUpdateRequest resourceUpdateRequest = getApiFileResourceUpdateRequest(originApiDefinition.getId(), originApiDefinition.getProjectId(), userId);
resourceUpdateRequest.setUploadFileIds(request.getUploadFileIds());
resourceUpdateRequest.setLinkFileIds(request.getLinkFileIds());
resourceUpdateRequest.setUnLinkRefIds(request.getUnLinkRefIds());
resourceUpdateRequest.setUnLinkFileIds(request.getUnLinkFileIds());
resourceUpdateRequest.setDeleteFileIds(request.getDeleteFileIds());
apiFileResourceService.updateFileResource(resourceUpdateRequest);
@ -850,7 +857,7 @@ public class ApiDefinitionService {
public ApiDefinitionDTO getApiDefinitionInfo(String id, String userId, ApiDefinition apiDefinition) {
ApiDefinitionDTO apiDefinitionDTO = new ApiDefinitionDTO();
// 2. 使用Optional避免空指针异常
apiDefinitionLogService.handleBlob(id, apiDefinitionDTO);
handleBlob(id, apiDefinitionDTO);
// 3. 查询自定义字段
handleCustomFields(id, apiDefinition.getProjectId(), apiDefinitionDTO);
// 3. 使用Stream简化集合操作
@ -861,6 +868,23 @@ public class ApiDefinitionService {
return apiDefinitionDTO;
}
public void handleBlob(String id, ApiDefinitionDTO apiDefinitionDTO) {
Optional<ApiDefinitionBlob> apiDefinitionBlobOptional = Optional.ofNullable(apiDefinitionBlobMapper.selectByPrimaryKey(id));
apiDefinitionBlobOptional.ifPresent(blob -> {
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(blob.getRequest()), AbstractMsTestElement.class);
apiCommonService.updateLinkFileInfo(id, msTestElement);
apiDefinitionDTO.setRequest(msTestElement);
// blob.getResponse() null 时不进行转换
if (blob.getResponse() != null) {
List<HttpResponse> httpResponses = ApiDataUtils.parseArray(new String(blob.getResponse()), HttpResponse.class);
for (HttpResponse httpResponse : httpResponses) {
apiCommonService.updateLinkFileInfo(id, httpResponse.getBody());
}
apiDefinitionDTO.setResponse(httpResponses);
}
});
}
public void handleCustomFields(String id, String projectId, ApiDefinitionDTO apiDefinitionDTO) {
List<ApiDefinitionCustomFieldDTO> customFields = extApiDefinitionCustomFieldMapper.getApiCustomFields(Collections.singletonList(id), projectId);
Map<String, List<ApiDefinitionCustomFieldDTO>> customFieldMap = customFields.stream().collect(Collectors.groupingBy(ApiDefinitionCustomFieldDTO::getApiId));
@ -875,7 +899,7 @@ public class ApiDefinitionService {
List<ApiDefinitionDTO> list = extApiDefinitionMapper.listDoc(request);
if (!list.isEmpty()) {
ApiDefinitionDTO first = list.get(0);
apiDefinitionLogService.handleBlob(first.getId(), first);
handleBlob(first.getId(), first);
String docTitle;
if (ApiDefinitionDocType.ALL.name().equals(request.getType())) {
docTitle = Translator.get(ALL_API);
@ -890,7 +914,7 @@ public class ApiDefinitionService {
ApiDefinition apiDefinition = checkApiDefinition(request.getApiId());
ApiDefinitionDTO apiDefinitionDTO = new ApiDefinitionDTO();
BeanUtils.copyBean(apiDefinitionDTO, apiDefinition);
apiDefinitionLogService.handleBlob(apiDefinition.getId(), apiDefinitionDTO);
handleBlob(apiDefinition.getId(), apiDefinitionDTO);
apiDefinitionDocDTO.setDocTitle(apiDefinitionDTO.getName());
apiDefinitionDocDTO.setDocInfo(apiDefinitionDTO);
}
@ -1055,4 +1079,40 @@ public class ApiDefinitionService {
throw new MSException("module.not.exist");
}
}
public void handleFileAssociationUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata) {
ApiDefinitionBlob apiDefinitionBlob = apiDefinitionBlobMapper.selectByPrimaryKey(originFileAssociation.getSourceId());
if (apiDefinitionBlob == null) {
return;
}
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiDefinitionBlob.getRequest()), AbstractMsTestElement.class);
// 获取接口中需要更新的文件
List<ApiFile> updateFiles = apiCommonService.getApiFilesByFileId(originFileAssociation.getFileId(), msTestElement);
// 如果有需要更新的文件则更新 request 字段
if (CollectionUtils.isNotEmpty(updateFiles)) {
// 替换文件的Id和name
apiCommonService.replaceApiFileInfo(updateFiles, newFileMetadata);
apiDefinitionBlob.setRequest(ApiDataUtils.toJSONString(msTestElement).getBytes());
apiDefinitionBlobMapper.updateByPrimaryKeySelective(apiDefinitionBlob);
}
// 处理响应的文件
if (apiDefinitionBlob.getResponse() != null) {
List<HttpResponse> httpResponses = ApiDataUtils.parseArray(new String(apiDefinitionBlob.getResponse()), HttpResponse.class);
List<ApiFile> responseUpdateFiles = new ArrayList<>(0);
for (HttpResponse httpResponse : httpResponses) {
responseUpdateFiles.addAll(apiCommonService.getApiBodyFiles(httpResponse.getBody())
.stream()
.filter(file -> StringUtils.equals(originFileAssociation.getFileId(), file.getFileId()))
.toList());
}
if (CollectionUtils.isNotEmpty(responseUpdateFiles)) {
// 替换文件的Id和name
apiCommonService.replaceApiFileInfo(responseUpdateFiles, newFileMetadata);
apiDefinitionBlob.setResponse(JSON.toJSONString(httpResponses).getBytes());
apiDefinitionBlobMapper.updateByPrimaryKeySelective(apiDefinitionBlob);
}
}
}
}

View File

@ -2,14 +2,18 @@ package io.metersphere.api.service.definition;
import io.metersphere.api.constants.ApiResourceType;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.ApiResourceModuleInfo;
import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.mapper.*;
import io.metersphere.api.service.ApiCommonService;
import io.metersphere.api.service.ApiFileResourceService;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileMetadata;
import io.metersphere.project.domain.Project;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.ApplicationNumScope;
@ -84,6 +88,9 @@ public class ApiTestCaseService {
private OperationHistoryService operationHistoryService;
@Resource
private ExtApiDefinitionMapper extApiDefinitionMapper;
@Resource
private ApiCommonService apiCommonService;
private static final String CASE_TABLE = "api_test_case";
private void checkProjectExist(String projectId) {
@ -257,7 +264,7 @@ public class ApiTestCaseService {
ApiFileResourceUpdateRequest resourceUpdateRequest = getApiFileResourceUpdateRequest(testCase.getId(), testCase.getProjectId(), userId);
resourceUpdateRequest.setUploadFileIds(request.getUploadFileIds());
resourceUpdateRequest.setLinkFileIds(request.getLinkFileIds());
resourceUpdateRequest.setUnLinkRefIds(request.getUnLinkRefIds());
resourceUpdateRequest.setUnLinkFileIds(request.getUnLinkFileIds());
resourceUpdateRequest.setDeleteFileIds(request.getDeleteFileIds());
apiFileResourceService.updateFileResource(resourceUpdateRequest);
return testCase;
@ -598,4 +605,22 @@ public class ApiTestCaseService {
moduleInfo.setResourceId(apiCaseDefinitionMap.get(moduleInfo.getResourceId())));
return moduleInfos;
}
public void handleFileAssociationUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata) {
ApiTestCaseBlob apiTestCaseBlob = apiTestCaseBlobMapper.selectByPrimaryKey(originFileAssociation.getSourceId());
if (apiTestCaseBlob == null) {
return;
}
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiTestCaseBlob.getRequest()), AbstractMsTestElement.class);
// 获取接口中需要更新的文件
List<ApiFile> updateFiles = apiCommonService.getApiFilesByFileId(originFileAssociation.getFileId(), msTestElement);
// 替换文件的Id和name
apiCommonService.replaceApiFileInfo(updateFiles, newFileMetadata);
// 如果有需要更新的文件则更新 request 字段
if (CollectionUtils.isNotEmpty(updateFiles)) {
apiTestCaseBlob.setRequest(ApiDataUtils.toJSONString(msTestElement).getBytes());
apiTestCaseBlobMapper.updateByPrimaryKeySelective(apiTestCaseBlob);
}
}
}

View File

@ -164,8 +164,8 @@ public class MockServerService {
} else if (StringUtils.equalsIgnoreCase(responseBody.getBodyType(), Body.BodyType.RAW.name())) {
return responseBody.getRawBody().getValue();
} else {
String fileId = responseBody.getBinaryBody().getFileId();
String fileName = responseBody.getBinaryBody().getFileName();
String fileId = responseBody.getBinaryBody().getFile().getFileId();
String fileName = responseBody.getBinaryBody().getFile().getFileName();
String fileType = StringUtils.substring(fileName, fileName.lastIndexOf(".") + 1);
MediaType mediaType = MediaType.parseMediaType("application/octet-stream");
if (responseBody.getBinaryBody().isSendAsBody()) {

View File

@ -4,10 +4,7 @@ import io.metersphere.api.constants.ApiResourceType;
import io.metersphere.api.constants.ApiScenarioStepRefType;
import io.metersphere.api.constants.ApiScenarioStepType;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.ApiResourceModuleInfo;
import io.metersphere.api.dto.ApiScenarioParamConfig;
import io.metersphere.api.dto.ApiScenarioParseEnvInfo;
import io.metersphere.api.dto.EnvironmentModeDTO;
import io.metersphere.api.dto.*;
import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest;
import io.metersphere.api.dto.debug.ApiResourceRunRequest;
import io.metersphere.api.dto.request.MsScenario;
@ -18,13 +15,16 @@ import io.metersphere.api.job.ApiScenarioScheduleJob;
import io.metersphere.api.mapper.*;
import io.metersphere.api.parser.step.StepParser;
import io.metersphere.api.parser.step.StepParserFactory;
import io.metersphere.api.service.ApiCommonService;
import io.metersphere.api.service.ApiExecuteService;
import io.metersphere.api.service.ApiFileResourceService;
import io.metersphere.api.service.definition.ApiDefinitionModuleService;
import io.metersphere.api.service.definition.ApiDefinitionService;
import io.metersphere.api.service.definition.ApiTestCaseService;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.api.utils.ApiScenarioBatchOperationUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileMetadata;
import io.metersphere.project.domain.Project;
import io.metersphere.project.domain.ProjectExample;
@ -168,6 +168,8 @@ public class ApiScenarioService {
private ExtApiTestCaseMapper extApiTestCaseMapper;
@Resource
private ApiDefinitionModuleService apiDefinitionModuleService;
@Resource
private ApiCommonService apiCommonService;
public static final String PRIORITY = "Priority";
public static final String STATUS = "Status";
@ -474,7 +476,7 @@ public class ApiScenarioService {
List<String> deleteRefs = ListUtils.subtract(dbRefFileIds, intersectionRef);
List<String> addRef = ListUtils.subtract(refFileIds, intersectionRef);
resourceUpdateRequest.setLinkFileIds(addRef);
resourceUpdateRequest.setUnLinkRefIds(deleteRefs);
resourceUpdateRequest.setUnLinkFileIds(deleteRefs);
//删除不存在的数据
deleteCsvResource(resourceUpdateRequest);
@ -569,15 +571,15 @@ public class ApiScenarioService {
apiScenarioCsvStepMapper.deleteByExample(stepExample);
}
List<String> unLinkRefIds = resourceUpdateRequest.getUnLinkRefIds();
List<String> unLinkFileIds = resourceUpdateRequest.getUnLinkFileIds();
// 处理关联文件
if (CollectionUtils.isNotEmpty(unLinkRefIds)) {
fileAssociationService.deleteBySourceIdAndFileIds(resourceUpdateRequest.getResourceId(), unLinkRefIds,
if (CollectionUtils.isNotEmpty(unLinkFileIds)) {
fileAssociationService.deleteBySourceIdAndFileIds(resourceUpdateRequest.getResourceId(), unLinkFileIds,
apiFileResourceService.createFileLogRecord(resourceUpdateRequest.getOperator(), resourceUpdateRequest.getProjectId(), resourceUpdateRequest.getLogModule()));
example.clear();
example.createCriteria()
.andScenarioIdEqualTo(resourceUpdateRequest.getResourceId())
.andFileIdIn(unLinkRefIds);
.andFileIdIn(unLinkFileIds);
apiScenarioCsvMapper.deleteByExample(example);
stepExample.clear();
stepExample.createCriteria().andFileIdIn(deleteFileIds);
@ -630,7 +632,7 @@ public class ApiScenarioService {
ApiFileResourceUpdateRequest resourceUpdateRequest = getApiFileResourceUpdateRequest(scenario.getId(), originScenario.getProjectId(), updater);
resourceUpdateRequest.setUploadFileIds(request.getUploadFileIds());
resourceUpdateRequest.setLinkFileIds(request.getLinkFileIds());
resourceUpdateRequest.setUnLinkRefIds(request.getUnLinkRefIds());
resourceUpdateRequest.setUnLinkFileIds(request.getUnLinkFileIds());
resourceUpdateRequest.setDeleteFileIds(request.getDeleteFileIds());
apiFileResourceService.updateFileResource(resourceUpdateRequest);
@ -1067,7 +1069,7 @@ public class ApiScenarioService {
runRequest.setTestId(request.getId());
runRequest.setReportId(request.getReportId());
runRequest.setResourceType(ApiResourceType.API_SCENARIO.name());
runRequest.setTempFileIds(request.getTempFileIds());
runRequest.setUploadFileIds(request.getUploadFileIds());
runRequest.setGrouped(request.getGrouped());
runRequest.setEnvironmentId(request.getEnvironmentId());
runRequest.setTestElement(msScenario);
@ -1092,6 +1094,7 @@ public class ApiScenarioService {
/**
* 设置 HttpElement 的模块信息
* 用户环境中的模块过滤
*
* @param stepTypeHttpElementMap
*/
private void setHttpElementModuleId(Map<String, List<MsHTTPElement>> stepTypeHttpElementMap) {
@ -1173,6 +1176,7 @@ public class ApiScenarioService {
/**
* 处理环境的 HTTP 配置模块匹配规则
* 查询新增子模块
*
* @param envInfoDTO
*/
private void handleHttpModuleMatchRule(EnvironmentInfoDTO envInfoDTO) {
@ -1631,7 +1635,16 @@ public class ApiScenarioService {
step.setRefType(ApiScenarioStepRefType.REF.name());
}
StepParser stepParser = StepParserFactory.getStepParser(step.getStepType());
return stepParser.parseDetail(step);
Object stepDetail = stepParser.parseDetail(step);
if (stepDetail instanceof MsHTTPElement msHTTPElement) {
// 设置关联的文件的最新信息
if (isRef(step.getRefType())) {
apiCommonService.updateLinkFileInfo(step.getResourceId(), msHTTPElement);
} else {
apiCommonService.updateLinkFileInfo(step.getScenarioId(), msHTTPElement);
}
}
return stepDetail;
}
private void checkTargetModule(String targetModuleId, String projectId) {
@ -2043,4 +2056,33 @@ public class ApiScenarioService {
extApiScenarioMapper::getLastPosEdit,
apiScenarioMapper::updateByPrimaryKeySelective);
}
public void handleFileAssociationUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata) {
// 查询有步骤详情的请求类型的步骤
List<String> stepIds = extApiScenarioStepMapper.getHasBlobRequestStepIds(originFileAssociation.getSourceId());
// 查询步骤详情
ApiScenarioStepBlobExample blobExample = new ApiScenarioStepBlobExample();
blobExample.createCriteria().andIdIn(stepIds);
List<ApiScenarioStepBlob> apiScenarioStepBlobs = apiScenarioStepBlobMapper.selectByExampleWithBLOBs(blobExample);
for (ApiScenarioStepBlob apiScenarioStepBlob : apiScenarioStepBlobs) {
AbstractMsTestElement msTestElement = null;
try {
msTestElement = ApiDataUtils.parseObject(new String(apiScenarioStepBlob.getContent()), AbstractMsTestElement.class);
// 如果插件删除会转换异常
} catch (Exception e) {
LogUtils.error(e);
}
if (msTestElement != null && msTestElement instanceof MsHTTPElement msHTTPElement) {
List<ApiFile> updateFiles = apiCommonService.getApiFilesByFileId(originFileAssociation.getFileId(), msHTTPElement);
// 替换文件的Id和name
apiCommonService.replaceApiFileInfo(updateFiles, newFileMetadata);
// 如果有需要更新的文件则更新步骤详情
if (CollectionUtils.isNotEmpty(updateFiles)) {
apiScenarioStepBlob.setContent(ApiDataUtils.toJSONString(msTestElement).getBytes());
apiScenarioStepBlobMapper.updateByPrimaryKeySelective(apiScenarioStepBlob);
}
}
}
}
}

View File

@ -5,8 +5,11 @@ import io.metersphere.api.controller.result.ApiResultCode;
import io.metersphere.api.domain.ApiDebug;
import io.metersphere.api.domain.ApiDebugBlob;
import io.metersphere.api.domain.ApiFileResource;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.assertion.MsAssertionConfig;
import io.metersphere.api.dto.debug.*;
import io.metersphere.api.dto.definition.ResponseBinaryBody;
import io.metersphere.api.dto.definition.ResponseBody;
import io.metersphere.api.dto.request.ApiEditPosRequest;
import io.metersphere.api.dto.request.MsCommonElement;
import io.metersphere.api.dto.request.http.MsHTTPElement;
@ -14,19 +17,19 @@ import io.metersphere.api.dto.request.http.RestParam;
import io.metersphere.api.dto.request.http.auth.BasicAuth;
import io.metersphere.api.dto.request.http.auth.DigestAuth;
import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig;
import io.metersphere.api.dto.request.http.body.Body;
import io.metersphere.api.dto.request.http.body.*;
import io.metersphere.api.mapper.ApiDebugBlobMapper;
import io.metersphere.api.mapper.ApiDebugMapper;
import io.metersphere.api.parser.ImportParserFactory;
import io.metersphere.api.parser.TestElementParserFactory;
import io.metersphere.api.service.ApiCommonService;
import io.metersphere.api.service.ApiFileResourceService;
import io.metersphere.api.service.BaseResourcePoolTestService;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.dto.filemanagement.FileInfo;
import io.metersphere.project.dto.filemanagement.request.FileUploadRequest;
import io.metersphere.api.service.BaseFileManagementTestService;
import io.metersphere.project.service.FileAssociationService;
import io.metersphere.project.service.FileMetadataService;
import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.file.FileCenter;
@ -41,7 +44,6 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@ -49,6 +51,7 @@ import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MvcResult;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@ -76,9 +79,11 @@ public class ApiDebugControllerTests extends BaseTest {
@Resource
private ApiFileResourceService apiFileResourceService;
@Resource
private FileMetadataService fileMetadataService;
@Resource
private BaseResourcePoolTestService baseResourcePoolTestService;
@Resource
private BaseFileManagementTestService baseFileManagementTestService;
@Resource
private ApiCommonService apiCommonService;
private static ApiDebug addApiDebug;
private static ApiDebug anotherAddApiDebug;
private static String fileMetadataId;
@ -95,7 +100,8 @@ public class ApiDebugControllerTests extends BaseTest {
// @@校验没有数据的情况
this.requestGetWithOk(DEFAULT_LIST, ApiConstants.HTTP_PROTOCOL);
// 准备数据上传文件管理文件
uploadFileMetadata();
MockMultipartFile file = new MockMultipartFile("file", IDGenerator.nextStr() + "_file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
fileMetadataId = baseFileManagementTestService.upload(file);
}
@Test
@ -144,6 +150,7 @@ public class ApiDebugControllerTests extends BaseTest {
request.setModuleId("default");
request.setProjectId(DEFAULT_PROJECT_ID);
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
msHttpElement.setBody(addBodyLinkFile(msHttpElement.getBody(), fileMetadataId));
request.setRequest(getMsElementParam(msHttpElement));
uploadFileId = doUploadTempFile(getMockMultipartFile());
@ -169,6 +176,9 @@ public class ApiDebugControllerTests extends BaseTest {
assertUploadFile(resultData.getId(), List.of());
assertLinkFile(resultData.getId(), List.of());
// 测试关联的文件更新
testHandleFileAssociationUpgrade();
// @@重名校验异常
assertErrorCode(this.requestPost(DEFAULT_ADD, request), API_DEBUG_EXIST);
// 校验项目是否存在
@ -183,18 +193,6 @@ public class ApiDebugControllerTests extends BaseTest {
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEBUG_ADD, DEFAULT_ADD, request);
}
/**
* 文件管理插入一条数据
* 便于测试关联文件
*/
private void uploadFileMetadata() throws Exception {
FileUploadRequest fileUploadRequest = new FileUploadRequest();
fileUploadRequest.setProjectId(DEFAULT_PROJECT_ID);
//导入正常文件
MockMultipartFile file = new MockMultipartFile("file", "file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
fileMetadataId = fileMetadataService.upload(fileUploadRequest, "admin", file);
}
@Test
@Order(3)
public void update() throws Exception {
@ -210,7 +208,7 @@ public class ApiDebugControllerTests extends BaseTest {
request.setRequest(getMsElementParam(msHttpElement));
// 不带文件的更新
request.setUnLinkRefIds(List.of(fileMetadataId));
request.setUnLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(List.of(uploadFileId));
this.requestPostWithOk(DEFAULT_UPDATE, request);
// 校验请求成功数据
@ -223,7 +221,7 @@ public class ApiDebugControllerTests extends BaseTest {
request.setUploadFileIds(List.of(fileId));
request.setLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(null);
request.setUnLinkRefIds(null);
request.setUnLinkFileIds(null);
this.requestPostWithOk(DEFAULT_UPDATE, request);
// 校验请求成功数据
assertUpdateApiDebug(request, msHttpElement, request.getId());
@ -234,7 +232,7 @@ public class ApiDebugControllerTests extends BaseTest {
request.setDeleteFileIds(List.of(fileId));
String newFileId1 = doUploadTempFile(getMockMultipartFile());
request.setUploadFileIds(List.of(newFileId1));
request.setUnLinkRefIds(List.of(fileMetadataId));
request.setUnLinkFileIds(List.of(fileMetadataId));
request.setLinkFileIds(List.of(fileMetadataId));
this.requestPostWithOk(DEFAULT_UPDATE, request);
assertUpdateApiDebug(request, msHttpElement, request.getId());
@ -244,6 +242,8 @@ public class ApiDebugControllerTests extends BaseTest {
// 已有一个文件再上传一个文件
String newFileId2 = doUploadTempFile(getMockMultipartFile());
request.setUploadFileIds(List.of(newFileId2));
msHttpElement.setBody(addBodyLinkFile(msHttpElement.getBody(), fileMetadataId));
request.setRequest(getMsElementParam(msHttpElement));
this.requestPostWithOk(DEFAULT_UPDATE, request);
// 校验请求成功数据
assertUpdateApiDebug(request, msHttpElement, request.getId());
@ -353,8 +353,17 @@ public class ApiDebugControllerTests extends BaseTest {
// 校验数据是否正确
ApiDebugDTO copyApiDebugDTO = BeanUtils.copyBean(new ApiDebugDTO(), apiDebugMapper.selectByPrimaryKey(addApiDebug.getId()));
ApiDebugBlob apiDebugBlob = apiDebugBlobMapper.selectByPrimaryKey(addApiDebug.getId());
copyApiDebugDTO.setRequest(ApiDataUtils.parseObject(new String(apiDebugBlob.getRequest()), AbstractMsTestElement.class));
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiDebugBlob.getRequest()), AbstractMsTestElement.class);
apiCommonService.updateLinkFileInfo(addApiDebug.getId(), msTestElement);
copyApiDebugDTO.setRequest(msTestElement);
Assertions.assertEquals(apiDebugDTO, copyApiDebugDTO);
// 删除关联文件
baseFileManagementTestService.deleteFile(fileMetadataId);
this.requestGetWithOk(DEFAULT_GET, addApiDebug.getId());
// 重新上传文件,执行时要使用
fileMetadataId = baseFileManagementTestService.upload(getMockMultipartFile());
// @@校验权限
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEBUG_READ, DEFAULT_GET, apiDebugDTO.getId());
}
@ -457,7 +466,8 @@ public class ApiDebugControllerTests extends BaseTest {
// 测试请求体
MockMultipartFile file = getMockMultipartFile();
String fileId = doUploadTempFile(file);
request.setTempFileIds(List.of(fileId, fileMetadataId));
request.setUploadFileIds(List.of(fileId, fileMetadataId));
request.setLinkFileIds(List.of(fileId, fileMetadataId));
Body generalBody = MsHTTPElementTest.getGeneralBody();
msHTTPElement = MsHTTPElementTest.getMsHttpElement();
msHTTPElement.setBody(generalBody);
@ -480,6 +490,28 @@ public class ApiDebugControllerTests extends BaseTest {
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEBUG_EXECUTE, DEBUG, request);
}
/**
* 测试关联的文件更新
* @throws Exception
*/
public void testHandleFileAssociationUpgrade() throws Exception {
List<ApiFile> originApiFiles = getApiFiles(fileMetadataId);
MockMultipartFile file = new MockMultipartFile("file", "file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
// 重新上传新文件
String newFileId = baseFileManagementTestService.reUpload(fileMetadataId, file);
// 更新关联的文件到最新文件
baseFileManagementTestService.upgrade(fileMetadataId, addApiDebug.getId());
// 校验文件是否替换
Assertions.assertEquals(originApiFiles.size(), getApiFiles(newFileId).size());
fileMetadataId = newFileId;
}
private List<ApiFile> getApiFiles(String fileId) {
ApiDebugBlob apiDebugBlob = apiDebugBlobMapper.selectByPrimaryKey(addApiDebug.getId());
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiDebugBlob.getRequest()), AbstractMsTestElement.class);
return apiCommonService.getApiFilesByFileId(fileId, msTestElement);
}
private List<RestParam> getRestParams() {
RestParam restParam1 = new RestParam();
restParam1.setKey("rest1");
@ -530,8 +562,48 @@ public class ApiDebugControllerTests extends BaseTest {
return JSON.parseObject(ApiDataUtils.toJSONString(msHTTPElement));
}
public static Body addBodyLinkFile(Body body, String fileMetadataId) {
if (body == null) {
body = MsHTTPElementTest.getGeneralBody();
}
if (body.getFormDataBody() == null) {
body.setFormDataBody(new FormDataBody());
body.getFormDataBody().setFormValues(new ArrayList<>(1));
}
List<FormDataKV> formValues = body.getFormDataBody().getFormValues();
FormDataKV formDataKV = new FormDataKV();
formDataKV.setKey("a");
formDataKV.setParamType(BodyParamType.FILE.getValue());
ApiFile apiFile = new ApiFile();
apiFile.setLocal(false);
apiFile.setFileId(fileMetadataId);
apiFile.setFileName("test");
formDataKV.setFiles(List.of(apiFile));
formValues.add(formDataKV);
if (body.getBinaryBody() == null) {
body.setBinaryBody(new BinaryBody());
}
body.getBinaryBody().setFile(apiFile);
return body;
}
public static ResponseBody addBodyLinkFile(ResponseBody body, String fileMetadataId) {
if (body == null) {
body = new ResponseBody();
}
ApiFile apiFile = new ApiFile();
apiFile.setLocal(false);
apiFile.setFileId(fileMetadataId);
apiFile.setFileName("test");
if (body.getBinaryBody() == null) {
body.setBinaryBody(new ResponseBinaryBody());
}
body.getBinaryBody().setFile(apiFile);
return body;
}
@Test
@Order(8)
@Order(17)
public void delete() throws Exception {
// @@请求成功
this.requestGetWithOk(DEFAULT_DELETE, addApiDebug.getId());

View File

@ -5,20 +5,21 @@ import io.metersphere.api.constants.ApiDefinitionDocType;
import io.metersphere.api.constants.ApiDefinitionStatus;
import io.metersphere.api.controller.result.ApiResultCode;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.request.ApiEditPosRequest;
import io.metersphere.api.dto.request.ImportRequest;
import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.mapper.*;
import io.metersphere.api.model.CheckLogModel;
import io.metersphere.api.service.ApiCommonService;
import io.metersphere.api.service.ApiFileResourceService;
import io.metersphere.api.service.BaseFileManagementTestService;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.dto.filemanagement.FileInfo;
import io.metersphere.project.dto.filemanagement.request.FileUploadRequest;
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.project.service.FileAssociationService;
import io.metersphere.project.service.FileMetadataService;
import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.SessionConstants;
@ -36,6 +37,7 @@ import io.metersphere.system.dto.request.OperationHistoryVersionRequest;
import io.metersphere.system.dto.sdk.BaseCondition;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.OperationHistoryMapper;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.Pager;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
@ -135,9 +137,10 @@ public class ApiDefinitionControllerTests extends BaseTest {
private ApiTestCaseMapper apiTestCaseMapper;
@Resource
private ApiTestCaseBlobMapper apiTestCaseBlobMapper;
@Resource
private FileMetadataService fileMetadataService;
private BaseFileManagementTestService baseFileManagementTestService;
@Resource
private ApiCommonService apiCommonService;
private static String fileMetadataId;
private static String uploadFileId;
@ -148,9 +151,9 @@ public class ApiDefinitionControllerTests extends BaseTest {
@Order(0)
public void uploadTempFile() throws Exception {
// 准备数据上传文件管理文件
uploadFileMetadata();
MockMultipartFile file = new MockMultipartFile("file", IDGenerator.nextStr() + "_file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
fileMetadataId = baseFileManagementTestService.upload(file);
// @@请求成功
MockMultipartFile file = getMockMultipartFile("file_upload.JPG");
String fileId = doUploadTempFile(file);
// 校验文件存在
@ -186,8 +189,10 @@ public class ApiDefinitionControllerTests extends BaseTest {
// 创建测试数据
ApiDefinitionAddRequest request = createApiDefinitionAddRequest();
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
msHttpElement.setBody(ApiDebugControllerTests.addBodyLinkFile(msHttpElement.getBody(), fileMetadataId));
request.setRequest(getMsElementParam(msHttpElement));
List<HttpResponse> msHttpResponse = MsHTTPElementTest.getMsHttpResponse();
msHttpResponse.get(0).setBody(ApiDebugControllerTests.addBodyLinkFile(msHttpResponse.get(0).getBody(), fileMetadataId));
request.setResponse(msHttpResponse);
uploadFileId = doUploadTempFile(getMockMultipartFile("file_upload.JPG"));
@ -210,6 +215,8 @@ public class ApiDefinitionControllerTests extends BaseTest {
resultData = getResultData(mvcResult, ApiDefinition.class);
assertAddApiDefinition(request, msHttpElement, resultData.getId());
testHandleFileAssociationUpgrade();
// @@重名校验异常
assertErrorCode(this.requestPost(ADD, request), ApiResultCode.API_DEFINITION_EXIST);
// @@响应名+响应码唯一校验异常
@ -240,6 +247,34 @@ public class ApiDefinitionControllerTests extends BaseTest {
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_ADD, ADD, request);
}
public void testHandleFileAssociationUpgrade() throws Exception {
List<ApiFile> originApiFiles = getApiFiles(fileMetadataId);
MockMultipartFile file = new MockMultipartFile("file", "file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
// 重新上传新文件
String newFileId = baseFileManagementTestService.reUpload(fileMetadataId, file);
// 更新关联的文件到最新文件
baseFileManagementTestService.upgrade(fileMetadataId, apiDefinition.getId());
// 校验文件是否替换
Assertions.assertEquals(originApiFiles.size(), getApiFiles(newFileId).size());
fileMetadataId = newFileId;
}
private List<ApiFile> getApiFiles(String fileId) {
ApiDefinitionBlob apiDefinitionBlob = apiDefinitionBlobMapper.selectByPrimaryKey(apiDefinition.getId());
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiDefinitionBlob.getRequest()), AbstractMsTestElement.class);
List<ApiFile> apiFiles = apiCommonService.getApiFilesByFileId(fileId, msTestElement);
List<HttpResponse> httpResponses = ApiDataUtils.parseArray(new String(apiDefinitionBlob.getRequest()), HttpResponse.class);
for (HttpResponse httpResponse : httpResponses) {
List<ApiFile> responseFiles = apiCommonService.getApiBodyFiles(httpResponse.getBody())
.stream()
.filter(file -> StringUtils.equals(fileId, file.getFileId()))
.toList();
apiFiles.addAll(responseFiles);
}
return apiFiles;
}
private Object getMsElementParam(MsHTTPElement msHTTPElement) {
return JSON.parseObject(ApiDataUtils.toJSONString(msHTTPElement));
}
@ -312,8 +347,14 @@ public class ApiDefinitionControllerTests extends BaseTest {
copyApiDefinitionDTO.setCustomFields(customFieldMap.get(apiDefinition.getId()));
}
if (apiDefinitionBlob != null) {
copyApiDefinitionDTO.setRequest(ApiDataUtils.parseObject(new String(apiDefinitionBlob.getRequest()), AbstractMsTestElement.class));
copyApiDefinitionDTO.setResponse(ApiDataUtils.parseArray(new String(apiDefinitionBlob.getResponse()), HttpResponse.class));
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiDefinitionBlob.getRequest()), AbstractMsTestElement.class);
apiCommonService.updateLinkFileInfo(apiDefinition.getId(), msTestElement);
copyApiDefinitionDTO.setRequest(msTestElement);
List<HttpResponse> httpResponses = ApiDataUtils.parseArray(new String(apiDefinitionBlob.getResponse()), HttpResponse.class);
for (HttpResponse httpResponse : httpResponses) {
apiCommonService.updateLinkFileInfo(apiDefinition.getId(), httpResponse.getBody());
}
copyApiDefinitionDTO.setResponse(httpResponses);
}
Assertions.assertEquals(apiDefinitionDTO, copyApiDefinitionDTO);
@ -345,7 +386,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
request.setResponse(msHttpResponse);
// 清除文件的更新
request.setUnLinkRefIds(List.of(fileMetadataId));
request.setUnLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(List.of(uploadFileId));
this.requestPostWithOk(UPDATE, request);
// 校验请求成功数据
@ -358,7 +399,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
request.setUploadFileIds(List.of(fileId));
request.setLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(null);
request.setUnLinkRefIds(null);
request.setUnLinkFileIds(null);
this.requestPostWithOk(UPDATE, request);
// 校验请求成功数据
apiDefinition = assertAddApiDefinition(request, msHttpElement, request.getId());
@ -369,7 +410,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
request.setDeleteFileIds(List.of(fileId));
String newFileId1 = doUploadTempFile(getMockMultipartFile("file_upload.JPG"));
request.setUploadFileIds(List.of(newFileId1));
request.setUnLinkRefIds(List.of(fileMetadataId));
request.setUnLinkFileIds(List.of(fileMetadataId));
request.setLinkFileIds(List.of(fileMetadataId));
this.requestPostWithOk(UPDATE, request);
apiDefinition = assertAddApiDefinition(request, msHttpElement, request.getId());
@ -379,7 +420,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
// 已有一个文件再上传一个文件
String newFileId2 = doUploadTempFile(getMockMultipartFile("file_update_upload.JPG"));
request.setUploadFileIds(List.of(newFileId2));
request.setUnLinkRefIds(null);
request.setUnLinkFileIds(null);
request.setDeleteFileIds(null);
request.setLinkFileIds(null);
this.requestPostWithOk(UPDATE, request);
@ -394,7 +435,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
request.setUploadFileIds(null);
request.setLinkFileIds(null);
request.setDeleteFileIds(null);
request.setUnLinkRefIds(null);
request.setUnLinkFileIds(null);
assertErrorCode(this.requestPost(UPDATE, request), ApiResultCode.API_DEFINITION_EXIST);
// @@响应名+响应码唯一校验异常
@ -498,18 +539,6 @@ public class ApiDefinitionControllerTests extends BaseTest {
return list;
}
/**
* 文件管理插入一条数据
* 便于测试关联文件
*/
private void uploadFileMetadata() throws Exception {
FileUploadRequest fileUploadRequest = new FileUploadRequest();
fileUploadRequest.setProjectId(DEFAULT_PROJECT_ID);
//导入正常文件
MockMultipartFile file = new MockMultipartFile("file", "file_update_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
fileMetadataId = fileMetadataService.upload(fileUploadRequest, "admin", file);
}
/**
* 校验上传的文件
*

View File

@ -4,6 +4,7 @@ import io.metersphere.api.constants.ApiConstants;
import io.metersphere.api.constants.ApiDefinitionStatus;
import io.metersphere.api.controller.result.ApiResultCode;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.definition.request.ApiDefinitionMockAddRequest;
import io.metersphere.api.dto.definition.request.ApiDefinitionMockPageRequest;
@ -212,8 +213,9 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
MockResponse mockResponse = new MockResponse();
mockResponse.setBody(new ResponseBody() {{
this.setBinaryBody(new ResponseBinaryBody() {{
this.setFileId(uploadFileId);
this.setFileName("file_upload.JPG");
this.setFile(new ApiFile());
this.getFile().setFileId(uploadFileId);
this.getFile().setFileName("file_upload.JPG");
}});
}});
request.setResponse(mockResponse);
@ -303,7 +305,7 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
request.setResponse(new MockResponse());
// 清除文件的更新
request.setUnLinkRefIds(List.of(fileMetadataId));
request.setUnLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(List.of(uploadFileId));
this.requestPostWithOk(UPDATE, request);
@ -317,7 +319,7 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
request.setUploadFileIds(List.of(fileId));
request.setLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(null);
request.setUnLinkRefIds(null);
request.setUnLinkFileIds(null);
this.requestPostWithOk(UPDATE, request);
// 校验请求成功数据
apiDefinitionMock = mockServerTestService.assertAddApiDefinitionMock(request, mockMatchRule, request.getId());
@ -328,7 +330,7 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
request.setDeleteFileIds(List.of(fileId));
String newFileId1 = doUploadTempFile(mockServerTestService.getMockMultipartFile("file_upload.JPG"));
request.setUploadFileIds(List.of(newFileId1));
request.setUnLinkRefIds(List.of(fileMetadataId));
request.setUnLinkFileIds(List.of(fileMetadataId));
request.setLinkFileIds(List.of(fileMetadataId));
this.requestPostWithOk(UPDATE, request);
apiDefinitionMock = mockServerTestService.assertAddApiDefinitionMock(request, mockMatchRule, request.getId());
@ -338,7 +340,7 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
// 已有一个文件再上传一个文件
String newFileId2 = doUploadTempFile(mockServerTestService.getMockMultipartFile("file_update_upload.JPG"));
request.setUploadFileIds(List.of(newFileId2));
request.setUnLinkRefIds(null);
request.setUnLinkFileIds(null);
request.setDeleteFileIds(null);
request.setLinkFileIds(null);
this.requestPostWithOk(UPDATE, request);
@ -347,7 +349,7 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
mockServerTestService.assertLinkFile(apiDefinitionMock.getId(), List.of(fileMetadataId));
// 修改 tags
request.setUploadFileIds(null);
request.setUnLinkRefIds(null);
request.setUnLinkFileIds(null);
request.setDeleteFileIds(null);
request.setLinkFileIds(null);
request.setTags(new LinkedHashSet<>(List.of("tag1", "tag2-update")));
@ -654,7 +656,7 @@ public class ApiDefinitionMockControllerTests extends BaseTest {
//判断响应体
if (StringUtils.equals(responseBody.getBodyType(), Body.BodyType.BINARY.name())) {
byte[] returnFileBytes = mockServerResponse.getContentAsByteArray();
String fileId = responseBody.getBinaryBody().getFileId();
String fileId = responseBody.getBinaryBody().getFile().getFileId();
byte[] bytes = new byte[0];
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(fileId);
if (fileMetadata != null) {

View File

@ -2,6 +2,7 @@ package io.metersphere.api.controller;
import io.metersphere.api.constants.*;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.assertion.MsAssertionConfig;
import io.metersphere.api.dto.debug.ModuleCreateRequest;
import io.metersphere.api.dto.definition.ApiDefinitionAddRequest;
@ -15,13 +16,16 @@ import io.metersphere.api.dto.response.OperationDataInfo;
import io.metersphere.api.dto.scenario.*;
import io.metersphere.api.job.ApiScenarioScheduleJob;
import io.metersphere.api.mapper.*;
import io.metersphere.api.service.ApiCommonService;
import io.metersphere.api.service.ApiScenarioBatchOperationTestService;
import io.metersphere.api.service.BaseFileManagementTestService;
import io.metersphere.api.service.BaseResourcePoolTestService;
import io.metersphere.api.service.definition.ApiDefinitionModuleService;
import io.metersphere.api.service.definition.ApiDefinitionService;
import io.metersphere.api.service.definition.ApiTestCaseService;
import io.metersphere.api.service.scenario.ApiScenarioService;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.api.KeyValueEnableParam;
import io.metersphere.project.api.assertion.MsResponseCodeAssertion;
import io.metersphere.project.api.assertion.MsScriptAssertion;
@ -157,6 +161,10 @@ public class ApiScenarioControllerTests extends BaseTest {
private ApiTestCaseMapper apiTestCaseMapper;
@Resource
private ApiDefinitionModuleService apiDefinitionModuleService;
@Resource
private BaseFileManagementTestService baseFileManagementTestService;
@Resource
private ApiCommonService apiCommonService;
private static String fileMetadataId;
private static String localFileId;
private static ApiScenario addApiScenario;
@ -256,6 +264,8 @@ public class ApiScenarioControllerTests extends BaseTest {
MockMultipartFile file = getMockMultipartFile();
localFileId = doUploadTempFile(file);
// 准备数据上传文件管理文件
fileMetadataId = baseFileManagementTestService.upload(file);
}
public void initApiScenarioTrash() {
@ -359,7 +369,11 @@ public class ApiScenarioControllerTests extends BaseTest {
}
private Object getMsHttpElementParam() {
return JSON.parseObject(ApiDataUtils.toJSONString(MsHTTPElementTest.getMsHttpElement()));
return getMsHttpElementStr(MsHTTPElementTest.getMsHttpElement());
}
private Object getMsHttpElementStr(MsHTTPElement msHTTPElement) {
return JSON.parseObject(ApiDataUtils.toJSONString(msHTTPElement));
}
/**
@ -576,8 +590,11 @@ public class ApiScenarioControllerTests extends BaseTest {
// 验证添加步骤
this.requestPostWithOk(DEFAULT_UPDATE, request);
Map<String, Object> steptDetailMap = new HashMap<>();
steptDetailMap.put(steps.get(0).getId(), getMsHttpElementParam());
steptDetailMap.put(steps.get(1).getId(), getMsHttpElementParam());
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
msHttpElement.setBody(ApiDebugControllerTests.addBodyLinkFile(msHttpElement.getBody(), fileMetadataId));
steptDetailMap.put(steps.get(0).getId(), getMsHttpElementStr(msHttpElement));
steptDetailMap.put(steps.get(1).getId(), getMsHttpElementStr(msHttpElement));
request.setSteps(steps);
request.setStepDetails(steptDetailMap);
request.setScenarioConfig(getScenarioConfig());
@ -598,6 +615,9 @@ public class ApiScenarioControllerTests extends BaseTest {
assertUpdateSteps(steps, steptDetailMap);
addApiScenarioSteps = steps;
// 测试关联的文件更新
testHandleFileAssociationUpgrade();
// @@重名校验异常
request.setName(anOtherAddApiScenario.getName());
assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), API_SCENARIO_EXIST);
@ -607,6 +627,36 @@ public class ApiScenarioControllerTests extends BaseTest {
requestPostPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_UPDATE, DEFAULT_UPDATE, request);
}
/**
* 测试关联的文件更新
* @throws Exception
*/
public void testHandleFileAssociationUpgrade() throws Exception {
List<ApiFile> originApiFiles = getApiFiles(fileMetadataId);
MockMultipartFile file = new MockMultipartFile("file", "file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
// 重新上传新文件
String newFileId = baseFileManagementTestService.reUpload(fileMetadataId, file);
// 更新关联的文件到最新文件
baseFileManagementTestService.upgrade(fileMetadataId, addApiScenario.getId());
// 校验文件是否替换
Assertions.assertEquals(originApiFiles.size(), getApiFiles(newFileId).size());
fileMetadataId = newFileId;
}
private List<ApiFile> getApiFiles(String fileId) {
ApiScenarioStepBlobExample example = new ApiScenarioStepBlobExample();
example.createCriteria().andScenarioIdEqualTo(addApiScenario.getId());
List<ApiScenarioStepBlob> apiScenarioStepBlobs = apiScenarioStepBlobMapper.selectByExampleWithBLOBs(example);
List<ApiFile> apiFiles = new ArrayList<>();
for (ApiScenarioStepBlob apiScenarioStepBlob : apiScenarioStepBlobs) {
try {
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiScenarioStepBlob.getContent()), AbstractMsTestElement.class);
apiFiles.addAll(apiCommonService.getApiFilesByFileId(fileId, msTestElement));
} catch (Exception e) {}
}
return apiFiles;
}
@Test
@Order(5)
public void uploadTempFile() throws Exception {
@ -899,7 +949,7 @@ public class ApiScenarioControllerTests extends BaseTest {
private static MockMultipartFile getMockMultipartFile() {
MockMultipartFile file = new MockMultipartFile(
"file",
"file_upload.JPG",
IDGenerator.nextStr() + "_file_upload.JPG",
MediaType.APPLICATION_OCTET_STREAM_VALUE,
"Hello, World!".getBytes()
);

View File

@ -3,19 +3,20 @@ package io.metersphere.api.controller;
import io.metersphere.api.constants.ApiConstants;
import io.metersphere.api.controller.param.ApiTestCaseAddRequestDefinition;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.request.http.MsHTTPElement;
import io.metersphere.api.mapper.*;
import io.metersphere.api.service.ApiCommonService;
import io.metersphere.api.service.ApiFileResourceService;
import io.metersphere.api.service.BaseFileManagementTestService;
import io.metersphere.api.service.definition.ApiReportService;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.domain.ProjectVersion;
import io.metersphere.project.dto.filemanagement.FileInfo;
import io.metersphere.project.dto.filemanagement.request.FileUploadRequest;
import io.metersphere.project.mapper.ProjectVersionMapper;
import io.metersphere.project.service.FileAssociationService;
import io.metersphere.project.service.FileMetadataService;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.domain.EnvironmentExample;
@ -112,8 +113,6 @@ public class ApiTestCaseControllerTests extends BaseTest {
private ExtApiTestCaseMapper extApiTestCaseMapper;
private static String uploadFileId;
@Resource
private FileMetadataService fileMetadataService;
@Resource
private ApiReportService apiReportService;
@Resource
private ProjectVersionMapper projectVersionMapper;
@ -121,6 +120,10 @@ public class ApiTestCaseControllerTests extends BaseTest {
private OperationHistoryService operationHistoryService;
@Resource
private ApiTestCaseRecordMapper apiTestCaseRecordMapper;
@Resource
private BaseFileManagementTestService baseFileManagementTestService;
@Resource
private ApiCommonService apiCommonService;
public static <T> T parseObjectFromMvcResult(MvcResult mvcResult, Class<T> parseClass) {
try {
@ -209,7 +212,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
private static MockMultipartFile getMockMultipartFile() {
MockMultipartFile file = new MockMultipartFile(
"file",
"file_upload.JPG",
IDGenerator.nextStr() + "_file_upload.JPG",
MediaType.APPLICATION_OCTET_STREAM_VALUE,
"Hello, World!".getBytes()
);
@ -261,20 +264,6 @@ public class ApiTestCaseControllerTests extends BaseTest {
Assertions.assertEquals(fileIds, linkFileIds);
}
@Test
@Order(0)
/**
* 文件管理插入一条数据
* 便于测试关联文件
*/
public void uploadFileMetadata() throws Exception {
FileUploadRequest fileUploadRequest = new FileUploadRequest();
fileUploadRequest.setProjectId(DEFAULT_PROJECT_ID);
//导入正常文件
MockMultipartFile file = new MockMultipartFile("file", "case_file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
fileMetadataId = fileMetadataService.upload(fileUploadRequest, "admin", file);
}
@Test
@Order(1)
public void uploadTempFile() throws Exception {
@ -290,6 +279,9 @@ public class ApiTestCaseControllerTests extends BaseTest {
requestUploadPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_ADD, UPLOAD_TEMP_FILE, file);
requestUploadPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE, UPLOAD_TEMP_FILE, file);
// 准备数据上传文件管理文件
fileMetadataId = baseFileManagementTestService.upload(file);
}
private ApiTestCase assertUpdateApiDebug(Object request, MsHTTPElement msHttpElement, String id) {
@ -326,6 +318,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
request.setTags(new LinkedHashSet<>(List.of("tag1", "tag2")));
request.setEnvironmentId(environments.get(0).getId());
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
msHttpElement.setBody(ApiDebugControllerTests.addBodyLinkFile(msHttpElement.getBody(), fileMetadataId));
request.setRequest(getMsElementParam(msHttpElement));
uploadFileId = doUploadTempFile(getMockMultipartFile());
@ -351,6 +344,9 @@ public class ApiTestCaseControllerTests extends BaseTest {
assertUploadFile(resultData.getId(), List.of());
assertLinkFile(resultData.getId(), List.of());
// 测试关联的文件更新
testHandleFileAssociationUpgrade();
// @@重名校验异常
this.requestPost(ADD, request).andExpect(ERROR_REQUEST_MATCHER);
// 校验接口是否存在
@ -374,6 +370,28 @@ public class ApiTestCaseControllerTests extends BaseTest {
}
/**
* 测试关联的文件更新
* @throws Exception
*/
public void testHandleFileAssociationUpgrade() throws Exception {
List<ApiFile> originApiFiles = getApiFiles(fileMetadataId);
MockMultipartFile file = new MockMultipartFile("file", "file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "aa".getBytes());
// 重新上传新文件
String newFileId = baseFileManagementTestService.reUpload(fileMetadataId, file);
// 更新关联的文件到最新文件
baseFileManagementTestService.upgrade(fileMetadataId, apiTestCase.getId());
// 校验文件是否替换
Assertions.assertEquals(originApiFiles.size(), getApiFiles(newFileId).size());
fileMetadataId = newFileId;
}
private List<ApiFile> getApiFiles(String fileId) {
ApiTestCaseBlob apiTestCaseBlob = apiTestCaseBlobMapper.selectByPrimaryKey(apiTestCase.getId());
AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(new String(apiTestCaseBlob.getRequest()), AbstractMsTestElement.class);
return apiCommonService.getApiFilesByFileId(fileId, msTestElement);
}
private Object getMsElementParam(MsHTTPElement msHTTPElement) {
return JSON.parseObject(ApiDataUtils.toJSONString(msHTTPElement));
}
@ -499,7 +517,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
MsHTTPElement msHttpElement = MsHTTPElementTest.getMsHttpElement();
request.setRequest(getMsElementParam(msHttpElement));
// 不带文件的更新
request.setUnLinkRefIds(List.of(fileMetadataId));
request.setUnLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(List.of(uploadFileId));
this.requestPostWithOk(UPDATE, request);
// 校验请求成功数据
@ -517,7 +535,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
request.setUploadFileIds(List.of(fileId));
request.setLinkFileIds(List.of(fileMetadataId));
request.setDeleteFileIds(null);
request.setUnLinkRefIds(null);
request.setUnLinkFileIds(null);
this.requestPostWithOk(UPDATE, request);
// 校验请求成功数据
assertUpdateApiDebug(request, msHttpElement, request.getId());
@ -528,7 +546,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
request.setDeleteFileIds(List.of(fileId));
String newFileId1 = doUploadTempFile(getMockMultipartFile());
request.setUploadFileIds(List.of(newFileId1));
request.setUnLinkRefIds(List.of(fileMetadataId));
request.setUnLinkFileIds(List.of(fileMetadataId));
request.setLinkFileIds(List.of(fileMetadataId));
this.requestPostWithOk(UPDATE, request);
assertUpdateApiDebug(request, msHttpElement, request.getId());

View File

@ -62,7 +62,6 @@ public class MsHTTPElementTest {
formDataKV.setEncode(true);
formDataKV.setMaxLength(10);
formDataKV.setMinLength(8);
formDataKV.setParamType("text");
formDataKV.setDescription("test");
formDataKV.setRequired(true);
formDataKV.setValue("@email");
@ -73,7 +72,9 @@ public class MsHTTPElementTest {
bodyFile.setFileName("aaa");
formDataFileKV.setFiles(List.of(bodyFile));
formDataFileKV.setKey("fileKey");
formDataBody.setFormValues(List.of(formDataKV));
List<FormDataKV> formDataKVS = new ArrayList<>();
formDataKVS.add(formDataFileKV);
formDataBody.setFormValues(formDataKVS);
body.setFormDataBody(formDataBody);
WWWFormKV wwwFormKV = BeanUtils.copyBean(new WWWFormKV(), formDataKV);
@ -82,7 +83,9 @@ public class MsHTTPElementTest {
body.setWwwFormBody(wwwFormBody);
JsonBody jsonBody = new JsonBody();
jsonBody.setJsonSchema(new JsonSchemaItem());
JsonSchemaItem jsonSchemaItem = new JsonSchemaItem();
jsonSchemaItem.setId("11");
jsonBody.setJsonSchema(jsonSchemaItem);
jsonBody.setEnableJsonSchema(false);
body.setJsonBody(jsonBody);

View File

@ -0,0 +1,70 @@
package io.metersphere.api.service;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileAssociationExample;
import io.metersphere.project.dto.filemanagement.FileLogRecord;
import io.metersphere.project.dto.filemanagement.request.FileBatchProcessRequest;
import io.metersphere.project.dto.filemanagement.request.FileReUploadRequest;
import io.metersphere.project.dto.filemanagement.request.FileUploadRequest;
import io.metersphere.project.mapper.FileAssociationMapper;
import io.metersphere.project.service.FileAssociationService;
import io.metersphere.project.service.FileManagementService;
import io.metersphere.project.service.FileMetadataService;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @Author: jianxing
* @CreateTime: 2023-10-20 11:32
*/
@Service
public class BaseFileManagementTestService {
@Resource
private FileMetadataService fileMetadataService;
@Resource
private FileAssociationService fileAssociationService;
@Resource
private FileAssociationMapper fileAssociationMapper;
@Resource
private FileManagementService fileManagementService;
public String upload(MultipartFile uploadFile) throws Exception {
FileUploadRequest request = new FileUploadRequest();
request.setProjectId(BaseTest.DEFAULT_PROJECT_ID);
request.setEnable(false);
return fileMetadataService.upload(request, "admin", uploadFile);
}
public String reUpload(String fileId, MultipartFile uploadFile) throws Exception {
FileReUploadRequest request = new FileReUploadRequest();
request.setFileId(fileId);
return fileMetadataService.reUpload(request, "admin", uploadFile);
}
public String upgrade(String originFileId, String resourceId) {
FileLogRecord fileLogRecord = FileLogRecord.builder()
.logModule(OperationLogModule.PROJECT_FILE_MANAGEMENT)
.operator(SessionUtils.getUserId())
.projectId(BaseTest.DEFAULT_PROJECT_ID)
.build();
FileAssociationExample example = new FileAssociationExample();
example.createCriteria().andFileIdEqualTo(originFileId)
.andSourceIdEqualTo(resourceId);
FileAssociation fileAssociation = fileAssociationMapper.selectByExample(example).get(0);
return fileAssociationService.upgrade(fileAssociation.getId(), fileLogRecord);
}
public void deleteFile(String fileId) {
FileBatchProcessRequest request = new FileBatchProcessRequest();
request.setSelectIds(List.of(fileId));
request.setProjectId(BaseTest.DEFAULT_PROJECT_ID);
fileManagementService.delete(request, SessionUtils.getUserId());
}
}

View File

@ -4,6 +4,7 @@ import io.metersphere.api.domain.ApiDefinitionBlob;
import io.metersphere.api.domain.ApiDefinitionMock;
import io.metersphere.api.domain.ApiDefinitionMockConfig;
import io.metersphere.api.domain.ApiFileResource;
import io.metersphere.api.dto.ApiFile;
import io.metersphere.api.dto.definition.HttpResponse;
import io.metersphere.api.dto.definition.ResponseBinaryBody;
import io.metersphere.api.dto.definition.ResponseBody;
@ -248,16 +249,18 @@ public class MockServerTestService {
body.setBodyType(Body.BodyType.BINARY.name());
body.setBinaryBody(new ResponseBinaryBody() {{
this.setSendAsBody(false);
this.setFileId(fileId);
this.setFileName(fileName);
this.setFile(new ApiFile());
this.getFile().setFileId(fileId);
this.getFile().setFileName(fileName);
}});
break;
case "file-body":
body.setBodyType(Body.BodyType.BINARY.name());
body.setBinaryBody(new ResponseBinaryBody() {{
this.setSendAsBody(false);
this.setFileId(fileId);
this.setFileName(fileName);
this.setFile(new ApiFile());
this.getFile().setFileId(fileId);
this.getFile().setFileName(fileName);
}});
break;
case "json":

View File

@ -0,0 +1,20 @@
package io.metersphere.project.invoker;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileMetadata;
import org.springframework.stereotype.Component;
/**
* @Author: jianxing
* @CreateTime: 2024-02-06 20:48
*/
@Component
public interface FileAssociationUpdateService {
/**
* 文件管理文件-用例最新文件时调用
* @param originFileAssociation 原来的文件ID
* @param newFileMetadata 最新文件
*/
void handleUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata);
}

View File

@ -0,0 +1,28 @@
package io.metersphere.project.invoker;
import io.metersphere.project.domain.FileAssociation;
import io.metersphere.project.domain.FileMetadata;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @Author: jianxing
* @CreateTime: 2024-02-20 18:55
*/
@Component
public class FileAssociationUpdateServiceInvoker implements FileAssociationUpdateService {
private final List<FileAssociationUpdateService> fileAssociationUpdateServices;
@Autowired
public FileAssociationUpdateServiceInvoker(List<FileAssociationUpdateService> services) {
this.fileAssociationUpdateServices = services;
}
@Override
public void handleUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata) {
this.fileAssociationUpdateServices.forEach(service -> service.handleUpgrade(originFileAssociation, newFileMetadata));
}
}

View File

@ -9,6 +9,7 @@ import io.metersphere.project.dto.filemanagement.FileInfo;
import io.metersphere.project.dto.filemanagement.FileLogRecord;
import io.metersphere.project.dto.filemanagement.response.FileAssociationResponse;
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
import io.metersphere.project.invoker.FileAssociationUpdateServiceInvoker;
import io.metersphere.project.mapper.ExtFileAssociationMapper;
import io.metersphere.project.mapper.FileAssociationMapper;
import io.metersphere.sdk.exception.MSException;
@ -19,7 +20,6 @@ import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -41,7 +41,7 @@ public class FileAssociationService {
@Resource
private FileAssociationLogService fileAssociationLogService;
@Resource
private SqlSessionFactory sqlSessionFactory;
private FileAssociationUpdateServiceInvoker fileAssociationUpdateServiceInvoker;
@Resource
private ExtFileAssociationMapper extFileAssociationMapper;
@ -199,6 +199,8 @@ public class FileAssociationService {
}
FileMetadata newFileMetadata = this.getNewVersionFileMetadata(fileAssociation.getFileId());
// 通知其他服务更新引用的文件
fileAssociationUpdateServiceInvoker.handleUpgrade(fileAssociation, newFileMetadata);
if(StringUtils.equals(newFileMetadata.getId(),fileAssociation.getFileId())){
return fileAssociation.getFileId();
}else {
@ -348,4 +350,12 @@ public class FileAssociationService {
public List<FileAssociation> getFileAssociations(List<String> sourceIds, String sourceType) {
return extFileAssociationMapper.selectFileIdsBySourceId(sourceIds, sourceType);
}
public List<FileAssociation> getByFileIdAndSourceId(String sourceId, String fileId) {
FileAssociationExample example = new FileAssociationExample();
example.createCriteria()
.andSourceIdEqualTo(sourceId)
.andFileIdEqualTo(fileId);
return fileAssociationMapper.selectByExample(example);
}
}

View File

@ -2572,5 +2572,8 @@ public class FileManagementControllerTests extends BaseTest {
this.checkLog(checkLogModel.getResourceId(), checkLogModel.getOperationType(), checkLogModel.getUrl());
}
}
// 接口模块单测调过了这里增加项目模块通过率
fileAssociationService.getByFileIdAndSourceId("a", "b");
}
}

View File

@ -93,8 +93,8 @@ public abstract class BaseTest {
protected static final String DEFAULT_UPDATE = "update";
protected static final String DEFAULT_DELETE = "delete/{0}";
protected static final String DEFAULT_USER_PASSWORD = "metersphere";
protected static final String DEFAULT_PROJECT_ID = "100001100001";
protected static final String DEFAULT_ORGANIZATION_ID = "100001";
public static final String DEFAULT_PROJECT_ID = "100001100001";
public static final String DEFAULT_ORGANIZATION_ID = "100001";
/**
* 可以重写该方法定义 BASE_PATH