|
@@ -0,0 +1,158 @@
|
|
|
+package com.citu.module.menduner.system.service.enterprise;
|
|
|
+
|
|
|
+
|
|
|
+import com.citu.module.menduner.system.controller.base.enterprise.auth.EnterpriseAuthPageReqVO;
|
|
|
+import com.citu.module.menduner.system.controller.base.enterprise.auth.EnterpriseAuthSaveReqVO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseAuthDO;
|
|
|
+import com.citu.module.menduner.system.dal.mysql.enterprise.EnterpriseAuthMapper;
|
|
|
+import com.citu.module.menduner.system.service.enterprise.auth.EnterpriseAuthServiceImpl;
|
|
|
+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 com.citu.framework.test.core.ut.BaseDbUnitTest;
|
|
|
+
|
|
|
+
|
|
|
+import com.citu.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 com.citu.framework.test.core.util.AssertUtils.*;
|
|
|
+import static com.citu.framework.test.core.util.RandomUtils.*;
|
|
|
+import static com.citu.framework.common.util.date.LocalDateTimeUtils.*;
|
|
|
+import static com.citu.framework.common.util.object.ObjectUtils.*;
|
|
|
+import static com.citu.framework.common.util.date.DateUtils.*;
|
|
|
+import static com.citu.module.menduner.system.enums.ErrorCodeConstants.ENTERPRISE_AUTH_NOT_EXISTS;
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+import static org.mockito.Mockito.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link EnterpriseAuthServiceImpl} 的单元测试类
|
|
|
+ *
|
|
|
+ * @author Rayson
|
|
|
+ */
|
|
|
+@Import(EnterpriseAuthServiceImpl.class)
|
|
|
+public class EnterpriseAuthServiceImplTest extends BaseDbUnitTest {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EnterpriseAuthServiceImpl enterpriseAuthService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EnterpriseAuthMapper enterpriseAuthMapper;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCreateEnterpriseAuth_success() {
|
|
|
+ // 准备参数
|
|
|
+ EnterpriseAuthSaveReqVO createReqVO = randomPojo(EnterpriseAuthSaveReqVO.class).setId(null);
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ Long enterpriseAuthId = enterpriseAuthService.createEnterpriseAuth(createReqVO);
|
|
|
+ // 断言
|
|
|
+ assertNotNull(enterpriseAuthId);
|
|
|
+ // 校验记录的属性是否正确
|
|
|
+ EnterpriseAuthDO enterpriseAuth = enterpriseAuthMapper.selectById(enterpriseAuthId);
|
|
|
+ assertPojoEquals(createReqVO, enterpriseAuth, "id");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateEnterpriseAuth_success() {
|
|
|
+ // mock 数据
|
|
|
+ EnterpriseAuthDO dbEnterpriseAuth = randomPojo(EnterpriseAuthDO.class);
|
|
|
+ enterpriseAuthMapper.insert(dbEnterpriseAuth);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ EnterpriseAuthSaveReqVO updateReqVO = randomPojo(EnterpriseAuthSaveReqVO.class, o -> {
|
|
|
+ o.setId(dbEnterpriseAuth.getId()); // 设置更新的 ID
|
|
|
+ });
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ enterpriseAuthService.updateEnterpriseAuth(updateReqVO);
|
|
|
+ // 校验是否更新正确
|
|
|
+ EnterpriseAuthDO enterpriseAuth = enterpriseAuthMapper.selectById(updateReqVO.getId()); // 获取最新的
|
|
|
+ assertPojoEquals(updateReqVO, enterpriseAuth);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateEnterpriseAuth_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ EnterpriseAuthSaveReqVO updateReqVO = randomPojo(EnterpriseAuthSaveReqVO.class);
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> enterpriseAuthService.updateEnterpriseAuth(updateReqVO), ENTERPRISE_AUTH_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteEnterpriseAuth_success() {
|
|
|
+ // mock 数据
|
|
|
+ EnterpriseAuthDO dbEnterpriseAuth = randomPojo(EnterpriseAuthDO.class);
|
|
|
+ enterpriseAuthMapper.insert(dbEnterpriseAuth);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ Long id = dbEnterpriseAuth.getId();
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ enterpriseAuthService.deleteEnterpriseAuth(id);
|
|
|
+ // 校验数据不存在了
|
|
|
+ assertNull(enterpriseAuthMapper.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteEnterpriseAuth_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ Long id = randomLongId();
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> enterpriseAuthService.deleteEnterpriseAuth(id), ENTERPRISE_AUTH_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
|
+ public void testGetEnterpriseAuthPage() {
|
|
|
+ // mock 数据
|
|
|
+ EnterpriseAuthDO dbEnterpriseAuth = randomPojo(EnterpriseAuthDO.class, o -> { // 等会查询到
|
|
|
+ o.setEnterpriseId(null);
|
|
|
+ o.setUserId(null);
|
|
|
+ o.setName(null);
|
|
|
+ o.setIdentityNo(null);
|
|
|
+ o.setFrontUrl(null);
|
|
|
+ o.setBackUrl(null);
|
|
|
+ o.setCreateTime(null);
|
|
|
+ });
|
|
|
+ enterpriseAuthMapper.insert(dbEnterpriseAuth);
|
|
|
+ // 测试 enterpriseId 不匹配
|
|
|
+ enterpriseAuthMapper.insert(cloneIgnoreId(dbEnterpriseAuth, o -> o.setEnterpriseId(null)));
|
|
|
+ // 测试 userId 不匹配
|
|
|
+ enterpriseAuthMapper.insert(cloneIgnoreId(dbEnterpriseAuth, o -> o.setUserId(null)));
|
|
|
+ // 测试 name 不匹配
|
|
|
+ enterpriseAuthMapper.insert(cloneIgnoreId(dbEnterpriseAuth, o -> o.setName(null)));
|
|
|
+ // 测试 identityNo 不匹配
|
|
|
+ enterpriseAuthMapper.insert(cloneIgnoreId(dbEnterpriseAuth, o -> o.setIdentityNo(null)));
|
|
|
+ // 测试 frontUrl 不匹配
|
|
|
+ enterpriseAuthMapper.insert(cloneIgnoreId(dbEnterpriseAuth, o -> o.setFrontUrl(null)));
|
|
|
+ // 测试 backUrl 不匹配
|
|
|
+ enterpriseAuthMapper.insert(cloneIgnoreId(dbEnterpriseAuth, o -> o.setBackUrl(null)));
|
|
|
+ // 测试 createTime 不匹配
|
|
|
+ enterpriseAuthMapper.insert(cloneIgnoreId(dbEnterpriseAuth, o -> o.setCreateTime(null)));
|
|
|
+ // 准备参数
|
|
|
+ EnterpriseAuthPageReqVO reqVO = new EnterpriseAuthPageReqVO();
|
|
|
+ reqVO.setEnterpriseId(null);
|
|
|
+ reqVO.setUserId(null);
|
|
|
+ reqVO.setName(null);
|
|
|
+ reqVO.setIdentityNo(null);
|
|
|
+ reqVO.setFrontUrl(null);
|
|
|
+ reqVO.setBackUrl(null);
|
|
|
+ reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ PageResult<EnterpriseAuthDO> pageResult = enterpriseAuthService.getEnterpriseAuthPage(reqVO);
|
|
|
+ // 断言
|
|
|
+ assertEquals(1, pageResult.getTotal());
|
|
|
+ assertEquals(1, pageResult.getList().size());
|
|
|
+ assertPojoEquals(dbEnterpriseAuth, pageResult.getList().get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|