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 个修改的文件
包含
42 行增加
和
33 行删除
+42
-33
FileConfigService.java
...er/yudao/module/infra/service/file/FileConfigService.java
+0
-10
FileConfigServiceImpl.java
...udao/module/infra/service/file/FileConfigServiceImpl.java
+4
-10
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
+29
-4
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
...
@@ -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
cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
java.util.Collection
;
import
java.util.List
;
/**
/**
* 文件配置 Service 接口
* 文件配置 Service 接口
...
@@ -60,14 +58,6 @@ public interface FileConfigService {
...
@@ -60,14 +58,6 @@ public interface FileConfigService {
*/
*/
FileConfigDO
getFileConfig
(
Long
id
);
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;
...
@@ -27,7 +27,6 @@ import org.springframework.validation.annotation.Validated;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.validation.Validator
;
import
javax.validation.Validator
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -95,7 +94,7 @@ public class FileConfigServiceImpl implements FileConfigService {
...
@@ -95,7 +94,7 @@ public class FileConfigServiceImpl implements FileConfigService {
@Override
@Override
public
void
updateFileConfig
(
FileConfigUpdateReqVO
updateReqVO
)
{
public
void
updateFileConfig
(
FileConfigUpdateReqVO
updateReqVO
)
{
// 校验存在
// 校验存在
FileConfigDO
config
=
this
.
validateFileConfigExists
(
updateReqVO
.
getId
());
FileConfigDO
config
=
validateFileConfigExists
(
updateReqVO
.
getId
());
// 更新
// 更新
FileConfigDO
updateObj
=
FileConfigConvert
.
INSTANCE
.
convert
(
updateReqVO
)
FileConfigDO
updateObj
=
FileConfigConvert
.
INSTANCE
.
convert
(
updateReqVO
)
.
setConfig
(
parseClientConfig
(
config
.
getStorage
(),
updateReqVO
.
getConfig
()));
.
setConfig
(
parseClientConfig
(
config
.
getStorage
(),
updateReqVO
.
getConfig
()));
...
@@ -108,7 +107,7 @@ public class FileConfigServiceImpl implements FileConfigService {
...
@@ -108,7 +107,7 @@ public class FileConfigServiceImpl implements FileConfigService {
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateFileConfigMaster
(
Long
id
)
{
public
void
updateFileConfigMaster
(
Long
id
)
{
// 校验存在
// 校验存在
this
.
validateFileConfigExists
(
id
);
validateFileConfigExists
(
id
);
// 更新其它为非 master
// 更新其它为非 master
fileConfigMapper
.
updateBatch
(
new
FileConfigDO
().
setMaster
(
false
));
fileConfigMapper
.
updateBatch
(
new
FileConfigDO
().
setMaster
(
false
));
// 更新
// 更新
...
@@ -138,7 +137,7 @@ public class FileConfigServiceImpl implements FileConfigService {
...
@@ -138,7 +137,7 @@ public class FileConfigServiceImpl implements FileConfigService {
@Override
@Override
public
void
deleteFileConfig
(
Long
id
)
{
public
void
deleteFileConfig
(
Long
id
)
{
// 校验存在
// 校验存在
FileConfigDO
config
=
this
.
validateFileConfigExists
(
id
);
FileConfigDO
config
=
validateFileConfigExists
(
id
);
if
(
Boolean
.
TRUE
.
equals
(
config
.
getMaster
()))
{
if
(
Boolean
.
TRUE
.
equals
(
config
.
getMaster
()))
{
throw
exception
(
FILE_CONFIG_DELETE_FAIL_MASTER
);
throw
exception
(
FILE_CONFIG_DELETE_FAIL_MASTER
);
}
}
...
@@ -161,11 +160,6 @@ public class FileConfigServiceImpl implements FileConfigService {
...
@@ -161,11 +160,6 @@ public class FileConfigServiceImpl implements FileConfigService {
return
fileConfigMapper
.
selectById
(
id
);
return
fileConfigMapper
.
selectById
(
id
);
}
}
@Override
public
List
<
FileConfigDO
>
getFileConfigList
(
Collection
<
Long
>
ids
)
{
return
fileConfigMapper
.
selectBatchIds
(
ids
);
}
@Override
@Override
public
PageResult
<
FileConfigDO
>
getFileConfigPage
(
FileConfigPageReqVO
pageReqVO
)
{
public
PageResult
<
FileConfigDO
>
getFileConfigPage
(
FileConfigPageReqVO
pageReqVO
)
{
return
fileConfigMapper
.
selectPage
(
pageReqVO
);
return
fileConfigMapper
.
selectPage
(
pageReqVO
);
...
@@ -174,7 +168,7 @@ public class FileConfigServiceImpl implements FileConfigService {
...
@@ -174,7 +168,7 @@ public class FileConfigServiceImpl implements FileConfigService {
@Override
@Override
public
String
testFileConfig
(
Long
id
)
throws
Exception
{
public
String
testFileConfig
(
Long
id
)
throws
Exception
{
// 校验存在
// 校验存在
this
.
validateFileConfigExists
(
id
);
validateFileConfigExists
(
id
);
// 上传文件
// 上传文件
byte
[]
content
=
ResourceUtil
.
readBytes
(
"file/erweima.jpg"
);
byte
[]
content
=
ResourceUtil
.
readBytes
(
"file/erweima.jpg"
);
return
fileClientFactory
.
getFileClient
(
id
).
upload
(
content
,
IdUtil
.
fastSimpleUUID
()
+
".jpg"
,
"image/jpeg"
);
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 {
...
@@ -69,7 +69,7 @@ public class FileServiceImpl implements FileService {
@Override
@Override
public
void
deleteFile
(
Long
id
)
throws
Exception
{
public
void
deleteFile
(
Long
id
)
throws
Exception
{
// 校验存在
// 校验存在
FileDO
file
=
this
.
validateFileExists
(
id
);
FileDO
file
=
validateFileExists
(
id
);
// 从文件存储器中删除
// 从文件存储器中删除
FileClient
client
=
fileConfigService
.
getFileClient
(
file
.
getConfigId
());
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 {
...
@@ -45,7 +45,7 @@ public class TestDemoServiceImpl implements TestDemoService {
@CacheEvict
(
value
=
"test"
,
key
=
"#updateReqVO.id"
)
@CacheEvict
(
value
=
"test"
,
key
=
"#updateReqVO.id"
)
public
void
updateTestDemo
(
TestDemoUpdateReqVO
updateReqVO
)
{
public
void
updateTestDemo
(
TestDemoUpdateReqVO
updateReqVO
)
{
// 校验存在
// 校验存在
this
.
validateTestDemoExists
(
updateReqVO
.
getId
());
validateTestDemoExists
(
updateReqVO
.
getId
());
// 更新
// 更新
TestDemoDO
updateObj
=
TestDemoConvert
.
INSTANCE
.
convert
(
updateReqVO
);
TestDemoDO
updateObj
=
TestDemoConvert
.
INSTANCE
.
convert
(
updateReqVO
);
testDemoMapper
.
updateById
(
updateObj
);
testDemoMapper
.
updateById
(
updateObj
);
...
@@ -55,7 +55,7 @@ public class TestDemoServiceImpl implements TestDemoService {
...
@@ -55,7 +55,7 @@ public class TestDemoServiceImpl implements TestDemoService {
@CacheEvict
(
value
=
"test"
,
key
=
"#id"
)
@CacheEvict
(
value
=
"test"
,
key
=
"#id"
)
public
void
deleteTestDemo
(
Long
id
)
{
public
void
deleteTestDemo
(
Long
id
)
{
// 校验存在
// 校验存在
this
.
validateTestDemoExists
(
id
);
validateTestDemoExists
(
id
);
// 删除
// 删除
testDemoMapper
.
deleteById
(
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.*;
...
@@ -29,7 +29,7 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
@Import
(
ConfigServiceImpl
.
class
)
@Import
(
ConfigServiceImpl
.
class
)
public
class
ConfigServiceTest
extends
BaseDbUnitTest
{
public
class
ConfigService
Impl
Test
extends
BaseDbUnitTest
{
@Resource
@Resource
private
ConfigServiceImpl
configService
;
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;
...
@@ -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.FileClient
;
import
cn.iocoder.yudao.framework.file.core.client.FileClientConfig
;
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.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.client.local.LocalFileClientConfig
;
import
cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum
;
import
cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum
;
import
cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest
;
import
cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest
;
...
@@ -41,10 +42,10 @@ import static org.mockito.ArgumentMatchers.eq;
...
@@ -41,10 +42,10 @@ import static org.mockito.ArgumentMatchers.eq;
import
static
org
.
mockito
.
Mockito
.*;
import
static
org
.
mockito
.
Mockito
.*;
/**
/**
* {@link FileConfigServiceImpl} 的单元测试类
* {@link FileConfigServiceImpl} 的单元测试类
*
*
* @author 芋道源码
* @author 芋道源码
*/
*/
@Import
(
FileConfigServiceImpl
.
class
)
@Import
(
FileConfigServiceImpl
.
class
)
public
class
FileConfigServiceImplTest
extends
BaseDbUnitTest
{
public
class
FileConfigServiceImplTest
extends
BaseDbUnitTest
{
...
@@ -242,6 +243,30 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
...
@@ -242,6 +243,30 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
assertEquals
(
"https://www.iocoder.cn"
,
fileConfigService
.
testFileConfig
(
id
));
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
()
{
private
FileConfigDO
randomFileConfigDO
()
{
return
randomPojo
(
FileConfigDO
.
class
).
setStorage
(
randomEle
(
FileStorageEnum
.
values
()).
getStorage
())
return
randomPojo
(
FileConfigDO
.
class
).
setStorage
(
randomEle
(
FileStorageEnum
.
values
()).
getStorage
())
.
setConfig
(
new
EmptyFileClientConfig
());
.
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;
...
@@ -16,7 +16,7 @@ import org.springframework.context.annotation.Import;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
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
.
AssertUtils
.
assertServiceException
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
test
.
core
.
util
.
RandomUtils
.*;
import
static
cn
.
iocoder
.
yudao
.
framework
.
test
.
core
.
util
.
RandomUtils
.*;
import
static
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
.
ErrorCodeConstants
.
FILE_NOT_EXISTS
;
import
static
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
.
ErrorCodeConstants
.
FILE_NOT_EXISTS
;
...
@@ -25,7 +25,7 @@ import static org.mockito.ArgumentMatchers.same;
...
@@ -25,7 +25,7 @@ import static org.mockito.ArgumentMatchers.same;
import
static
org
.
mockito
.
Mockito
.*;
import
static
org
.
mockito
.
Mockito
.*;
@Import
({
FileServiceImpl
.
class
})
@Import
({
FileServiceImpl
.
class
})
public
class
FileServiceTest
extends
BaseDbUnitTest
{
public
class
FileService
Impl
Test
extends
BaseDbUnitTest
{
@Resource
@Resource
private
FileService
fileService
;
private
FileService
fileService
;
...
@@ -42,7 +42,7 @@ public class FileServiceTest extends BaseDbUnitTest {
...
@@ -42,7 +42,7 @@ public class FileServiceTest extends BaseDbUnitTest {
FileDO
dbFile
=
randomPojo
(
FileDO
.
class
,
o
->
{
// 等会查询到
FileDO
dbFile
=
randomPojo
(
FileDO
.
class
,
o
->
{
// 等会查询到
o
.
setPath
(
"yunai"
);
o
.
setPath
(
"yunai"
);
o
.
setType
(
"image/jpg"
);
o
.
setType
(
"image/jpg"
);
o
.
setCreateTime
(
build
LocalDate
Time
(
2021
,
1
,
15
));
o
.
setCreateTime
(
buildTime
(
2021
,
1
,
15
));
});
});
fileMapper
.
insert
(
dbFile
);
fileMapper
.
insert
(
dbFile
);
// 测试 path 不匹配
// 测试 path 不匹配
...
@@ -53,13 +53,13 @@ public class FileServiceTest extends BaseDbUnitTest {
...
@@ -53,13 +53,13 @@ public class FileServiceTest extends BaseDbUnitTest {
}));
}));
// 测试 createTime 不匹配
// 测试 createTime 不匹配
fileMapper
.
insert
(
ObjectUtils
.
cloneIgnoreId
(
dbFile
,
o
->
{
fileMapper
.
insert
(
ObjectUtils
.
cloneIgnoreId
(
dbFile
,
o
->
{
o
.
setCreateTime
(
build
LocalDate
Time
(
2020
,
1
,
15
));
o
.
setCreateTime
(
buildTime
(
2020
,
1
,
15
));
}));
}));
// 准备参数
// 准备参数
FilePageReqVO
reqVO
=
new
FilePageReqVO
();
FilePageReqVO
reqVO
=
new
FilePageReqVO
();
reqVO
.
setPath
(
"yunai"
);
reqVO
.
setPath
(
"yunai"
);
reqVO
.
setType
(
"jp"
);
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
);
PageResult
<
FileDO
>
pageResult
=
fileService
.
getFilePage
(
reqVO
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论