|
| 1 | +package com.wechat.pay.java.core.notification; |
| 2 | + |
| 3 | +import static com.wechat.pay.java.core.model.TestConfig.API_V3_KEY; |
| 4 | +import static com.wechat.pay.java.core.model.TestConfig.MERCHANT_CERTIFICATE_SERIAL_NUMBER; |
| 5 | +import static com.wechat.pay.java.core.model.TestConfig.MERCHANT_PRIVATE_KEY_STRING; |
| 6 | +import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER; |
| 7 | +import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY; |
| 8 | +import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY_PATH; |
| 9 | +import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY_STRING; |
| 10 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 11 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 12 | + |
| 13 | +import com.wechat.pay.java.core.notification.RSACombinedNotificationConfig.Builder; |
| 14 | +import java.util.stream.Stream; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | +import org.junit.jupiter.params.ParameterizedTest; |
| 17 | +import org.junit.jupiter.params.provider.MethodSource; |
| 18 | + |
| 19 | +class RSACombinedNotificationConfigTest implements NotificationConfigTest { |
| 20 | + |
| 21 | + @ParameterizedTest |
| 22 | + @MethodSource("BuilderProvider") |
| 23 | + void testConfigWithBuilderProvider(Builder builder) { |
| 24 | + RSACombinedNotificationConfig c = builder.build(); |
| 25 | + |
| 26 | + assertNotNull(c); |
| 27 | + assertNotNull(c.createAeadCipher()); |
| 28 | + assertNotNull(c.createVerifier()); |
| 29 | + assertNotNull(c.getCipherType()); |
| 30 | + assertNotNull(c.getSignType()); |
| 31 | + } |
| 32 | + |
| 33 | + static Stream<Builder> BuilderProvider() { |
| 34 | + return Stream.of( |
| 35 | + // from string |
| 36 | + new Builder() |
| 37 | + .merchantId("123456") |
| 38 | + .privateKey(MERCHANT_PRIVATE_KEY_STRING) |
| 39 | + .merchantSerialNumber(MERCHANT_CERTIFICATE_SERIAL_NUMBER) |
| 40 | + .publicKey(WECHAT_PAY_PUBLIC_KEY_STRING) |
| 41 | + .publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER) |
| 42 | + .apiV3Key(API_V3_KEY), |
| 43 | + |
| 44 | + // from path |
| 45 | + new Builder() |
| 46 | + .merchantId("123456") |
| 47 | + .privateKey(MERCHANT_PRIVATE_KEY_STRING) |
| 48 | + .merchantSerialNumber(MERCHANT_CERTIFICATE_SERIAL_NUMBER) |
| 49 | + .publicKeyFromPath(WECHAT_PAY_PUBLIC_KEY_PATH) |
| 50 | + .publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER) |
| 51 | + .apiV3Key(API_V3_KEY), |
| 52 | + |
| 53 | + // with publickey |
| 54 | + new Builder() |
| 55 | + .merchantId("123456") |
| 56 | + .privateKey(MERCHANT_PRIVATE_KEY_STRING) |
| 57 | + .merchantSerialNumber(MERCHANT_CERTIFICATE_SERIAL_NUMBER) |
| 58 | + .publicKey(WECHAT_PAY_PUBLIC_KEY) |
| 59 | + .publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER) |
| 60 | + .apiV3Key(API_V3_KEY)); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + void testBuildConfigWithoutEnoughParam() { |
| 65 | + Builder builder = new Builder().apiV3Key(API_V3_KEY); |
| 66 | + assertThrows(NullPointerException.class, builder::build); |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public NotificationConfig buildNotificationConfig() { |
| 71 | + return new Builder() |
| 72 | + .publicKey(WECHAT_PAY_PUBLIC_KEY) |
| 73 | + .publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER) |
| 74 | + .build(); |
| 75 | + } |
| 76 | +} |
0 commit comments