mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
Merge branch 'master' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into pay_extension
This commit is contained in:
commit
7da46d1cfb
@ -1,13 +1,12 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.file;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties;
|
||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
@ -15,14 +14,10 @@ import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@Import({InfFileCoreServiceImpl.class, FileProperties.class})
|
||||
public class InfFileServiceTest extends BaseDbUnitTest {
|
||||
@ -36,59 +31,6 @@ public class InfFileServiceTest extends BaseDbUnitTest {
|
||||
@Resource
|
||||
private InfFileCoreMapper fileMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateFile_success() {
|
||||
// 准备参数
|
||||
String path = randomString();
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
|
||||
// 调用
|
||||
String url = fileService.createFile(path, content);
|
||||
// 断言
|
||||
assertEquals(fileProperties.getBasePath() + path, url);
|
||||
// 校验数据
|
||||
InfFileDO file = fileMapper.selectById(path);
|
||||
assertEquals(path, file.getId());
|
||||
assertEquals("jpg", file.getType());
|
||||
assertArrayEquals(content, file.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFile_exists() {
|
||||
// mock 数据
|
||||
InfFileDO dbFile = randomPojo(InfFileDO.class);
|
||||
fileMapper.insert(dbFile);
|
||||
// 准备参数
|
||||
String path = dbFile.getId(); // 模拟已存在
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> fileService.createFile(path, content), FILE_PATH_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFile_success() {
|
||||
// mock 数据
|
||||
InfFileDO dbFile = randomPojo(InfFileDO.class);
|
||||
fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
String id = dbFile.getId();
|
||||
|
||||
// 调用
|
||||
fileService.deleteFile(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(fileMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFile_notExists() {
|
||||
// 准备参数
|
||||
String id = randomString();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> fileService.deleteFile(id), FILE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFilePage() {
|
||||
// mock 数据
|
||||
|
@ -3,9 +3,9 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yudao</artifactId>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<version>1.2.0-snapshot</version>
|
||||
<artifactId>yudao</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -17,4 +17,5 @@ public interface SysErrorCodeConstants {
|
||||
// ========= 文件相关 1006001000=================
|
||||
ErrorCode FILE_PATH_EXISTS = new ErrorCode(1006001000, "文件路径已存在");
|
||||
ErrorCode FILE_NOT_EXISTS = new ErrorCode(1006001002, "文件不存在");
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.infra.service.file;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.iocoder.yudao.coreservice.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Import({InfFileCoreServiceImpl.class, FileProperties.class})
|
||||
public class InfFileCoreServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfFileCoreService fileCoreService;
|
||||
|
||||
@MockBean
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@Resource
|
||||
private InfFileCoreMapper fileMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateFile_success() {
|
||||
// 准备参数
|
||||
String path = randomString();
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
|
||||
// 调用
|
||||
String url = fileCoreService.createFile(path, content);
|
||||
// 断言
|
||||
assertEquals(fileProperties.getBasePath() + path, url);
|
||||
// 校验数据
|
||||
InfFileDO file = fileMapper.selectById(path);
|
||||
assertEquals(path, file.getId());
|
||||
assertEquals("jpg", file.getType());
|
||||
assertArrayEquals(content, file.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFile_exists() {
|
||||
// mock 数据
|
||||
InfFileDO dbFile = randomPojo(InfFileDO.class);
|
||||
fileMapper.insert(dbFile);
|
||||
// 准备参数
|
||||
String path = dbFile.getId(); // 模拟已存在
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> fileCoreService.createFile(path, content), FILE_PATH_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFile_success() {
|
||||
// mock 数据
|
||||
InfFileDO dbFile = randomPojo(InfFileDO.class);
|
||||
fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
String id = dbFile.getId();
|
||||
|
||||
// 调用
|
||||
fileCoreService.deleteFile(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(fileMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFile_notExists() {
|
||||
// 准备参数
|
||||
String id = randomString();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> fileCoreService.deleteFile(id), FILE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
}
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
@ -1,5 +1,6 @@
|
||||
-- inf 开头的 DB
|
||||
DELETE FROM "inf_api_access_log";
|
||||
DELETE FROM "inf_file";
|
||||
DELETE FROM "inf_api_error_log";
|
||||
|
||||
-- sys 开头的 DB
|
||||
|
@ -1,5 +1,17 @@
|
||||
-- inf 开头的 DB
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "inf_file" (
|
||||
"id" varchar(188) NOT NULL,
|
||||
"type" varchar(63) DEFAULT NULL,
|
||||
"content" blob NOT NULL,
|
||||
"creator" varchar(64) DEFAULT '',
|
||||
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '文件表';
|
||||
|
||||
-- sys 开头的 DB
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sys_user_session` (
|
||||
|
Loading…
Reference in New Issue
Block a user