|
@@ -18,10 +18,10 @@ import static org.mockito.Mockito.*;
|
|
|
/** 发送Apple类型化通知并以Apple接受结果为准,不把队列成功当投递接受。 */
|
|
/** 发送Apple类型化通知并以Apple接受结果为准,不把队列成功当投递接受。 */
|
|
|
class ApnsPushyTransportTest {
|
|
class ApnsPushyTransportTest {
|
|
|
@Test
|
|
@Test
|
|
|
- void productionTestNeverReusesSandboxClientAndClientsAreReusedAndClosed() throws Exception {
|
|
|
|
|
|
|
+ void configuredTestEnvironmentNeverReusesOtherGatewayAndClientsAreReusedAndClosed() throws Exception {
|
|
|
var properties = new BusinessPushProperties();
|
|
var properties = new BusinessPushProperties();
|
|
|
properties.setMode(BusinessPushProperties.Mode.NATIVE);
|
|
properties.setMode(BusinessPushProperties.Mode.NATIVE);
|
|
|
- properties.setApnsEnvironment(BusinessPushProperties.ApnsEnvironment.DEVELOPMENT);
|
|
|
|
|
|
|
+ properties.setApnsEnvironment(BusinessPushProperties.ApnsEnvironment.PRODUCTION);
|
|
|
for (RecipientApp app : RecipientApp.values()) {
|
|
for (RecipientApp app : RecipientApp.values()) {
|
|
|
var config = new BusinessPushProperties.AppProperties();
|
|
var config = new BusinessPushProperties.AppProperties();
|
|
|
config.setApnsCertificatePath(app.name() + ".p12");
|
|
config.setApnsCertificatePath(app.name() + ".p12");
|
|
@@ -41,11 +41,13 @@ class ApnsPushyTransportTest {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
// 测试客户端可以先初始化;之后 native 启动仍须加载三端业务客户端。
|
|
// 测试客户端可以先初始化;之后 native 启动仍须加载三端业务客户端。
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "test", "body", "{}");
|
|
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "a".repeat(64), "test", "body", "{}");
|
|
|
|
|
+ properties.setApnsEnvironment(BusinessPushProperties.ApnsEnvironment.DEVELOPMENT);
|
|
|
sender.initialize();
|
|
sender.initialize();
|
|
|
sender.initialize();
|
|
sender.initialize();
|
|
|
sender.send(RecipientApp.USER, "a".repeat(64), "business", "body", "{}");
|
|
sender.send(RecipientApp.USER, "a".repeat(64), "business", "body", "{}");
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "test", "body", "{}");
|
|
|
|
|
|
|
+ properties.setApnsEnvironment(BusinessPushProperties.ApnsEnvironment.PRODUCTION);
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "a".repeat(64), "test", "body", "{}");
|
|
|
assertEquals(java.util.List.of("USER:PRODUCTION", "USER:DEVELOPMENT", "MERCHANT:DEVELOPMENT", "RIDER:DEVELOPMENT"), factoryCalls);
|
|
assertEquals(java.util.List.of("USER:PRODUCTION", "USER:DEVELOPMENT", "MERCHANT:DEVELOPMENT", "RIDER:DEVELOPMENT"), factoryCalls);
|
|
|
verify(production, times(2)).sendNotification(any(SimpleApnsPushNotification.class));
|
|
verify(production, times(2)).sendNotification(any(SimpleApnsPushNotification.class));
|
|
|
verify(sandbox).sendNotification(any(SimpleApnsPushNotification.class));
|
|
verify(sandbox).sendNotification(any(SimpleApnsPushNotification.class));
|
|
@@ -97,7 +99,7 @@ class ApnsPushyTransportTest {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
IllegalStateException rejected = assertThrows(IllegalStateException.class, () ->
|
|
IllegalStateException rejected = assertThrows(IllegalStateException.class, () ->
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "title", "body", "{\"ddId\":123}"));
|
|
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "a".repeat(64), "title", "body", "{\"ddId\":123}"));
|
|
|
assertEquals("APNS_BadDeviceToken", rejected.getMessage());
|
|
assertEquals("APNS_BadDeviceToken", rejected.getMessage());
|
|
|
var capture = org.mockito.ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
|
var capture = org.mockito.ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
|
|
verify(client).sendNotification(capture.capture());
|
|
verify(client).sendNotification(capture.capture());
|
|
@@ -108,31 +110,31 @@ class ApnsPushyTransportTest {
|
|
|
assertEquals(DeliveryPriority.IMMEDIATE, notification.getPriority());
|
|
assertEquals(DeliveryPriority.IMMEDIATE, notification.getPriority());
|
|
|
assertEquals("123", JSON.parseObject(notification.getPayload()).getString("ddId"));
|
|
assertEquals("123", JSON.parseObject(notification.getPayload()).getString("ddId"));
|
|
|
when(response.isAccepted()).thenReturn(true);
|
|
when(response.isAccepted()).thenReturn(true);
|
|
|
- assertDoesNotThrow(() -> sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "title", "body", "{}"));
|
|
|
|
|
|
|
+ assertDoesNotThrow(() -> sender.sendForTest(RecipientApp.USER, "a".repeat(64), "title", "body", "{}"));
|
|
|
|
|
|
|
|
when(response.isAccepted()).thenReturn(false);
|
|
when(response.isAccepted()).thenReturn(false);
|
|
|
when(response.getRejectionReason()).thenReturn("token=" + "a".repeat(64));
|
|
when(response.getRejectionReason()).thenReturn("token=" + "a".repeat(64));
|
|
|
assertEquals("APNS_REJECTED", assertThrows(IllegalStateException.class, () ->
|
|
assertEquals("APNS_REJECTED", assertThrows(IllegalStateException.class, () ->
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "title", "body", "{}")).getMessage());
|
|
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "a".repeat(64), "title", "body", "{}")).getMessage());
|
|
|
doThrow(new TimeoutException()).when(future).get(10, TimeUnit.SECONDS);
|
|
doThrow(new TimeoutException()).when(future).get(10, TimeUnit.SECONDS);
|
|
|
assertEquals("APNS_TIMEOUT", assertThrows(IllegalStateException.class, () ->
|
|
assertEquals("APNS_TIMEOUT", assertThrows(IllegalStateException.class, () ->
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "title", "body", "{}")).getMessage());
|
|
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "a".repeat(64), "title", "body", "{}")).getMessage());
|
|
|
doThrow(new ExecutionException(new Exception("token=" + "a".repeat(64)))).when(future).get(10, TimeUnit.SECONDS);
|
|
doThrow(new ExecutionException(new Exception("token=" + "a".repeat(64)))).when(future).get(10, TimeUnit.SECONDS);
|
|
|
assertEquals("APNS_TRANSPORT_ERROR", assertThrows(IllegalStateException.class, () ->
|
|
assertEquals("APNS_TRANSPORT_ERROR", assertThrows(IllegalStateException.class, () ->
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "title", "body", "{}")).getMessage());
|
|
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "a".repeat(64), "title", "body", "{}")).getMessage());
|
|
|
doThrow(new InterruptedException()).when(future).get(10, TimeUnit.SECONDS);
|
|
doThrow(new InterruptedException()).when(future).get(10, TimeUnit.SECONDS);
|
|
|
try {
|
|
try {
|
|
|
assertEquals("APNS_INTERRUPTED", assertThrows(IllegalStateException.class, () ->
|
|
assertEquals("APNS_INTERRUPTED", assertThrows(IllegalStateException.class, () ->
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "title", "body", "{}")).getMessage());
|
|
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "a".repeat(64), "title", "body", "{}")).getMessage());
|
|
|
assertTrue(Thread.currentThread().isInterrupted());
|
|
assertTrue(Thread.currentThread().isInterrupted());
|
|
|
} finally {
|
|
} finally {
|
|
|
Thread.interrupted();
|
|
Thread.interrupted();
|
|
|
}
|
|
}
|
|
|
clearInvocations(client);
|
|
clearInvocations(client);
|
|
|
assertEquals("APNS_TOKEN_INVALID", assertThrows(IllegalStateException.class, () ->
|
|
assertEquals("APNS_TOKEN_INVALID", assertThrows(IllegalStateException.class, () ->
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "invalid", "title", "body", "{}")).getMessage());
|
|
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "invalid", "title", "body", "{}")).getMessage());
|
|
|
assertEquals("APNS_PAYLOAD_TOO_LARGE", assertThrows(IllegalStateException.class, () ->
|
|
assertEquals("APNS_PAYLOAD_TOO_LARGE", assertThrows(IllegalStateException.class, () ->
|
|
|
- sender.sendForTestProduction(RecipientApp.USER, "a".repeat(64), "title", "大".repeat(2000), "{}")).getMessage());
|
|
|
|
|
|
|
+ sender.sendForTest(RecipientApp.USER, "a".repeat(64), "title", "大".repeat(2000), "{}")).getMessage());
|
|
|
verifyNoInteractions(client);
|
|
verifyNoInteractions(client);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|