protected void createFutureNotification(final Account account, final DateTime timeOfNextCheck, final InternalCallContext context) { final OverdueCheckNotificationKey notificationKey = new OverdueCheckNotificationKey(account.getId()); checkPoster.insertOverdueNotification(account.getId(), timeOfNextCheck, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, notificationKey, context); }
@Test(groups = "fast") public void testOverdueNotificationKeyJson() throws Exception { final UUID uuid = UUID.randomUUID(); final OverdueCheckNotificationKey e = new OverdueCheckNotificationKey(uuid); final String json = mapper.writeValueAsString(e); final Class<?> claz = Class.forName(OverdueCheckNotificationKey.class.getName()); final Object obj = mapper.readValue(json, claz); Assert.assertTrue(obj.equals(e)); }
private void insertOverdueCheckAndVerifyQueueContent(final Account account, final int nbDaysInFuture, final int expectedNbDaysInFuture) throws IOException { final DateTime futureNotificationTime = testReferenceTime.plusDays(nbDaysInFuture); final OverdueCheckNotificationKey notificationKey = new OverdueCheckNotificationKey(account.getId()); checkPoster.insertOverdueNotification(account.getId(), futureNotificationTime, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, notificationKey, internalCallContext); final Collection<NotificationEventWithMetadata<OverdueCheckNotificationKey>> notificationsForKey = getNotificationsForOverdueable(account); Assert.assertEquals(notificationsForKey.size(), 1); final NotificationEventWithMetadata nm = notificationsForKey.iterator().next(); Assert.assertEquals(nm.getEvent(), notificationKey); Assert.assertEquals(nm.getEffectiveDate(), testReferenceTime.plusDays(expectedNbDaysInFuture)); }
@Test(groups = "slow") public void test() throws Exception { final UUID accountId = new UUID(0L, 1L); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); final DateTime now = clock.getUTCNow(); final DateTime readyTime = now.plusMillis(2000); final OverdueCheckNotificationKey notificationKey = new OverdueCheckNotificationKey(accountId); checkPoster.insertOverdueNotification(accountId, readyTime, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, notificationKey, internalCallContext); // Move time in the future after the notification effectiveDate clock.setDeltaFromReality(3000); await().atMost(5, SECONDS).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return mockDispatcher.getEventCount() == 1; } }); Assert.assertEquals(mockDispatcher.getEventCount(), 1); Assert.assertEquals(mockDispatcher.getLatestAccountId(), accountId); } }