1. 【修复】单元测试报错
2. 【优化】yudao-module-xx-impl 调整成 yudao-module-xx-biz,更加符合定位
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
package cn.iocoder.yudao.module.pay.service.merchant;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.app.PayAppCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.app.PayAppExportReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.app.PayAppPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.app.PayAppUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayAppDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayMerchantDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.merchant.PayAppMapper;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.merchant.PayMerchantMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||
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.pay.enums.ErrorCodeConstants.PAY_APP_NOT_FOUND;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Import(PayAppServiceImpl.class)
|
||||
public class PayAppServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PayAppServiceImpl appService;
|
||||
|
||||
@Resource
|
||||
private PayAppMapper appMapper;
|
||||
|
||||
@MockBean(name = "payMerchantMapper")
|
||||
private PayMerchantMapper payMerchantMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateApp_success() {
|
||||
// 准备参数
|
||||
PayAppCreateReqVO reqVO = randomPojo(PayAppCreateReqVO.class, o ->
|
||||
o.setStatus((RandomUtil.randomEle(CommonStatusEnum.values()).getStatus())));
|
||||
|
||||
// 调用
|
||||
Long appId = appService.createApp(reqVO);
|
||||
// 断言
|
||||
assertNotNull(appId);
|
||||
// 校验记录的属性是否正确
|
||||
PayAppDO app = appMapper.selectById(appId);
|
||||
assertPojoEquals(reqVO, app);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateApp_success() {
|
||||
// mock 数据
|
||||
PayAppDO dbApp = randomPojo(PayAppDO.class, o ->
|
||||
o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
appMapper.insert(dbApp);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
PayAppUpdateReqVO reqVO = randomPojo(PayAppUpdateReqVO.class, o -> {
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setId(dbApp.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
appService.updateApp(reqVO);
|
||||
// 校验是否更新正确
|
||||
PayAppDO app = appMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, app);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateApp_notExists() {
|
||||
// 准备参数
|
||||
PayAppUpdateReqVO reqVO = randomPojo(PayAppUpdateReqVO.class, o ->
|
||||
o.setStatus((RandomUtil.randomEle(CommonStatusEnum.values()).getStatus())));
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> appService.updateApp(reqVO), PAY_APP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteApp_success() {
|
||||
// mock 数据
|
||||
PayAppDO dbApp = randomPojo(PayAppDO.class, o ->
|
||||
o.setStatus((RandomUtil.randomEle(CommonStatusEnum.values()).getStatus())));
|
||||
appMapper.insert(dbApp);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbApp.getId();
|
||||
|
||||
// 调用
|
||||
appService.deleteApp(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(appMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteApp_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> appService.deleteApp(id), PAY_APP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAppPage() {
|
||||
Long merchantId = 1L;
|
||||
Long mismatchMerchantId = 2L;
|
||||
|
||||
// mock 数据
|
||||
PayAppDO dbApp = randomPojo(PayAppDO.class, o -> { // 等会查询到
|
||||
o.setName("灿灿姐的杂货铺");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setRemark("敏敏姐的小卖铺");
|
||||
o.setPayNotifyUrl("https://www.hc.com");
|
||||
o.setRefundNotifyUrl("https://www.xm.com");
|
||||
o.setMerchantId(merchantId);
|
||||
o.setCreateTime(buildTime(2021,11,20));
|
||||
});
|
||||
|
||||
// mock 数据
|
||||
PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, o -> { // 等会查询到
|
||||
o.setId(merchantId);
|
||||
o.setNo("M1008611");
|
||||
o.setName("灿哥的杂货铺");
|
||||
o.setShortName("灿灿子");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setRemark("灿哥的杂货铺");
|
||||
o.setCreateTime(buildTime(2021,11,3));
|
||||
});
|
||||
|
||||
Mockito.when(payMerchantMapper.getMerchantListByName(dbMerchant.getName()))
|
||||
.thenReturn(Collections.singletonList(dbMerchant));
|
||||
|
||||
appMapper.insert(dbApp);
|
||||
// 测试 name 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setName("敏敏姐的杂货铺")));
|
||||
// 测试 status 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
// 测试 remark 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setRemark("灿灿姐的小卖部")));
|
||||
// 测试 payNotifyUrl 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setPayNotifyUrl("xm.com")));
|
||||
// 测试 refundNotifyUrl 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setRefundNotifyUrl("hc.com")));
|
||||
// 测试 merchantId 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setMerchantId(mismatchMerchantId)));
|
||||
// 测试 createTime 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setCreateTime(buildTime(2021,12,21))));
|
||||
// 准备参数
|
||||
PayAppPageReqVO reqVO = new PayAppPageReqVO();
|
||||
reqVO.setName("灿灿姐的杂货铺");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setRemark("敏敏姐的小卖铺");
|
||||
reqVO.setPayNotifyUrl("https://www.hc.com");
|
||||
reqVO.setRefundNotifyUrl("https://www.xm.com");
|
||||
reqVO.setMerchantName(dbMerchant.getName());
|
||||
reqVO.setBeginCreateTime(buildTime(2021,11,19));
|
||||
reqVO.setEndCreateTime(buildTime(2021,11,21));
|
||||
|
||||
// 调用
|
||||
PageResult<PayAppDO> pageResult = appService.getAppPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbApp, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test // TODO 请修改 null 为需要的值
|
||||
public void testGetAppList() {
|
||||
Long merchantId = 1L;
|
||||
Long mismatchMerchantId = 2L;
|
||||
|
||||
// mock 数据
|
||||
PayAppDO dbApp = randomPojo(PayAppDO.class, o -> { // 等会查询到
|
||||
o.setName("灿灿姐的杂货铺");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setRemark("敏敏姐的小卖铺");
|
||||
o.setPayNotifyUrl("https://www.hc.com");
|
||||
o.setRefundNotifyUrl("https://www.xm.com");
|
||||
o.setMerchantId(merchantId);
|
||||
o.setCreateTime(buildTime(2021,11,20));
|
||||
});
|
||||
|
||||
// mock 数据
|
||||
PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, o -> { // 等会查询到
|
||||
o.setId(merchantId);
|
||||
o.setNo("M1008611");
|
||||
o.setName("灿哥的杂货铺");
|
||||
o.setShortName("灿灿子");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setRemark("灿哥的杂货铺");
|
||||
o.setCreateTime(buildTime(2021,11,3));
|
||||
});
|
||||
|
||||
Mockito.when(payMerchantMapper.getMerchantListByName(dbMerchant.getName()))
|
||||
.thenReturn(Collections.singletonList(dbMerchant));
|
||||
|
||||
appMapper.insert(dbApp);
|
||||
// 测试 name 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setName("敏敏姐的杂货铺")));
|
||||
// 测试 status 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
// 测试 remark 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setRemark("灿灿姐的小卖部")));
|
||||
// 测试 payNotifyUrl 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setPayNotifyUrl("xm.com")));
|
||||
// 测试 refundNotifyUrl 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setRefundNotifyUrl("hc.com")));
|
||||
// 测试 merchantId 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setMerchantId(mismatchMerchantId)));
|
||||
// 测试 createTime 不匹配
|
||||
appMapper.insert(cloneIgnoreId(dbApp, o -> o.setCreateTime(buildTime(2021,12,21))));
|
||||
// 准备参数
|
||||
PayAppExportReqVO reqVO = new PayAppExportReqVO();
|
||||
reqVO.setName("灿灿姐的杂货铺");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setRemark("敏敏姐的小卖铺");
|
||||
reqVO.setPayNotifyUrl("https://www.hc.com");
|
||||
reqVO.setRefundNotifyUrl("https://www.xm.com");
|
||||
reqVO.setMerchantName(dbMerchant.getName());
|
||||
reqVO.setBeginCreateTime(buildTime(2021,11,19));
|
||||
reqVO.setEndCreateTime(buildTime(2021,11,21));
|
||||
|
||||
// 调用
|
||||
List<PayAppDO> list = appService.getAppList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbApp, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,400 @@
|
||||
package cn.iocoder.yudao.module.pay.service.merchant;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.channel.PayChannelCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.channel.PayChannelExportReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.channel.PayChannelPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.channel.PayChannelUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayChannelDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.merchant.PayChannelMapper;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Validator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||
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.pay.enums.ErrorCodeConstants.CHANNEL_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Import({PayChannelServiceImpl.class})
|
||||
public class PayChannelServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PayChannelServiceImpl channelService;
|
||||
|
||||
@Resource
|
||||
private PayChannelMapper channelMapper;
|
||||
|
||||
@MockBean
|
||||
private PayClientFactory payClientFactory;
|
||||
@MockBean
|
||||
private Validator validator;
|
||||
|
||||
@Test
|
||||
public void testCreateWechatVersion2Channel_success() {
|
||||
// 准备参数
|
||||
|
||||
WXPayClientConfig v2Config = getV2Config();
|
||||
PayChannelCreateReqVO reqVO = randomPojo(PayChannelCreateReqVO.class, o -> {
|
||||
o.setCode(PayChannelEnum.WX_PUB.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setConfig(JSON.toJSONString(v2Config));
|
||||
});
|
||||
|
||||
// 调用
|
||||
Long channelId = channelService.createChannel(reqVO);
|
||||
// 断言
|
||||
assertNotNull(channelId);
|
||||
// 校验记录的属性是否正确
|
||||
PayChannelDO channel = channelMapper.selectById(channelId);
|
||||
assertPojoEquals(reqVO, channel, "config");
|
||||
// 关于config 对象应该拿出来重新对比
|
||||
assertPojoEquals(v2Config, channel.getConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWechatVersion3Channel_success() {
|
||||
// 准备参数
|
||||
WXPayClientConfig v3Config = getV3Config();
|
||||
PayChannelCreateReqVO reqVO = randomPojo(PayChannelCreateReqVO.class, o -> {
|
||||
o.setCode(PayChannelEnum.WX_PUB.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setConfig(JSON.toJSONString(v3Config));
|
||||
});
|
||||
|
||||
// 调用
|
||||
Long channelId = channelService.createChannel(reqVO);
|
||||
// 断言
|
||||
assertNotNull(channelId);
|
||||
// 校验记录的属性是否正确
|
||||
PayChannelDO channel = channelMapper.selectById(channelId);
|
||||
assertPojoEquals(reqVO, channel, "config");
|
||||
// 关于config 对象应该拿出来重新对比
|
||||
assertPojoEquals(v3Config, channel.getConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAliPayPublicKeyChannel_success() {
|
||||
// 准备参数
|
||||
|
||||
AlipayPayClientConfig payClientConfig = getPublicKeyConfig();
|
||||
PayChannelCreateReqVO reqVO = randomPojo(PayChannelCreateReqVO.class, o -> {
|
||||
o.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setConfig(JSON.toJSONString(payClientConfig));
|
||||
});
|
||||
|
||||
// 调用
|
||||
Long channelId = channelService.createChannel(reqVO);
|
||||
// 断言
|
||||
assertNotNull(channelId);
|
||||
// 校验记录的属性是否正确
|
||||
PayChannelDO channel = channelMapper.selectById(channelId);
|
||||
assertPojoEquals(reqVO, channel, "config");
|
||||
// 关于config 对象应该拿出来重新对比
|
||||
assertPojoEquals(payClientConfig, channel.getConfig());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAliPayCertificateChannel_success() {
|
||||
// 准备参数
|
||||
|
||||
AlipayPayClientConfig payClientConfig = getCertificateConfig();
|
||||
PayChannelCreateReqVO reqVO = randomPojo(PayChannelCreateReqVO.class, o -> {
|
||||
o.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setConfig(JSON.toJSONString(payClientConfig));
|
||||
});
|
||||
|
||||
// 调用
|
||||
Long channelId = channelService.createChannel(reqVO);
|
||||
// 断言
|
||||
assertNotNull(channelId);
|
||||
// 校验记录的属性是否正确
|
||||
PayChannelDO channel = channelMapper.selectById(channelId);
|
||||
assertPojoEquals(reqVO, channel, "config");
|
||||
// 关于config 对象应该拿出来重新对比
|
||||
assertPojoEquals(payClientConfig, channel.getConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateChannel_success() {
|
||||
// mock 数据
|
||||
AlipayPayClientConfig payClientConfig = getCertificateConfig();
|
||||
PayChannelDO dbChannel = randomPojo(PayChannelDO.class, o -> {
|
||||
o.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setConfig(payClientConfig);
|
||||
});
|
||||
channelMapper.insert(dbChannel);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
AlipayPayClientConfig payClientPublicKeyConfig = getPublicKeyConfig();
|
||||
PayChannelUpdateReqVO reqVO = randomPojo(PayChannelUpdateReqVO.class, o -> {
|
||||
o.setCode(dbChannel.getCode());
|
||||
o.setStatus(dbChannel.getStatus());
|
||||
o.setConfig(JSON.toJSONString(payClientPublicKeyConfig));
|
||||
o.setId(dbChannel.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
channelService.updateChannel(reqVO);
|
||||
// 校验是否更新正确
|
||||
PayChannelDO channel = channelMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, channel, "config");
|
||||
assertPojoEquals(payClientPublicKeyConfig, channel.getConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateChannel_notExists() {
|
||||
// 准备参数
|
||||
AlipayPayClientConfig payClientPublicKeyConfig = getPublicKeyConfig();
|
||||
PayChannelUpdateReqVO reqVO = randomPojo(PayChannelUpdateReqVO.class, o -> {
|
||||
o.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setConfig(JSON.toJSONString(payClientPublicKeyConfig));
|
||||
});
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> channelService.updateChannel(reqVO), CHANNEL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteChannel_success() {
|
||||
// mock 数据
|
||||
AlipayPayClientConfig payClientConfig = getCertificateConfig();
|
||||
PayChannelDO dbChannel = randomPojo(PayChannelDO.class, o -> {
|
||||
o.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setConfig(payClientConfig);
|
||||
});
|
||||
channelMapper.insert(dbChannel);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbChannel.getId();
|
||||
|
||||
// 调用
|
||||
channelService.deleteChannel(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(channelMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteChannel_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> channelService.deleteChannel(id), CHANNEL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test // TODO 请修改 null 为需要的值
|
||||
public void testGetChannelPage() {
|
||||
// mock 数据
|
||||
AlipayPayClientConfig payClientConfig = getCertificateConfig();
|
||||
PayChannelDO dbChannel = randomPojo(PayChannelDO.class, o -> { // 等会查询到
|
||||
o.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setRemark("灿灿子的支付渠道");
|
||||
o.setFeeRate(0.03);
|
||||
o.setMerchantId(1L);
|
||||
o.setAppId(1L);
|
||||
o.setConfig(payClientConfig);
|
||||
o.setCreateTime(buildTime(2021,11,20));
|
||||
});
|
||||
channelMapper.insert(dbChannel);
|
||||
// 执行拷贝的时候会出现异常,所以在插入后要重置为null 后续在写入新的
|
||||
dbChannel.setConfig(null);
|
||||
// 测试 code 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setCode(PayChannelEnum.WX_PUB.getCode());
|
||||
}));
|
||||
// 测试 status 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
}));
|
||||
// 测试 remark 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o ->{
|
||||
o.setConfig(payClientConfig);
|
||||
o.setRemark("敏敏子的渠道");
|
||||
}));
|
||||
// 测试 feeRate 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setFeeRate(1.23);
|
||||
}));
|
||||
// 测试 merchantId 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setMerchantId(2L);
|
||||
}));
|
||||
// 测试 appId 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setAppId(2L);
|
||||
}));
|
||||
// 测试 createTime 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setCreateTime(buildTime(2021, 10, 20));
|
||||
}));
|
||||
// 准备参数
|
||||
PayChannelPageReqVO reqVO = new PayChannelPageReqVO();
|
||||
reqVO.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setRemark("灿灿子的支付渠道");
|
||||
reqVO.setFeeRate(0.03);
|
||||
reqVO.setMerchantId(1L);
|
||||
reqVO.setAppId(1L);
|
||||
reqVO.setConfig(JSON.toJSONString(payClientConfig));
|
||||
reqVO.setBeginCreateTime(buildTime(2021,11,19));
|
||||
reqVO.setEndCreateTime(buildTime(2021,11,21));
|
||||
|
||||
// 调用
|
||||
PageResult<PayChannelDO> pageResult = channelService.getChannelPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbChannel, pageResult.getList().get(0), "config");
|
||||
assertPojoEquals(payClientConfig, pageResult.getList().get(0).getConfig());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetChannelList() {
|
||||
// mock 数据
|
||||
AlipayPayClientConfig payClientConfig = getCertificateConfig();
|
||||
PayChannelDO dbChannel = randomPojo(PayChannelDO.class, o -> { // 等会查询到
|
||||
o.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setRemark("灿灿子的支付渠道");
|
||||
o.setFeeRate(0.03);
|
||||
o.setMerchantId(1L);
|
||||
o.setAppId(1L);
|
||||
o.setConfig(payClientConfig);
|
||||
o.setCreateTime(buildTime(2021,11,20));
|
||||
});
|
||||
channelMapper.insert(dbChannel);
|
||||
// 执行拷贝的时候会出现异常,所以在插入后要重置为null 后续在写入新的
|
||||
dbChannel.setConfig(null);
|
||||
// 测试 code 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setCode(PayChannelEnum.WX_PUB.getCode());
|
||||
}));
|
||||
// 测试 status 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
}));
|
||||
// 测试 remark 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o ->{
|
||||
o.setConfig(payClientConfig);
|
||||
o.setRemark("敏敏子的渠道");
|
||||
}));
|
||||
// 测试 feeRate 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setFeeRate(1.23);
|
||||
}));
|
||||
// 测试 merchantId 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setMerchantId(2L);
|
||||
}));
|
||||
// 测试 appId 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setAppId(2L);
|
||||
}));
|
||||
// 测试 createTime 不匹配
|
||||
channelMapper.insert(cloneIgnoreId(dbChannel, o -> {
|
||||
o.setConfig(payClientConfig);
|
||||
o.setCreateTime(buildTime(2021, 10, 20));
|
||||
}));
|
||||
// 准备参数
|
||||
PayChannelExportReqVO reqVO = new PayChannelExportReqVO();
|
||||
reqVO.setCode(PayChannelEnum.ALIPAY_APP.getCode());
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setRemark("灿灿子的支付渠道");
|
||||
reqVO.setFeeRate(0.03);
|
||||
reqVO.setMerchantId(1L);
|
||||
reqVO.setAppId(1L);
|
||||
reqVO.setConfig(JSON.toJSONString(payClientConfig));
|
||||
reqVO.setBeginCreateTime(buildTime(2021,11,19));
|
||||
reqVO.setEndCreateTime(buildTime(2021,11,21));
|
||||
|
||||
// 调用
|
||||
List<PayChannelDO> list = channelService.getChannelList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbChannel, list.get(0), "config");
|
||||
assertPojoEquals(payClientConfig, list.get(0).getConfig());
|
||||
}
|
||||
|
||||
public WXPayClientConfig getV2Config() {
|
||||
return new WXPayClientConfig()
|
||||
.setAppId("APP00001")
|
||||
.setMchId("MCH00001")
|
||||
.setApiVersion(WXPayClientConfig.API_VERSION_V2)
|
||||
.setMchKey("dsa1d5s6a1d6sa16d1sa56d15a61das6")
|
||||
.setApiV3Key("")
|
||||
.setPrivateCertContent("")
|
||||
.setPrivateKeyContent("");
|
||||
}
|
||||
|
||||
public WXPayClientConfig getV3Config() {
|
||||
return new WXPayClientConfig()
|
||||
.setAppId("APP00001")
|
||||
.setMchId("MCH00001")
|
||||
.setApiVersion(WXPayClientConfig.API_VERSION_V3)
|
||||
.setMchKey("")
|
||||
.setApiV3Key("sdadasdsadadsa")
|
||||
.setPrivateKeyContent("dsa445das415d15asd16ad156as")
|
||||
.setPrivateCertContent("dsadasd45asd4s5a");
|
||||
|
||||
}
|
||||
|
||||
public AlipayPayClientConfig getPublicKeyConfig() {
|
||||
return new AlipayPayClientConfig()
|
||||
.setServerUrl(AlipayPayClientConfig.SERVER_URL_PROD)
|
||||
.setAppId("APP00001")
|
||||
.setSignType(AlipayPayClientConfig.SIGN_TYPE_DEFAULT)
|
||||
.setMode(AlipayPayClientConfig.MODE_PUBLIC_KEY)
|
||||
.setPrivateKey("13131321312")
|
||||
.setAlipayPublicKey("13321321321")
|
||||
.setAppCertContent("")
|
||||
.setAlipayPublicCertContent("")
|
||||
.setRootCertContent("");
|
||||
}
|
||||
|
||||
public AlipayPayClientConfig getCertificateConfig() {
|
||||
return new AlipayPayClientConfig()
|
||||
.setServerUrl(AlipayPayClientConfig.SERVER_URL_PROD)
|
||||
.setAppId("APP00001")
|
||||
.setSignType(AlipayPayClientConfig.SIGN_TYPE_DEFAULT)
|
||||
.setMode(AlipayPayClientConfig.MODE_CERTIFICATE)
|
||||
.setPrivateKey("")
|
||||
.setAlipayPublicKey("")
|
||||
.setAppCertContent("13321321321sda")
|
||||
.setAlipayPublicCertContent("13321321321aqeqw")
|
||||
.setRootCertContent("13321321321dsad");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package cn.iocoder.yudao.module.pay.service.merchant;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.merchant.PayMerchantCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.merchant.PayMerchantExportReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.merchant.PayMerchantPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.merchant.PayMerchantUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayMerchantDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.merchant.PayMerchantMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||
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.pay.enums.ErrorCodeConstants.PAY_MERCHANT_NOT_EXISTS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link PayMerchantServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author aquan
|
||||
*/
|
||||
@Import(PayMerchantServiceImpl.class)
|
||||
public class PayMerchantServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PayMerchantServiceImpl merchantService;
|
||||
|
||||
@Resource
|
||||
private PayMerchantMapper merchantMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateMerchant_success() {
|
||||
// 准备参数
|
||||
PayMerchantCreateReqVO reqVO = randomPojo(PayMerchantCreateReqVO.class,o ->
|
||||
o.setStatus(RandomUtil.randomEle(CommonStatusEnum.values()).getStatus()));
|
||||
|
||||
// 调用
|
||||
Long merchantId = merchantService.createMerchant(reqVO);
|
||||
// 断言
|
||||
assertNotNull(merchantId);
|
||||
// 校验记录的属性是否正确
|
||||
PayMerchantDO merchant = merchantMapper.selectById(merchantId);
|
||||
assertPojoEquals(reqVO, merchant);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMerchant_success() {
|
||||
// mock 数据
|
||||
PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, o ->
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
merchantMapper.insert(dbMerchant);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
PayMerchantUpdateReqVO reqVO = randomPojo(PayMerchantUpdateReqVO.class, o -> {
|
||||
o.setId(dbMerchant.getId()); // 设置更新的 ID
|
||||
o.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
});
|
||||
|
||||
// 调用
|
||||
merchantService.updateMerchant(reqVO);
|
||||
// 校验是否更新正确
|
||||
PayMerchantDO merchant = merchantMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, merchant);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMerchant_notExists() {
|
||||
// 准备参数
|
||||
PayMerchantUpdateReqVO reqVO = randomPojo(PayMerchantUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> merchantService.updateMerchant(reqVO), PAY_MERCHANT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMerchant_success() {
|
||||
// mock 数据
|
||||
PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class,
|
||||
o-> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
merchantMapper.insert(dbMerchant);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbMerchant.getId();
|
||||
|
||||
// 调用
|
||||
merchantService.deleteMerchant(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(merchantMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMerchant_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> merchantService.deleteMerchant(id), PAY_MERCHANT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMerchantPage() {
|
||||
// mock 数据
|
||||
PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, o -> { // 等会查询到
|
||||
o.setNo("M1008611");
|
||||
o.setName("灿哥的杂货铺");
|
||||
o.setShortName("灿灿子");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setRemark("灿哥的杂货铺");
|
||||
o.setCreateTime(buildTime(2021,11,3));
|
||||
});
|
||||
merchantMapper.insert(dbMerchant);
|
||||
// 测试 no 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setNo("M200000")));
|
||||
// 测试 name 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setName("斌哥的杂货铺")));
|
||||
// 测试 shortName 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setShortName("斌斌子")));
|
||||
// 测试 status 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
// 测试 remark 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setRemark("斌哥的杂货铺")));
|
||||
// 测试 createTime 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setCreateTime(buildTime(2022,12,4))));
|
||||
// 准备参数
|
||||
PayMerchantPageReqVO reqVO = new PayMerchantPageReqVO();
|
||||
reqVO.setNo("M1008611");
|
||||
reqVO.setName("灿哥的杂货铺");
|
||||
reqVO.setShortName("灿灿子");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setRemark("灿哥的杂货铺");
|
||||
reqVO.setBeginCreateTime(buildTime(2021,11,2));
|
||||
reqVO.setEndCreateTime(buildTime(2021,11,4));
|
||||
|
||||
// 调用
|
||||
PageResult<PayMerchantDO> pageResult = merchantService.getMerchantPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbMerchant, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMerchantList() {
|
||||
// mock 数据
|
||||
PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, o -> { // 等会查询到
|
||||
o.setNo("M1008611");
|
||||
o.setName("灿哥的杂货铺");
|
||||
o.setShortName("灿灿子");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setRemark("灿哥的杂货铺");
|
||||
o.setCreateTime(buildTime(2021,11,3));
|
||||
});
|
||||
merchantMapper.insert(dbMerchant);
|
||||
// 测试 no 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setNo("M200000")));
|
||||
// 测试 name 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setName("斌哥的杂货铺")));
|
||||
// 测试 shortName 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setShortName("斌斌子")));
|
||||
// 测试 status 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
// 测试 remark 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setRemark("斌哥的杂货铺")));
|
||||
// 测试 createTime 不匹配
|
||||
merchantMapper.insert(cloneIgnoreId(dbMerchant, o -> o.setCreateTime(buildTime(2022,12,4))));
|
||||
// 准备参数
|
||||
PayMerchantExportReqVO reqVO = new PayMerchantExportReqVO();
|
||||
reqVO.setNo("M1008611");
|
||||
reqVO.setName("灿哥的杂货铺");
|
||||
reqVO.setShortName("灿灿子");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setRemark("灿哥的杂货铺");
|
||||
reqVO.setBeginCreateTime(buildTime(2021,11,2));
|
||||
reqVO.setEndCreateTime(buildTime(2021,11,4));
|
||||
|
||||
// 调用
|
||||
List<PayMerchantDO> list = merchantService.getMerchantList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbMerchant, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package cn.iocoder.yudao.module.pay.service.order;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.pay.config.PayProperties;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderExportReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.order.PayOrderMapper;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderNotifyStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.merchant.PayAppService;
|
||||
import cn.iocoder.yudao.module.pay.service.merchant.PayChannelService;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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.RandomUtils.randomPojo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* {@link PayOrderServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋艿
|
||||
*/
|
||||
@Import({PayOrderServiceImpl.class})
|
||||
public class PayOrderServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PayOrderServiceImpl orderService;
|
||||
|
||||
@Resource
|
||||
private PayOrderMapper orderMapper;
|
||||
|
||||
@MockBean
|
||||
private PayClientFactory payClientFactory;
|
||||
@MockBean
|
||||
private PayProperties properties;
|
||||
@MockBean
|
||||
private PayAppService appService;
|
||||
@MockBean
|
||||
private PayChannelService channelService;
|
||||
@MockBean
|
||||
private PayNotifyService notifyService;
|
||||
|
||||
public String generateNo() {
|
||||
return DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomInt(100000, 999999);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrderPage() {
|
||||
|
||||
String merchantOrderId = generateNo();
|
||||
String channelOrderId = generateNo();
|
||||
|
||||
// mock 数据
|
||||
PayOrderDO dbOrder = randomPojo(PayOrderDO.class, o -> { // 等会查询到
|
||||
o.setMerchantId(1L);
|
||||
o.setAppId(1L);
|
||||
o.setChannelId(1L);
|
||||
o.setChannelCode(PayChannelEnum.WX_PUB.getCode());
|
||||
o.setMerchantOrderId(merchantOrderId);
|
||||
o.setSubject("灿灿子的炸弹猫");
|
||||
o.setBody("斌斌子送给灿灿子的炸弹猫");
|
||||
o.setNotifyUrl("https://hc.com/lbh");
|
||||
o.setNotifyStatus(PayOrderNotifyStatusEnum.SUCCESS.getStatus());
|
||||
o.setAmount(10000L);
|
||||
o.setChannelFeeRate(0.01);
|
||||
o.setChannelFeeAmount(1L);
|
||||
o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus());
|
||||
o.setUserIp("127.0.0.1");
|
||||
o.setCreateTime(DateUtils.buildTime(2018, 1, 1, 10, 1, 0));
|
||||
o.setExpireTime(DateUtils.buildTime(2018, 1, 1, 10, 30, 0));
|
||||
o.setSuccessTime(DateUtils.buildTime(2018, 1, 1, 10, 10, 2));
|
||||
o.setNotifyTime(DateUtils.buildTime(2018, 1, 1, 10, 10, 15));
|
||||
o.setSuccessExtensionId(1L);
|
||||
o.setRefundStatus(PayRefundTypeEnum.NO.getStatus());
|
||||
o.setRefundTimes(0);
|
||||
o.setRefundAmount(0L);
|
||||
o.setChannelUserId("1008611");
|
||||
o.setChannelOrderNo(channelOrderId);
|
||||
o.setUpdateTime(DateUtils.buildTime(2018, 1, 1, 10, 10, 15));
|
||||
});
|
||||
orderMapper.insert(dbOrder);
|
||||
// 测试 merchantId 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setMerchantId(2L)));
|
||||
// 测试 appId 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setAppId(2L)));
|
||||
// 测试 channelId 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setChannelId(2L)));
|
||||
// 测试 channelCode 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setChannelCode(PayChannelEnum.ALIPAY_APP.getCode())));
|
||||
// 测试 merchantOrderId 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setMerchantOrderId(generateNo())));
|
||||
// 测试 notifyStatus 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setNotifyStatus(PayOrderNotifyStatusEnum.FAILURE.getStatus())));
|
||||
// 测试 status 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus())));
|
||||
// 测试 refundStatus 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setRefundStatus(PayRefundTypeEnum.ALL.getStatus())));
|
||||
// 测试 createTime 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setCreateTime(DateUtils.buildTime(2019, 1, 1, 10, 10,
|
||||
1))));
|
||||
// 准备参数
|
||||
PayOrderPageReqVO reqVO = new PayOrderPageReqVO();
|
||||
reqVO.setMerchantId(1L);
|
||||
reqVO.setAppId(1L);
|
||||
reqVO.setChannelId(1L);
|
||||
reqVO.setChannelCode(PayChannelEnum.WX_PUB.getCode());
|
||||
reqVO.setMerchantOrderId(merchantOrderId);
|
||||
reqVO.setNotifyStatus(PayOrderNotifyStatusEnum.SUCCESS.getStatus());
|
||||
reqVO.setStatus(PayOrderStatusEnum.SUCCESS.getStatus());
|
||||
reqVO.setRefundStatus(PayRefundTypeEnum.NO.getStatus());
|
||||
reqVO.setBeginCreateTime(DateUtils.buildTime(2018, 1, 1, 10, 1, 0));
|
||||
reqVO.setEndCreateTime(DateUtils.buildTime(2018, 1, 1, 10, 1, 0));
|
||||
|
||||
// 调用
|
||||
PageResult<PayOrderDO> pageResult = orderService.getOrderPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbOrder, pageResult.getList().get(0));
|
||||
// assertEquals(0, dbOrder.getUpdateTime().compareTo(pageResult.getList().get(0).getUpdateTime()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrderList() {
|
||||
// mock 数据
|
||||
String merchantOrderId = generateNo();
|
||||
String channelOrderId = generateNo();
|
||||
PayOrderDO dbOrder = randomPojo(PayOrderDO.class, o -> { // 等会查询到
|
||||
o.setMerchantId(1L);
|
||||
o.setAppId(1L);
|
||||
o.setChannelId(1L);
|
||||
o.setChannelCode(PayChannelEnum.WX_PUB.getCode());
|
||||
o.setMerchantOrderId(merchantOrderId);
|
||||
o.setSubject("灿灿子的炸弹猫");
|
||||
o.setBody("斌斌子送给灿灿子的炸弹猫");
|
||||
o.setNotifyUrl("https://hc.com/lbh");
|
||||
o.setNotifyStatus(PayOrderNotifyStatusEnum.SUCCESS.getStatus());
|
||||
o.setAmount(10000L);
|
||||
o.setChannelFeeRate(0.01);
|
||||
o.setChannelFeeAmount(1L);
|
||||
o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus());
|
||||
o.setUserIp("127.0.0.1");
|
||||
o.setCreateTime(DateUtils.buildTime(2018, 1, 1, 10, 1, 0));
|
||||
o.setExpireTime(DateUtils.buildTime(2018, 1, 1, 10, 30, 0));
|
||||
o.setSuccessTime(DateUtils.buildTime(2018, 1, 1, 10, 10, 2));
|
||||
o.setNotifyTime(DateUtils.buildTime(2018, 1, 1, 10, 10, 15));
|
||||
o.setSuccessExtensionId(1L);
|
||||
o.setRefundStatus(PayRefundTypeEnum.NO.getStatus());
|
||||
o.setRefundTimes(0);
|
||||
o.setRefundAmount(0L);
|
||||
o.setChannelUserId("1008611");
|
||||
o.setChannelOrderNo(channelOrderId);
|
||||
o.setUpdateTime(DateUtils.buildTime(2018, 1, 1, 10, 10, 15));
|
||||
|
||||
});
|
||||
orderMapper.insert(dbOrder);
|
||||
// 测试 merchantId 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setMerchantId(2L)));
|
||||
// 测试 appId 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setAppId(2L)));
|
||||
// 测试 channelId 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setChannelId(2L)));
|
||||
// 测试 channelCode 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setChannelCode(PayChannelEnum.ALIPAY_APP.getCode())));
|
||||
// 测试 merchantOrderId 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setMerchantOrderId(generateNo())));
|
||||
// 测试 notifyStatus 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setNotifyStatus(PayOrderNotifyStatusEnum.FAILURE.getStatus())));
|
||||
// 测试 status 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus())));
|
||||
// 测试 refundStatus 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setRefundStatus(PayRefundTypeEnum.ALL.getStatus())));
|
||||
// 测试 createTime 不匹配
|
||||
orderMapper.insert(cloneIgnoreId(dbOrder, o -> o.setCreateTime(DateUtils.buildTime(2019, 1, 1, 10, 10,
|
||||
1))));
|
||||
// 准备参数
|
||||
PayOrderExportReqVO reqVO = new PayOrderExportReqVO();
|
||||
reqVO.setMerchantId(1L);
|
||||
reqVO.setAppId(1L);
|
||||
reqVO.setChannelId(1L);
|
||||
reqVO.setChannelCode(PayChannelEnum.WX_PUB.getCode());
|
||||
reqVO.setMerchantOrderId(merchantOrderId);
|
||||
reqVO.setNotifyStatus(PayOrderNotifyStatusEnum.SUCCESS.getStatus());
|
||||
reqVO.setStatus(PayOrderStatusEnum.SUCCESS.getStatus());
|
||||
reqVO.setRefundStatus(PayRefundTypeEnum.NO.getStatus());
|
||||
reqVO.setBeginCreateTime(DateUtils.buildTime(2018, 1, 1, 10, 1, 0));
|
||||
reqVO.setEndCreateTime(DateUtils.buildTime(2018, 1, 1, 10, 1, 0));
|
||||
|
||||
// 调用
|
||||
List<PayOrderDO> list = orderService.getOrderList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbOrder, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
package cn.iocoder.yudao.module.pay.service.refund;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.refund.vo.PayRefundExportReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.refund.vo.PayRefundPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO;
|
||||
import cn.iocoder.yudao.module.pay.dal.mysql.refund.PayRefundMapper;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderNotifyStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.merchant.PayAppService;
|
||||
import cn.iocoder.yudao.module.pay.service.merchant.PayChannelService;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderExtensionService;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
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.RandomUtils.randomPojo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@Import(PayRefundServiceImpl.class)
|
||||
public class PayRefundServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PayRefundServiceImpl refundService;
|
||||
|
||||
@Resource
|
||||
private PayRefundMapper refundMapper;
|
||||
|
||||
@MockBean
|
||||
private PayClientFactory payClientFactory;
|
||||
@MockBean
|
||||
private PayOrderService orderService;
|
||||
@MockBean
|
||||
private PayOrderExtensionService orderExtensionService;
|
||||
@MockBean
|
||||
private PayAppService appService;
|
||||
@MockBean
|
||||
private PayChannelService channelService;
|
||||
@MockBean
|
||||
private PayNotifyService notifyService;
|
||||
|
||||
@Test
|
||||
public void testGetRefundPage() {
|
||||
// mock 数据
|
||||
PayRefundDO dbRefund = randomPojo(PayRefundDO.class, o -> { // 等会查询到
|
||||
o.setMerchantId(1L);
|
||||
o.setAppId(1L);
|
||||
o.setChannelId(1L);
|
||||
o.setChannelCode(PayChannelEnum.WX_PUB.getCode());
|
||||
o.setOrderId(1L);
|
||||
o.setTradeNo("OT0000001");
|
||||
o.setMerchantOrderId("MOT0000001");
|
||||
o.setMerchantRefundNo("MRF0000001");
|
||||
o.setNotifyUrl("https://www.cancanzi.com");
|
||||
o.setNotifyStatus(PayOrderNotifyStatusEnum.SUCCESS.getStatus());
|
||||
o.setStatus(PayRefundStatusEnum.SUCCESS.getStatus());
|
||||
o.setType(PayRefundTypeEnum.SOME.getStatus());
|
||||
o.setPayAmount(100L);
|
||||
o.setRefundAmount(500L);
|
||||
o.setReason("就是想退款了,你有意见吗");
|
||||
o.setUserIp("127.0.0.1");
|
||||
o.setChannelOrderNo("CH0000001");
|
||||
o.setChannelRefundNo("CHR0000001");
|
||||
o.setChannelErrorCode("");
|
||||
o.setChannelErrorMsg("");
|
||||
o.setChannelExtras("");
|
||||
o.setExpireTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 30));
|
||||
o.setSuccessTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 15));
|
||||
o.setNotifyTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 20));
|
||||
o.setCreateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 10));
|
||||
o.setUpdateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 35));
|
||||
});
|
||||
refundMapper.insert(dbRefund);
|
||||
// 测试 merchantId 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setMerchantId(2L)));
|
||||
// 测试 appId 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setAppId(2L)));
|
||||
// 测试 channelCode 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setChannelCode(PayChannelEnum.ALIPAY_APP.getCode())));
|
||||
// 测试 merchantRefundNo 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setMerchantRefundNo("MRF1111112")));
|
||||
// 测试 notifyStatus 不匹配
|
||||
refundMapper.insert(
|
||||
cloneIgnoreId(dbRefund, o -> o.setNotifyStatus(PayOrderNotifyStatusEnum.FAILURE.getStatus())));
|
||||
// 测试 status 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setStatus(PayRefundStatusEnum.CLOSE.getStatus())));
|
||||
// 测试 type 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setType(PayRefundTypeEnum.ALL.getStatus())));
|
||||
// 测试 createTime 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o ->
|
||||
o.setCreateTime(DateUtils.buildTime(2022, 1, 1, 10, 10, 10))));
|
||||
// 准备参数
|
||||
PayRefundPageReqVO reqVO = new PayRefundPageReqVO();
|
||||
reqVO.setMerchantId(1L);
|
||||
reqVO.setAppId(1L);
|
||||
reqVO.setChannelCode(PayChannelEnum.WX_PUB.getCode());
|
||||
reqVO.setMerchantRefundNo("MRF0000001");
|
||||
reqVO.setNotifyStatus(PayOrderNotifyStatusEnum.SUCCESS.getStatus());
|
||||
reqVO.setStatus(PayRefundStatusEnum.SUCCESS.getStatus());
|
||||
reqVO.setType(PayRefundTypeEnum.SOME.getStatus());
|
||||
reqVO.setBeginCreateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 10));
|
||||
reqVO.setEndCreateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 12));
|
||||
|
||||
|
||||
// 调用
|
||||
PageResult<PayRefundDO> pageResult = refundService.getRefundPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbRefund, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRefundList() {
|
||||
// mock 数据
|
||||
PayRefundDO dbRefund = randomPojo(PayRefundDO.class, o -> { // 等会查询到
|
||||
o.setMerchantId(1L);
|
||||
o.setAppId(1L);
|
||||
o.setChannelId(1L);
|
||||
o.setChannelCode(PayChannelEnum.WX_PUB.getCode());
|
||||
o.setOrderId(1L);
|
||||
o.setTradeNo("OT0000001");
|
||||
o.setMerchantOrderId("MOT0000001");
|
||||
o.setMerchantRefundNo("MRF0000001");
|
||||
o.setNotifyUrl("https://www.cancanzi.com");
|
||||
o.setNotifyStatus(PayOrderNotifyStatusEnum.SUCCESS.getStatus());
|
||||
o.setStatus(PayRefundStatusEnum.SUCCESS.getStatus());
|
||||
o.setType(PayRefundTypeEnum.SOME.getStatus());
|
||||
o.setPayAmount(100L);
|
||||
o.setRefundAmount(500L);
|
||||
o.setReason("就是想退款了,你有意见吗");
|
||||
o.setUserIp("127.0.0.1");
|
||||
o.setChannelOrderNo("CH0000001");
|
||||
o.setChannelRefundNo("CHR0000001");
|
||||
o.setChannelErrorCode("");
|
||||
o.setChannelErrorMsg("");
|
||||
o.setChannelExtras("");
|
||||
o.setExpireTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 30));
|
||||
o.setSuccessTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 15));
|
||||
o.setNotifyTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 20));
|
||||
o.setCreateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 10));
|
||||
o.setUpdateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 35));
|
||||
});
|
||||
refundMapper.insert(dbRefund);
|
||||
// 测试 merchantId 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setMerchantId(2L)));
|
||||
// 测试 appId 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setAppId(2L)));
|
||||
// 测试 channelCode 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setChannelCode(PayChannelEnum.ALIPAY_APP.getCode())));
|
||||
// 测试 merchantRefundNo 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setMerchantRefundNo("MRF1111112")));
|
||||
// 测试 notifyStatus 不匹配
|
||||
refundMapper.insert(
|
||||
cloneIgnoreId(dbRefund, o -> o.setNotifyStatus(PayOrderNotifyStatusEnum.FAILURE.getStatus())));
|
||||
// 测试 status 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setStatus(PayRefundStatusEnum.CLOSE.getStatus())));
|
||||
// 测试 type 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setType(PayRefundTypeEnum.ALL.getStatus())));
|
||||
// 测试 createTime 不匹配
|
||||
refundMapper.insert(cloneIgnoreId(dbRefund, o ->
|
||||
o.setCreateTime(DateUtils.buildTime(2022, 1, 1, 10, 10, 10))));
|
||||
|
||||
// 准备参数
|
||||
PayRefundExportReqVO reqVO = new PayRefundExportReqVO();
|
||||
reqVO.setMerchantId(1L);
|
||||
reqVO.setAppId(1L);
|
||||
reqVO.setChannelCode(PayChannelEnum.WX_PUB.getCode());
|
||||
reqVO.setMerchantRefundNo("MRF0000001");
|
||||
reqVO.setNotifyStatus(PayOrderNotifyStatusEnum.SUCCESS.getStatus());
|
||||
reqVO.setStatus(PayRefundStatusEnum.SUCCESS.getStatus());
|
||||
reqVO.setType(PayRefundTypeEnum.SOME.getStatus());
|
||||
reqVO.setBeginCreateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 10));
|
||||
reqVO.setEndCreateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 12));
|
||||
|
||||
// 调用
|
||||
List<PayRefundDO> list = refundService.getRefundList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRefund, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
spring:
|
||||
main:
|
||||
lazy-initialization: true # 开启懒加载,加快速度
|
||||
banner-mode: off # 单元测试,禁用 Banner
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
|
||||
spring:
|
||||
# 数据源配置项
|
||||
datasource:
|
||||
name: ruoyi-vue-pro
|
||||
url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false; # MODE 使用 MySQL 模式;DATABASE_TO_UPPER 配置表和字段使用小写
|
||||
driver-class-name: org.h2.Driver
|
||||
username: sa
|
||||
password:
|
||||
druid:
|
||||
async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度
|
||||
initial-size: 1 # 单元测试,配置为 1,提升启动速度
|
||||
sql:
|
||||
init:
|
||||
schema-locations: classpath:/sql/create_tables.sql
|
||||
|
||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||
redis:
|
||||
host: 127.0.0.1 # 地址
|
||||
port: 16379 # 端口(单元测试,使用 16379 端口)
|
||||
database: 0 # 数据库索引
|
||||
|
||||
mybatis:
|
||||
lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
|
||||
--- #################### 配置中心相关配置 ####################
|
||||
|
||||
--- #################### 服务保障相关配置 ####################
|
||||
|
||||
# Lock4j 配置项(单元测试,禁用 Lock4j)
|
||||
|
||||
# Resilience4j 配置项
|
||||
|
||||
--- #################### 监控相关配置 ####################
|
||||
|
||||
--- #################### 芋道相关配置 ####################
|
||||
|
||||
# 芋道配置项,设置当前项目所有自定义的配置
|
||||
yudao:
|
||||
info:
|
||||
base-package: cn.iocoder.yudao.module
|
||||
@@ -0,0 +1,4 @@
|
||||
<configuration>
|
||||
<!-- 引用 Spring Boot 的 logback 基础配置 -->
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
|
||||
</configuration>
|
||||
@@ -0,0 +1,5 @@
|
||||
DELETE FROM pay_merchant;
|
||||
DELETE FROM pay_app;
|
||||
DELETE FROM pay_channel;
|
||||
DELETE FROM pay_order;
|
||||
DELETE FROM pay_refund;
|
||||
@@ -0,0 +1,114 @@
|
||||
CREATE TABLE IF NOT EXISTS "pay_merchant" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"no" varchar(32) NOT NULL,
|
||||
"name" varchar(64) NOT NULL,
|
||||
"short_name" varchar(64) NOT NULL,
|
||||
"status" tinyint NOT NULL,
|
||||
"remark" varchar(255) DEFAULT NULL,
|
||||
"creator" varchar(64) DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '支付商户信息';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "pay_app" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"name" varchar(64) NOT NULL,
|
||||
"status" tinyint NOT NULL,
|
||||
"remark" varchar(255) DEFAULT NULL,
|
||||
`pay_notify_url` varchar(1024) NOT NULL,
|
||||
`refund_notify_url` varchar(1024) NOT NULL,
|
||||
`merchant_id` bigint(20) NOT NULL,
|
||||
"creator" varchar(64) DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '支付应用信息';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "pay_channel" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"code" varchar(32) NOT NULL,
|
||||
"status" tinyint(4) NOT NULL,
|
||||
"remark" varchar(255) DEFAULT NULL,
|
||||
"fee_rate" double NOT NULL DEFAULT 0,
|
||||
"merchant_id" bigint(20) NOT NULL,
|
||||
"app_id" bigint(20) NOT NULL,
|
||||
"config" varchar(10240) NOT NULL,
|
||||
"creator" varchar(64) NULL DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) NULL DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '支付渠道';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `pay_order` (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`merchant_id` bigint(20) NOT NULL,
|
||||
`app_id` bigint(20) NOT NULL,
|
||||
`channel_id` bigint(20) DEFAULT NULL,
|
||||
`channel_code` varchar(32) DEFAULT NULL,
|
||||
`merchant_order_id` varchar(64) NOT NULL,
|
||||
`subject` varchar(32) NOT NULL,
|
||||
`body` varchar(128) NOT NULL,
|
||||
`notify_url` varchar(1024) NOT NULL,
|
||||
`notify_status` tinyint(4) NOT NULL,
|
||||
`amount` bigint(20) NOT NULL,
|
||||
`channel_fee_rate` double DEFAULT 0,
|
||||
`channel_fee_amount` bigint(20) DEFAULT 0,
|
||||
`status` tinyint(4) NOT NULL,
|
||||
`user_ip` varchar(50) NOT NULL,
|
||||
`expire_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`success_time` datetime(0) DEFAULT CURRENT_TIMESTAMP,
|
||||
`notify_time` datetime(0) DEFAULT CURRENT_TIMESTAMP,
|
||||
`success_extension_id` bigint(20) DEFAULT NULL COMMENT '支付成功的订单拓展单编号',
|
||||
`refund_status` tinyint(4) NOT NULL,
|
||||
`refund_times` tinyint(4) NOT NULL,
|
||||
`refund_amount` bigint(20) NOT NULL,
|
||||
`channel_user_id` varchar(255) DEFAULT NULL,
|
||||
`channel_order_no` varchar(64) DEFAULT NULL,
|
||||
`creator` varchar(64) DEFAULT '',
|
||||
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updater` varchar(64) DEFAULT '',
|
||||
`update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '支付订单';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `pay_refund` (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`merchant_id` bigint(20) NOT NULL,
|
||||
`app_id` bigint(20) NOT NULL,
|
||||
`channel_id` bigint(20) NOT NULL,
|
||||
`channel_code` varchar(32) NOT NULL,
|
||||
`order_id` bigint(20) NOT NULL,
|
||||
`trade_no` varchar(64) NOT NULL,
|
||||
`merchant_order_id` varchar(64) NOT NULL,
|
||||
`merchant_refund_no` varchar(64) NOT NULL,
|
||||
`notify_url` varchar(1024) NOT NULL,
|
||||
`notify_status` tinyint(4) NOT NULL,
|
||||
`status` tinyint(4) NOT NULL,
|
||||
`type` tinyint(4) NOT NULL,
|
||||
`pay_amount` bigint(20) NOT NULL,
|
||||
`refund_amount` bigint(20) NOT NULL,
|
||||
`reason` varchar(256) NOT NULL,
|
||||
`user_ip` varchar(50) NULL DEFAULT NULL,
|
||||
`channel_order_no` varchar(64) NOT NULL,
|
||||
`channel_refund_no` varchar(64) NULL DEFAULT NULL,
|
||||
`channel_error_code` varchar(128) NULL DEFAULT NULL,
|
||||
`channel_error_msg` varchar(256) NULL DEFAULT NULL,
|
||||
`channel_extras` varchar(1024) NULL DEFAULT NULL,
|
||||
`expire_time` datetime(0) NULL DEFAULT NULL,
|
||||
`success_time` datetime(0) NULL DEFAULT NULL,
|
||||
`notify_time` datetime(0) NULL DEFAULT NULL,
|
||||
`creator` varchar(64) NULL DEFAULT '',
|
||||
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updater` varchar(64) NULL DEFAULT '',
|
||||
`update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '退款订单';
|
||||
Reference in New Issue
Block a user