forked from sfms3.0/sfms3.0
1 changed files with 0 additions and 251 deletions
@ -1,251 +0,0 @@ |
|||||
package com.win.module.wms.service.enterprise; |
|
||||
|
|
||||
import com.win.module.wms.controller.enterprise.vo.EnterpriseCreateReqVO; |
|
||||
import com.win.module.wms.controller.enterprise.vo.EnterpriseExportReqVO; |
|
||||
import com.win.module.wms.controller.enterprise.vo.EnterprisePageReqVO; |
|
||||
import com.win.module.wms.controller.enterprise.vo.EnterpriseUpdateReqVO; |
|
||||
import org.junit.jupiter.api.Disabled; |
|
||||
import org.junit.jupiter.api.Test; |
|
||||
|
|
||||
import javax.annotation.Resource; |
|
||||
|
|
||||
import com.win.framework.test.core.ut.BaseDbUnitTest; |
|
||||
|
|
||||
import com.win.module.wms.dal.dataobject.enterprise.EnterpriseDO; |
|
||||
import com.win.module.wms.dal.mysql.enterprise.EnterpriseMapper; |
|
||||
import com.win.framework.common.pojo.PageResult; |
|
||||
|
|
||||
import org.springframework.context.annotation.Import; |
|
||||
import java.util.*; |
|
||||
|
|
||||
import static com.win.framework.test.core.util.AssertUtils.*; |
|
||||
import static com.win.framework.test.core.util.RandomUtils.*; |
|
||||
import static com.win.framework.common.util.date.LocalDateTimeUtils.*; |
|
||||
import static com.win.framework.common.util.object.ObjectUtils.*; |
|
||||
import static org.junit.jupiter.api.Assertions.*; |
|
||||
|
|
||||
/** |
|
||||
* {@link EnterpriseServiceImpl} 的单元测试类 |
|
||||
* |
|
||||
* @author 超级管理员 |
|
||||
*/ |
|
||||
@Import(EnterpriseServiceImpl.class) |
|
||||
public class EnterpriseServiceImplTest extends BaseDbUnitTest { |
|
||||
|
|
||||
@Resource |
|
||||
private EnterpriseServiceImpl enterpriseService; |
|
||||
|
|
||||
@Resource |
|
||||
private EnterpriseMapper enterpriseMapper; |
|
||||
|
|
||||
@Test |
|
||||
public void testCreateEnterprise_success() { |
|
||||
// 准备参数
|
|
||||
EnterpriseCreateReqVO reqVO = randomPojo(EnterpriseCreateReqVO.class); |
|
||||
|
|
||||
// 调用
|
|
||||
Long enterpriseId = enterpriseService.createEnterprise(reqVO); |
|
||||
// 断言
|
|
||||
assertNotNull(enterpriseId); |
|
||||
// 校验记录的属性是否正确
|
|
||||
EnterpriseDO enterprise = enterpriseMapper.selectById(enterpriseId); |
|
||||
assertPojoEquals(reqVO, enterprise); |
|
||||
} |
|
||||
|
|
||||
@Test |
|
||||
public void testUpdateEnterprise_success() { |
|
||||
// mock 数据
|
|
||||
EnterpriseDO dbEnterprise = randomPojo(EnterpriseDO.class); |
|
||||
enterpriseMapper.insert(dbEnterprise);// @Sql: 先插入出一条存在的数据
|
|
||||
// 准备参数
|
|
||||
EnterpriseUpdateReqVO reqVO = randomPojo(EnterpriseUpdateReqVO.class, o -> { |
|
||||
o.setId(dbEnterprise.getId()); // 设置更新的 ID
|
|
||||
}); |
|
||||
|
|
||||
// 调用
|
|
||||
enterpriseService.updateEnterprise(reqVO); |
|
||||
// 校验是否更新正确
|
|
||||
EnterpriseDO enterprise = enterpriseMapper.selectById(reqVO.getId()); // 获取最新的
|
|
||||
assertPojoEquals(reqVO, enterprise); |
|
||||
} |
|
||||
|
|
||||
@Test |
|
||||
public void testUpdateEnterprise_notExists() { |
|
||||
// 准备参数
|
|
||||
EnterpriseUpdateReqVO reqVO = randomPojo(EnterpriseUpdateReqVO.class); |
|
||||
|
|
||||
// 调用, 并断言异常
|
|
||||
assertServiceException(() -> enterpriseService.updateEnterprise(reqVO), ENTERPRISE_NOT_EXISTS); |
|
||||
} |
|
||||
|
|
||||
@Test |
|
||||
public void testDeleteEnterprise_success() { |
|
||||
// mock 数据
|
|
||||
EnterpriseDO dbEnterprise = randomPojo(EnterpriseDO.class); |
|
||||
enterpriseMapper.insert(dbEnterprise);// @Sql: 先插入出一条存在的数据
|
|
||||
// 准备参数
|
|
||||
Long id = dbEnterprise.getId(); |
|
||||
|
|
||||
// 调用
|
|
||||
enterpriseService.deleteEnterprise(id); |
|
||||
// 校验数据不存在了
|
|
||||
assertNull(enterpriseMapper.selectById(id)); |
|
||||
} |
|
||||
|
|
||||
@Test |
|
||||
public void testDeleteEnterprise_notExists() { |
|
||||
// 准备参数
|
|
||||
Long id = randomLongId(); |
|
||||
|
|
||||
// 调用, 并断言异常
|
|
||||
assertServiceException(() -> enterpriseService.deleteEnterprise(id), ENTERPRISE_NOT_EXISTS); |
|
||||
} |
|
||||
|
|
||||
@Test |
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
||||
public void testGetEnterprisePage() { |
|
||||
// mock 数据
|
|
||||
EnterpriseDO dbEnterprise = randomPojo(EnterpriseDO.class, o -> { // 等会查询到
|
|
||||
o.setCode(null); |
|
||||
o.setName(null); |
|
||||
o.setShortName(null); |
|
||||
o.setAddress(null); |
|
||||
o.setAvailable(null); |
|
||||
o.setActiveTime(null); |
|
||||
o.setExpireTime(null); |
|
||||
o.setRemark(null); |
|
||||
o.setCreateTime(null); |
|
||||
o.setDeletionTime(null); |
|
||||
o.setDeleterId(null); |
|
||||
o.setExtraProperties(null); |
|
||||
o.setConcurrencyStamp(null); |
|
||||
o.setSiteId(null); |
|
||||
}); |
|
||||
enterpriseMapper.insert(dbEnterprise); |
|
||||
// 测试 code 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setCode(null))); |
|
||||
// 测试 name 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setName(null))); |
|
||||
// 测试 shortName 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setShortName(null))); |
|
||||
// 测试 address 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setAddress(null))); |
|
||||
// 测试 available 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setAvailable(null))); |
|
||||
// 测试 activeTime 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setActiveTime(null))); |
|
||||
// 测试 expireTime 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setExpireTime(null))); |
|
||||
// 测试 remark 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setRemark(null))); |
|
||||
// 测试 createTime 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setCreateTime(null))); |
|
||||
// 测试 deletionTime 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setDeletionTime(null))); |
|
||||
// 测试 deleterId 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setDeleterId(null))); |
|
||||
// 测试 extraProperties 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setExtraProperties(null))); |
|
||||
// 测试 concurrencyStamp 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setConcurrencyStamp(null))); |
|
||||
// 测试 siteId 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setSiteId(null))); |
|
||||
// 准备参数
|
|
||||
EnterprisePageReqVO reqVO = new EnterprisePageReqVO(); |
|
||||
reqVO.setCode(null); |
|
||||
reqVO.setName(null); |
|
||||
reqVO.setShortName(null); |
|
||||
reqVO.setAddress(null); |
|
||||
reqVO.setAvailable(null); |
|
||||
reqVO.setActiveTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); |
|
||||
reqVO.setExpireTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); |
|
||||
reqVO.setRemark(null); |
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); |
|
||||
reqVO.setDeletionTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); |
|
||||
reqVO.setDeleterId(null); |
|
||||
reqVO.setExtraProperties(null); |
|
||||
reqVO.setConcurrencyStamp(null); |
|
||||
reqVO.setSiteId(null); |
|
||||
|
|
||||
// 调用
|
|
||||
PageResult<EnterpriseDO> pageResult = enterpriseService.getEnterprisePage(reqVO); |
|
||||
// 断言
|
|
||||
assertEquals(1, pageResult.getTotal()); |
|
||||
assertEquals(1, pageResult.getList().size()); |
|
||||
assertPojoEquals(dbEnterprise, pageResult.getList().get(0)); |
|
||||
} |
|
||||
|
|
||||
@Test |
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
||||
public void testGetEnterpriseList() { |
|
||||
// mock 数据
|
|
||||
EnterpriseDO dbEnterprise = randomPojo(EnterpriseDO.class, o -> { // 等会查询到
|
|
||||
o.setCode(null); |
|
||||
o.setName(null); |
|
||||
o.setShortName(null); |
|
||||
o.setAddress(null); |
|
||||
o.setAvailable(null); |
|
||||
o.setActiveTime(null); |
|
||||
o.setExpireTime(null); |
|
||||
o.setRemark(null); |
|
||||
o.setCreateTime(null); |
|
||||
o.setDeletionTime(null); |
|
||||
o.setDeleterId(null); |
|
||||
o.setExtraProperties(null); |
|
||||
o.setConcurrencyStamp(null); |
|
||||
o.setSiteId(null); |
|
||||
}); |
|
||||
enterpriseMapper.insert(dbEnterprise); |
|
||||
// 测试 code 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setCode(null))); |
|
||||
// 测试 name 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setName(null))); |
|
||||
// 测试 shortName 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setShortName(null))); |
|
||||
// 测试 address 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setAddress(null))); |
|
||||
// 测试 available 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setAvailable(null))); |
|
||||
// 测试 activeTime 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setActiveTime(null))); |
|
||||
// 测试 expireTime 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setExpireTime(null))); |
|
||||
// 测试 remark 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setRemark(null))); |
|
||||
// 测试 createTime 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setCreateTime(null))); |
|
||||
// 测试 deletionTime 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setDeletionTime(null))); |
|
||||
// 测试 deleterId 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setDeleterId(null))); |
|
||||
// 测试 extraProperties 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setExtraProperties(null))); |
|
||||
// 测试 concurrencyStamp 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setConcurrencyStamp(null))); |
|
||||
// 测试 siteId 不匹配
|
|
||||
enterpriseMapper.insert(cloneIgnoreId(dbEnterprise, o -> o.setSiteId(null))); |
|
||||
// 准备参数
|
|
||||
EnterpriseExportReqVO reqVO = new EnterpriseExportReqVO(); |
|
||||
reqVO.setCode(null); |
|
||||
reqVO.setName(null); |
|
||||
reqVO.setShortName(null); |
|
||||
reqVO.setAddress(null); |
|
||||
reqVO.setAvailable(null); |
|
||||
reqVO.setActiveTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); |
|
||||
reqVO.setExpireTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); |
|
||||
reqVO.setRemark(null); |
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); |
|
||||
reqVO.setDeletionTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); |
|
||||
reqVO.setDeleterId(null); |
|
||||
reqVO.setExtraProperties(null); |
|
||||
reqVO.setConcurrencyStamp(null); |
|
||||
reqVO.setSiteId(null); |
|
||||
|
|
||||
// 调用
|
|
||||
List<EnterpriseDO> list = enterpriseService.getEnterpriseList(reqVO); |
|
||||
// 断言
|
|
||||
assertEquals(1, list.size()); |
|
||||
assertPojoEquals(dbEnterprise, list.get(0)); |
|
||||
} |
|
||||
|
|
||||
} |
|
Loading…
Reference in new issue