|
@@ -0,0 +1,162 @@
|
|
|
+// package cn.iocoder.yudao.module.asset.service.assetinfo;
|
|
|
+//
|
|
|
+// 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.asset.controller.admin.assetinfo.vo.*;
|
|
|
+// import cn.iocoder.yudao.module.asset.dal.dataobject.assetinfo.AssetInfoDO;
|
|
|
+// import cn.iocoder.yudao.module.asset.dal.mysql.assetinfo.AssetInfoMapper;
|
|
|
+// 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.asset.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 AssetInfoServiceImpl} 的单元测试类
|
|
|
+// *
|
|
|
+// * @author dp
|
|
|
+// */
|
|
|
+// @Import(AssetInfoServiceImpl.class)
|
|
|
+// public class AssetInfoServiceImplTest extends BaseDbUnitTest {
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private AssetInfoServiceImpl infoService;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private AssetInfoMapper infoMapper;
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testCreateInfo_success() {
|
|
|
+// // 准备参数
|
|
|
+// AssetInfoSaveReqVO createReqVO = randomPojo(AssetInfoSaveReqVO.class).setId(null);
|
|
|
+//
|
|
|
+// // 调用
|
|
|
+// Long infoId = infoService.createInfo(createReqVO);
|
|
|
+// // 断言
|
|
|
+// assertNotNull(infoId);
|
|
|
+// // 校验记录的属性是否正确
|
|
|
+// AssetInfoDO info = infoMapper.selectById(infoId);
|
|
|
+// assertPojoEquals(createReqVO, info, "id");
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testUpdateInfo_success() {
|
|
|
+// // mock 数据
|
|
|
+// AssetInfoDO dbInfo = randomPojo(AssetInfoDO.class);
|
|
|
+// infoMapper.insert(dbInfo);// @Sql: 先插入出一条存在的数据
|
|
|
+// // 准备参数
|
|
|
+// AssetInfoSaveReqVO updateReqVO = randomPojo(AssetInfoSaveReqVO.class, o -> {
|
|
|
+// o.setId(dbInfo.getId()); // 设置更新的 ID
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 调用
|
|
|
+// infoService.updateInfo(updateReqVO);
|
|
|
+// // 校验是否更新正确
|
|
|
+// AssetInfoDO info = infoMapper.selectById(updateReqVO.getId()); // 获取最新的
|
|
|
+// assertPojoEquals(updateReqVO, info);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testUpdateInfo_notExists() {
|
|
|
+// // 准备参数
|
|
|
+// AssetInfoSaveReqVO updateReqVO = randomPojo(AssetInfoSaveReqVO.class);
|
|
|
+//
|
|
|
+// // 调用, 并断言异常
|
|
|
+// assertServiceException(() -> infoService.updateInfo(updateReqVO), INFO_NOT_EXISTS);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testDeleteInfo_success() {
|
|
|
+// // mock 数据
|
|
|
+// AssetInfoDO dbInfo = randomPojo(AssetInfoDO.class);
|
|
|
+// infoMapper.insert(dbInfo);// @Sql: 先插入出一条存在的数据
|
|
|
+// // 准备参数
|
|
|
+// Long id = dbInfo.getId();
|
|
|
+//
|
|
|
+// // 调用
|
|
|
+// infoService.deleteInfo(id);
|
|
|
+// // 校验数据不存在了
|
|
|
+// assertNull(infoMapper.selectById(id));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testDeleteInfo_notExists() {
|
|
|
+// // 准备参数
|
|
|
+// Long id = randomLongId();
|
|
|
+//
|
|
|
+// // 调用, 并断言异常
|
|
|
+// assertServiceException(() -> infoService.deleteInfo(id), INFO_NOT_EXISTS);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
|
+// public void testGetInfoPage() {
|
|
|
+// // mock 数据
|
|
|
+// AssetInfoDO dbInfo = randomPojo(AssetInfoDO.class, o -> { // 等会查询到
|
|
|
+// o.setAssetInfoUuid(null);
|
|
|
+// o.setName(null);
|
|
|
+// o.setTypeNumber(null);
|
|
|
+// o.setSerialNumber(null);
|
|
|
+// o.setCapitalizationDate(null);
|
|
|
+// o.setDepreciationYear(null);
|
|
|
+// o.setAssetState(null);
|
|
|
+// o.setReceiveEmployeeId(null);
|
|
|
+// o.setAssetDeptId(null);
|
|
|
+// });
|
|
|
+// infoMapper.insert(dbInfo);
|
|
|
+// // 测试 assetInfoUuid 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setAssetInfoUuid(null)));
|
|
|
+// // 测试 name 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setName(null)));
|
|
|
+// // 测试 typeNumber 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setTypeNumber(null)));
|
|
|
+// // 测试 serialNumber 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setSerialNumber(null)));
|
|
|
+// // 测试 capitalizationDate 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setCapitalizationDate(null)));
|
|
|
+// // 测试 depreciationYear 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setDepreciationYear(null)));
|
|
|
+// // 测试 assetState 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setAssetState(null)));
|
|
|
+// // 测试 receiveEmployeeId 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setReceiveEmployeeId(null)));
|
|
|
+// // 测试 assetDeptId 不匹配
|
|
|
+// infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setAssetDeptId(null)));
|
|
|
+// // 准备参数
|
|
|
+// AssetInfoPageReqVO reqVO = new AssetInfoPageReqVO();
|
|
|
+// reqVO.setAssetInfoUuid(null);
|
|
|
+// reqVO.setName(null);
|
|
|
+// reqVO.setTypeNumber(null);
|
|
|
+// reqVO.setSerialNumber(null);
|
|
|
+// reqVO.setCapitalizationDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+// reqVO.setDepreciationYear(null);
|
|
|
+// reqVO.setAssetState(null);
|
|
|
+// reqVO.setReceiveEmployeeId(null);
|
|
|
+// reqVO.setAssetDeptId(null);
|
|
|
+//
|
|
|
+// // 调用
|
|
|
+// PageResult<AssetInfoDO> pageResult = infoService.getInfoPage(reqVO);
|
|
|
+// // 断言
|
|
|
+// assertEquals(1, pageResult.getTotal());
|
|
|
+// assertEquals(1, pageResult.getList().size());
|
|
|
+// assertPojoEquals(dbInfo, pageResult.getList().get(0));
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|