The APNs server appears to be lying to us about unregistrations
// FREEBIE
This commit is contained in:
parent
51c3257df9
commit
9d32300612
|
@ -155,14 +155,14 @@ public class APNSender implements Managed {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("APN Unregister timestamp matches!");
|
logger.info("APN Unregister timestamp matches: " + device.get().getApnId() + ", " + device.get().getVoipApnId());
|
||||||
device.get().setApnId(null);
|
// device.get().setApnId(null);
|
||||||
device.get().setVoipApnId(null);
|
// device.get().setVoipApnId(null);
|
||||||
device.get().setFetchesMessages(false);
|
// device.get().setFetchesMessages(false);
|
||||||
accountsManager.update(account.get());
|
// accountsManager.update(account.get());
|
||||||
|
|
||||||
if (fallbackManager != null) {
|
// if (fallbackManager != null) {
|
||||||
fallbackManager.cancel(new WebsocketAddress(number, deviceId));
|
// fallbackManager.cancel(new WebsocketAddress(number, deviceId));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,209 +124,209 @@ public class APNSenderTest {
|
||||||
verifyNoMoreInteractions(fallbackManager);
|
verifyNoMoreInteractions(fallbackManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void testUnregisteredUser() throws Exception {
|
// public void testUnregisteredUser() throws Exception {
|
||||||
ApnsClient apnsClient = mock(ApnsClient.class);
|
// ApnsClient apnsClient = mock(ApnsClient.class);
|
||||||
|
//
|
||||||
|
// PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||||
|
// when(response.isAccepted()).thenReturn(false);
|
||||||
|
// when(response.getRejectionReason()).thenReturn("Unregistered");
|
||||||
|
//
|
||||||
|
// DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
||||||
|
// result.setSuccess(response);
|
||||||
|
//
|
||||||
|
// when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||||
|
// .thenReturn(result);
|
||||||
|
//
|
||||||
|
// RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||||
|
// ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||||
|
// APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||||
|
// apnSender.setApnFallbackManager(fallbackManager);
|
||||||
|
//
|
||||||
|
// when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
||||||
|
// when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
|
||||||
|
//
|
||||||
|
// ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
||||||
|
// ApnResult apnResult = sendFuture.get();
|
||||||
|
//
|
||||||
|
// Thread.sleep(1000); // =(
|
||||||
|
//
|
||||||
|
// ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||||
|
// verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||||
|
//
|
||||||
|
// assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||||
|
// assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||||
|
// assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||||
|
// assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||||
|
//
|
||||||
|
// assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||||
|
//
|
||||||
|
// verifyNoMoreInteractions(apnsClient);
|
||||||
|
// verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
||||||
|
// verify(destinationAccount, times(1)).getDevice(1);
|
||||||
|
// verify(destinationDevice, times(1)).getApnId();
|
||||||
|
// verify(destinationDevice, times(1)).getPushTimestamp();
|
||||||
|
// verify(destinationDevice, times(1)).setApnId(eq((String)null));
|
||||||
|
// verify(destinationDevice, times(1)).setVoipApnId(eq((String)null));
|
||||||
|
// verify(destinationDevice, times(1)).setFetchesMessages(eq(false));
|
||||||
|
// verify(accountsManager, times(1)).update(eq(destinationAccount));
|
||||||
|
// verify(fallbackManager, times(1)).cancel(eq(new WebsocketAddress(DESTINATION_NUMBER, 1)));
|
||||||
|
//
|
||||||
|
// verifyNoMoreInteractions(accountsManager);
|
||||||
|
// verifyNoMoreInteractions(fallbackManager);
|
||||||
|
// }
|
||||||
|
|
||||||
PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
// @Test
|
||||||
when(response.isAccepted()).thenReturn(false);
|
// public void testVoipUnregisteredUser() throws Exception {
|
||||||
when(response.getRejectionReason()).thenReturn("Unregistered");
|
// ApnsClient apnsClient = mock(ApnsClient.class);
|
||||||
|
//
|
||||||
|
// PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||||
|
// when(response.isAccepted()).thenReturn(false);
|
||||||
|
// when(response.getRejectionReason()).thenReturn("Unregistered");
|
||||||
|
//
|
||||||
|
// DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
||||||
|
// result.setSuccess(response);
|
||||||
|
//
|
||||||
|
// when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||||
|
// .thenReturn(result);
|
||||||
|
//
|
||||||
|
// RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||||
|
// ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||||
|
// APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||||
|
// apnSender.setApnFallbackManager(fallbackManager);
|
||||||
|
//
|
||||||
|
// when(destinationDevice.getApnId()).thenReturn("baz");
|
||||||
|
// when(destinationDevice.getVoipApnId()).thenReturn(DESTINATION_APN_ID);
|
||||||
|
// when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
|
||||||
|
//
|
||||||
|
// ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
||||||
|
// ApnResult apnResult = sendFuture.get();
|
||||||
|
//
|
||||||
|
// Thread.sleep(1000); // =(
|
||||||
|
//
|
||||||
|
// ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||||
|
// verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||||
|
//
|
||||||
|
// assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||||
|
// assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||||
|
// assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||||
|
// assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||||
|
//
|
||||||
|
// assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||||
|
//
|
||||||
|
// verifyNoMoreInteractions(apnsClient);
|
||||||
|
// verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
||||||
|
// verify(destinationAccount, times(1)).getDevice(1);
|
||||||
|
// verify(destinationDevice, times(1)).getApnId();
|
||||||
|
// verify(destinationDevice, times(1)).getVoipApnId();
|
||||||
|
// verify(destinationDevice, times(1)).getPushTimestamp();
|
||||||
|
// verify(destinationDevice, times(1)).setApnId(eq((String)null));
|
||||||
|
// verify(destinationDevice, times(1)).setVoipApnId(eq((String)null));
|
||||||
|
// verify(destinationDevice, times(1)).setFetchesMessages(eq(false));
|
||||||
|
// verify(accountsManager, times(1)).update(eq(destinationAccount));
|
||||||
|
// verify(fallbackManager, times(1)).cancel(eq(new WebsocketAddress(DESTINATION_NUMBER, 1)));
|
||||||
|
//
|
||||||
|
// verifyNoMoreInteractions(accountsManager);
|
||||||
|
// verifyNoMoreInteractions(fallbackManager);
|
||||||
|
// }
|
||||||
|
|
||||||
DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
// @Test
|
||||||
result.setSuccess(response);
|
// public void testRecentUnregisteredUser() throws Exception {
|
||||||
|
// ApnsClient apnsClient = mock(ApnsClient.class);
|
||||||
|
//
|
||||||
|
// PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||||
|
// when(response.isAccepted()).thenReturn(false);
|
||||||
|
// when(response.getRejectionReason()).thenReturn("Unregistered");
|
||||||
|
//
|
||||||
|
// DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
||||||
|
// result.setSuccess(response);
|
||||||
|
//
|
||||||
|
// when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||||
|
// .thenReturn(result);
|
||||||
|
//
|
||||||
|
// RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||||
|
// ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||||
|
// APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||||
|
// apnSender.setApnFallbackManager(fallbackManager);
|
||||||
|
//
|
||||||
|
// when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
||||||
|
// when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis());
|
||||||
|
//
|
||||||
|
// ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
||||||
|
// ApnResult apnResult = sendFuture.get();
|
||||||
|
//
|
||||||
|
// Thread.sleep(1000); // =(
|
||||||
|
//
|
||||||
|
// ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||||
|
// verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||||
|
//
|
||||||
|
// assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||||
|
// assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||||
|
// assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||||
|
// assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||||
|
//
|
||||||
|
// assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||||
|
//
|
||||||
|
// verifyNoMoreInteractions(apnsClient);
|
||||||
|
// verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
||||||
|
// verify(destinationAccount, times(1)).getDevice(1);
|
||||||
|
// verify(destinationDevice, times(1)).getApnId();
|
||||||
|
// verify(destinationDevice, times(1)).getPushTimestamp();
|
||||||
|
//
|
||||||
|
// verifyNoMoreInteractions(destinationDevice);
|
||||||
|
// verifyNoMoreInteractions(destinationAccount);
|
||||||
|
// verifyNoMoreInteractions(accountsManager);
|
||||||
|
// verifyNoMoreInteractions(fallbackManager);
|
||||||
|
// }
|
||||||
|
|
||||||
when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
// @Test
|
||||||
.thenReturn(result);
|
// public void testUnregisteredUserOldApnId() throws Exception {
|
||||||
|
// ApnsClient apnsClient = mock(ApnsClient.class);
|
||||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
//
|
||||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
// PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
// when(response.isAccepted()).thenReturn(false);
|
||||||
apnSender.setApnFallbackManager(fallbackManager);
|
// when(response.getRejectionReason()).thenReturn("Unregistered");
|
||||||
|
//
|
||||||
when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
// DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
||||||
when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
|
// result.setSuccess(response);
|
||||||
|
//
|
||||||
ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
// when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||||
ApnResult apnResult = sendFuture.get();
|
// .thenReturn(result);
|
||||||
|
//
|
||||||
Thread.sleep(1000); // =(
|
// RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||||
|
// ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||||
ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
// APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
// apnSender.setApnFallbackManager(fallbackManager);
|
||||||
|
//
|
||||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
// when(destinationDevice.getApnId()).thenReturn("baz");
|
||||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
// when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(12));
|
||||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
//
|
||||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
// ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
||||||
|
// ApnResult apnResult = sendFuture.get();
|
||||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
//
|
||||||
|
// Thread.sleep(1000); // =(
|
||||||
verifyNoMoreInteractions(apnsClient);
|
//
|
||||||
verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
// ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||||
verify(destinationAccount, times(1)).getDevice(1);
|
// verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||||
verify(destinationDevice, times(1)).getApnId();
|
//
|
||||||
verify(destinationDevice, times(1)).getPushTimestamp();
|
// assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||||
verify(destinationDevice, times(1)).setApnId(eq((String)null));
|
// assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||||
verify(destinationDevice, times(1)).setVoipApnId(eq((String)null));
|
// assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||||
verify(destinationDevice, times(1)).setFetchesMessages(eq(false));
|
// assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||||
verify(accountsManager, times(1)).update(eq(destinationAccount));
|
//
|
||||||
verify(fallbackManager, times(1)).cancel(eq(new WebsocketAddress(DESTINATION_NUMBER, 1)));
|
// assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||||
|
//
|
||||||
verifyNoMoreInteractions(accountsManager);
|
// verifyNoMoreInteractions(apnsClient);
|
||||||
verifyNoMoreInteractions(fallbackManager);
|
// verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
||||||
}
|
// verify(destinationAccount, times(1)).getDevice(1);
|
||||||
|
// verify(destinationDevice, times(2)).getApnId();
|
||||||
@Test
|
// verify(destinationDevice, times(2)).getVoipApnId();
|
||||||
public void testVoipUnregisteredUser() throws Exception {
|
//
|
||||||
ApnsClient apnsClient = mock(ApnsClient.class);
|
// verifyNoMoreInteractions(destinationDevice);
|
||||||
|
// verifyNoMoreInteractions(destinationAccount);
|
||||||
PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
// verifyNoMoreInteractions(accountsManager);
|
||||||
when(response.isAccepted()).thenReturn(false);
|
// verifyNoMoreInteractions(fallbackManager);
|
||||||
when(response.getRejectionReason()).thenReturn("Unregistered");
|
// }
|
||||||
|
|
||||||
DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
|
||||||
result.setSuccess(response);
|
|
||||||
|
|
||||||
when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
|
||||||
.thenReturn(result);
|
|
||||||
|
|
||||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
|
||||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
|
||||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
|
||||||
apnSender.setApnFallbackManager(fallbackManager);
|
|
||||||
|
|
||||||
when(destinationDevice.getApnId()).thenReturn("baz");
|
|
||||||
when(destinationDevice.getVoipApnId()).thenReturn(DESTINATION_APN_ID);
|
|
||||||
when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
|
|
||||||
|
|
||||||
ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
|
||||||
ApnResult apnResult = sendFuture.get();
|
|
||||||
|
|
||||||
Thread.sleep(1000); // =(
|
|
||||||
|
|
||||||
ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
|
||||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
|
||||||
|
|
||||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
|
||||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
|
||||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
|
||||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
|
||||||
|
|
||||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(apnsClient);
|
|
||||||
verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
|
||||||
verify(destinationAccount, times(1)).getDevice(1);
|
|
||||||
verify(destinationDevice, times(1)).getApnId();
|
|
||||||
verify(destinationDevice, times(1)).getVoipApnId();
|
|
||||||
verify(destinationDevice, times(1)).getPushTimestamp();
|
|
||||||
verify(destinationDevice, times(1)).setApnId(eq((String)null));
|
|
||||||
verify(destinationDevice, times(1)).setVoipApnId(eq((String)null));
|
|
||||||
verify(destinationDevice, times(1)).setFetchesMessages(eq(false));
|
|
||||||
verify(accountsManager, times(1)).update(eq(destinationAccount));
|
|
||||||
verify(fallbackManager, times(1)).cancel(eq(new WebsocketAddress(DESTINATION_NUMBER, 1)));
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(accountsManager);
|
|
||||||
verifyNoMoreInteractions(fallbackManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRecentUnregisteredUser() throws Exception {
|
|
||||||
ApnsClient apnsClient = mock(ApnsClient.class);
|
|
||||||
|
|
||||||
PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
|
||||||
when(response.isAccepted()).thenReturn(false);
|
|
||||||
when(response.getRejectionReason()).thenReturn("Unregistered");
|
|
||||||
|
|
||||||
DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
|
||||||
result.setSuccess(response);
|
|
||||||
|
|
||||||
when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
|
||||||
.thenReturn(result);
|
|
||||||
|
|
||||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
|
||||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
|
||||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
|
||||||
apnSender.setApnFallbackManager(fallbackManager);
|
|
||||||
|
|
||||||
when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
|
||||||
when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis());
|
|
||||||
|
|
||||||
ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
|
||||||
ApnResult apnResult = sendFuture.get();
|
|
||||||
|
|
||||||
Thread.sleep(1000); // =(
|
|
||||||
|
|
||||||
ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
|
||||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
|
||||||
|
|
||||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
|
||||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
|
||||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
|
||||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
|
||||||
|
|
||||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(apnsClient);
|
|
||||||
verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
|
||||||
verify(destinationAccount, times(1)).getDevice(1);
|
|
||||||
verify(destinationDevice, times(1)).getApnId();
|
|
||||||
verify(destinationDevice, times(1)).getPushTimestamp();
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(destinationDevice);
|
|
||||||
verifyNoMoreInteractions(destinationAccount);
|
|
||||||
verifyNoMoreInteractions(accountsManager);
|
|
||||||
verifyNoMoreInteractions(fallbackManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUnregisteredUserOldApnId() throws Exception {
|
|
||||||
ApnsClient apnsClient = mock(ApnsClient.class);
|
|
||||||
|
|
||||||
PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
|
||||||
when(response.isAccepted()).thenReturn(false);
|
|
||||||
when(response.getRejectionReason()).thenReturn("Unregistered");
|
|
||||||
|
|
||||||
DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
|
||||||
result.setSuccess(response);
|
|
||||||
|
|
||||||
when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
|
||||||
.thenReturn(result);
|
|
||||||
|
|
||||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
|
||||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
|
||||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
|
||||||
apnSender.setApnFallbackManager(fallbackManager);
|
|
||||||
|
|
||||||
when(destinationDevice.getApnId()).thenReturn("baz");
|
|
||||||
when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(12));
|
|
||||||
|
|
||||||
ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
|
||||||
ApnResult apnResult = sendFuture.get();
|
|
||||||
|
|
||||||
Thread.sleep(1000); // =(
|
|
||||||
|
|
||||||
ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
|
||||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
|
||||||
|
|
||||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
|
||||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
|
||||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
|
||||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
|
||||||
|
|
||||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(apnsClient);
|
|
||||||
verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
|
||||||
verify(destinationAccount, times(1)).getDevice(1);
|
|
||||||
verify(destinationDevice, times(2)).getApnId();
|
|
||||||
verify(destinationDevice, times(2)).getVoipApnId();
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(destinationDevice);
|
|
||||||
verifyNoMoreInteractions(destinationAccount);
|
|
||||||
verifyNoMoreInteractions(accountsManager);
|
|
||||||
verifyNoMoreInteractions(fallbackManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenericFailure() throws Exception {
|
public void testGenericFailure() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue