Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
ee7cb505
提交
ee7cb505
authored
2月 03, 2023
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
infra:完善 file 的单元测试
上级
ac661150
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
69 行增加
和
60 行删除
+69
-60
FileConfigService.java
...er/yudao/module/infra/service/file/FileConfigService.java
+0
-10
FileConfigServiceImpl.java
...udao/module/infra/service/file/FileConfigServiceImpl.java
+5
-11
FileServiceImpl.java
...oder/yudao/module/infra/service/file/FileServiceImpl.java
+1
-1
TestDemoServiceImpl.java
.../yudao/module/infra/service/test/TestDemoServiceImpl.java
+2
-2
ConfigServiceImplTest.java
...ao/module/infra/service/config/ConfigServiceImplTest.java
+1
-1
FileConfigServiceImplTest.java
.../module/infra/service/file/FileConfigServiceImplTest.java
+55
-30
FileServiceImplTest.java
.../yudao/module/infra/service/file/FileServiceImplTest.java
+5
-5
没有找到文件。
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java
浏览文件 @
ee7cb505
...
...
@@ -8,8 +8,6 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigU
import
cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO
;
import
javax.validation.Valid
;
import
java.util.Collection
;
import
java.util.List
;
/**
* 文件配置 Service 接口
...
...
@@ -60,14 +58,6 @@ public interface FileConfigService {
*/
FileConfigDO
getFileConfig
(
Long
id
);
/**
* 获得文件配置列表
*
* @param ids 编号
* @return 文件配置列表
*/
List
<
FileConfigDO
>
getFileConfigList
(
Collection
<
Long
>
ids
);
/**
* 获得文件配置分页
*
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java
浏览文件 @
ee7cb505
...
...
@@ -27,7 +27,6 @@ import org.springframework.validation.annotation.Validated;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
javax.validation.Validator
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -95,7 +94,7 @@ public class FileConfigServiceImpl implements FileConfigService {
@Override
public
void
updateFileConfig
(
FileConfigUpdateReqVO
updateReqVO
)
{
// 校验存在
FileConfigDO
config
=
this
.
validateFileConfigExists
(
updateReqVO
.
getId
());
FileConfigDO
config
=
validateFileConfigExists
(
updateReqVO
.
getId
());
// 更新
FileConfigDO
updateObj
=
FileConfigConvert
.
INSTANCE
.
convert
(
updateReqVO
)
.
setConfig
(
parseClientConfig
(
config
.
getStorage
(),
updateReqVO
.
getConfig
()));
...
...
@@ -108,7 +107,7 @@ public class FileConfigServiceImpl implements FileConfigService {
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateFileConfigMaster
(
Long
id
)
{
// 校验存在
this
.
validateFileConfigExists
(
id
);
validateFileConfigExists
(
id
);
// 更新其它为非 master
fileConfigMapper
.
updateBatch
(
new
FileConfigDO
().
setMaster
(
false
));
// 更新
...
...
@@ -138,9 +137,9 @@ public class FileConfigServiceImpl implements FileConfigService {
@Override
public
void
deleteFileConfig
(
Long
id
)
{
// 校验存在
FileConfigDO
config
=
this
.
validateFileConfigExists
(
id
);
FileConfigDO
config
=
validateFileConfigExists
(
id
);
if
(
Boolean
.
TRUE
.
equals
(
config
.
getMaster
()))
{
throw
exception
(
FILE_CONFIG_DELETE_FAIL_MASTER
);
throw
exception
(
FILE_CONFIG_DELETE_FAIL_MASTER
);
}
// 删除
fileConfigMapper
.
deleteById
(
id
);
...
...
@@ -161,11 +160,6 @@ public class FileConfigServiceImpl implements FileConfigService {
return
fileConfigMapper
.
selectById
(
id
);
}
@Override
public
List
<
FileConfigDO
>
getFileConfigList
(
Collection
<
Long
>
ids
)
{
return
fileConfigMapper
.
selectBatchIds
(
ids
);
}
@Override
public
PageResult
<
FileConfigDO
>
getFileConfigPage
(
FileConfigPageReqVO
pageReqVO
)
{
return
fileConfigMapper
.
selectPage
(
pageReqVO
);
...
...
@@ -174,7 +168,7 @@ public class FileConfigServiceImpl implements FileConfigService {
@Override
public
String
testFileConfig
(
Long
id
)
throws
Exception
{
// 校验存在
this
.
validateFileConfigExists
(
id
);
validateFileConfigExists
(
id
);
// 上传文件
byte
[]
content
=
ResourceUtil
.
readBytes
(
"file/erweima.jpg"
);
return
fileClientFactory
.
getFileClient
(
id
).
upload
(
content
,
IdUtil
.
fastSimpleUUID
()
+
".jpg"
,
"image/jpeg"
);
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
浏览文件 @
ee7cb505
...
...
@@ -69,7 +69,7 @@ public class FileServiceImpl implements FileService {
@Override
public
void
deleteFile
(
Long
id
)
throws
Exception
{
// 校验存在
FileDO
file
=
this
.
validateFileExists
(
id
);
FileDO
file
=
validateFileExists
(
id
);
// 从文件存储器中删除
FileClient
client
=
fileConfigService
.
getFileClient
(
file
.
getConfigId
());
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/test/TestDemoServiceImpl.java
浏览文件 @
ee7cb505
...
...
@@ -45,7 +45,7 @@ public class TestDemoServiceImpl implements TestDemoService {
@CacheEvict
(
value
=
"test"
,
key
=
"#updateReqVO.id"
)
public
void
updateTestDemo
(
TestDemoUpdateReqVO
updateReqVO
)
{
// 校验存在
this
.
validateTestDemoExists
(
updateReqVO
.
getId
());
validateTestDemoExists
(
updateReqVO
.
getId
());
// 更新
TestDemoDO
updateObj
=
TestDemoConvert
.
INSTANCE
.
convert
(
updateReqVO
);
testDemoMapper
.
updateById
(
updateObj
);
...
...
@@ -55,7 +55,7 @@ public class TestDemoServiceImpl implements TestDemoService {
@CacheEvict
(
value
=
"test"
,
key
=
"#id"
)
public
void
deleteTestDemo
(
Long
id
)
{
// 校验存在
this
.
validateTestDemoExists
(
id
);
validateTestDemoExists
(
id
);
// 删除
testDemoMapper
.
deleteById
(
id
);
}
...
...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceTest.java
→
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigService
Impl
Test.java
浏览文件 @
ee7cb505
...
...
@@ -29,7 +29,7 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
@Import
(
ConfigServiceImpl
.
class
)
public
class
ConfigServiceTest
extends
BaseDbUnitTest
{
public
class
ConfigService
Impl
Test
extends
BaseDbUnitTest
{
@Resource
private
ConfigServiceImpl
configService
;
...
...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java
浏览文件 @
ee7cb505
...
...
@@ -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
());
...
...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
→
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileService
Impl
Test.java
浏览文件 @
ee7cb505
...
...
@@ -16,7 +16,7 @@ import org.springframework.context.annotation.Import;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
util
.
date
.
DateUtils
.
buildLocalDate
Time
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
util
.
date
.
LocalDateTimeUtils
.
build
Time
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
test
.
core
.
util
.
AssertUtils
.
assertServiceException
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
test
.
core
.
util
.
RandomUtils
.*;
import
static
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
.
ErrorCodeConstants
.
FILE_NOT_EXISTS
;
...
...
@@ -25,7 +25,7 @@ import static org.mockito.ArgumentMatchers.same;
import
static
org
.
mockito
.
Mockito
.*;
@Import
({
FileServiceImpl
.
class
})
public
class
FileServiceTest
extends
BaseDbUnitTest
{
public
class
FileService
Impl
Test
extends
BaseDbUnitTest
{
@Resource
private
FileService
fileService
;
...
...
@@ -42,7 +42,7 @@ public class FileServiceTest extends BaseDbUnitTest {
FileDO
dbFile
=
randomPojo
(
FileDO
.
class
,
o
->
{
// 等会查询到
o
.
setPath
(
"yunai"
);
o
.
setType
(
"image/jpg"
);
o
.
setCreateTime
(
build
LocalDate
Time
(
2021
,
1
,
15
));
o
.
setCreateTime
(
buildTime
(
2021
,
1
,
15
));
});
fileMapper
.
insert
(
dbFile
);
// 测试 path 不匹配
...
...
@@ -53,13 +53,13 @@ public class FileServiceTest extends BaseDbUnitTest {
}));
// 测试 createTime 不匹配
fileMapper
.
insert
(
ObjectUtils
.
cloneIgnoreId
(
dbFile
,
o
->
{
o
.
setCreateTime
(
build
LocalDate
Time
(
2020
,
1
,
15
));
o
.
setCreateTime
(
buildTime
(
2020
,
1
,
15
));
}));
// 准备参数
FilePageReqVO
reqVO
=
new
FilePageReqVO
();
reqVO
.
setPath
(
"yunai"
);
reqVO
.
setType
(
"jp"
);
reqVO
.
setCreateTime
((
new
LocalDateTime
[]{
build
LocalDateTime
(
2021
,
1
,
10
),
buildLocalDate
Time
(
2021
,
1
,
20
)}));
reqVO
.
setCreateTime
((
new
LocalDateTime
[]{
build
Time
(
2021
,
1
,
10
),
build
Time
(
2021
,
1
,
20
)}));
// 调用
PageResult
<
FileDO
>
pageResult
=
fileService
.
getFilePage
(
reqVO
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论