Commit a62399fbca01d7ff4f03cef1da460609218c5f2a
1 parent
da829f7c
✅ 增加 infra logger 模块的单测覆盖率
Showing
5 changed files
with
71 additions
and
19 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java
| ... | ... | @@ -7,8 +7,6 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; |
| 7 | 7 | import org.quartz.SchedulerException; |
| 8 | 8 | |
| 9 | 9 | import javax.validation.Valid; |
| 10 | -import java.util.Collection; | |
| 11 | -import java.util.List; | |
| 12 | 10 | |
| 13 | 11 | /** |
| 14 | 12 | * 定时任务 Service 接口 |
| ... | ... | @@ -63,14 +61,6 @@ public interface JobService { |
| 63 | 61 | JobDO getJob(Long id); |
| 64 | 62 | |
| 65 | 63 | /** |
| 66 | - * 获得定时任务列表 | |
| 67 | - * | |
| 68 | - * @param ids 编号 | |
| 69 | - * @return 定时任务列表 | |
| 70 | - */ | |
| 71 | - List<JobDO> getJobList(Collection<Long> ids); | |
| 72 | - | |
| 73 | - /** | |
| 74 | 64 | * 获得定时任务分页 |
| 75 | 65 | * |
| 76 | 66 | * @param pageReqVO 分页查询 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java
| ... | ... | @@ -148,11 +148,6 @@ public class JobServiceImpl implements JobService { |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | @Override |
| 151 | - public List<JobDO> getJobList(Collection<Long> ids) { | |
| 152 | - return jobMapper.selectBatchIds(ids); | |
| 153 | - } | |
| 154 | - | |
| 155 | - @Override | |
| 156 | 151 | public PageResult<JobDO> getJobPage(JobPageReqVO pageReqVO) { |
| 157 | 152 | return jobMapper.selectPage(pageReqVO); |
| 158 | 153 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java
| ... | ... | @@ -10,8 +10,11 @@ import org.junit.jupiter.api.Test; |
| 10 | 10 | import org.springframework.context.annotation.Import; |
| 11 | 11 | |
| 12 | 12 | import javax.annotation.Resource; |
| 13 | +import java.time.Duration; | |
| 13 | 14 | import java.time.LocalDateTime; |
| 15 | +import java.util.List; | |
| 14 | 16 | |
| 17 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime; | |
| 15 | 18 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| 16 | 19 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 17 | 20 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| ... | ... | @@ -93,6 +96,28 @@ public class JobLogServiceImplTest extends BaseDbUnitTest { |
| 93 | 96 | } |
| 94 | 97 | |
| 95 | 98 | @Test |
| 99 | + public void testCleanJobLog() { | |
| 100 | + // mock 数据 | |
| 101 | + JobLogDO log01 = randomPojo(JobLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3)))) | |
| 102 | + .setExecuteIndex(1); | |
| 103 | + jobLogMapper.insert(log01); | |
| 104 | + JobLogDO log02 = randomPojo(JobLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)))) | |
| 105 | + .setExecuteIndex(1); | |
| 106 | + jobLogMapper.insert(log02); | |
| 107 | + // 准备参数 | |
| 108 | + Integer exceedDay = 2; | |
| 109 | + Integer deleteLimit = 1; | |
| 110 | + | |
| 111 | + // 调用 | |
| 112 | + Integer count = jobLogService.cleanJobLog(exceedDay, deleteLimit); | |
| 113 | + // 断言 | |
| 114 | + assertEquals(1, count); | |
| 115 | + List<JobLogDO> logs = jobLogMapper.selectList(); | |
| 116 | + assertEquals(1, logs.size()); | |
| 117 | + assertEquals(log02, logs.get(0)); | |
| 118 | + } | |
| 119 | + | |
| 120 | + @Test | |
| 96 | 121 | public void testGetJobLog() { |
| 97 | 122 | // mock 数据 |
| 98 | 123 | JobLogDO dbJobLog = randomPojo(JobLogDO.class, o -> o.setExecuteIndex(1)); | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImplTest.java
| ... | ... | @@ -12,9 +12,10 @@ import org.junit.jupiter.api.Test; |
| 12 | 12 | import org.springframework.context.annotation.Import; |
| 13 | 13 | |
| 14 | 14 | import javax.annotation.Resource; |
| 15 | +import java.time.Duration; | |
| 16 | +import java.util.List; | |
| 15 | 17 | |
| 16 | -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | |
| 17 | -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | |
| 18 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 18 | 19 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 19 | 20 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 20 | 21 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| ... | ... | @@ -74,6 +75,26 @@ public class ApiAccessLogServiceImplTest extends BaseDbUnitTest { |
| 74 | 75 | } |
| 75 | 76 | |
| 76 | 77 | @Test |
| 78 | + public void testCleanJobLog() { | |
| 79 | + // mock 数据 | |
| 80 | + ApiAccessLogDO log01 = randomPojo(ApiAccessLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3)))); | |
| 81 | + apiAccessLogMapper.insert(log01); | |
| 82 | + ApiAccessLogDO log02 = randomPojo(ApiAccessLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)))); | |
| 83 | + apiAccessLogMapper.insert(log02); | |
| 84 | + // 准备参数 | |
| 85 | + Integer exceedDay = 2; | |
| 86 | + Integer deleteLimit = 1; | |
| 87 | + | |
| 88 | + // 调用 | |
| 89 | + Integer count = apiAccessLogService.cleanAccessLog(exceedDay, deleteLimit); | |
| 90 | + // 断言 | |
| 91 | + assertEquals(1, count); | |
| 92 | + List<ApiAccessLogDO> logs = apiAccessLogMapper.selectList(); | |
| 93 | + assertEquals(1, logs.size()); | |
| 94 | + assertEquals(log02, logs.get(0)); | |
| 95 | + } | |
| 96 | + | |
| 97 | + @Test | |
| 77 | 98 | public void testCreateApiAccessLog() { |
| 78 | 99 | // 准备参数 |
| 79 | 100 | ApiAccessLogCreateReqDTO createDTO = randomPojo(ApiAccessLogCreateReqDTO.class); | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImplTest.java
| ... | ... | @@ -12,10 +12,11 @@ import org.junit.jupiter.api.Test; |
| 12 | 12 | import org.springframework.context.annotation.Import; |
| 13 | 13 | |
| 14 | 14 | import javax.annotation.Resource; |
| 15 | +import java.time.Duration; | |
| 16 | +import java.util.List; | |
| 15 | 17 | |
| 16 | 18 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 17 | -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | |
| 18 | -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | |
| 19 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 19 | 20 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 20 | 21 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 21 | 22 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| ... | ... | @@ -139,4 +140,24 @@ public class ApiErrorLogServiceImplTest extends BaseDbUnitTest { |
| 139 | 140 | API_ERROR_LOG_NOT_FOUND); |
| 140 | 141 | } |
| 141 | 142 | |
| 143 | + @Test | |
| 144 | + public void testCleanJobLog() { | |
| 145 | + // mock 数据 | |
| 146 | + ApiErrorLogDO log01 = randomPojo(ApiErrorLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3)))); | |
| 147 | + apiErrorLogMapper.insert(log01); | |
| 148 | + ApiErrorLogDO log02 = randomPojo(ApiErrorLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)))); | |
| 149 | + apiErrorLogMapper.insert(log02); | |
| 150 | + // 准备参数 | |
| 151 | + Integer exceedDay = 2; | |
| 152 | + Integer deleteLimit = 1; | |
| 153 | + | |
| 154 | + // 调用 | |
| 155 | + Integer count = apiErrorLogService.cleanErrorLog(exceedDay, deleteLimit); | |
| 156 | + // 断言 | |
| 157 | + assertEquals(1, count); | |
| 158 | + List<ApiErrorLogDO> logs = apiErrorLogMapper.selectList(); | |
| 159 | + assertEquals(1, logs.size()); | |
| 160 | + assertEquals(log02, logs.get(0)); | |
| 161 | + } | |
| 162 | + | |
| 142 | 163 | } | ... | ... |