Commit 7da46d1cfb3ebfe128f349848fa86e94899b3384
Merge branch 'master' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into pay_extension
Showing
7 changed files
with
106 additions
and
63 deletions
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/infra/service/file/InfFileServiceTest.java
| 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.file; | 1 | package cn.iocoder.yudao.adminserver.modules.infra.service.file; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.io.resource.ResourceUtil; | ||
| 4 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; | 3 | import cn.iocoder.yudao.adminserver.BaseDbUnitTest; |
| 5 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; | 4 | import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO; |
| 6 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | 5 | import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; |
| 7 | import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper; | 6 | import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper; |
| 7 | +import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; | ||
| 8 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl; | 8 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl; |
| 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | -import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; | ||
| 11 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 10 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 12 | import org.junit.jupiter.api.Test; | 11 | import org.junit.jupiter.api.Test; |
| 13 | import org.springframework.boot.test.mock.mockito.MockBean; | 12 | import org.springframework.boot.test.mock.mockito.MockBean; |
| @@ -15,14 +14,10 @@ import org.springframework.context.annotation.Import; | @@ -15,14 +14,10 @@ import org.springframework.context.annotation.Import; | ||
| 15 | 14 | ||
| 16 | import javax.annotation.Resource; | 15 | import javax.annotation.Resource; |
| 17 | 16 | ||
| 18 | -import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS; | 17 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; |
| 19 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 20 | -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS; | ||
| 21 | -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | ||
| 22 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | 19 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 23 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | ||
| 24 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; | ||
| 25 | -import static org.junit.jupiter.api.Assertions.*; | 20 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 26 | 21 | ||
| 27 | @Import({InfFileCoreServiceImpl.class, FileProperties.class}) | 22 | @Import({InfFileCoreServiceImpl.class, FileProperties.class}) |
| 28 | public class InfFileServiceTest extends BaseDbUnitTest { | 23 | public class InfFileServiceTest extends BaseDbUnitTest { |
| @@ -37,59 +32,6 @@ public class InfFileServiceTest extends BaseDbUnitTest { | @@ -37,59 +32,6 @@ public class InfFileServiceTest extends BaseDbUnitTest { | ||
| 37 | private InfFileCoreMapper fileMapper; | 32 | private InfFileCoreMapper fileMapper; |
| 38 | 33 | ||
| 39 | @Test | 34 | @Test |
| 40 | - public void testCreateFile_success() { | ||
| 41 | - // 准备参数 | ||
| 42 | - String path = randomString(); | ||
| 43 | - byte[] content = ResourceUtil.readBytes("file/erweima.jpg"); | ||
| 44 | - | ||
| 45 | - // 调用 | ||
| 46 | - String url = fileService.createFile(path, content); | ||
| 47 | - // 断言 | ||
| 48 | - assertEquals(fileProperties.getBasePath() + path, url); | ||
| 49 | - // 校验数据 | ||
| 50 | - InfFileDO file = fileMapper.selectById(path); | ||
| 51 | - assertEquals(path, file.getId()); | ||
| 52 | - assertEquals("jpg", file.getType()); | ||
| 53 | - assertArrayEquals(content, file.getContent()); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - @Test | ||
| 57 | - public void testCreateFile_exists() { | ||
| 58 | - // mock 数据 | ||
| 59 | - InfFileDO dbFile = randomPojo(InfFileDO.class); | ||
| 60 | - fileMapper.insert(dbFile); | ||
| 61 | - // 准备参数 | ||
| 62 | - String path = dbFile.getId(); // 模拟已存在 | ||
| 63 | - byte[] content = ResourceUtil.readBytes("file/erweima.jpg"); | ||
| 64 | - | ||
| 65 | - // 调用,并断言异常 | ||
| 66 | - assertServiceException(() -> fileService.createFile(path, content), FILE_PATH_EXISTS); | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - @Test | ||
| 70 | - public void testDeleteFile_success() { | ||
| 71 | - // mock 数据 | ||
| 72 | - InfFileDO dbFile = randomPojo(InfFileDO.class); | ||
| 73 | - fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据 | ||
| 74 | - // 准备参数 | ||
| 75 | - String id = dbFile.getId(); | ||
| 76 | - | ||
| 77 | - // 调用 | ||
| 78 | - fileService.deleteFile(id); | ||
| 79 | - // 校验数据不存在了 | ||
| 80 | - assertNull(fileMapper.selectById(id)); | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - @Test | ||
| 84 | - public void testDeleteFile_notExists() { | ||
| 85 | - // 准备参数 | ||
| 86 | - String id = randomString(); | ||
| 87 | - | ||
| 88 | - // 调用, 并断言异常 | ||
| 89 | - assertServiceException(() -> fileService.deleteFile(id), FILE_NOT_EXISTS); | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - @Test | ||
| 93 | public void testGetFilePage() { | 35 | public void testGetFilePage() { |
| 94 | // mock 数据 | 36 | // mock 数据 |
| 95 | InfFileDO dbFile = randomPojo(InfFileDO.class, o -> { // 等会查询到 | 37 | InfFileDO dbFile = randomPojo(InfFileDO.class, o -> { // 等会查询到 |
yudao-core-service/pom.xml
| @@ -3,9 +3,9 @@ | @@ -3,9 +3,9 @@ | ||
| 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | 4 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 5 | <parent> | 5 | <parent> |
| 6 | - <artifactId>yudao</artifactId> | ||
| 7 | <groupId>cn.iocoder.boot</groupId> | 6 | <groupId>cn.iocoder.boot</groupId> |
| 8 | - <version>1.2.0-snapshot</version> | 7 | + <artifactId>yudao</artifactId> |
| 8 | + <version>${revision}</version> | ||
| 9 | </parent> | 9 | </parent> |
| 10 | <modelVersion>4.0.0</modelVersion> | 10 | <modelVersion>4.0.0</modelVersion> |
| 11 | 11 |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/enums/SysErrorCodeConstants.java
| @@ -17,4 +17,5 @@ public interface SysErrorCodeConstants { | @@ -17,4 +17,5 @@ public interface SysErrorCodeConstants { | ||
| 17 | // ========= 文件相关 1006001000================= | 17 | // ========= 文件相关 1006001000================= |
| 18 | ErrorCode FILE_PATH_EXISTS = new ErrorCode(1006001000, "文件路径已存在"); | 18 | ErrorCode FILE_PATH_EXISTS = new ErrorCode(1006001000, "文件路径已存在"); |
| 19 | ErrorCode FILE_NOT_EXISTS = new ErrorCode(1006001002, "文件不存在"); | 19 | ErrorCode FILE_NOT_EXISTS = new ErrorCode(1006001002, "文件不存在"); |
| 20 | + | ||
| 20 | } | 21 | } |
yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreServiceTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.coreservice.modules.infra.service.file; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.io.resource.ResourceUtil; | ||
| 4 | +import cn.iocoder.yudao.coreservice.BaseDbUnitTest; | ||
| 5 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 6 | +import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper; | ||
| 7 | +import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties; | ||
| 8 | +import cn.iocoder.yudao.coreservice.modules.infra.service.file.impl.InfFileCoreServiceImpl; | ||
| 9 | +import org.junit.jupiter.api.Test; | ||
| 10 | +import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 11 | +import org.springframework.context.annotation.Import; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | + | ||
| 15 | +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_NOT_EXISTS; | ||
| 16 | +import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS; | ||
| 17 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | ||
| 18 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 19 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | ||
| 20 | +import static org.junit.jupiter.api.Assertions.*; | ||
| 21 | + | ||
| 22 | +@Import({InfFileCoreServiceImpl.class, FileProperties.class}) | ||
| 23 | +public class InfFileCoreServiceTest extends BaseDbUnitTest { | ||
| 24 | + | ||
| 25 | + @Resource | ||
| 26 | + private InfFileCoreService fileCoreService; | ||
| 27 | + | ||
| 28 | + @MockBean | ||
| 29 | + private FileProperties fileProperties; | ||
| 30 | + | ||
| 31 | + @Resource | ||
| 32 | + private InfFileCoreMapper fileMapper; | ||
| 33 | + | ||
| 34 | + @Test | ||
| 35 | + public void testCreateFile_success() { | ||
| 36 | + // 准备参数 | ||
| 37 | + String path = randomString(); | ||
| 38 | + byte[] content = ResourceUtil.readBytes("file/erweima.jpg"); | ||
| 39 | + | ||
| 40 | + // 调用 | ||
| 41 | + String url = fileCoreService.createFile(path, content); | ||
| 42 | + // 断言 | ||
| 43 | + assertEquals(fileProperties.getBasePath() + path, url); | ||
| 44 | + // 校验数据 | ||
| 45 | + InfFileDO file = fileMapper.selectById(path); | ||
| 46 | + assertEquals(path, file.getId()); | ||
| 47 | + assertEquals("jpg", file.getType()); | ||
| 48 | + assertArrayEquals(content, file.getContent()); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @Test | ||
| 52 | + public void testCreateFile_exists() { | ||
| 53 | + // mock 数据 | ||
| 54 | + InfFileDO dbFile = randomPojo(InfFileDO.class); | ||
| 55 | + fileMapper.insert(dbFile); | ||
| 56 | + // 准备参数 | ||
| 57 | + String path = dbFile.getId(); // 模拟已存在 | ||
| 58 | + byte[] content = ResourceUtil.readBytes("file/erweima.jpg"); | ||
| 59 | + | ||
| 60 | + // 调用,并断言异常 | ||
| 61 | + assertServiceException(() -> fileCoreService.createFile(path, content), FILE_PATH_EXISTS); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Test | ||
| 65 | + public void testDeleteFile_success() { | ||
| 66 | + // mock 数据 | ||
| 67 | + InfFileDO dbFile = randomPojo(InfFileDO.class); | ||
| 68 | + fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据 | ||
| 69 | + // 准备参数 | ||
| 70 | + String id = dbFile.getId(); | ||
| 71 | + | ||
| 72 | + // 调用 | ||
| 73 | + fileCoreService.deleteFile(id); | ||
| 74 | + // 校验数据不存在了 | ||
| 75 | + assertNull(fileMapper.selectById(id)); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Test | ||
| 79 | + public void testDeleteFile_notExists() { | ||
| 80 | + // 准备参数 | ||
| 81 | + String id = randomString(); | ||
| 82 | + | ||
| 83 | + // 调用, 并断言异常 | ||
| 84 | + assertServiceException(() -> fileCoreService.deleteFile(id), FILE_NOT_EXISTS); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | +} |
yudao-admin-server/src/test/resources/file/erweima.jpg renamed to yudao-core-service/src/test/resources/file/erweima.jpg
18 KB
yudao-core-service/src/test/resources/sql/clean.sql
yudao-core-service/src/test/resources/sql/create_tables.sql
| 1 | -- inf 开头的 DB | 1 | -- inf 开头的 DB |
| 2 | 2 | ||
| 3 | +CREATE TABLE IF NOT EXISTS "inf_file" ( | ||
| 4 | + "id" varchar(188) NOT NULL, | ||
| 5 | + "type" varchar(63) DEFAULT NULL, | ||
| 6 | + "content" blob NOT NULL, | ||
| 7 | + "creator" varchar(64) DEFAULT '', | ||
| 8 | + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 9 | + "updater" varchar(64) DEFAULT '', | ||
| 10 | + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| 11 | + "deleted" bit NOT NULL DEFAULT FALSE, | ||
| 12 | + PRIMARY KEY ("id") | ||
| 13 | +) COMMENT '文件表'; | ||
| 14 | + | ||
| 3 | -- sys 开头的 DB | 15 | -- sys 开头的 DB |
| 4 | 16 | ||
| 5 | CREATE TABLE IF NOT EXISTS `sys_user_session` ( | 17 | CREATE TABLE IF NOT EXISTS `sys_user_session` ( |