|
@@ -0,0 +1,138 @@
|
|
|
|
+// package cn.iocoder.yudao.module.system.service.agreement;
|
|
|
|
+//
|
|
|
|
+// 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.system.controller.admin.agreement.vo.*;
|
|
|
|
+// import cn.iocoder.yudao.module.system.dal.dataobject.agreement.AgreementDO;
|
|
|
|
+// import cn.iocoder.yudao.module.system.dal.mysql.agreement.AgreementMapper;
|
|
|
|
+// 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.system.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 AgreementServiceImpl} 的单元测试类
|
|
|
|
+// *
|
|
|
|
+// * @author dp
|
|
|
|
+// */
|
|
|
|
+// @Import(AgreementServiceImpl.class)
|
|
|
|
+// public class AgreementServiceImplTest extends BaseDbUnitTest {
|
|
|
|
+//
|
|
|
|
+// @Resource
|
|
|
|
+// private AgreementServiceImpl agreementService;
|
|
|
|
+//
|
|
|
|
+// @Resource
|
|
|
|
+// private AgreementMapper agreementMapper;
|
|
|
|
+//
|
|
|
|
+// @Test
|
|
|
|
+// public void testCreateAgreement_success() {
|
|
|
|
+// // 准备参数
|
|
|
|
+// AgreementSaveReqVO createReqVO = randomPojo(AgreementSaveReqVO.class).setId(null);
|
|
|
|
+//
|
|
|
|
+// // 调用
|
|
|
|
+// Long agreementId = agreementService.createAgreement(createReqVO);
|
|
|
|
+// // 断言
|
|
|
|
+// assertNotNull(agreementId);
|
|
|
|
+// // 校验记录的属性是否正确
|
|
|
|
+// AgreementDO agreement = agreementMapper.selectById(agreementId);
|
|
|
|
+// assertPojoEquals(createReqVO, agreement, "id");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Test
|
|
|
|
+// public void testUpdateAgreement_success() {
|
|
|
|
+// // mock 数据
|
|
|
|
+// AgreementDO dbAgreement = randomPojo(AgreementDO.class);
|
|
|
|
+// agreementMapper.insert(dbAgreement);// @Sql: 先插入出一条存在的数据
|
|
|
|
+// // 准备参数
|
|
|
|
+// AgreementSaveReqVO updateReqVO = randomPojo(AgreementSaveReqVO.class, o -> {
|
|
|
|
+// o.setId(dbAgreement.getId()); // 设置更新的 ID
|
|
|
|
+// });
|
|
|
|
+//
|
|
|
|
+// // 调用
|
|
|
|
+// agreementService.updateAgreement(updateReqVO);
|
|
|
|
+// // 校验是否更新正确
|
|
|
|
+// AgreementDO agreement = agreementMapper.selectById(updateReqVO.getId()); // 获取最新的
|
|
|
|
+// assertPojoEquals(updateReqVO, agreement);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Test
|
|
|
|
+// public void testUpdateAgreement_notExists() {
|
|
|
|
+// // 准备参数
|
|
|
|
+// AgreementSaveReqVO updateReqVO = randomPojo(AgreementSaveReqVO.class);
|
|
|
|
+//
|
|
|
|
+// // 调用, 并断言异常
|
|
|
|
+// assertServiceException(() -> agreementService.updateAgreement(updateReqVO), AGREEMENT_NOT_EXISTS);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Test
|
|
|
|
+// public void testDeleteAgreement_success() {
|
|
|
|
+// // mock 数据
|
|
|
|
+// AgreementDO dbAgreement = randomPojo(AgreementDO.class);
|
|
|
|
+// agreementMapper.insert(dbAgreement);// @Sql: 先插入出一条存在的数据
|
|
|
|
+// // 准备参数
|
|
|
|
+// Long id = dbAgreement.getId();
|
|
|
|
+//
|
|
|
|
+// // 调用
|
|
|
|
+// agreementService.deleteAgreement(id);
|
|
|
|
+// // 校验数据不存在了
|
|
|
|
+// assertNull(agreementMapper.selectById(id));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Test
|
|
|
|
+// public void testDeleteAgreement_notExists() {
|
|
|
|
+// // 准备参数
|
|
|
|
+// Long id = randomLongId();
|
|
|
|
+//
|
|
|
|
+// // 调用, 并断言异常
|
|
|
|
+// assertServiceException(() -> agreementService.deleteAgreement(id), AGREEMENT_NOT_EXISTS);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Test
|
|
|
|
+// @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
|
|
+// public void testGetAgreementPage() {
|
|
|
|
+// // mock 数据
|
|
|
|
+// AgreementDO dbAgreement = randomPojo(AgreementDO.class, o -> { // 等会查询到
|
|
|
|
+// o.setType(null);
|
|
|
|
+// o.setPath(null);
|
|
|
|
+// o.setContent(null);
|
|
|
|
+// });
|
|
|
|
+// agreementMapper.insert(dbAgreement);
|
|
|
|
+// // 测试 type 不匹配
|
|
|
|
+// agreementMapper.insert(cloneIgnoreId(dbAgreement, o -> o.setType(null)));
|
|
|
|
+// // 测试 path 不匹配
|
|
|
|
+// agreementMapper.insert(cloneIgnoreId(dbAgreement, o -> o.setPath(null)));
|
|
|
|
+// // 测试 content 不匹配
|
|
|
|
+// agreementMapper.insert(cloneIgnoreId(dbAgreement, o -> o.setContent(null)));
|
|
|
|
+// // 准备参数
|
|
|
|
+// AgreementPageReqVO reqVO = new AgreementPageReqVO();
|
|
|
|
+// reqVO.setType(null);
|
|
|
|
+// reqVO.setPath(null);
|
|
|
|
+// reqVO.setContent(null);
|
|
|
|
+//
|
|
|
|
+// // 调用
|
|
|
|
+// PageResult<AgreementDO> pageResult = agreementService.getAgreementPage(reqVO);
|
|
|
|
+// // 断言
|
|
|
|
+// assertEquals(1, pageResult.getTotal());
|
|
|
|
+// assertEquals(1, pageResult.getList().size());
|
|
|
|
+// assertPojoEquals(dbAgreement, pageResult.getList().get(0));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }
|