use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestNextBillingDateNotifier method testInvoiceNotifier.
@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);
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestNextBillingDatePoster method testDryRunWithSameSubscriptionLater.
@Test(groups = "slow")
public void testDryRunWithSameSubscriptionLater() throws Exception {
final Account account = invoiceUtil.createAccount(callContext);
final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(account.getId(), ObjectType.ACCOUNT, null);
final LocalDate notificationDate1 = clock.getUTCToday().plusDays(30);
final SubscriptionBase subscription = invoiceUtil.createSubscription();
final UUID subscriptionId = subscription.getId();
final FutureAccountNotifications futureAccountNotifications1 = createFutureAccountNotifications(subscriptionId, notificationDate1);
// Add 3 seconds to make it more interesting
clock.addDeltaFromReality(3000);
invoiceDao.setFutureAccountNotificationsForEmptyInvoice(account.getId(), futureAccountNotifications1, internalCallContext);
clock.addDays(1);
final LocalDate notificationDate2 = clock.getUTCToday().plusDays(30);
final FutureAccountNotifications futureAccountNotifications2 = createFutureAccountNotifications(subscriptionId, notificationDate2);
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);
// We expect only two notifications, one for each date
Assert.assertEquals(futureNotificationsList.size(), 2);
final NotificationEventWithMetadata<NextBillingDateNotificationKey> notification1 = futureNotificationsList.get(0);
Assert.assertEquals(notification1.getEffectiveDate(), internalCallContext.toUTCDateTime(notificationDate1));
final Iterable<UUID> uuidKeys1 = notification1.getEvent().getUuidKeys();
Assert.assertFalse(Iterables.isEmpty(uuidKeys1));
final List<UUID> uuidKeysList1 = ImmutableList.copyOf(uuidKeys1);
Assert.assertEquals(uuidKeysList1.size(), 1);
Assert.assertEquals(uuidKeysList1.get(0), subscriptionId);
final NotificationEventWithMetadata<NextBillingDateNotificationKey> notification2 = futureNotificationsList.get(1);
Assert.assertEquals(notification2.getEffectiveDate(), internalCallContext.toUTCDateTime(notificationDate2));
final Iterable<UUID> uuidKeys2 = notification2.getEvent().getUuidKeys();
Assert.assertFalse(Iterables.isEmpty(uuidKeys2));
final List<UUID> uuidKeysList2 = ImmutableList.copyOf(uuidKeys2);
Assert.assertEquals(uuidKeysList2.size(), 1);
Assert.assertEquals(uuidKeysList2.get(0), subscriptionId);
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestNextBillingDatePoster method testDryRunUpdateWithNewSubscription.
@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);
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class DefaultEntitlementApiBase method pause.
public void pause(final UUID bundleId, @Nullable final LocalDate localEffectiveDate, final Iterable<PluginProperty> properties, final InternalCallContext internalCallContext) throws EntitlementApiException {
final BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifier = new DefaultBaseEntitlementWithAddOnsSpecifier(bundleId, null, null, localEffectiveDate, localEffectiveDate, false);
final List<BaseEntitlementWithAddOnsSpecifier> baseEntitlementWithAddOnsSpecifierList = new ArrayList<BaseEntitlementWithAddOnsSpecifier>();
baseEntitlementWithAddOnsSpecifierList.add(baseEntitlementWithAddOnsSpecifier);
final EntitlementContext pluginContext = new DefaultEntitlementContext(OperationType.PAUSE_BUNDLE, null, null, null, null, properties, internalCallContextFactory.createCallContext(internalCallContext));
final WithEntitlementPlugin<Void> pauseWithPlugin = new WithEntitlementPlugin<Void>() {
@Override
public Void doCall(final EntitlementApi entitlementApi, final DefaultEntitlementContext updatedPluginContext) throws EntitlementApiException {
try {
final SubscriptionBase baseSubscription = subscriptionInternalApi.getBaseSubscription(bundleId, internalCallContext);
blockUnblockBundle(bundleId, DefaultEntitlementApi.ENT_STATE_BLOCKED, KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName(), localEffectiveDate, true, true, true, baseSubscription, internalCallContext);
} catch (SubscriptionBaseApiException e) {
throw new EntitlementApiException(e);
}
return null;
}
};
pluginExecution.executeWithPlugin(pauseWithPlugin, pluginContext);
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class DefaultEntitlementApi method populateEventsStreamForBaseSubscriptionPerBundleCache.
private void populateEventsStreamForBaseSubscriptionPerBundleCache(final UUID bundleId, final Map<UUID, Optional<EventsStream>> eventsStreamForBaseSubscriptionPerBundle, final TenantContext callContext, final InternalCallContext contextWithValidAccountRecordId) throws EntitlementApiException {
if (eventsStreamForBaseSubscriptionPerBundle.get(bundleId) == null) {
final List<SubscriptionBase> subscriptionsByBundle;
try {
subscriptionsByBundle = subscriptionBaseInternalApi.getSubscriptionsForBundle(bundleId, null, contextWithValidAccountRecordId);
if (subscriptionsByBundle == null || subscriptionsByBundle.isEmpty()) {
throw new EntitlementApiException(ErrorCode.SUB_NO_ACTIVE_SUBSCRIPTIONS, bundleId);
}
} catch (final SubscriptionBaseApiException e) {
throw new EntitlementApiException(e);
}
final boolean isStandalone = Iterables.any(subscriptionsByBundle, new Predicate<SubscriptionBase>() {
@Override
public boolean apply(final SubscriptionBase input) {
return ProductCategory.STANDALONE.equals(input.getCategory());
}
});
if (!isStandalone) {
final EventsStream eventsStreamForBaseSubscription = eventsStreamBuilder.buildForBaseSubscription(bundleId, callContext);
eventsStreamForBaseSubscriptionPerBundle.put(bundleId, Optional.<EventsStream>of(eventsStreamForBaseSubscription));
} else {
eventsStreamForBaseSubscriptionPerBundle.put(bundleId, Optional.<EventsStream>absent());
}
}
}
Aggregations