mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 17:40:05 +08:00
✅ 增加 infra logger 模块的单测覆盖率
This commit is contained in:
parent
da829f7cf5
commit
a62399fbca
@ -7,8 +7,6 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO;
|
|||||||
import org.quartz.SchedulerException;
|
import org.quartz.SchedulerException;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务 Service 接口
|
* 定时任务 Service 接口
|
||||||
@ -62,14 +60,6 @@ public interface JobService {
|
|||||||
*/
|
*/
|
||||||
JobDO getJob(Long id);
|
JobDO getJob(Long id);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得定时任务列表
|
|
||||||
*
|
|
||||||
* @param ids 编号
|
|
||||||
* @return 定时任务列表
|
|
||||||
*/
|
|
||||||
List<JobDO> getJobList(Collection<Long> ids);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得定时任务分页
|
* 获得定时任务分页
|
||||||
*
|
*
|
||||||
|
@ -147,11 +147,6 @@ public class JobServiceImpl implements JobService {
|
|||||||
return jobMapper.selectById(id);
|
return jobMapper.selectById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<JobDO> getJobList(Collection<Long> ids) {
|
|
||||||
return jobMapper.selectBatchIds(ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<JobDO> getJobPage(JobPageReqVO pageReqVO) {
|
public PageResult<JobDO> getJobPage(JobPageReqVO pageReqVO) {
|
||||||
return jobMapper.selectPage(pageReqVO);
|
return jobMapper.selectPage(pageReqVO);
|
||||||
|
@ -10,8 +10,11 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
||||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
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.assertPojoEquals;
|
||||||
@ -92,6 +95,28 @@ public class JobLogServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertEquals(result, dbLog.getResult());
|
assertEquals(result, dbLog.getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCleanJobLog() {
|
||||||
|
// mock 数据
|
||||||
|
JobLogDO log01 = randomPojo(JobLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3))))
|
||||||
|
.setExecuteIndex(1);
|
||||||
|
jobLogMapper.insert(log01);
|
||||||
|
JobLogDO log02 = randomPojo(JobLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1))))
|
||||||
|
.setExecuteIndex(1);
|
||||||
|
jobLogMapper.insert(log02);
|
||||||
|
// 准备参数
|
||||||
|
Integer exceedDay = 2;
|
||||||
|
Integer deleteLimit = 1;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Integer count = jobLogService.cleanJobLog(exceedDay, deleteLimit);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, count);
|
||||||
|
List<JobLogDO> logs = jobLogMapper.selectList();
|
||||||
|
assertEquals(1, logs.size());
|
||||||
|
assertEquals(log02, logs.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetJobLog() {
|
public void testGetJobLog() {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
|
@ -12,9 +12,10 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
|
||||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
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.assertPojoEquals;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||||
@ -73,6 +74,26 @@ public class ApiAccessLogServiceImplTest extends BaseDbUnitTest {
|
|||||||
assertPojoEquals(apiAccessLogDO, pageResult.getList().get(0));
|
assertPojoEquals(apiAccessLogDO, pageResult.getList().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCleanJobLog() {
|
||||||
|
// mock 数据
|
||||||
|
ApiAccessLogDO log01 = randomPojo(ApiAccessLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3))));
|
||||||
|
apiAccessLogMapper.insert(log01);
|
||||||
|
ApiAccessLogDO log02 = randomPojo(ApiAccessLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1))));
|
||||||
|
apiAccessLogMapper.insert(log02);
|
||||||
|
// 准备参数
|
||||||
|
Integer exceedDay = 2;
|
||||||
|
Integer deleteLimit = 1;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Integer count = apiAccessLogService.cleanAccessLog(exceedDay, deleteLimit);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, count);
|
||||||
|
List<ApiAccessLogDO> logs = apiAccessLogMapper.selectList();
|
||||||
|
assertEquals(1, logs.size());
|
||||||
|
assertEquals(log02, logs.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateApiAccessLog() {
|
public void testCreateApiAccessLog() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
|
@ -12,10 +12,11 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
|
||||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
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.assertPojoEquals;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
@ -139,4 +140,24 @@ public class ApiErrorLogServiceImplTest extends BaseDbUnitTest {
|
|||||||
API_ERROR_LOG_NOT_FOUND);
|
API_ERROR_LOG_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCleanJobLog() {
|
||||||
|
// mock 数据
|
||||||
|
ApiErrorLogDO log01 = randomPojo(ApiErrorLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3))));
|
||||||
|
apiErrorLogMapper.insert(log01);
|
||||||
|
ApiErrorLogDO log02 = randomPojo(ApiErrorLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1))));
|
||||||
|
apiErrorLogMapper.insert(log02);
|
||||||
|
// 准备参数
|
||||||
|
Integer exceedDay = 2;
|
||||||
|
Integer deleteLimit = 1;
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Integer count = apiErrorLogService.cleanErrorLog(exceedDay, deleteLimit);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, count);
|
||||||
|
List<ApiErrorLogDO> logs = apiErrorLogMapper.selectList();
|
||||||
|
assertEquals(1, logs.size());
|
||||||
|
assertEquals(log02, logs.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user