fix:seckillTime => seckillConfig

This commit is contained in:
puhui999
2023-06-17 21:17:02 +08:00
parent 217a31a123
commit 32cca12cd2
28 changed files with 1056 additions and 661 deletions

View File

@@ -0,0 +1,190 @@
package cn.iocoder.yudao.module.promotion.service.seckillconfig;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.config.SeckillConfigUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillconfig.SeckillConfigDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillconfig.SeckillConfigMapper;
import cn.iocoder.yudao.module.promotion.service.seckill.seckillconfig.SeckillConfigServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
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.randomPojo;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_TIME_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* {@link SeckillConfigServiceImpl} 的单元测试类
*
* @author 芋道源码
*/
@Import(SeckillConfigServiceImpl.class)
@Disabled // TODO 芋艿:未来开启
public class SeckillConfigServiceImplTest extends BaseDbUnitTest {
@Resource
private SeckillConfigServiceImpl SeckillConfigService;
@Resource
private SeckillConfigMapper seckillConfigMapper;
@Resource
private ObjectMapper objectMapper;
@Test
public void testJacksonSerializ() {
// 准备参数
SeckillConfigCreateReqVO reqVO = randomPojo(SeckillConfigCreateReqVO.class);
// ObjectMapper objectMapper = new ObjectMapper();
try {
String string = objectMapper.writeValueAsString(reqVO);
System.out.println(string);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
@Test
public void testCreateSeckillConfig_success() {
// 准备参数
SeckillConfigCreateReqVO reqVO = randomPojo(SeckillConfigCreateReqVO.class);
// 调用
Long SeckillConfigId = SeckillConfigService.createSeckillConfig(reqVO);
// 断言
assertNotNull(SeckillConfigId);
// 校验记录的属性是否正确
SeckillConfigDO SeckillConfig = seckillConfigMapper.selectById(SeckillConfigId);
assertPojoEquals(reqVO, SeckillConfig);
}
@Test
public void testUpdateSeckillConfig_success() {
// mock 数据
SeckillConfigDO dbSeckillConfig = randomPojo(SeckillConfigDO.class);
seckillConfigMapper.insert(dbSeckillConfig);// @Sql: 先插入出一条存在的数据
// 准备参数
SeckillConfigUpdateReqVO reqVO = randomPojo(SeckillConfigUpdateReqVO.class, o -> {
o.setId(dbSeckillConfig.getId()); // 设置更新的 ID
});
// 调用
SeckillConfigService.updateSeckillConfig(reqVO);
// 校验是否更新正确
SeckillConfigDO SeckillConfig = seckillConfigMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, SeckillConfig);
}
@Test
public void testUpdateSeckillConfig_notExists() {
// 准备参数
SeckillConfigUpdateReqVO reqVO = randomPojo(SeckillConfigUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> SeckillConfigService.updateSeckillConfig(reqVO), SECKILL_TIME_NOT_EXISTS);
}
@Test
public void testDeleteSeckillConfig_success() {
// mock 数据
SeckillConfigDO dbSeckillConfig = randomPojo(SeckillConfigDO.class);
seckillConfigMapper.insert(dbSeckillConfig);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbSeckillConfig.getId();
// 调用
SeckillConfigService.deleteSeckillConfig(id);
// 校验数据不存在了
assertNull(seckillConfigMapper.selectById(id));
}
@Test
public void testDeleteSeckillConfig_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> SeckillConfigService.deleteSeckillConfig(id), SECKILL_TIME_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetSeckillConfigPage() {
// mock 数据
// SeckillConfigDO dbSeckillConfig = randomPojo(SeckillConfigDO.class, o -> { // 等会查询到
// o.setName(null);
// o.setStartTime(null);
// o.setEndTime(null);
// o.setCreateTime(null);
// });
// seckillConfigMapper.insert(dbSeckillConfig);
// // 测试 name 不匹配
// seckillConfigMapper.insert(cloneIgnoreId(dbSeckillConfig, o -> o.setName(null)));
// // 测试 startTime 不匹配
// seckillConfigMapper.insert(cloneIgnoreId(dbSeckillConfig, o -> o.setStartTime(null)));
// // 测试 endTime 不匹配
// seckillConfigMapper.insert(cloneIgnoreId(dbSeckillConfig, o -> o.setEndTime(null)));
// // 测试 createTime 不匹配
// seckillConfigMapper.insert(cloneIgnoreId(dbSeckillConfig, o -> o.setCreateTime(null)));
// // 准备参数
// SeckillConfigPageReqVO reqVO = new SeckillConfigPageReqVO();
// reqVO.setName(null);
//// reqVO.setStartTime((new LocalTime()));
//// reqVO.setEndTime((new LocalTime[]{}));
//// reqVO.setCreateTime((new Date[]{}));
//
// // 调用
// PageResult<SeckillConfigDO> pageResult = SeckillConfigService.getSeckillConfigPage(reqVO);
// // 断言
// assertEquals(1, pageResult.getTotal());
// assertEquals(1, pageResult.getList().size());
// assertPojoEquals(dbSeckillConfig, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetSeckillConfigList() {
// mock 数据
SeckillConfigDO dbSeckillConfig = randomPojo(SeckillConfigDO.class, o -> { // 等会查询到
o.setName(null);
o.setStartTime(null);
o.setEndTime(null);
o.setCreateTime(null);
});
seckillConfigMapper.insert(dbSeckillConfig);
// 测试 name 不匹配
seckillConfigMapper.insert(cloneIgnoreId(dbSeckillConfig, o -> o.setName(null)));
// 测试 startTime 不匹配
seckillConfigMapper.insert(cloneIgnoreId(dbSeckillConfig, o -> o.setStartTime(null)));
// 测试 endTime 不匹配
seckillConfigMapper.insert(cloneIgnoreId(dbSeckillConfig, o -> o.setEndTime(null)));
// 测试 createTime 不匹配
seckillConfigMapper.insert(cloneIgnoreId(dbSeckillConfig, o -> o.setCreateTime(null)));
// 准备参数
// SeckillConfigExportReqVO reqVO = new SeckillConfigExportReqVO();
// reqVO.setName(null);
// reqVO.setStartTime((new LocalTime[]{}));
// reqVO.setEndTime((new LocalTime[]{}));
// reqVO.setCreateTime((new Date[]{}));
//
// // 调用
// List<SeckillConfigDO> list = SeckillConfigService.getSeckillConfigList(reqVO);
// // 断言
// assertEquals(1, list.size());
// assertPojoEquals(dbSeckillConfig, list.get(0));
}
}

View File

@@ -1,190 +0,0 @@
package cn.iocoder.yudao.module.promotion.service.seckilltime;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.time.SeckillTimeUpdateReqVO;
import cn.iocoder.yudao.module.promotion.service.seckill.seckilltime.SeckillTimeServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckilltime.SeckillTimeDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckilltime.SeckillTimeMapper;
import org.springframework.context.annotation.Import;
import static cn.iocoder.yudao.module.promotion.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.object.ObjectUtils.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link SeckillTimeServiceImpl} 的单元测试类
*
* @author 芋道源码
*/
@Import(SeckillTimeServiceImpl.class)
@Disabled // TODO 芋艿:未来开启
public class SeckillTimeServiceImplTest extends BaseDbUnitTest {
@Resource
private SeckillTimeServiceImpl seckillTimeService;
@Resource
private SeckillTimeMapper seckillTimeMapper;
@Resource
private ObjectMapper objectMapper;
@Test
public void testJacksonSerializ(){
// 准备参数
SeckillTimeCreateReqVO reqVO = randomPojo(SeckillTimeCreateReqVO.class);
// ObjectMapper objectMapper = new ObjectMapper();
try {
String string = objectMapper.writeValueAsString(reqVO);
System.out.println(string);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
@Test
public void testCreateSeckillTime_success() {
// 准备参数
SeckillTimeCreateReqVO reqVO = randomPojo(SeckillTimeCreateReqVO.class);
// 调用
Long seckillTimeId = seckillTimeService.createSeckillTime(reqVO);
// 断言
assertNotNull(seckillTimeId);
// 校验记录的属性是否正确
SeckillTimeDO seckillTime = seckillTimeMapper.selectById(seckillTimeId);
assertPojoEquals(reqVO, seckillTime);
}
@Test
public void testUpdateSeckillTime_success() {
// mock 数据
SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class);
seckillTimeMapper.insert(dbSeckillTime);// @Sql: 先插入出一条存在的数据
// 准备参数
SeckillTimeUpdateReqVO reqVO = randomPojo(SeckillTimeUpdateReqVO.class, o -> {
o.setId(dbSeckillTime.getId()); // 设置更新的 ID
});
// 调用
seckillTimeService.updateSeckillTime(reqVO);
// 校验是否更新正确
SeckillTimeDO seckillTime = seckillTimeMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, seckillTime);
}
@Test
public void testUpdateSeckillTime_notExists() {
// 准备参数
SeckillTimeUpdateReqVO reqVO = randomPojo(SeckillTimeUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> seckillTimeService.updateSeckillTime(reqVO), SECKILL_TIME_NOT_EXISTS);
}
@Test
public void testDeleteSeckillTime_success() {
// mock 数据
SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class);
seckillTimeMapper.insert(dbSeckillTime);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbSeckillTime.getId();
// 调用
seckillTimeService.deleteSeckillTime(id);
// 校验数据不存在了
assertNull(seckillTimeMapper.selectById(id));
}
@Test
public void testDeleteSeckillTime_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> seckillTimeService.deleteSeckillTime(id), SECKILL_TIME_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetSeckillTimePage() {
// mock 数据
// SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class, o -> { // 等会查询到
// o.setName(null);
// o.setStartTime(null);
// o.setEndTime(null);
// o.setCreateTime(null);
// });
// seckillTimeMapper.insert(dbSeckillTime);
// // 测试 name 不匹配
// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setName(null)));
// // 测试 startTime 不匹配
// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setStartTime(null)));
// // 测试 endTime 不匹配
// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setEndTime(null)));
// // 测试 createTime 不匹配
// seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setCreateTime(null)));
// // 准备参数
// SeckillTimePageReqVO reqVO = new SeckillTimePageReqVO();
// reqVO.setName(null);
//// reqVO.setStartTime((new LocalTime()));
//// reqVO.setEndTime((new LocalTime[]{}));
//// reqVO.setCreateTime((new Date[]{}));
//
// // 调用
// PageResult<SeckillTimeDO> pageResult = seckillTimeService.getSeckillTimePage(reqVO);
// // 断言
// assertEquals(1, pageResult.getTotal());
// assertEquals(1, pageResult.getList().size());
// assertPojoEquals(dbSeckillTime, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetSeckillTimeList() {
// mock 数据
SeckillTimeDO dbSeckillTime = randomPojo(SeckillTimeDO.class, o -> { // 等会查询到
o.setName(null);
o.setStartTime(null);
o.setEndTime(null);
o.setCreateTime(null);
});
seckillTimeMapper.insert(dbSeckillTime);
// 测试 name 不匹配
seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setName(null)));
// 测试 startTime 不匹配
seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setStartTime(null)));
// 测试 endTime 不匹配
seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setEndTime(null)));
// 测试 createTime 不匹配
seckillTimeMapper.insert(cloneIgnoreId(dbSeckillTime, o -> o.setCreateTime(null)));
// 准备参数
// SeckillTimeExportReqVO reqVO = new SeckillTimeExportReqVO();
// reqVO.setName(null);
// reqVO.setStartTime((new LocalTime[]{}));
// reqVO.setEndTime((new LocalTime[]{}));
// reqVO.setCreateTime((new Date[]{}));
//
// // 调用
// List<SeckillTimeDO> list = seckillTimeService.getSeckillTimeList(reqVO);
// // 断言
// assertEquals(1, list.size());
// assertPojoEquals(dbSeckillTime, list.get(0));
}
}

View File

@@ -1,6 +1,14 @@
DELETE FROM "market_activity";
DELETE FROM "promotion_coupon_template";
DELETE FROM "promotion_coupon";
DELETE FROM "promotion_reward_activity";
DELETE FROM "promotion_discount_activity";
DELETE FROM "promotion_discount_product";
DELETE
FROM "market_activity";
DELETE
FROM "promotion_coupon_template";
DELETE
FROM "promotion_coupon";
DELETE
FROM "promotion_reward_activity";
DELETE
FROM "promotion_discount_activity";
DELETE
FROM "promotion_discount_product";
DELETE
FROM "promotion_seckill_config";

View File

@@ -108,17 +108,122 @@ CREATE TABLE IF NOT EXISTS "promotion_discount_activity" (
) COMMENT '限时折扣活动';
CREATE TABLE IF NOT EXISTS "promotion_discount_product" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"activity_id" bigint NOT NULL,
"spu_id" bigint NOT NULL,
"sku_id" bigint NOT NULL,
"discount_type" int NOT NULL,
"discount_percent" int,
"discount_price" int,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '限时折扣活动';
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"activity_id" bigint NOT NULL,
"spu_id" bigint NOT NULL,
"sku_id" bigint NOT NULL,
"discount_type" int NOT NULL,
"discount_percent"
int,
"discount_price"
int,
"creator"
varchar
DEFAULT
'',
"create_time"
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP,
"updater"
varchar
DEFAULT
'',
"update_time"
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
ON
UPDATE
CURRENT_TIMESTAMP,
"deleted"
bit
NOT
NULL
DEFAULT
FALSE,
PRIMARY
KEY
(
"id"
)
) COMMENT '限时折扣活动';
CREATE TABLE IF NOT EXISTS "promotion_seckill_config"
(
"id"
bigint
NOT
NULL
GENERATED
BY
DEFAULT AS
IDENTITY,
"name"
varchar
NOT
NULL,
"start_time"
varchar
NOT
NULL,
"end_time"
varchar
NOT
NULL,
"seckill_activity_count"
int
NOT
NULL,
"pic_url"
varchar
NOT
NULL,
"status"
varchar
NOT
NULL,
"creator"
varchar
DEFAULT
'',
"create_time"
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP,
"updater"
varchar
DEFAULT
'',
"update_time"
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
ON
UPDATE
CURRENT_TIMESTAMP,
"deleted"
bit
NOT
NULL
DEFAULT
FALSE,
"tenant_id"
bigint
NOT
NULL,
PRIMARY
KEY
(
"id"
)
) COMMENT '秒杀时段配置';