@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE) public void initialize() { try { final NotificationQueueHandler queueHandler = new NotificationQueueHandler() { @Override public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) { if (!(inputKey instanceof SubscriptionNotificationKey)) { log.error("SubscriptionBase service received an unexpected event className='{}'", inputKey.getClass().getName()); return; } final SubscriptionNotificationKey key = (SubscriptionNotificationKey) inputKey; final SubscriptionBaseEvent event = dao.getEventById(key.getEventId(), internalCallContextFactory.createInternalTenantContext(tenantRecordId, accountRecordId)); if (event == null) { // This can be expected if the event is soft deleted (is_active = 0) log.debug("Failed to extract event for notification key {}", inputKey); return; } final InternalCallContext context = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "SubscriptionEventQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken); processEventReady(event, key.getSeqId(), context); } }; subscriptionEventQueue = notificationQueueService.createNotificationQueue(KILLBILL_SERVICES.SUBSCRIPTION_BASE_SERVICE.getServiceName(), NOTIFICATION_QUEUE_NAME, queueHandler); } catch (final NotificationQueueAlreadyExists e) { throw new RuntimeException(e); } }
final NotificationQueue nextBillingQueue = notificationQueueService.getNotificationQueue(KILLBILL_SERVICES.INVOICE_SERVICE.getServiceName(), DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE); final Iterable<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotifications = nextBillingQueue.getFutureNotificationForSearchKeys(accountRecordId, internalCallContext.getTenantRecordId());
@Test(groups = "slow") public void testDryRunUpdateWithNewSubscription() throws Exception { final Account account = invoiceUtil.createAccount(callContext); final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(account.getId(), ObjectType.ACCOUNT, null); final LocalDate notificationDate = clock.getUTCToday().plusDays(30); final SubscriptionBase subscription1 = invoiceUtil.createSubscription(); final UUID subscriptionId1 = subscription1.getId(); final FutureAccountNotifications futureAccountNotifications1 = createFutureAccountNotifications(subscriptionId1, notificationDate); invoiceDao.setFutureAccountNotificationsForEmptyInvoice(account.getId(), futureAccountNotifications1, internalCallContext); final SubscriptionBase subscription2 = invoiceUtil.createSubscription(); final UUID subscriptionId2 = subscription2.getId(); final FutureAccountNotifications futureAccountNotifications2 = createFutureAccountNotifications(subscriptionId2, notificationDate); invoiceDao.setFutureAccountNotificationsForEmptyInvoice(account.getId(), futureAccountNotifications2, internalCallContext); final NotificationQueue nextBillingQueue = notificationQueueService.getNotificationQueue(KILLBILL_SERVICES.INVOICE_SERVICE.getServiceName(), DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE); final Iterable<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotifications = nextBillingQueue.getFutureNotificationForSearchKeys(accountRecordId, internalCallContext.getTenantRecordId()); final ImmutableList<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotificationsList = ImmutableList.copyOf(futureNotifications); Assert.assertEquals(futureNotificationsList.size(), 1); // We expect only one notification but this time we should see a list with both subscriptionIds. final NotificationEventWithMetadata<NextBillingDateNotificationKey> notification = futureNotificationsList.get(0); Assert.assertEquals(notification.getEffectiveDate(), internalCallContext.toUTCDateTime(notificationDate)); final Iterable<UUID> uuidKeys = notification.getEvent().getUuidKeys(); Assert.assertFalse(Iterables.isEmpty(uuidKeys)); final List<UUID> uuidKeysList = ImmutableList.copyOf(uuidKeys); Assert.assertEquals(uuidKeysList.size(), 2); Assert.assertEquals(uuidKeysList.get(0), subscriptionId1); Assert.assertEquals(uuidKeysList.get(1), subscriptionId2); }
@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE) public void initialize() { try { final NotificationQueueHandler queueHandler = new NotificationQueueHandler() { @Override public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) { if (!(inputKey instanceof SubscriptionNotificationKey)) { log.error("SubscriptionBase service received an unexpected event className='{}'", inputKey.getClass().getName()); return; } final SubscriptionNotificationKey key = (SubscriptionNotificationKey) inputKey; final SubscriptionBaseEvent event = dao.getEventById(key.getEventId(), internalCallContextFactory.createInternalTenantContext(tenantRecordId, accountRecordId)); if (event == null) { // This can be expected if the event is soft deleted (is_active = 0) log.debug("Failed to extract event for notification key {}", inputKey); return; } final InternalCallContext context = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "SubscriptionEventQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken); processEventReady(event, key.getSeqId(), context); } }; subscriptionEventQueue = notificationQueueService.createNotificationQueue(KILLBILL_SERVICES.SUBSCRIPTION_BASE_SERVICE.getServiceName(), NOTIFICATION_QUEUE_NAME, queueHandler); } catch (final NotificationQueueAlreadyExists e) { throw new RuntimeException(e); } }
@Override public void initialize() throws NotificationQueueAlreadyExists { final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() { @Override public void handleReadyNotification(final NotificationEvent notificationKey, final DateTime eventDate, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) { if (!(notificationKey instanceof NextBillingDateNotificationKey)) { log.error("Invoice service received an unexpected event className='{}", notificationKey.getClass()); return; } final NextBillingDateNotificationKey key = (NextBillingDateNotificationKey) notificationKey; // Just to ensure compatibility with json that might not have that targetDate field (old versions < 0.13.6) final DateTime targetDate = key.getTargetDate() != null ? key.getTargetDate() : eventDate; final UUID firstSubscriptionId = key.getUuidKeys().iterator().next(); if (key.isDryRunForInvoiceNotification() != null && // Just to ensure compatibility with json that might not have that field (old versions < 0.13.6) key.isDryRunForInvoiceNotification()) { processEventForInvoiceNotification(firstSubscriptionId, targetDate, userToken, accountRecordId, tenantRecordId); } else { final boolean isRescheduled = key.isRescheduled() == Boolean.TRUE; // Handle null value (old versions < 0.19.7) processEventForInvoiceGeneration(firstSubscriptionId, targetDate, isRescheduled, userToken, accountRecordId, tenantRecordId); } } }; final NotificationQueueHandler retryableHandler = new RetryableHandler(clock, this, notificationQueueHandler); nextBillingQueue = notificationQueueService.createNotificationQueue(KILLBILL_SERVICES.INVOICE_SERVICE.getServiceName(), NEXT_BILLING_DATE_NOTIFIER_QUEUE, retryableHandler); super.initialize(nextBillingQueue, notificationQueueHandler); }
private void testPauseAccountAtPhaseAndPauseOtherSubscriptionFutureStarted(final UUID subscriptionId1, final UUID subscriptionId2) throws Exception { final DateTime now = clock.getUTCNow(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(subscriptionId2, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(UUID.randomUUID(), BlockingStateType.ACCOUNT, "stuff", "svc1", true, true, now.plusDays(30))); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); allEvents.add(createEvent(subscriptionId2, SubscriptionEventType.START_BILLING, now.plusDays(40))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 8); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.PHASE); if (subscriptionId1.compareTo(subscriptionId2) >= 0) { Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(5).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(6).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); } else { Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(5).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); Assert.assertEquals(allEvents.get(6).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); } Assert.assertEquals(allEvents.get(7).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); }
@Test(groups = "fast", invocationCount = 10) public void testDifferentTypesOfBlockingSameService() throws Exception { final DateTime now = clock.getUTCNow(); final UUID subscriptionId1 = UUID.randomUUID(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(UUID.randomUUID(), BlockingStateType.ACCOUNT, "stuff", "svc1", false, true, now.plusDays(10))); // Same service blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc1", true, false, now.plusDays(15))); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc1", false, false, now.plusDays(20))); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.ACCOUNT, "stuff", "svc1", false, false, now.plusDays(30))); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 8); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.RESUME_BILLING); Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(5).getSubscriptionEventType(), SubscriptionEventType.RESUME_ENTITLEMENT); Assert.assertEquals(allEvents.get(6).getSubscriptionEventType(), SubscriptionEventType.PHASE); Assert.assertEquals(allEvents.get(7).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE); }
@Test(groups = "fast", invocationCount = 10) public void testDifferentTypesOfBlockingDifferentServices() throws Exception { final DateTime now = clock.getUTCNow(); final UUID subscriptionId1 = UUID.randomUUID(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(UUID.randomUUID(), BlockingStateType.ACCOUNT, "stuff", "svc1", false, true, now.plusDays(10))); // Different service blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc2", true, false, now.plusDays(15))); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc2", false, false, now.plusDays(20))); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.ACCOUNT, "stuff", "svc1", false, false, now.plusDays(30))); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 7); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.RESUME_ENTITLEMENT); Assert.assertEquals(allEvents.get(5).getSubscriptionEventType(), SubscriptionEventType.PHASE); Assert.assertEquals(allEvents.get(6).getSubscriptionEventType(), SubscriptionEventType.RESUME_BILLING); }
@Test(groups = "slow") public void testDryRunReInsertion() throws Exception { final Account account = invoiceUtil.createAccount(callContext); final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(account.getId(), ObjectType.ACCOUNT, null); final LocalDate notificationDate = clock.getUTCToday().plusDays(30); final SubscriptionBase subscription = invoiceUtil.createSubscription(); final UUID subscriptionId = subscription.getId(); final FutureAccountNotifications futureAccountNotifications = createFutureAccountNotifications(subscriptionId, notificationDate); invoiceDao.setFutureAccountNotificationsForEmptyInvoice(account.getId(), futureAccountNotifications, internalCallContext); invoiceDao.setFutureAccountNotificationsForEmptyInvoice(account.getId(), futureAccountNotifications, internalCallContext); final NotificationQueue nextBillingQueue = notificationQueueService.getNotificationQueue(KILLBILL_SERVICES.INVOICE_SERVICE.getServiceName(), DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE); final Iterable<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotifications = nextBillingQueue.getFutureNotificationForSearchKeys(accountRecordId, internalCallContext.getTenantRecordId()); final ImmutableList<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotificationsList = ImmutableList.copyOf(futureNotifications); Assert.assertEquals(futureNotificationsList.size(), 1); // We expect only one notification for which effectiveDate matches our original effectiveDate (conversion DateTime -> LocalDate -> DateTime) final NotificationEventWithMetadata<NextBillingDateNotificationKey> notification = futureNotificationsList.get(0); Assert.assertEquals(notification.getEffectiveDate(), internalCallContext.toUTCDateTime(notificationDate)); final Iterable<UUID> uuidKeys = notification.getEvent().getUuidKeys(); Assert.assertFalse(Iterables.isEmpty(uuidKeys)); final List<UUID> uuidKeysList = ImmutableList.copyOf(uuidKeys); Assert.assertEquals(uuidKeysList.size(), 1); Assert.assertEquals(uuidKeysList.get(0), subscriptionId); }
@Test(groups = "slow") public void testInvoiceNotifier() throws Exception { final Account account = invoiceUtil.createAccount(callContext); final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(account.getId(), ObjectType.ACCOUNT, null); final SubscriptionBase subscription = invoiceUtil.createSubscription(); final UUID subscriptionId = subscription.getId(); final DateTime now = clock.getUTCNow(); final NotificationQueue nextBillingQueue = notificationQueueService.getNotificationQueue(KILLBILL_SERVICES.INVOICE_SERVICE.getServiceName(), DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE); nextBillingQueue.recordFutureNotification(now, new NextBillingDateNotificationKey(null, ImmutableList.<UUID>of(subscriptionId), now, Boolean.FALSE, Boolean.FALSE), internalCallContext.getUserToken(), accountRecordId, internalCallContext.getTenantRecordId()); // Move time in the future after the notification effectiveDate clock.setDeltaFromReality(3000); await().atMost(1, MINUTES).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return testInvoiceNotificationQListener.getEventCount() == 1; } }); Assert.assertEquals(testInvoiceNotificationQListener.getEventCount(), 1); Assert.assertEquals(testInvoiceNotificationQListener.getLatestSubscriptionId(), subscriptionId); } }
@Override public void initialize() throws NotificationQueueAlreadyExists { final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() { @Override public void handleReadyNotification(final NotificationEvent notificationKey, final DateTime eventDate, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) { try { if (!(notificationKey instanceof ParentInvoiceCommitmentNotificationKey)) { log.error("Invoice service received an unexpected event type {}", notificationKey.getClass().getName()); return; } final ParentInvoiceCommitmentNotificationKey key = (ParentInvoiceCommitmentNotificationKey) notificationKey; listener.handleParentInvoiceCommitmentEvent(key.getUuidKey(), userToken, accountRecordId, tenantRecordId); } catch (IllegalArgumentException e) { log.error("The key returned from the ParentInvoiceCommitmentQueue is not a valid UUID", e); } } }; commitInvoiceQueue = notificationQueueService.createNotificationQueue(KILLBILL_SERVICES.INVOICE_SERVICE.getServiceName(), PARENT_INVOICE_COMMITMENT_NOTIFIER_QUEUE, notificationQueueHandler); }
@Test(groups = "fast", invocationCount = 10) public void testPauseResumeAtPhase() throws Exception { final DateTime now = clock.getUTCNow(); final UUID subscriptionId1 = UUID.randomUUID(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc1", true, true, now.plusDays(30))); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc1", false, false, now.plusDays(30))); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 7); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); Assert.assertEquals(allEvents.get(5).getSubscriptionEventType(), SubscriptionEventType.RESUME_ENTITLEMENT); Assert.assertEquals(allEvents.get(6).getSubscriptionEventType(), SubscriptionEventType.RESUME_BILLING); }
@Override public Boolean call() throws Exception { boolean completed = true; final Iterator<NotificationEventWithMetadata<NotificationEvent>> iterator = notificationQueueService.getNotificationQueue(KILLBILL_SERVICES.PAYMENT_SERVICE.getServiceName(), Janitor.QUEUE_NAME).getFutureOrInProcessingNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId()).iterator(); try { while (iterator.hasNext()) { final NotificationEventWithMetadata<NotificationEvent> notificationEvent = iterator.next(); if (!notificationEvent.getEffectiveDate().isAfter(clock.getUTCNow())) { completed = false; } } } finally { // Go through all results to close the connection while (iterator.hasNext()) { iterator.next(); } } return completed; } });
@Test(groups = "fast", invocationCount = 10) public void test_ENT_STATE_IsNotInterpreted() throws Exception { final DateTime now = clock.getUTCNow(); final UUID subscriptionId1 = UUID.randomUUID(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, "svc1", false, false, now.plusDays(1))); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_CANCELLED, "svc1", false, false, now.plusDays(2))); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 5); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE); Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PHASE); }
private void doCheckActualBlockingStatesToCancel(final DefaultEntitlement addOnEntitlement, final DateTime effectiveCancellationDateTime, final boolean approximateDateCheck, final Collection<BlockingState> blockingStatesForCancellation) { if (effectiveCancellationDateTime == null) { Assert.assertEquals(blockingStatesForCancellation.size(), 0); } else { Assert.assertEquals(blockingStatesForCancellation.size(), 1); final BlockingState blockingState = blockingStatesForCancellation.iterator().next(); Assert.assertEquals(blockingState.getBlockedId(), addOnEntitlement.getId()); if (approximateDateCheck) { Assert.assertEquals(blockingState.getEffectiveDate().toLocalDate(), effectiveCancellationDateTime.toLocalDate()); Assert.assertEquals(blockingState.getEffectiveDate().getMinuteOfDay(), effectiveCancellationDateTime.getMinuteOfDay()); } else { Assert.assertEquals(blockingState.getEffectiveDate(), effectiveCancellationDateTime); } Assert.assertEquals(blockingState.getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingState.getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingState.getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); } }
@Test(groups = "fast", invocationCount = 10) public void testPauseAccountAtPhase() throws Exception { final DateTime now = clock.getUTCNow(); final UUID subscriptionId1 = UUID.randomUUID(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(UUID.randomUUID(), BlockingStateType.ACCOUNT, "stuff", "svc1", true, true, now.plusDays(30))); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 5); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); }
@Test(groups = "fast", invocationCount = 10) public void testPauseAtPhase() throws Exception { final DateTime now = clock.getUTCNow(); final UUID subscriptionId1 = UUID.randomUUID(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc1", true, true, now.plusDays(30))); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 5); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); }
@Test(groups = "fast", invocationCount = 10) public void testPauseAtStart() throws Exception { final DateTime now = clock.getUTCNow(); final UUID subscriptionId1 = UUID.randomUUID(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc1", true, true, now)); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 5); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PHASE); }
@Test(groups = "fast", invocationCount = 10) public void testPausePostPhase() throws Exception { final DateTime now = clock.getUTCNow(); final UUID subscriptionId1 = UUID.randomUUID(); final Collection<BlockingState> blockingStates = new LinkedList<BlockingState>(); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), false, false, now)); blockingStates.add(createBlockingState(subscriptionId1, BlockingStateType.SUBSCRIPTION, "stuff", "svc1", true, true, now.plusDays(40))); final LinkedList<SubscriptionEvent> allEvents = new LinkedList<SubscriptionEvent>(); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.START_BILLING, now)); allEvents.add(createEvent(subscriptionId1, SubscriptionEventType.PHASE, now.plusDays(30))); computeEvents(allEvents, blockingStates); Assert.assertEquals(allEvents.size(), 5); Assert.assertEquals(allEvents.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT); Assert.assertEquals(allEvents.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING); Assert.assertEquals(allEvents.get(2).getSubscriptionEventType(), SubscriptionEventType.PHASE); Assert.assertEquals(allEvents.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT); Assert.assertEquals(allEvents.get(4).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING); }
private void checkBlockingStatesDAO(final DefaultEntitlement baseEntitlement, final DefaultEntitlement addOnEntitlement, final LocalDate effectiveBaseCancellationDate, final LocalDate effectiveAddOnCancellationDate, final boolean isBaseCancelled) { final List<BlockingState> blockingStatesForBaseEntitlement = blockingStatesForBlockedId(baseEntitlement.getId()); Assert.assertEquals(blockingStatesForBaseEntitlement.size(), isBaseCancelled ? 2 : 1); if (isBaseCancelled) { Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getBlockedId(), baseEntitlement.getId()); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getEffectiveDate().toLocalDate(), effectiveBaseCancellationDate); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); } final List<BlockingState> blockingStatesForAddOn = blockingStatesForBlockedId(addOnEntitlement.getId()); Assert.assertEquals(blockingStatesForAddOn.size(), 2); Assert.assertEquals(blockingStatesForAddOn.get(1).getBlockedId(), addOnEntitlement.getId()); Assert.assertEquals(blockingStatesForAddOn.get(1).getEffectiveDate().toLocalDate(), effectiveAddOnCancellationDate); Assert.assertEquals(blockingStatesForAddOn.get(1).getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingStatesForAddOn.get(1).getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingStatesForAddOn.get(1).getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); }