Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
dfffbe38
提交
dfffbe38
authored
2月 01, 2023
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完善 NoticeServiceImpl 单元测试
上级
608f1772
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
46 行增加
和
79 行删除
+46
-79
NoticeController.java
...dule/system/controller/admin/notice/NoticeController.java
+2
-2
NoticeService.java
...der/yudao/module/system/service/notice/NoticeService.java
+1
-1
NoticeServiceImpl.java
...yudao/module/system/service/notice/NoticeServiceImpl.java
+7
-7
NoticeServiceImplTest.java
...o/module/system/service/notice/NoticeServiceImplTest.java
+36
-69
没有找到文件。
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java
浏览文件 @
dfffbe38
...
...
@@ -57,8 +57,8 @@ public class NoticeController {
@GetMapping
(
"/page"
)
@ApiOperation
(
"获取通知公告列表"
)
@PreAuthorize
(
"@ss.hasPermission('system:notice:query')"
)
public
CommonResult
<
PageResult
<
NoticeRespVO
>>
pageNotices
(
@Validated
NoticePageReqVO
reqVO
)
{
return
success
(
NoticeConvert
.
INSTANCE
.
convertPage
(
noticeService
.
pageNotices
(
reqVO
)));
public
CommonResult
<
PageResult
<
NoticeRespVO
>>
getNoticePage
(
@Validated
NoticePageReqVO
reqVO
)
{
return
success
(
NoticeConvert
.
INSTANCE
.
convertPage
(
noticeService
.
getNoticePage
(
reqVO
)));
}
@GetMapping
(
"/get"
)
...
...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java
浏览文件 @
dfffbe38
...
...
@@ -39,7 +39,7 @@ public interface NoticeService {
* @param reqVO 分页条件
* @return 部门分页列表
*/
PageResult
<
NoticeDO
>
pageNotices
(
NoticePageReqVO
reqVO
);
PageResult
<
NoticeDO
>
getNoticePage
(
NoticePageReqVO
reqVO
);
/**
* 获得岗位公告公告信息
...
...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java
浏览文件 @
dfffbe38
package
cn
.
iocoder
.
yudao
.
module
.
system
.
service
.
notice
;
import
cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO
;
import
cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO
;
import
cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO
;
import
cn.iocoder.yudao.module.system.convert.notice.NoticeConvert
;
import
cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper
;
import
cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO
;
import
cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper
;
import
com.google.common.annotations.VisibleForTesting
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
exception
.
util
.
ServiceExceptionUtil
.
exception
;
import
static
cn
.
iocoder
.
yudao
.
module
.
system
.
enums
.
ErrorCodeConstants
.
NOTICE_NOT_FOUND
;
/**
...
...
@@ -36,7 +36,7 @@ public class NoticeServiceImpl implements NoticeService {
@Override
public
void
updateNotice
(
NoticeUpdateReqVO
reqVO
)
{
// 校验是否存在
this
.
check
NoticeExists
(
reqVO
.
getId
());
validate
NoticeExists
(
reqVO
.
getId
());
// 更新通知公告
NoticeDO
updateObj
=
NoticeConvert
.
INSTANCE
.
convert
(
reqVO
);
noticeMapper
.
updateById
(
updateObj
);
...
...
@@ -45,13 +45,13 @@ public class NoticeServiceImpl implements NoticeService {
@Override
public
void
deleteNotice
(
Long
id
)
{
// 校验是否存在
this
.
check
NoticeExists
(
id
);
validate
NoticeExists
(
id
);
// 删除通知公告
noticeMapper
.
deleteById
(
id
);
}
@Override
public
PageResult
<
NoticeDO
>
pageNotices
(
NoticePageReqVO
reqVO
)
{
public
PageResult
<
NoticeDO
>
getNoticePage
(
NoticePageReqVO
reqVO
)
{
return
noticeMapper
.
selectPage
(
reqVO
);
}
...
...
@@ -61,13 +61,13 @@ public class NoticeServiceImpl implements NoticeService {
}
@VisibleForTesting
public
void
check
NoticeExists
(
Long
id
)
{
public
void
validate
NoticeExists
(
Long
id
)
{
if
(
id
==
null
)
{
return
;
}
NoticeDO
notice
=
noticeMapper
.
selectById
(
id
);
if
(
notice
==
null
)
{
throw
ServiceExceptionUtil
.
exception
(
NOTICE_NOT_FOUND
);
throw
exception
(
NOTICE_NOT_FOUND
);
}
}
...
...
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java
浏览文件 @
dfffbe38
...
...
@@ -2,75 +2,67 @@ package cn.iocoder.yudao.module.system.service.notice;
import
cn.iocoder.yudao.framework.common.enums.CommonStatusEnum
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest
;
import
cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO
;
import
cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO
;
import
cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO
;
import
cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO
;
import
cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper
;
import
cn.iocoder.yudao.module.system.enums.notice.NoticeTypeEnum
;
import
cn.iocoder.yudao.framework.common.util.object.ObjectUtils
;
import
cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.context.annotation.Import
;
import
javax.annotation.Resource
;
import
java.util.function.Consumer
;
import
static
cn
.
hutool
.
core
.
util
.
RandomUtil
.
randomEle
;
import
static
cn
.
iocoder
.
yudao
.
module
.
system
.
enums
.
ErrorCodeConstants
.
NOTICE_NOT_FOUND
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
util
.
object
.
ObjectUtils
.
cloneIgnoreId
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
test
.
core
.
util
.
AssertUtils
.
assertPojoEquals
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
test
.
core
.
util
.
AssertUtils
.
assertServiceException
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
test
.
core
.
util
.
RandomUtils
.
randomLongId
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
test
.
core
.
util
.
RandomUtils
.
randomPojo
;
import
static
cn
.
iocoder
.
yudao
.
module
.
system
.
enums
.
ErrorCodeConstants
.
NOTICE_NOT_FOUND
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
@Import
(
NoticeServiceImpl
.
class
)
class
NoticeServiceImplTest
extends
BaseDbUnitTest
{
@Resource
private
NoticeServiceImpl
sysN
oticeService
;
private
NoticeServiceImpl
n
oticeService
;
@Resource
private
NoticeMapper
sysN
oticeMapper
;
private
NoticeMapper
n
oticeMapper
;
@Test
public
void
test
PageNotices
_success
()
{
public
void
test
GetNoticePage
_success
()
{
// 插入前置数据
NoticeDO
dbNotice
=
randomPojo
(
NoticeDO
.
class
,
o
->
{
o
.
setTitle
(
"尼古拉斯赵四来啦!"
);
o
.
setStatus
(
CommonStatusEnum
.
ENABLE
.
getStatus
());
o
.
setType
(
randomEle
(
NoticeTypeEnum
.
values
()).
getType
());
});
sysNoticeMapper
.
insert
(
dbNotice
);
noticeMapper
.
insert
(
dbNotice
);
// 测试 title 不匹配
sysNoticeMapper
.
insert
(
ObjectUtils
.
cloneIgnoreId
(
dbNotice
,
o
->
o
.
setTitle
(
"尼古拉斯凯奇也来啦!"
)));
noticeMapper
.
insert
(
cloneIgnoreId
(
dbNotice
,
o
->
o
.
setTitle
(
"尼古拉斯凯奇也来啦!"
)));
// 测试 status 不匹配
sysNoticeMapper
.
insert
(
ObjectUtils
.
cloneIgnoreId
(
dbNotice
,
o
->
o
.
setStatus
(
CommonStatusEnum
.
DISABLE
.
getStatus
())));
// 查询
noticeMapper
.
insert
(
cloneIgnoreId
(
dbNotice
,
o
->
o
.
setStatus
(
CommonStatusEnum
.
DISABLE
.
getStatus
())));
// 准备参数
NoticePageReqVO
reqVO
=
new
NoticePageReqVO
();
reqVO
.
setTitle
(
"尼古拉斯赵四来啦!"
);
reqVO
.
setStatus
(
CommonStatusEnum
.
ENABLE
.
getStatus
());
PageResult
<
NoticeDO
>
pageResult
=
sysNoticeService
.
pageNotices
(
reqVO
);
// 调用
PageResult
<
NoticeDO
>
pageResult
=
noticeService
.
getNoticePage
(
reqVO
);
// 验证查询结果经过筛选
assertEquals
(
1
,
pageResult
.
getTotal
());
assertEquals
(
1
,
pageResult
.
getList
().
size
());
assertPojoEquals
(
dbNotice
,
pageResult
.
getList
().
get
(
0
));
}
@Test
public
void
testGetNotice_success
()
{
// 插入前置数据
NoticeDO
dbNotice
=
random
NoticeDO
(
);
sysN
oticeMapper
.
insert
(
dbNotice
);
NoticeDO
dbNotice
=
random
Pojo
(
NoticeDO
.
class
);
n
oticeMapper
.
insert
(
dbNotice
);
// 查询
NoticeDO
notice
=
sysN
oticeService
.
getNotice
(
dbNotice
.
getId
());
NoticeDO
notice
=
n
oticeService
.
getNotice
(
dbNotice
.
getId
());
// 验证插入与读取对象是否一致
assertNotNull
(
notice
);
...
...
@@ -80,84 +72,59 @@ class NoticeServiceImplTest extends BaseDbUnitTest {
@Test
public
void
testCreateNotice_success
()
{
// 准备参数
NoticeCreateReqVO
reqVO
=
randomNoticeCreateReqVO
();
// 校验插入是否成功
Long
noticeId
=
sysNoticeService
.
createNotice
(
reqVO
);
assertNotNull
(
noticeId
);
NoticeCreateReqVO
reqVO
=
randomPojo
(
NoticeCreateReqVO
.
class
);
// 调用
Long
noticeId
=
noticeService
.
createNotice
(
reqVO
);
// 校验插入属性是否正确
NoticeDO
notice
=
sysNoticeMapper
.
selectById
(
noticeId
);
assertNotNull
(
noticeId
);
NoticeDO
notice
=
noticeMapper
.
selectById
(
noticeId
);
assertPojoEquals
(
reqVO
,
notice
);
}
@Test
public
void
testUpdateNotice_success
()
{
// 插入前置数据
NoticeDO
dbNoticeDO
=
random
NoticeDO
(
);
sysN
oticeMapper
.
insert
(
dbNoticeDO
);
NoticeDO
dbNoticeDO
=
random
Pojo
(
NoticeDO
.
class
);
n
oticeMapper
.
insert
(
dbNoticeDO
);
// 准备更新参数
NoticeUpdateReqVO
reqVO
=
random
NoticeUpdateReqVO
(
o
->
o
.
setId
(
dbNoticeDO
.
getId
()));
NoticeUpdateReqVO
reqVO
=
random
Pojo
(
NoticeUpdateReqVO
.
class
,
o
->
o
.
setId
(
dbNoticeDO
.
getId
()));
// 更新
sysNoticeService
.
updateNotice
(
reqVO
);
noticeService
.
updateNotice
(
reqVO
);
// 检验是否更新成功
NoticeDO
notice
=
sysN
oticeMapper
.
selectById
(
reqVO
.
getId
());
NoticeDO
notice
=
n
oticeMapper
.
selectById
(
reqVO
.
getId
());
assertPojoEquals
(
reqVO
,
notice
);
}
@Test
public
void
testDeleteNotice_success
()
{
// 插入前置数据
NoticeDO
dbNotice
=
random
NoticeDO
(
);
sysN
oticeMapper
.
insert
(
dbNotice
);
NoticeDO
dbNotice
=
random
Pojo
(
NoticeDO
.
class
);
n
oticeMapper
.
insert
(
dbNotice
);
// 删除
sysN
oticeService
.
deleteNotice
(
dbNotice
.
getId
());
n
oticeService
.
deleteNotice
(
dbNotice
.
getId
());
// 检查是否删除成功
assertNull
(
sysN
oticeMapper
.
selectById
(
dbNotice
.
getId
()));
assertNull
(
n
oticeMapper
.
selectById
(
dbNotice
.
getId
()));
}
@Test
public
void
check
NoticeExists_success
()
{
public
void
testValidate
NoticeExists_success
()
{
// 插入前置数据
NoticeDO
dbNotice
=
random
NoticeDO
(
);
sysN
oticeMapper
.
insert
(
dbNotice
);
NoticeDO
dbNotice
=
random
Pojo
(
NoticeDO
.
class
);
n
oticeMapper
.
insert
(
dbNotice
);
// 成功调用
sysNoticeService
.
check
NoticeExists
(
dbNotice
.
getId
());
noticeService
.
validate
NoticeExists
(
dbNotice
.
getId
());
}
@Test
public
void
checkNoticeExists_noExists
()
{
assertServiceException
(()
->
sysNoticeService
.
checkNoticeExists
(
randomLongId
()),
NOTICE_NOT_FOUND
);
public
void
testValidateNoticeExists_noExists
()
{
assertServiceException
(()
->
noticeService
.
validateNoticeExists
(
randomLongId
()),
NOTICE_NOT_FOUND
);
}
@SafeVarargs
private
static
NoticeDO
randomNoticeDO
(
Consumer
<
NoticeDO
>...
consumers
)
{
NoticeDO
notice
=
randomPojo
(
NoticeDO
.
class
,
consumers
);
notice
.
setType
(
randomEle
(
NoticeTypeEnum
.
values
()).
getType
());
notice
.
setStatus
(
CommonStatusEnum
.
ENABLE
.
getStatus
());
return
notice
;
}
@SafeVarargs
private
static
NoticeUpdateReqVO
randomNoticeUpdateReqVO
(
Consumer
<
NoticeUpdateReqVO
>...
consumers
)
{
NoticeUpdateReqVO
reqVO
=
randomPojo
(
NoticeUpdateReqVO
.
class
,
consumers
);
reqVO
.
setType
(
randomEle
(
NoticeTypeEnum
.
values
()).
getType
());
reqVO
.
setStatus
(
CommonStatusEnum
.
ENABLE
.
getStatus
());
return
reqVO
;
}
private
static
NoticeCreateReqVO
randomNoticeCreateReqVO
()
{
NoticeCreateReqVO
reqVO
=
randomPojo
(
NoticeCreateReqVO
.
class
);
reqVO
.
setType
(
randomEle
(
NoticeTypeEnum
.
values
()).
getType
());
reqVO
.
setStatus
(
CommonStatusEnum
.
ENABLE
.
getStatus
());
return
reqVO
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论