[测试][商品分类]测试创建商品分类
This commit is contained in:
parent
5674bfafc8
commit
b0c73b786a
@ -18,6 +18,7 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq
|
|||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||||
|
import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.PARENT_ID_NULL;
|
||||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS;
|
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.CATEGORY_NOT_EXISTS;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@ -38,9 +39,16 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateCategory_success() {
|
public void testCreateCategory_success() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
ProductCategoryCreateReqVO reqVO = randomPojo(ProductCategoryCreateReqVO.class);
|
ProductCategoryCreateReqVO reqVO = randomPojo(ProductCategoryCreateReqVO.class,o -> {
|
||||||
|
// 设置PC端图片可为空
|
||||||
|
o.setBigPicUrl(null);
|
||||||
|
});
|
||||||
|
|
||||||
// mock 父类
|
// mock 父类
|
||||||
ProductCategoryDO parentProductCategory = randomPojo(ProductCategoryDO.class, o -> o.setId(reqVO.getParentId()));
|
ProductCategoryDO parentProductCategory = randomPojo(ProductCategoryDO.class, o -> {
|
||||||
|
reqVO.setParentId(o.getId());
|
||||||
|
o.setParentId(PARENT_ID_NULL);
|
||||||
|
});
|
||||||
productCategoryMapper.insert(parentProductCategory);
|
productCategoryMapper.insert(parentProductCategory);
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
@ -108,7 +116,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
|
|||||||
public void testGetCategoryLevel() {
|
public void testGetCategoryLevel() {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
ProductCategoryDO category1 = randomPojo(ProductCategoryDO.class,
|
ProductCategoryDO category1 = randomPojo(ProductCategoryDO.class,
|
||||||
o -> o.setParentId(ProductCategoryDO.PARENT_ID_NULL));
|
o -> o.setParentId(PARENT_ID_NULL));
|
||||||
productCategoryMapper.insert(category1);
|
productCategoryMapper.insert(category1);
|
||||||
ProductCategoryDO category2 = randomPojo(ProductCategoryDO.class,
|
ProductCategoryDO category2 = randomPojo(ProductCategoryDO.class,
|
||||||
o -> o.setParentId(category1.getId()));
|
o -> o.setParentId(category1.getId()));
|
||||||
@ -129,7 +137,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
|
|||||||
ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到
|
ProductCategoryDO dbCategory = randomPojo(ProductCategoryDO.class, o -> { // 等会查询到
|
||||||
o.setName("奥特曼");
|
o.setName("奥特曼");
|
||||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
o.setParentId(ProductCategoryDO.PARENT_ID_NULL);
|
o.setParentId(PARENT_ID_NULL);
|
||||||
});
|
});
|
||||||
productCategoryMapper.insert(dbCategory);
|
productCategoryMapper.insert(dbCategory);
|
||||||
// 测试 name 不匹配
|
// 测试 name 不匹配
|
||||||
@ -142,7 +150,7 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
|
|||||||
ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO();
|
ProductCategoryListReqVO reqVO = new ProductCategoryListReqVO();
|
||||||
reqVO.setName("特曼");
|
reqVO.setName("特曼");
|
||||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
reqVO.setParentId(ProductCategoryDO.PARENT_ID_NULL);
|
reqVO.setParentId(PARENT_ID_NULL);
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO);
|
List<ProductCategoryDO> list = productCategoryService.getEnableCategoryList(reqVO);
|
||||||
|
Loading…
Reference in New Issue
Block a user