feat(项目设置): 文件管理增加jar文件开启/关闭功能

This commit is contained in:
song-tianyang 2023-10-30 18:36:45 +08:00 committed by Craftsman
parent 9ef52a211d
commit e24437d4bb
19 changed files with 290 additions and 49 deletions

View File

@ -1,16 +1,12 @@
package io.metersphere.project.domain;
import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated;
import io.metersphere.validation.groups.*;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import lombok.Data;
@Data
public class FileMetadata implements Serializable {
@ -69,6 +65,9 @@ public class FileMetadata implements Serializable {
@NotNull(message = "{file_metadata.latest.not_blank}", groups = {Created.class})
private Boolean latest;
@Schema(description = "启用/禁用;启用禁用一般常用于jar文件")
private Boolean enable;
@Schema(description = "同版本数据关联的ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{file_metadata.ref_id.not_blank}", groups = {Created.class})
@Size(min = 1, max = 50, message = "{file_metadata.ref_id.length_range}", groups = {Created.class, Updated.class})
@ -95,6 +94,7 @@ public class FileMetadata implements Serializable {
moduleId("module_id", "moduleId", "VARCHAR", false),
path("path", "path", "VARCHAR", true),
latest("latest", "latest", "BIT", false),
enable("enable", "enable", "BIT", true),
refId("ref_id", "refId", "VARCHAR", false),
fileVersion("file_version", "fileVersion", "VARCHAR", false);

View File

@ -1114,6 +1114,66 @@ public class FileMetadataExample {
return (Criteria) this;
}
public Criteria andEnableIsNull() {
addCriterion("`enable` is null");
return (Criteria) this;
}
public Criteria andEnableIsNotNull() {
addCriterion("`enable` is not null");
return (Criteria) this;
}
public Criteria andEnableEqualTo(Boolean value) {
addCriterion("`enable` =", value, "enable");
return (Criteria) this;
}
public Criteria andEnableNotEqualTo(Boolean value) {
addCriterion("`enable` <>", value, "enable");
return (Criteria) this;
}
public Criteria andEnableGreaterThan(Boolean value) {
addCriterion("`enable` >", value, "enable");
return (Criteria) this;
}
public Criteria andEnableGreaterThanOrEqualTo(Boolean value) {
addCriterion("`enable` >=", value, "enable");
return (Criteria) this;
}
public Criteria andEnableLessThan(Boolean value) {
addCriterion("`enable` <", value, "enable");
return (Criteria) this;
}
public Criteria andEnableLessThanOrEqualTo(Boolean value) {
addCriterion("`enable` <=", value, "enable");
return (Criteria) this;
}
public Criteria andEnableIn(List<Boolean> values) {
addCriterion("`enable` in", values, "enable");
return (Criteria) this;
}
public Criteria andEnableNotIn(List<Boolean> values) {
addCriterion("`enable` not in", values, "enable");
return (Criteria) this;
}
public Criteria andEnableBetween(Boolean value1, Boolean value2) {
addCriterion("`enable` between", value1, value2, "enable");
return (Criteria) this;
}
public Criteria andEnableNotBetween(Boolean value1, Boolean value2) {
addCriterion("`enable` not between", value1, value2, "enable");
return (Criteria) this;
}
public Criteria andRefIdIsNull() {
addCriterion("ref_id is null");
return (Criteria) this;

View File

@ -17,6 +17,7 @@
<result column="module_id" jdbcType="VARCHAR" property="moduleId" />
<result column="path" jdbcType="VARCHAR" property="path" />
<result column="latest" jdbcType="BIT" property="latest" />
<result column="enable" jdbcType="BIT" property="enable" />
<result column="ref_id" jdbcType="VARCHAR" property="refId" />
<result column="file_version" jdbcType="VARCHAR" property="fileVersion" />
</resultMap>
@ -80,7 +81,7 @@
</sql>
<sql id="Base_Column_List">
id, `name`, `type`, `size`, create_time, update_time, project_id, `storage`, create_user,
update_user, tags, description, module_id, `path`, latest, ref_id, file_version
update_user, tags, description, module_id, `path`, latest, `enable`, ref_id, file_version
</sql>
<select id="selectByExample" parameterType="io.metersphere.project.domain.FileMetadataExample" resultMap="BaseResultMap">
select
@ -118,13 +119,15 @@
project_id, `storage`, create_user,
update_user, tags, description,
module_id, `path`, latest,
ref_id, file_version)
`enable`, ref_id, file_version
)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
#{size,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{projectId,jdbcType=VARCHAR}, #{storage,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR},
#{updateUser,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{moduleId,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{latest,jdbcType=BIT},
#{refId,jdbcType=VARCHAR}, #{fileVersion,jdbcType=VARCHAR})
#{enable,jdbcType=BIT}, #{refId,jdbcType=VARCHAR}, #{fileVersion,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.project.domain.FileMetadata">
insert into file_metadata
@ -174,6 +177,9 @@
<if test="latest != null">
latest,
</if>
<if test="enable != null">
`enable`,
</if>
<if test="refId != null">
ref_id,
</if>
@ -227,6 +233,9 @@
<if test="latest != null">
#{latest,jdbcType=BIT},
</if>
<if test="enable != null">
#{enable,jdbcType=BIT},
</if>
<if test="refId != null">
#{refId,jdbcType=VARCHAR},
</if>
@ -289,6 +298,9 @@
<if test="record.latest != null">
latest = #{record.latest,jdbcType=BIT},
</if>
<if test="record.enable != null">
`enable` = #{record.enable,jdbcType=BIT},
</if>
<if test="record.refId != null">
ref_id = #{record.refId,jdbcType=VARCHAR},
</if>
@ -317,6 +329,7 @@
module_id = #{record.moduleId,jdbcType=VARCHAR},
`path` = #{record.path,jdbcType=VARCHAR},
latest = #{record.latest,jdbcType=BIT},
`enable` = #{record.enable,jdbcType=BIT},
ref_id = #{record.refId,jdbcType=VARCHAR},
file_version = #{record.fileVersion,jdbcType=VARCHAR}
<if test="_parameter != null">
@ -368,6 +381,9 @@
<if test="latest != null">
latest = #{latest,jdbcType=BIT},
</if>
<if test="enable != null">
`enable` = #{enable,jdbcType=BIT},
</if>
<if test="refId != null">
ref_id = #{refId,jdbcType=VARCHAR},
</if>
@ -393,6 +409,7 @@
module_id = #{moduleId,jdbcType=VARCHAR},
`path` = #{path,jdbcType=VARCHAR},
latest = #{latest,jdbcType=BIT},
`enable` = #{enable,jdbcType=BIT},
ref_id = #{refId,jdbcType=VARCHAR},
file_version = #{fileVersion,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
@ -400,7 +417,7 @@
<insert id="batchInsert" parameterType="map">
insert into file_metadata
(id, `name`, `type`, `size`, create_time, update_time, project_id, `storage`, create_user,
update_user, tags, description, module_id, `path`, latest, ref_id, file_version
update_user, tags, description, module_id, `path`, latest, `enable`, ref_id, file_version
)
values
<foreach collection="list" item="item" separator=",">
@ -409,7 +426,8 @@
#{item.projectId,jdbcType=VARCHAR}, #{item.storage,jdbcType=VARCHAR}, #{item.createUser,jdbcType=VARCHAR},
#{item.updateUser,jdbcType=VARCHAR}, #{item.tags,jdbcType=VARCHAR}, #{item.description,jdbcType=VARCHAR},
#{item.moduleId,jdbcType=VARCHAR}, #{item.path,jdbcType=VARCHAR}, #{item.latest,jdbcType=BIT},
#{item.refId,jdbcType=VARCHAR}, #{item.fileVersion,jdbcType=VARCHAR})
#{item.enable,jdbcType=BIT}, #{item.refId,jdbcType=VARCHAR}, #{item.fileVersion,jdbcType=VARCHAR}
)
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -467,6 +485,9 @@
<if test="'latest'.toString() == column.value">
#{item.latest,jdbcType=BIT}
</if>
<if test="'enable'.toString() == column.value">
#{item.enable,jdbcType=BIT}
</if>
<if test="'ref_id'.toString() == column.value">
#{item.refId,jdbcType=VARCHAR}
</if>

View File

@ -90,6 +90,7 @@ CREATE TABLE IF NOT EXISTS file_metadata
`module_id` VARCHAR(50) COMMENT '文件所属模块',
`path` VARCHAR(1000) COMMENT '文件存储路径',
`latest` BIT NOT NULL DEFAULT 1 COMMENT '是否是最新版',
`enable` BIT NOT NULL DEFAULT 0 COMMENT '启用/禁用;启用禁用一般常用于jar文件',
`ref_id` VARCHAR(50) NOT NULL COMMENT '同版本数据关联的ID',
`file_version` VARCHAR(50) COMMENT '文件版本号',
PRIMARY KEY (id)

View File

@ -418,6 +418,8 @@ file_module.parent.not.exist=文件模块父节点不存在
upload.file.error=上传文件失败
file.not.exist=文件不存在
old.file.not.exist=旧文件不存在
file.not.jar=不是jar文件
change.jar.enable=修改了jar文件的启用状态
file.name.exist=文件名已存在
file.log.delete_module=模块下的所有数据全部被删除
file.module.root=根目录

View File

@ -454,6 +454,8 @@ file_module.parent.not.exist=File module parent does not exist
upload.file.error=Upload file error
file.not.exist=File does not exist
old.file.not.exist=Old file does not exist
file.not.jar=Not jar file
change.jar.enable=Change jar file enable
file.name.exist=File name already exists
file.log.delete_module=has be deleted
file.module.root=root module

View File

@ -453,6 +453,8 @@ file_module.parent.not.exist=文件模块父节点不存在
upload.file.error=上传文件失败
file.not.exist=文件不存在
old.file.not.exist=旧文件不存在
file.not.jar=不是jar文件
change.jar.enable=修改了jar文件的启用状态
file.name.exist=文件名已存在
file.log.delete_module=模块下的所有数据全部被删除
file.module.root=根目录

View File

@ -454,6 +454,8 @@ file_module.parent.not.exist=文件模塊父節點不存在
upload.file.error=上傳文件失敗
file.not.exist=文件不存在
old.file.not.exist=舊文件不存在
file.not.jar=不是jar文件
change.jar.enable=修改了jar文件的啟用狀態
file.name.exist=文件名已存在
file.log.delete_module=模塊下的所有數據全部被刪除
file.module.root=根目錄

View File

@ -60,7 +60,6 @@ public class FileManagementController {
return fileMetadataService.moduleCount(request, SessionUtils.getUserId());
}
@PostMapping("/upload")
@Operation(summary = "项目管理-文件管理-上传文件")
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_ADD)
@ -104,6 +103,13 @@ public class FileManagementController {
fileMetadataService.update(request, SessionUtils.getUserId());
}
@GetMapping(value = "/jar-file-status/{fileId}/{enable}")
@Operation(summary = "项目管理-文件管理-下载文件")
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_UPDATE)
public void changeJarFileStatus(@PathVariable String fileId, @PathVariable boolean enable) {
fileMetadataService.changeJarFileStatus(fileId, enable, SessionUtils.getUserId());
}
@PostMapping(value = "/batch-download")
@Operation(summary = "项目管理-文件管理-批量下载文件")
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DOWNLOAD)

View File

@ -18,6 +18,7 @@
f.path,
f.project_id,
f.size,
f.enable,
f.storage
FROM file_metadata f
INNER JOIN user updateUser ON f.update_user = updateUser.id

View File

@ -25,4 +25,7 @@ public class FileUpdateRequest {
@Schema(description = "模块ID")
private String moduleId;
@Schema(description = "开启/关闭(目前用于jar文件)")
private Boolean enable;
}

View File

@ -10,9 +10,9 @@ import io.metersphere.project.mapper.FileModuleMapper;
import io.metersphere.project.request.filemanagement.FileBatchProcessDTO;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.file.FileRequest;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.TempFileUtils;
import io.metersphere.system.file.FileRequest;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -101,18 +101,21 @@ public class FileManagementService {
public List<FileMetadata> getProcessList(FileBatchProcessDTO request) {
List<String> processIds = request.getSelectIds();
List<FileMetadata> refFileList = new ArrayList<>();
List<FileMetadata> processFileList = new ArrayList<>();
if (request.isSelectAll()) {
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
refFileList = extFileMetadataMapper.selectByKeywordAndFileType(pageDTO);
processFileList = extFileMetadataMapper.selectByKeywordAndFileType(pageDTO);
//去除未选择的文件
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
refFileList = refFileList.stream().filter(fileMetadata -> !request.getExcludeIds().contains(fileMetadata.getId())).collect(Collectors.toList());
processFileList = processFileList.stream().filter(fileMetadata -> !request.getExcludeIds().contains(fileMetadata.getId())).collect(Collectors.toList());
}
} else if (CollectionUtils.isNotEmpty(processIds)) {
refFileList = extFileMetadataMapper.selectRefIdByIds(processIds);
FileMetadataExample example = new FileMetadataExample();
example.createCriteria().andIdIn(processIds);
processFileList = fileMetadataMapper.selectByExample(example);
}
return refFileList;
return processFileList;
}
public void deleteByModuleIds(List<String> deleteModuleIds) {

View File

@ -5,12 +5,12 @@ import io.metersphere.project.domain.Project;
import io.metersphere.project.mapper.FileMetadataMapper;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.dto.builder.LogDTOBuilder;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.builder.LogDTOBuilder;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
@ -101,4 +101,21 @@ public class FileMetadataLogService {
operationLogService.batchAdd(list);
}
public void saveChangeJarFileStatusLog(FileMetadata module, boolean enable, String operator) {
Project project = projectMapper.selectByPrimaryKey(module.getProjectId());
LogDTO dto = LogDTOBuilder.builder()
.projectId(project.getId())
.organizationId(project.getOrganizationId())
.type(OperationLogType.UPDATE.name())
.module(OperationLogModule.PROJECT_FILE_MANAGEMENT)
.method(HttpMethodConstants.POST.name())
.path("/project/file/jar-file-status")
.sourceId(module.getId())
.content(Translator.get("change.jar.enable") + ":" + enable)
.originalValue(JSON.toJSONBytes(module))
.createUser(operator)
.build().getLogDTO();
operationLogService.add(dto);
}
}

View File

@ -44,6 +44,8 @@ import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
public class FileMetadataService {
private static final String JAR_FILE_PREFIX = "jar";
@Resource
private FileMetadataMapper fileMetadataMapper;
@Resource
@ -128,6 +130,7 @@ public class FileMetadataService {
fileMetadata.setSize(uploadFile.getSize());
fileMetadata.setLatest(true);
fileMetadata.setRefId(fileMetadata.getId());
fileMetadata.setEnable(false);
fileMetadataMapper.insert(fileMetadata);
//记录日志
@ -222,6 +225,12 @@ public class FileMetadataService {
if (CollectionUtils.isNotEmpty(request.getTags())) {
updateExample.setTags(JSON.toJSONString(request.getTags()));
}
if (request.getEnable() != null) {
if (!StringUtils.equalsIgnoreCase(fileMetadata.getType(), JAR_FILE_PREFIX)) {
throw new MSException(Translator.get("file.not.jar"));
}
updateExample.setEnable(request.getEnable());
}
updateExample.setUpdateUser(operator);
updateExample.setUpdateTime(System.currentTimeMillis());
fileMetadataMapper.updateByPrimaryKeySelective(updateExample);
@ -309,6 +318,7 @@ public class FileMetadataService {
fileMetadata.setUpdateUser(operator);
fileMetadata.setSize(uploadFile.getSize());
fileMetadata.setRefId(oldFile.getRefId());
fileMetadata.setEnable(oldFile.getEnable());
fileMetadata.setLatest(true);
fileMetadataMapper.insert(fileMetadata);
@ -369,4 +379,19 @@ public class FileMetadataService {
public List<String> getFileType(String projectId) {
return extFileMetadataMapper.selectFileTypeByProjectId(projectId);
}
public void changeJarFileStatus(String fileId, boolean enable, String operator) {
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(fileId);
if (fileMetadata == null) {
throw new MSException(Translator.get("file.not.exist"));
}
if (!StringUtils.equalsIgnoreCase(fileMetadata.getType(), JAR_FILE_PREFIX)) {
throw new MSException(Translator.get("file.not.jar"));
}
FileMetadata updateModel = new FileMetadata();
updateModel.setId(fileMetadata.getId());
updateModel.setEnable(enable);
fileMetadataMapper.updateByPrimaryKeySelective(updateModel);
fileMetadataLogService.saveChangeJarFileStatusLog(fileMetadata, enable, operator);
}
}

View File

@ -70,22 +70,22 @@
</javaClientGenerator>
<!--要生成的数据库表 -->
<table tableName="custom_function"/>
<table tableName="fake_error"/>
<!-- <table tableName="custom_function"/>-->
<!-- <table tableName="fake_error"/>-->
<table tableName="file_metadata"/>
<table tableName="file_module"/>
<table tableName="project"/>
<table tableName="project_application"/>
<table tableName="project_version"/>
<table tableName="file_module_blob"/>
<table tableName="custom_function_blob"/>
<table tableName="fake_error_blob"/>
<table tableName="file_metadata_blob"/>
<table tableName="project_extend"/>
<table tableName="message_task"/>
<table tableName="message_task_blob"/>
<table tableName="notification"/>
<table tableName="project_test_resource_pool"/>
<!-- <table tableName="file_module"/>-->
<!-- <table tableName="project"/>-->
<!-- <table tableName="project_application"/>-->
<!-- <table tableName="project_version"/>-->
<!-- <table tableName="file_module_blob"/>-->
<!-- <table tableName="custom_function_blob"/>-->
<!-- <table tableName="fake_error_blob"/>-->
<!-- <table tableName="file_metadata_blob"/>-->
<!-- <table tableName="project_extend"/>-->
<!-- <table tableName="message_task"/>-->
<!-- <table tableName="message_task_blob"/>-->
<!-- <table tableName="notification"/>-->
<!-- <table tableName="project_test_resource_pool"/>-->
<!-- 要忽略的字段-->
<!-- <table tableName="test_case">
<ignoreColumn column="follow_people"/>

View File

@ -10,6 +10,7 @@ import io.metersphere.project.service.FileModuleService;
import io.metersphere.project.utils.FileManagementBaseUtils;
import io.metersphere.project.utils.FileManagementRequestUtils;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.constants.StorageType;
import io.metersphere.sdk.util.JSON;
@ -58,7 +59,7 @@ public class FileManagementControllerTests extends BaseTest {
private static String reUploadFileId;
private static String picFileId;
private static String txtFileId;
private static String jarFileId;
@Resource
private FileModuleService fileModuleService;
@ -401,6 +402,26 @@ public class FileManagementControllerTests extends BaseTest {
Assertions.assertTrue(uploadedFileTypes.contains(fileType));
}
//在来个jar文件
filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test-jar.jar")).getPath();
file = new MockMultipartFile("file", "test-jar.jar", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileManagementBaseUtils.getFileBytes(filePath));
paramMap = new LinkedMultiValueMap<>();
paramMap.add("file", file);
paramMap.add("request", JSON.toJSONString(fileUploadRequest));
mvcResult = this.requestMultipartWithOkAndReturn(FileManagementRequestUtils.URL_FILE_UPLOAD, paramMap);
returnId = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData().toString();
checkLog(returnId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_UPLOAD);
FILE_ID_PATH.put(returnId, filePath);
jarFileId = returnId;
uploadedFileTypes.add("jar");
//检查文件类型获取接口有没有获取到数据
fileTypes = this.getFileType();
Assertions.assertEquals(fileTypes.size(), uploadedFileTypes.size());
for (String fileType : fileTypes) {
Assertions.assertTrue(uploadedFileTypes.contains(fileType));
}
//文件上传到a1-a1节点
BaseTreeNode a1a1Node = FileManagementBaseUtils.getNodeByName(preliminaryTreeNodes, "a1-a1");
fileUploadRequest = new FileUploadRequest();
@ -415,7 +436,6 @@ public class FileManagementControllerTests extends BaseTest {
returnId = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData().toString();
checkLog(returnId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_UPLOAD);
FILE_ID_PATH.put(returnId, filePath);
txtFileId = returnId;
uploadedFileTypes.add("txt");
//检查文件类型获取接口有没有获取到数据
@ -562,6 +582,9 @@ public class FileManagementControllerTests extends BaseTest {
String downloadMD5 = FileManagementBaseUtils.getFileMD5(fileBytes);
Assertions.assertEquals(fileMD5, downloadMD5);
}
//测试权限
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DOWNLOAD, String.format(FileManagementRequestUtils.URL_FILE_DOWNLOAD, picFileId));
}
@Test
@ -698,14 +721,24 @@ public class FileManagementControllerTests extends BaseTest {
if (MapUtils.isEmpty(FILE_ID_PATH)) {
this.fileReUploadTestSuccess();
}
//下载全部文件
//通过ID下载文件
FileBatchProcessDTO batchProcessDTO = new FileBatchProcessDTO();
batchProcessDTO.setSelectAll(true);
batchProcessDTO.setSelectAll(false);
batchProcessDTO.setProjectId(project.getId());
batchProcessDTO.setSelectIds(new ArrayList<>(FILE_ID_PATH.keySet()));
MvcResult mvcResult = this.batchDownloadFile(FileManagementRequestUtils.URL_FILE_BATCH_DOWNLOAD, batchProcessDTO);
byte[] fileBytes = mvcResult.getResponse().getContentAsByteArray();
Assertions.assertTrue(fileBytes.length > 0);
//下载全部文件
batchProcessDTO = new FileBatchProcessDTO();
batchProcessDTO.setSelectAll(true);
batchProcessDTO.setProjectId(project.getId());
mvcResult = this.batchDownloadFile(FileManagementRequestUtils.URL_FILE_BATCH_DOWNLOAD, batchProcessDTO);
fileBytes = mvcResult.getResponse().getContentAsByteArray();
Assertions.assertTrue(fileBytes.length > 0);
//全部文件大小超过默认配置(600M)的限制 事先存储20个大小为50M的数据过后删除
for (int i = 0; i < 20; i++) {
String id = "test_" + i;
@ -726,6 +759,7 @@ public class FileManagementControllerTests extends BaseTest {
fileMetadata.setSize(52428800L);
fileMetadata.setLatest(true);
fileMetadata.setRefId(fileMetadata.getId());
fileMetadata.setEnable(false);
fileMetadataMapper.insert(fileMetadata);
}
@ -748,6 +782,14 @@ public class FileManagementControllerTests extends BaseTest {
mockMvc.perform(getPostRequestBuilder(FileManagementRequestUtils.URL_FILE_BATCH_DOWNLOAD, batchProcessDTO))
.andExpect(status().is5xxServerError());
//权限判断
batchProcessDTO = new FileBatchProcessDTO();
batchProcessDTO.setSelectAll(false);
batchProcessDTO.setProjectId(DEFAULT_PROJECT_ID);
batchProcessDTO.setSelectIds(new ArrayList<>(FILE_ID_PATH.keySet()));
this.requestPostPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DOWNLOAD, FileManagementRequestUtils.URL_FILE_BATCH_DOWNLOAD, batchProcessDTO);
}
@Test
@ -895,6 +937,12 @@ public class FileManagementControllerTests extends BaseTest {
Assertions.assertTrue(list.size() == 1);
Assertions.assertTrue(StringUtils.equals(list.get(0), "tag1"));
//判断更改jar文件的启用禁用
updateRequest = new FileUpdateRequest();
updateRequest.setId(jarFileId);
updateRequest.setEnable(true);
this.requestPostWithOk(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest);
//判断什么也不改
updateRequest = new FileUpdateRequest();
updateRequest.setId(updateFileId);
@ -923,6 +971,12 @@ public class FileManagementControllerTests extends BaseTest {
updateRequest.setId(IDGenerator.nextStr());
this.requestPost(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest).andExpect(status().is5xxServerError());
//判断更改非jar文件的启用禁用
updateRequest = new FileUpdateRequest();
updateRequest.setId(picFileId);
updateRequest.setEnable(true);
this.requestPostWithOk(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest);
//模块不存在
if (MapUtils.isEmpty(FILE_ID_PATH)) {
this.fileReUploadTestSuccess();
@ -948,6 +1002,22 @@ public class FileManagementControllerTests extends BaseTest {
Assertions.assertTrue(StringUtils.isEmpty(dto.getId()));
}
@Test
@Order(24)
public void changeJarEnableTest() throws Exception {
if (MapUtils.isEmpty(FILE_ID_PATH)) {
this.fileReUploadTestSuccess();
}
//测试启用
this.requestGetWithOk(String.format(FileManagementRequestUtils.URL_CHANGE_JAR_ENABLE, jarFileId, true));
this.checkLog(jarFileId, OperationLogType.UPDATE, "/project/file/jar-file-status");
//测试禁用
this.requestGetWithOk(String.format(FileManagementRequestUtils.URL_CHANGE_JAR_ENABLE, jarFileId, false));
//文件不存在
this.requestGet(String.format(FileManagementRequestUtils.URL_CHANGE_JAR_ENABLE, IDGenerator.nextNum(), true));
//文件不是jar文件
this.requestGet(String.format(FileManagementRequestUtils.URL_CHANGE_JAR_ENABLE, picFileId, true));
}
@Test
@Order(80)
public void moveTest() throws Exception {

View File

@ -5,9 +5,10 @@ import io.metersphere.project.utils.FileManagementBaseUtils;
import io.metersphere.project.utils.FileManagementRequestUtils;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.dto.sdk.request.NodeMoveRequest;
import io.metersphere.system.uid.IDGenerator;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@ -38,7 +39,6 @@ public class FileManagementPermissionControllerTests extends BaseTest {
}
@Test
@Order(2)
public void updateModuleTestSuccess() throws Exception {
FileModuleUpdateRequest updateRequest = new FileModuleUpdateRequest();
@ -93,6 +93,7 @@ public class FileManagementPermissionControllerTests extends BaseTest {
}
@Test
@Order(6)
void moduleCountTestSuccess() throws Exception {
FileMetadataTableRequest request = new FileMetadataTableRequest() {{
this.setCurrent(1);
@ -103,6 +104,7 @@ public class FileManagementPermissionControllerTests extends BaseTest {
}
@Test
@Order(7)
public void fileDeleteSuccess() throws Exception {
FileBatchProcessDTO fileBatchProcessDTO = new FileBatchProcessDTO();
fileBatchProcessDTO.setProjectId(DEFAULT_PROJECT_ID);
@ -113,6 +115,7 @@ public class FileManagementPermissionControllerTests extends BaseTest {
}
@Test
@Order(8)
public void fileUpdateSuccess() throws Exception {
FileUpdateRequest updateRequest = new FileUpdateRequest();
@ -126,16 +129,37 @@ public class FileManagementPermissionControllerTests extends BaseTest {
@Test
@Order(9)
public void moveTest() throws Exception {
{
NodeMoveRequest request = new NodeMoveRequest();
request.setDragNodeId(TEST_ID);
request.setDropNodeId(ModuleConstants.ROOT_NODE_PARENT_ID);
request.setDropPosition(0);
this.requestPostPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_UPDATE, FileManagementRequestUtils.URL_MODULE_MOVE, request);
}
}
@Test
@Order(10)
public void moduleTreeTest() throws Exception {
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ, String.format(FileManagementRequestUtils.URL_MODULE_TREE, DEFAULT_PROJECT_ID));
}
@Test
@Order(11)
public void fileTypeTest() throws Exception {
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ, String.format(FileManagementRequestUtils.URL_FILE_TYPE, DEFAULT_PROJECT_ID));
}
@Test
@Order(12)
public void fileInfoTest() throws Exception {
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ, String.format(FileManagementRequestUtils.URL_FILE, DEFAULT_PROJECT_ID));
}
@Test
@Order(13)
public void changeJarStatusTest() throws Exception {
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_UPDATE, String.format(FileManagementRequestUtils.URL_CHANGE_JAR_ENABLE, IDGenerator.nextNum(), true));
}
@Test
@ -144,5 +168,4 @@ public class FileManagementPermissionControllerTests extends BaseTest {
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DELETE, String.format(FileManagementRequestUtils.URL_MODULE_DELETE, TEST_ID));
}
}

View File

@ -24,14 +24,16 @@ public class FileManagementRequestUtils {
public static final String URL_FILE_MODULE_COUNT = "/project/file/module/count";
//文件重传
public static final String URL_FILE_RE_UPLOAD = "/project/file/re-upload";
//文件下载
//文件下载权限判断需要提前上传文件所以放在了主测试类里
public static final String URL_FILE_DOWNLOAD = "/project/file/download/%s";
//文件预览缩略图下载
public static final String URL_FILE_PREVIEW_COMPRESSED = "/file/preview/compressed/%s/%s";
//文件预览原图下载
public static final String URL_FILE_PREVIEW_ORIGINAL = "/file/preview/original/%s/%s";
//文件批量下载
//文件批量下载 权限判断需要提前上传文件所以放在了主测试类里
public static final String URL_FILE_BATCH_DOWNLOAD = "/project/file/batch-download";
//启用/禁用jar文件
public static final String URL_CHANGE_JAR_ENABLE = "/project/file/jar-file-status/%s/%s";
//文件批量删除
public static final String URL_FILE_DELETE = "/project/file/delete";
//文件信息修改

View File

@ -0,0 +1 @@
这是用来做反例测试的