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); }
@Override public void handleReadyNotification(final NotificationEvent notificationKey, final DateTime eventDate, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) { try { if (!(notificationKey instanceof OverdueCheckNotificationKey)) { log.error("Overdue service received Unexpected notificationKey {}", notificationKey.getClass().getName()); return; } final OverdueCheckNotificationKey key = (OverdueCheckNotificationKey) notificationKey; dispatcher.processOverdueForAccount(key.getUuidKey(), createCallContext(userToken, accountRecordId, tenantRecordId)); } catch (IllegalArgumentException e) { log.error("The key returned from the NextBillingNotificationQueue is not a valid UUID", e); } } }
@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)); }
@Test(groups = "fast") public void testOverdueNotificationKeyJsonWithNoKey() throws Exception { final String uuidString = "bab0fca4-c628-4997-8980-14d6c3a98c48"; final String json = "{\"uuidKey\":\"" + uuidString + "\"}"; final Class<?> claz = Class.forName(OverdueCheckNotificationKey.class.getName()); final OverdueCheckNotificationKey obj = (OverdueCheckNotificationKey) mapper.readValue(json, claz); assertEquals(obj.getUuidKey().toString(), uuidString); } }
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); } }