use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.
the class TestDefaultBlockingState method testComparisonSameEffectiveDate.
@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/174")
public void testComparisonSameEffectiveDate() throws Exception {
final DateTime effectiveDate = clock.getUTCNow();
final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), UUID.randomUUID(), BlockingStateType.ACCOUNT, "OD3", "test", true, true, true, effectiveDate, effectiveDate, effectiveDate, 3L);
final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), UUID.randomUUID(), BlockingStateType.ACCOUNT, "OD2", "test", false, false, false, effectiveDate, effectiveDate, effectiveDate, 4L);
final BlockingState bs3 = new DefaultBlockingState(UUID.randomUUID(), UUID.randomUUID(), BlockingStateType.ACCOUNT, "OD1", "test", true, true, true, effectiveDate.plusMillis(1), effectiveDate, effectiveDate, 5L);
Assert.assertTrue(bs1.compareTo(bs2) < 0);
Assert.assertTrue(bs1.compareTo(bs3) < 0);
Assert.assertTrue(bs2.compareTo(bs1) > 0);
Assert.assertTrue(bs2.compareTo(bs3) < 0);
Assert.assertTrue(bs3.compareTo(bs2) > 0);
Assert.assertTrue(bs3.compareTo(bs1) > 0);
}
use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.
the class TestBlockingCalculator method testSimpleWithClearBlockingDuration.
@Test(groups = "fast")
public void testSimpleWithClearBlockingDuration() throws Exception {
final BillingEvent trial = createRealEvent(new LocalDate(2012, 5, 1).toDateTimeAtStartOfDay(DateTimeZone.UTC), subscription1, SubscriptionBaseTransitionType.CREATE);
final BillingEvent phase = createRealEvent(new LocalDate(2012, 5, 31).toDateTimeAtStartOfDay(DateTimeZone.UTC), subscription1, SubscriptionBaseTransitionType.PHASE);
final BillingEvent upgrade = createRealEvent(new LocalDate(2012, 7, 25).toDateTimeAtStartOfDay(DateTimeZone.UTC), subscription1, SubscriptionBaseTransitionType.CHANGE);
final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>();
billingEvents.add(trial);
billingEvents.add(phase);
billingEvents.add(upgrade);
final BlockingState blockingState1 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, false, false, new LocalDate(2012, 7, 5).toDateTimeAtStartOfDay(DateTimeZone.UTC));
final BlockingState blockingState2 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, new LocalDate(2012, 7, 15).toDateTimeAtStartOfDay(DateTimeZone.UTC));
final BlockingState blockingState3 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, new LocalDate(2012, 7, 24).toDateTimeAtStartOfDay(DateTimeZone.UTC));
final BlockingState blockingState4 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, new LocalDate(2012, 7, 25).toDateTimeAtStartOfDay(DateTimeZone.UTC));
blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState1, Optional.<UUID>absent(), blockingState2, Optional.<UUID>absent(), blockingState3, Optional.<UUID>absent(), blockingState4, Optional.<UUID>absent()), internalCallContext);
blockingCalculator.insertBlockingEvents(billingEvents, new HashSet<UUID>(), internalCallContext);
assertEquals(billingEvents.size(), 5);
final List<BillingEvent> events = new ArrayList<BillingEvent>(billingEvents);
assertEquals(events.get(0).getEffectiveDate(), new LocalDate(2012, 5, 1).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE);
assertEquals(events.get(1).getEffectiveDate(), new LocalDate(2012, 5, 31).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(1).getTransitionType(), SubscriptionBaseTransitionType.PHASE);
assertEquals(events.get(2).getEffectiveDate(), new LocalDate(2012, 7, 15).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(2).getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
assertEquals(events.get(3).getEffectiveDate(), new LocalDate(2012, 7, 25).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(3).getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
assertEquals(events.get(4).getEffectiveDate(), new LocalDate(2012, 7, 25).toDateTimeAtStartOfDay(DateTimeZone.UTC));
assertEquals(events.get(4).getTransitionType(), SubscriptionBaseTransitionType.CHANGE);
}
use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.
the class BlockingCalculator method getPerTypeBlockingEvents.
final Map<UUID, List<BlockingState>> getPerTypeBlockingEvents(final BlockingStateType type, final List<BlockingState> blockingEvents) {
final Iterable<BlockingState> bundleBlockingEvents = Iterables.filter(blockingEvents, new Predicate<BlockingState>() {
@Override
public boolean apply(final BlockingState input) {
return type == input.getType();
}
});
final Map<UUID, List<BlockingState>> perTypeBlockingEvents = new HashMap<UUID, List<BlockingState>>();
for (final BlockingState cur : bundleBlockingEvents) {
if (!perTypeBlockingEvents.containsKey(cur.getBlockedId())) {
perTypeBlockingEvents.put(cur.getBlockedId(), new ArrayList<BlockingState>());
}
perTypeBlockingEvents.get(cur.getBlockedId()).add(cur);
}
return perTypeBlockingEvents;
}
use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.
the class TestBlockingCalculator method testInsertBlockingEventsForBundle.
// S1-S2-S3 subscriptions in B1
// B1 -----[--------]
// S1 --A-------------------------------------
// S2 --B------C------------------------------
// S3 ------------------D---------------------
//Result
// S1 --A--[-------]--------------------------
// S2 --B--[-------]--------------------------
// S3 ------------------D---------------------
@Test(groups = "fast")
public void testInsertBlockingEventsForBundle() throws CatalogApiException {
final DateTime now = clock.getUTCNow();
final BillingEvent A = createRealEvent(now.minusDays(1).minusHours(1), subscription1);
final BillingEvent B = createRealEvent(now.minusDays(1), subscription2);
final BillingEvent C = createRealEvent(now.plusDays(1), subscription2);
final BillingEvent D = createRealEvent(now.plusDays(3), subscription3);
final SortedSet<BillingEvent> billingEvents = new TreeSet<BillingEvent>();
billingEvents.add(A);
billingEvents.add(B);
billingEvents.add(C);
billingEvents.add(D);
final BlockingState blockingState1 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now);
final BlockingState blockingState2 = new DefaultBlockingState(bundleId1, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(2));
blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState1, Optional.<UUID>absent(), blockingState2, Optional.<UUID>absent()), internalCallContext);
blockingCalculator.insertBlockingEvents(billingEvents, new HashSet<UUID>(), internalCallContext);
assertEquals(billingEvents.size(), 7);
final SortedSet<BillingEvent> s1Events = blockingCalculator.filter(billingEvents, subscription1);
final Iterator<BillingEvent> it1 = s1Events.iterator();
assertEquals(it1.next(), A);
assertEquals(it1.next().getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
assertEquals(it1.next().getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
final SortedSet<BillingEvent> s2Events = blockingCalculator.filter(billingEvents, subscription2);
final Iterator<BillingEvent> it2 = s2Events.iterator();
assertEquals(it2.next(), B);
assertEquals(it2.next().getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
assertEquals(it2.next().getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
final SortedSet<BillingEvent> s3Events = blockingCalculator.filter(billingEvents, subscription3);
final Iterator<BillingEvent> it3 = s3Events.iterator();
assertEquals(it3.next(), D);
}
use of org.killbill.billing.entitlement.api.BlockingState in project killbill by killbill.
the class TestWithBCDUpdate method testBlockPastUnpaidPeriodAndRealignBCD.
@Test(groups = "slow")
public void testBlockPastUnpaidPeriodAndRealignBCD() throws Exception {
final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>();
List<Invoice> invoices = null;
final DateTime initialDate = new DateTime(2016, 4, 1, 0, 13, 42, 0, testTimeZone);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0));
assertNotNull(account);
// BP creation : Will set Account BCD to the first (2016-4-1 + 30 days = 2016-5-1)
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final DefaultEntitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
paymentPlugin.makeNextPaymentFailWithError();
// 2016-5-1 : BP out of TRIAL
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR, NextEvent.INVOICE_PAYMENT_ERROR);
clock.addDays(30);
assertListenerStatus();
//
// Let's assume 15 days later, the customer comes back and wants to continue using the service (after he updated his payment method)
//
// The company 'a.b.c' decides to block both the billing and entitlement for the past 15 days and also move his BCD to
// the 16 so he gets to pay right away and for a full period (MONTHLY)
//
// 2016-5-16
busHandler.pushExpectedEvents(NextEvent.INVOICE_PAYMENT_ERROR, NextEvent.PAYMENT_ERROR);
paymentPlugin.makeNextPaymentFailWithError();
clock.addDays(15);
assertListenerStatus();
// First BLOCK subscription starting from the 2016-5-1
// This will generate the credit for the full period, bringing by account balance to 0
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
final BlockingState blockingState = new DefaultBlockingState(baseEntitlement.getId(), BlockingStateType.SUBSCRIPTION, "COURTESY_BLOCK", "company.a.b.c", true, true, true, null);
subscriptionApi.addBlockingState(blockingState, new LocalDate(2016, 5, 1), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 1), new LocalDate(2016, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-249.95")));
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 16), new LocalDate(2016, 5, 16), InvoiceItemType.CBA_ADJ, new BigDecimal("249.95")));
invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, expectedInvoices);
expectedInvoices.clear();
// Second, move the BCD to the 16
// Because we did not unblock yet, we don't have a new invoice but we see the NULL_INVOICE event
busHandler.pushExpectedEvents(NextEvent.BCD_CHANGE, NextEvent.NULL_INVOICE);
subscriptionBaseInternalApi.updateBCD(baseEntitlement.getId(), 16, null, internalCallContext);
assertListenerStatus();
// Third, unblock starting at the 16, will generate a full period invoice
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
final BlockingState unblockingState = new DefaultBlockingState(baseEntitlement.getId(), BlockingStateType.SUBSCRIPTION, "END_OF_COURTESY_BLOCK", "company.a.b.c", false, false, false, null);
subscriptionApi.addBlockingState(unblockingState, new LocalDate(2016, 5, 16), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2016, 5, 16), new LocalDate(2016, 6, 16), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
invoiceChecker.checkInvoice(invoices.get(3).getId(), callContext, expectedInvoices);
expectedInvoices.clear();
}
Aggregations