提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.service.logger; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.pojo.PageResult; |
|
4 |
import com.iailab.framework.test.core.ut.BaseDbUnitTest; |
|
5 |
import com.iailab.framework.test.core.util.RandomUtils; |
|
6 |
import com.iailab.module.system.api.logger.dto.OperateLogCreateReqDTO; |
|
7 |
import com.iailab.module.system.api.logger.dto.OperateLogPageReqDTO; |
|
8 |
import com.iailab.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; |
|
9 |
import com.iailab.module.system.dal.dataobject.logger.OperateLogDO; |
|
10 |
import com.iailab.module.system.dal.mysql.logger.OperateLogMapper; |
|
11 |
import org.junit.jupiter.api.Test; |
|
12 |
import org.springframework.context.annotation.Import; |
|
13 |
|
|
14 |
import javax.annotation.Resource; |
|
15 |
|
|
16 |
import static com.iailab.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; |
|
17 |
import static com.iailab.framework.common.util.date.LocalDateTimeUtils.buildTime; |
|
18 |
import static com.iailab.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
|
19 |
import static com.iailab.framework.test.core.util.AssertUtils.assertPojoEquals; |
|
20 |
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
21 |
|
|
22 |
@Import({OperateLogServiceImpl.class}) |
|
23 |
public class OperateLogServiceImplTest extends BaseDbUnitTest { |
|
24 |
|
|
25 |
@Resource |
|
26 |
private OperateLogService operateLogServiceImpl; |
|
27 |
|
|
28 |
@Resource |
|
29 |
private OperateLogMapper operateLogMapper; |
|
30 |
|
|
31 |
@Test |
|
32 |
public void testCreateOperateLog() { |
|
33 |
OperateLogCreateReqDTO reqVO = RandomUtils.randomPojo(OperateLogCreateReqDTO.class); |
|
34 |
|
|
35 |
// 调研 |
|
36 |
operateLogServiceImpl.createOperateLog(reqVO); |
|
37 |
// 断言 |
|
38 |
OperateLogDO operateLogDO = operateLogMapper.selectOne(null); |
|
39 |
assertPojoEquals(reqVO, operateLogDO); |
|
40 |
} |
|
41 |
|
|
42 |
@Test |
|
43 |
public void testGetOperateLogPage_vo() { |
|
44 |
// 构造操作日志 |
|
45 |
OperateLogDO operateLogDO = RandomUtils.randomPojo(OperateLogDO.class, o -> { |
|
46 |
o.setUserId(2048L); |
|
47 |
o.setBizId(999L); |
|
48 |
o.setType("订单"); |
|
49 |
o.setSubType("创建订单"); |
|
50 |
o.setAction("修改编号为 1 的用户信息"); |
|
51 |
o.setCreateTime(buildTime(2021, 3, 6)); |
|
52 |
}); |
|
53 |
operateLogMapper.insert(operateLogDO); |
|
54 |
// 测试 userId 不匹配 |
|
55 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setUserId(1024L))); |
|
56 |
// 测试 bizId 不匹配 |
|
57 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setBizId(888L))); |
|
58 |
// 测试 type 不匹配 |
|
59 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setType("退款"))); |
|
60 |
// 测试 subType 不匹配 |
|
61 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setSubType("创建退款"))); |
|
62 |
// 测试 action 不匹配 |
|
63 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setAction("修改编号为 1 退款信息"))); |
|
64 |
// 测试 createTime 不匹配 |
|
65 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setCreateTime(buildTime(2021, 2, 6)))); |
|
66 |
|
|
67 |
// 构造调用参数 |
|
68 |
OperateLogPageReqVO reqVO = new OperateLogPageReqVO(); |
|
69 |
reqVO.setUserId(2048L); |
|
70 |
reqVO.setBizId(999L); |
|
71 |
reqVO.setType("订"); |
|
72 |
reqVO.setSubType("订单"); |
|
73 |
reqVO.setAction("用户信息"); |
|
74 |
reqVO.setCreateTime(buildBetweenTime(2021, 3, 5, 2021, 3, 7)); |
|
75 |
|
|
76 |
// 调用 |
|
77 |
PageResult<OperateLogDO> pageResult = operateLogServiceImpl.getOperateLogPage(reqVO); |
|
78 |
// 断言,只查到了一条符合条件的 |
|
79 |
assertEquals(1, pageResult.getTotal()); |
|
80 |
assertEquals(1, pageResult.getList().size()); |
|
81 |
assertPojoEquals(operateLogDO, pageResult.getList().get(0)); |
|
82 |
} |
|
83 |
|
|
84 |
@Test |
|
85 |
public void testGetOperateLogPage_dto() { |
|
86 |
// 构造操作日志 |
|
87 |
OperateLogDO operateLogDO = RandomUtils.randomPojo(OperateLogDO.class, o -> { |
|
88 |
o.setUserId(2048L); |
|
89 |
o.setBizId(999L); |
|
90 |
o.setType("订单"); |
|
91 |
}); |
|
92 |
operateLogMapper.insert(operateLogDO); |
|
93 |
// 测试 userId 不匹配 |
|
94 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setUserId(1024L))); |
|
95 |
// 测试 bizId 不匹配 |
|
96 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setBizId(888L))); |
|
97 |
// 测试 type 不匹配 |
|
98 |
operateLogMapper.insert(cloneIgnoreId(operateLogDO, o -> o.setType("退款"))); |
|
99 |
|
|
100 |
// 构造调用参数 |
|
101 |
OperateLogPageReqDTO reqDTO = new OperateLogPageReqDTO(); |
|
102 |
reqDTO.setUserId(2048L); |
|
103 |
reqDTO.setBizId(999L); |
|
104 |
reqDTO.setType("订单"); |
|
105 |
|
|
106 |
// 调用 |
|
107 |
PageResult<OperateLogDO> pageResult = operateLogServiceImpl.getOperateLogPage(reqDTO); |
|
108 |
// 断言,只查到了一条符合条件的 |
|
109 |
assertEquals(1, pageResult.getTotal()); |
|
110 |
assertEquals(1, pageResult.getList().size()); |
|
111 |
assertPojoEquals(operateLogDO, pageResult.getList().get(0)); |
|
112 |
} |
|
113 |
|
|
114 |
} |