|
|
|
|
@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
import cn.iocoder.yudao.framework.file.core.client.FileClient;
|
|
|
|
|
import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
|
|
|
|
|
import cn.iocoder.yudao.framework.file.core.client.FileClientFactory;
|
|
|
|
|
import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClient;
|
|
|
|
|
import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClientConfig;
|
|
|
|
|
import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum;
|
|
|
|
|
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
|
|
|
|
@ -41,10 +42,10 @@ import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@link FileConfigServiceImpl} 的单元测试类
|
|
|
|
|
*
|
|
|
|
|
* @author 芋道源码
|
|
|
|
|
*/
|
|
|
|
|
* {@link FileConfigServiceImpl} 的单元测试类
|
|
|
|
|
*
|
|
|
|
|
* @author 芋道源码
|
|
|
|
|
*/
|
|
|
|
|
@Import(FileConfigServiceImpl.class)
|
|
|
|
|
public class FileConfigServiceImplTest extends BaseDbUnitTest {
|
|
|
|
|
|
|
|
|
|
@ -171,8 +172,8 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
|
|
|
|
|
|
|
|
|
|
// 调用
|
|
|
|
|
fileConfigService.deleteFileConfig(id);
|
|
|
|
|
// 校验数据不存在了
|
|
|
|
|
assertNull(fileConfigMapper.selectById(id));
|
|
|
|
|
// 校验数据不存在了
|
|
|
|
|
assertNull(fileConfigMapper.selectById(id));
|
|
|
|
|
// verify 调用
|
|
|
|
|
verify(fileConfigProducer).sendFileConfigRefreshMessage();
|
|
|
|
|
}
|
|
|
|
|
@ -200,30 +201,30 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGetFileConfigPage() {
|
|
|
|
|
// mock 数据
|
|
|
|
|
FileConfigDO dbFileConfig = randomFileConfigDO().setName("芋道源码")
|
|
|
|
|
.setStorage(FileStorageEnum.LOCAL.getStorage());
|
|
|
|
|
dbFileConfig.setCreateTime(LocalDateTimeUtil.parse("2020-01-23", DatePattern.NORM_DATE_PATTERN));// 等会查询到
|
|
|
|
|
fileConfigMapper.insert(dbFileConfig);
|
|
|
|
|
// 测试 name 不匹配
|
|
|
|
|
fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setName("源码")));
|
|
|
|
|
// 测试 storage 不匹配
|
|
|
|
|
fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setStorage(FileStorageEnum.DB.getStorage())));
|
|
|
|
|
// 测试 createTime 不匹配
|
|
|
|
|
fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setCreateTime(LocalDateTimeUtil.parse("2020-11-23", DatePattern.NORM_DATE_PATTERN))));
|
|
|
|
|
// 准备参数
|
|
|
|
|
FileConfigPageReqVO reqVO = new FileConfigPageReqVO();
|
|
|
|
|
reqVO.setName("芋道");
|
|
|
|
|
reqVO.setStorage(FileStorageEnum.LOCAL.getStorage());
|
|
|
|
|
reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 1, 1),
|
|
|
|
|
buildTime(2020, 1, 24)}));
|
|
|
|
|
|
|
|
|
|
// 调用
|
|
|
|
|
PageResult<FileConfigDO> pageResult = fileConfigService.getFileConfigPage(reqVO);
|
|
|
|
|
// 断言
|
|
|
|
|
assertEquals(1, pageResult.getTotal());
|
|
|
|
|
assertEquals(1, pageResult.getList().size());
|
|
|
|
|
assertPojoEquals(dbFileConfig, pageResult.getList().get(0));
|
|
|
|
|
// mock 数据
|
|
|
|
|
FileConfigDO dbFileConfig = randomFileConfigDO().setName("芋道源码")
|
|
|
|
|
.setStorage(FileStorageEnum.LOCAL.getStorage());
|
|
|
|
|
dbFileConfig.setCreateTime(LocalDateTimeUtil.parse("2020-01-23", DatePattern.NORM_DATE_PATTERN));// 等会查询到
|
|
|
|
|
fileConfigMapper.insert(dbFileConfig);
|
|
|
|
|
// 测试 name 不匹配
|
|
|
|
|
fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setName("源码")));
|
|
|
|
|
// 测试 storage 不匹配
|
|
|
|
|
fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setStorage(FileStorageEnum.DB.getStorage())));
|
|
|
|
|
// 测试 createTime 不匹配
|
|
|
|
|
fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setCreateTime(LocalDateTimeUtil.parse("2020-11-23", DatePattern.NORM_DATE_PATTERN))));
|
|
|
|
|
// 准备参数
|
|
|
|
|
FileConfigPageReqVO reqVO = new FileConfigPageReqVO();
|
|
|
|
|
reqVO.setName("芋道");
|
|
|
|
|
reqVO.setStorage(FileStorageEnum.LOCAL.getStorage());
|
|
|
|
|
reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 1, 1),
|
|
|
|
|
buildTime(2020, 1, 24)}));
|
|
|
|
|
|
|
|
|
|
// 调用
|
|
|
|
|
PageResult<FileConfigDO> pageResult = fileConfigService.getFileConfigPage(reqVO);
|
|
|
|
|
// 断言
|
|
|
|
|
assertEquals(1, pageResult.getTotal());
|
|
|
|
|
assertEquals(1, pageResult.getList().size());
|
|
|
|
|
assertPojoEquals(dbFileConfig, pageResult.getList().get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@ -242,6 +243,30 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
|
|
|
|
|
assertEquals("https://www.iocoder.cn", fileConfigService.testFileConfig(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGetFileConfig() {
|
|
|
|
|
// mock 数据
|
|
|
|
|
FileConfigDO dbFileConfig = randomFileConfigDO().setMaster(false);
|
|
|
|
|
fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据
|
|
|
|
|
// 准备参数
|
|
|
|
|
Long id = dbFileConfig.getId();
|
|
|
|
|
|
|
|
|
|
// 调用,并断言
|
|
|
|
|
assertPojoEquals(dbFileConfig, fileConfigService.getFileConfig(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGetFileClient() {
|
|
|
|
|
// 准备参数
|
|
|
|
|
Long id = randomLongId();
|
|
|
|
|
// mock 获得 Client
|
|
|
|
|
FileClient fileClient = new LocalFileClient(id, new LocalFileClientConfig());
|
|
|
|
|
when(fileClientFactory.getFileClient(eq(id))).thenReturn(fileClient);
|
|
|
|
|
|
|
|
|
|
// 调用,并断言
|
|
|
|
|
assertSame(fileClient, fileConfigService.getFileClient(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private FileConfigDO randomFileConfigDO() {
|
|
|
|
|
return randomPojo(FileConfigDO.class).setStorage(randomEle(FileStorageEnum.values()).getStorage())
|
|
|
|
|
.setConfig(new EmptyFileClientConfig());
|
|
|
|
|
|