|
|
@@ -0,0 +1,79 @@
|
|
|
+package com.ruoyi.app.push;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
+
|
|
|
+class BusinessPushPropertiesTest {
|
|
|
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
+ .withUserConfiguration(PushConfiguration.class);
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void defaultsToUniWithoutNativeCredentials() {
|
|
|
+ contextRunner.run(context -> {
|
|
|
+ assertTrue(context.isRunning());
|
|
|
+ assertEquals(BusinessPushProperties.Mode.UNI,
|
|
|
+ context.getBean(BusinessPushProperties.class).getMode());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void explicitUniDoesNotRequireNativeCredentials() {
|
|
|
+ contextRunner.withPropertyValues("business-push.mode=uni")
|
|
|
+ .run(context -> assertTrue(context.isRunning()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void nativeModeRejectsIncompleteAppConfiguration() {
|
|
|
+ contextRunner.withPropertyValues("business-push.mode=native")
|
|
|
+ .run(context -> assertNotNull(context.getStartupFailure()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void nativeModeAcceptsThreeCompleteAppConfigurations() {
|
|
|
+ contextRunner.withPropertyValues(completeNativeProperties())
|
|
|
+ .run(context -> {
|
|
|
+ assertTrue(context.isRunning());
|
|
|
+ BusinessPushProperties properties = context.getBean(BusinessPushProperties.class);
|
|
|
+ assertEquals(BusinessPushProperties.Mode.NATIVE, properties.getMode());
|
|
|
+ assertEquals("user.json", properties.getApp(RecipientApp.USER).getFcmCredentialsPath());
|
|
|
+ assertEquals("merchant.json", properties.getApp(RecipientApp.MERCHANT).getFcmCredentialsPath());
|
|
|
+ assertEquals("rider.json", properties.getApp(RecipientApp.RIDER).getFcmCredentialsPath());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void nativeModeRejectsUnknownApnsEnvironment() {
|
|
|
+ String[] values = completeNativeProperties();
|
|
|
+ values[1] = "business-push.apns-environment=staging";
|
|
|
+ contextRunner.withPropertyValues(values)
|
|
|
+ .run(context -> assertNotNull(context.getStartupFailure()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String[] completeNativeProperties() {
|
|
|
+ return new String[]{
|
|
|
+ "business-push.mode=native",
|
|
|
+ "business-push.apns-environment=production",
|
|
|
+ "business-push.apps.user.fcm-credentials-path=user.json",
|
|
|
+ "business-push.apps.user.apns-certificate-path=user.p12",
|
|
|
+ "business-push.apps.user.apns-certificate-password=secret",
|
|
|
+ "business-push.apps.user.apns-topic=com.example.user",
|
|
|
+ "business-push.apps.merchant.fcm-credentials-path=merchant.json",
|
|
|
+ "business-push.apps.merchant.apns-certificate-path=merchant.p12",
|
|
|
+ "business-push.apps.merchant.apns-certificate-password=secret",
|
|
|
+ "business-push.apps.merchant.apns-topic=com.example.merchant",
|
|
|
+ "business-push.apps.rider.fcm-credentials-path=rider.json",
|
|
|
+ "business-push.apps.rider.apns-certificate-path=rider.p12",
|
|
|
+ "business-push.apps.rider.apns-certificate-password=secret",
|
|
|
+ "business-push.apps.rider.apns-topic=com.example.rider"
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ @EnableConfigurationProperties(BusinessPushProperties.class)
|
|
|
+ static class PushConfiguration {
|
|
|
+ }
|
|
|
+}
|