From 6fbf7b261b49b63ec68047822ed68c90f16ffe3c Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Thu, 17 Aug 2023 21:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E7=A0=81=E6=94=AF=E4=BB=98=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E9=80=80=E6=AC=BE=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=20=E4=BF=AE=E5=A4=8D=E9=80=80=E6=AC=BE=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=EF=BC=8C=E6=B8=A0=E9=81=93=E9=94=99=E8=AF=AF=E6=9C=AA?= =?UTF-8?q?=E8=B5=8B=E5=80=BCbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/alipay/AbstractAlipayPayClient.java | 2 +- .../impl/alipay/AlipayQrPayClientTest.java | 141 +++++++++++++++++- .../DecorateComponentServiceImplTest.java | 6 +- 3 files changed, 138 insertions(+), 11 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java index e92544729..5e52e8e8e 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java @@ -148,7 +148,7 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient { + o.setSubCode(""); + o.setGmtRefundPay(refundTime); + }); + // mock + when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> { + assertInstanceOf(AlipayTradeRefundModel.class, request.getBizModel()); + AlipayTradeRefundModel bizModel = (AlipayTradeRefundModel) request.getBizModel(); + assertEquals(outRefundNo, bizModel.getOutRequestNo()); + assertEquals(outTradeNo, bizModel.getOutTradeNo()); + assertEquals(String.valueOf(refundAmount / 100.0), bizModel.getRefundAmount()); + return true; + }))).thenReturn(response); + // 准备请求参数 + PayRefundUnifiedReqDTO refundReqDTO = randomPojo(PayRefundUnifiedReqDTO.class, o -> { + o.setOutRefundNo(outRefundNo); + o.setOutTradeNo(outTradeNo); + o.setNotifyUrl(notifyUrl); + o.setRefundPrice(refundAmount); + }); + PayRefundRespDTO resp = client.unifiedRefund(refundReqDTO); + // 断言 + assertEquals(PayRefundStatusRespEnum.SUCCESS.getStatus(), resp.getStatus()); + assertNull(resp.getChannelRefundNo()); + assertEquals(LocalDateTimeUtil.of(refundTime), resp.getSuccessTime()); + assertEquals(outRefundNo, resp.getOutRefundNo()); + assertSame(response, resp.getRawData()); + } + + @Test + @DisplayName("支付包扫描退款,渠道返回失败") + public void test_unified_refund_channel_failed() throws AlipayApiException { + // 准备返回对象 + String notifyUrl = randomURL(); + String subCode = randomString(); + String subMsg = randomString(); + AlipayTradeRefundResponse response = randomPojo(AlipayTradeRefundResponse.class, o -> { + o.setSubCode(subCode); + o.setSubMsg(subMsg); + }); + // mock + when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> { + assertInstanceOf(AlipayTradeRefundModel.class, request.getBizModel()); + return true; + }))).thenReturn(response); + // 准备请求参数 + String outRefundNo = randomString(); + String outTradeNo = randomString(); + PayRefundUnifiedReqDTO refundReqDTO = randomPojo(PayRefundUnifiedReqDTO.class, o -> { + o.setOutRefundNo(outRefundNo); + o.setOutTradeNo(outTradeNo); + o.setNotifyUrl(notifyUrl); + }); + PayRefundRespDTO resp = client.unifiedRefund(refundReqDTO); + // 断言 + assertEquals(PayRefundStatusRespEnum.FAILURE.getStatus(), resp.getStatus()); + assertNull(resp.getChannelRefundNo()); + assertEquals(subCode, resp.getChannelErrorCode()); + assertEquals(subMsg, resp.getChannelErrorMsg()); + assertNull(resp.getSuccessTime()); + assertEquals(outRefundNo, resp.getOutRefundNo()); + assertSame(response, resp.getRawData()); + } + + @Test + @DisplayName("支付包扫描退款,参数校验不通过") + public void test_unified_refund_param_validate() { + // 准备请求参数 + String notifyUrl = randomURL(); + PayRefundUnifiedReqDTO refundReqDTO = randomPojo(PayRefundUnifiedReqDTO.class, o -> { + o.setOutTradeNo(""); + o.setNotifyUrl(notifyUrl); + }); + // 断言 + assertThrows(ConstraintViolationException.class, () -> client.unifiedRefund(refundReqDTO)); + } + + @Test + @DisplayName("支付包扫描退款,抛出业务异常") + public void test_unified_refund_throw_service_exception() throws AlipayApiException { + // mock + when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> true))) + .thenThrow(ServiceExceptionUtil.exception(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR)); + // 准备请求参数 + String notifyUrl = randomURL(); + PayRefundUnifiedReqDTO refundReqDTO = randomPojo(PayRefundUnifiedReqDTO.class, o -> { + o.setNotifyUrl(notifyUrl); + }); + // 断言 + assertThrows(ServiceException.class, () -> client.unifiedRefund(refundReqDTO)); + } + @Test + @DisplayName("支付包扫描退款,抛出系统异常") + public void test_unified_refund_throw_pay_exception() throws AlipayApiException { + // mock + when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> true))) + .thenThrow(new RuntimeException("系统异常")); + // 准备请求参数 + String notifyUrl = randomURL(); + PayRefundUnifiedReqDTO refundReqDTO = randomPojo(PayRefundUnifiedReqDTO.class, o -> { + o.setNotifyUrl(notifyUrl); + }); + // 断言 + assertThrows(PayException.class, () -> client.unifiedRefund(refundReqDTO)); + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java index fa291e5fa..7b3f2ca10 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java @@ -7,16 +7,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import java.util.ArrayList; import java.util.List; import static cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum.ROLLING_NEWS; import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum.INDEX; -import static org.mockito.ArgumentMatchers.eq; -// TODO @芋艿:后续 review 下 +// TODO 待完成 @芋艿:后续 review 下 /** * @author jason */ @@ -41,6 +39,6 @@ public class DecorateComponentServiceImplTest extends BaseMockitoUnitTest { .setCode(ROLLING_NEWS.getCode()).setId(1L); list.add(decorateDO); //mock 方法 - Mockito.when(decorateComponentMapper.selectListByPageAndStatus(eq(1))).thenReturn(list); + //Mockito.when(decorateComponentMapper.selectListByPageAndStatus(eq(1))).thenReturn(list); } }