办公用品
This commit is contained in:
parent
e4b25d7a1a
commit
dcad4cd75f
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.home.dal.mysql.bgyp.BgypMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
@ -0,0 +1,182 @@
|
||||
package cn.iocoder.yudao.module.home.service.bgyp;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.home.controller.admin.bgyp.vo.*;
|
||||
import cn.iocoder.yudao.module.home.dal.dataobject.bgyp.BgypDO;
|
||||
import cn.iocoder.yudao.module.home.dal.mysql.bgyp.BgypMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.home.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link BgypServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 君风
|
||||
*/
|
||||
@Import(BgypServiceImpl.class)
|
||||
public class BgypServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private BgypServiceImpl bgypService;
|
||||
|
||||
@Resource
|
||||
private BgypMapper bgypMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateBgyp_success() {
|
||||
// 准备参数
|
||||
BgypSaveReqVO createReqVO = randomPojo(BgypSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long bgypId = bgypService.createBgyp(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(bgypId);
|
||||
// 校验记录的属性是否正确
|
||||
BgypDO bgyp = bgypMapper.selectById(bgypId);
|
||||
assertPojoEquals(createReqVO, bgyp, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBgyp_success() {
|
||||
// mock 数据
|
||||
BgypDO dbBgyp = randomPojo(BgypDO.class);
|
||||
bgypMapper.insert(dbBgyp);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
BgypSaveReqVO updateReqVO = randomPojo(BgypSaveReqVO.class, o -> {
|
||||
o.setId(dbBgyp.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
bgypService.updateBgyp(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
BgypDO bgyp = bgypMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, bgyp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBgyp_notExists() {
|
||||
// 准备参数
|
||||
BgypSaveReqVO updateReqVO = randomPojo(BgypSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> bgypService.updateBgyp(updateReqVO), BGYP_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBgyp_success() {
|
||||
// mock 数据
|
||||
BgypDO dbBgyp = randomPojo(BgypDO.class);
|
||||
bgypMapper.insert(dbBgyp);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbBgyp.getId();
|
||||
|
||||
// 调用
|
||||
bgypService.deleteBgyp(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(bgypMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBgyp_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> bgypService.deleteBgyp(id), BGYP_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetBgypPage() {
|
||||
// mock 数据
|
||||
BgypDO dbBgyp = randomPojo(BgypDO.class, o -> { // 等会查询到
|
||||
o.setTitle(null);
|
||||
o.setUserName(null);
|
||||
o.setDeptName(null);
|
||||
o.setDeptId(null);
|
||||
o.setUsageName(null);
|
||||
o.setUsageId(null);
|
||||
o.setUsageQuantity(null);
|
||||
o.setUnit(null);
|
||||
o.setUsagePurpose(null);
|
||||
o.setUsageDate(null);
|
||||
o.setStatus(null);
|
||||
o.setUserId(null);
|
||||
o.setProcessInstanceId(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
bgypMapper.insert(dbBgyp);
|
||||
// 测试 title 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setTitle(null)));
|
||||
// 测试 userName 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUserName(null)));
|
||||
// 测试 deptName 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setDeptName(null)));
|
||||
// 测试 deptId 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setDeptId(null)));
|
||||
// 测试 usageName 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsageName(null)));
|
||||
// 测试 usageId 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsageId(null)));
|
||||
// 测试 usageQuantity 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsageQuantity(null)));
|
||||
// 测试 unit 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUnit(null)));
|
||||
// 测试 usagePurpose 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsagePurpose(null)));
|
||||
// 测试 usageDate 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUsageDate(null)));
|
||||
// 测试 status 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setStatus(null)));
|
||||
// 测试 userId 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setUserId(null)));
|
||||
// 测试 processInstanceId 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setProcessInstanceId(null)));
|
||||
// 测试 createTime 不匹配
|
||||
bgypMapper.insert(cloneIgnoreId(dbBgyp, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
BgypPageReqVO reqVO = new BgypPageReqVO();
|
||||
reqVO.setTitle(null);
|
||||
reqVO.setUserName(null);
|
||||
reqVO.setDeptName(null);
|
||||
reqVO.setDeptId(null);
|
||||
reqVO.setUsageName(null);
|
||||
reqVO.setUsageId(null);
|
||||
reqVO.setUsageQuantity(null);
|
||||
reqVO.setUnit(null);
|
||||
reqVO.setUsagePurpose(null);
|
||||
reqVO.setUsageDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setUserId(null);
|
||||
reqVO.setProcessInstanceId(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<BgypDO> pageResult = bgypService.getBgypPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbBgyp, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user