use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.
the class TestInvoiceOptimizerExp method testInArrearP0M.
@Test(groups = "fast")
public void testInArrearP0M() {
final LocalDate startDate = new LocalDate(2021, 2, 1);
LocalDate targetDate = new LocalDate(2021, 6, 1);
// Proposed: invoice from 2021-2-1 -> 2021-6-1
final List<InvoiceItem> proposedItems = new ArrayList<InvoiceItem>();
final Invoice proposed = createInvoice(targetDate);
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, startDate, new LocalDate(2021, 3, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 3, 1), new LocalDate(2021, 4, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 4, 1), new LocalDate(2021, 5, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 5, 1), new LocalDate(2021, 6, 1)));
// P0M
final LocalDate cutoffDate = targetDate;
// Existing: invoice from 2021-2-1 -> 2021-5-1
// Existing (filtered) empty
final List<Invoice> existing = new ArrayList<Invoice>();
final Invoice invoice = createInvoice(cutoffDate);
existing.add(invoice);
final AccountInvoicesExp test = new AccountInvoicesExp(cutoffDate, null, existing);
final DefaultBillingEventSet billingEvents = new DefaultBillingEventSet(false, false, false);
billingEvents.add(createBillingEvent(startDate, BillingMode.IN_ARREAR, SubscriptionBaseTransitionType.CREATE));
test.filterProposedItems(proposedItems, billingEvents, internalCallContext);
Assert.assertEquals(proposedItems.size(), 1);
// New proposed item
Assert.assertEquals(proposedItems.get(0).getStartDate(), new LocalDate(2021, 5, 1));
Assert.assertEquals(proposedItems.get(0).getEndDate(), new LocalDate(2021, 6, 1));
}
use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.
the class TestInvoiceOptimizerExp method testInArrearLateP1M.
@Test(groups = "fast")
public void testInArrearLateP1M() {
final LocalDate startDate = new LocalDate(2021, 2, 1);
LocalDate targetDate = new LocalDate(2021, 6, 1);
// Proposed: invoice from 2021-2-1 -> 2021-6-1
final List<InvoiceItem> proposedItems = new ArrayList<InvoiceItem>();
final Invoice proposed = createInvoice(targetDate);
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, startDate, new LocalDate(2021, 3, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 3, 1), new LocalDate(2021, 4, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 4, 1), new LocalDate(2021, 5, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 5, 1), new LocalDate(2021, 6, 1)));
// P1M
// We assume we did not bill last N period so there is no filtered
final LocalDate cutoffDate = targetDate.minusMonths(1);
// Existing: empty
// Existing (filtered) empty
final List<Invoice> existing = new ArrayList<Invoice>();
final Invoice invoice = createInvoice(cutoffDate);
existing.add(invoice);
final AccountInvoicesExp test = new AccountInvoicesExp(cutoffDate, null, existing);
final DefaultBillingEventSet billingEvents = new DefaultBillingEventSet(false, false, false);
billingEvents.add(createBillingEvent(startDate, BillingMode.IN_ARREAR, SubscriptionBaseTransitionType.CREATE));
//
// Output is similar to previous test 'testInArrearP1M', i.e we have a proposed
// for last period and new one (but because there is no existing for last period)
// it would remain when coming back from the tree
//
test.filterProposedItems(proposedItems, billingEvents, internalCallContext);
Assert.assertEquals(proposedItems.size(), 2);
// Latest existing (P1M)
Assert.assertEquals(proposedItems.get(0).getStartDate(), new LocalDate(2021, 4, 1));
Assert.assertEquals(proposedItems.get(0).getEndDate(), new LocalDate(2021, 5, 1));
// New proposed item
Assert.assertEquals(proposedItems.get(1).getStartDate(), new LocalDate(2021, 5, 1));
Assert.assertEquals(proposedItems.get(1).getEndDate(), new LocalDate(2021, 6, 1));
}
use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.
the class TestInvoiceOptimizerExp method testInAdvanceP0M.
@Test(groups = "fast")
public void testInAdvanceP0M() {
final LocalDate startDate = new LocalDate(2021, 2, 1);
LocalDate targetDate = new LocalDate(2021, 5, 1);
// Proposed: invoice from 2021-2-1 -> 2021-6-1
final List<InvoiceItem> proposedItems = new ArrayList<InvoiceItem>();
final Invoice proposed = createInvoice(targetDate);
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, startDate, new LocalDate(2021, 3, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 3, 1), new LocalDate(2021, 4, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 4, 1), new LocalDate(2021, 5, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 5, 1), new LocalDate(2021, 6, 1)));
// P0M
final LocalDate cutoffDate = targetDate;
// Existing: invoice from 2021-2-1 -> 2021-5-1
// Existing (filtered) empty
final List<Invoice> existing = new ArrayList<Invoice>();
final Invoice invoice = createInvoice(cutoffDate);
existing.add(invoice);
final DefaultBillingEventSet billingEvents = new DefaultBillingEventSet(false, false, false);
billingEvents.add(createBillingEvent(startDate, BillingMode.IN_ADVANCE, SubscriptionBaseTransitionType.CREATE));
final AccountInvoicesExp test = new AccountInvoicesExp(cutoffDate, null, existing);
test.filterProposedItems(proposedItems, billingEvents, internalCallContext);
Assert.assertEquals(proposedItems.size(), 1);
// New proposed item
Assert.assertEquals(proposedItems.get(0).getStartDate(), new LocalDate(2021, 5, 1));
Assert.assertEquals(proposedItems.get(0).getEndDate(), new LocalDate(2021, 6, 1));
}
use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.
the class TestInvoiceOptimizerExp method testInAdvanceWithCancellationP0M.
@Test(groups = "fast")
public void testInAdvanceWithCancellationP0M() {
final LocalDate startDate = new LocalDate(2021, 2, 1);
final LocalDate cancelDate = new LocalDate(2021, 4, 30);
final LocalDate targetDate = new LocalDate(2021, 5, 1);
// Proposed: invoice from 2021-2-1 -> 2021-4-30
final List<InvoiceItem> proposedItems = new ArrayList<InvoiceItem>();
final Invoice proposed = createInvoice(targetDate);
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, startDate, new LocalDate(2021, 3, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 3, 1), new LocalDate(2021, 4, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 4, 1), cancelDate));
// P0M
final LocalDate cutoffDate = targetDate;
// Existing: invoice from 2021-2-1 -> 2021-4-30
// Existing (filtered) empty
final List<Invoice> existing = new ArrayList<Invoice>();
final Invoice invoice = createInvoice(cutoffDate);
existing.add(invoice);
// Note that we don't really need the billing events except to fetch Plan info in AccountInvoicesExp#filterProposedItems
// so we don't need to explicitly add the CANCEL billing event
final DefaultBillingEventSet billingEvents = new DefaultBillingEventSet(false, false, false);
billingEvents.add(createBillingEvent(startDate, BillingMode.IN_ADVANCE, SubscriptionBaseTransitionType.CREATE));
final AccountInvoicesExp test = new AccountInvoicesExp(cutoffDate, null, existing);
test.filterProposedItems(proposedItems, billingEvents, internalCallContext);
Assert.assertEquals(proposedItems.size(), 0);
}
use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.
the class TestInvoiceOptimizerExp method testInArrearWithCancellationP1M.
@Test(groups = "fast")
public void testInArrearWithCancellationP1M() {
final LocalDate startDate = new LocalDate(2021, 2, 1);
final LocalDate cancelDate = new LocalDate(2021, 4, 30);
LocalDate targetDate = new LocalDate(2021, 6, 1);
// Proposed: invoice from 2021-2-1 -> 2021-4-30
final List<InvoiceItem> proposedItems = new ArrayList<InvoiceItem>();
final Invoice proposed = createInvoice(targetDate);
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, startDate, new LocalDate(2021, 3, 1)));
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 3, 1), new LocalDate(2021, 4, 1)));
// cancelDate
proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, new BigDecimal("9.88"), new LocalDate(2021, 4, 1), new LocalDate(2021, 4, 30)));
// P1M
final LocalDate cutoffDate = targetDate.minusMonths(1);
// Existing: invoice from 2021-2-1 -> 2021-4-30
// Existing (filtered) 2021-4-1 -> 2021-4-30
final List<Invoice> existing = new ArrayList<Invoice>();
final Invoice invoice = createInvoice(cutoffDate);
final InvoiceItem newItem = createItem(invoice.getId(), BigDecimal.TEN, new BigDecimal("9.88"), new LocalDate(2021, 4, 1), new LocalDate(2021, 4, 30));
invoice.addInvoiceItem(newItem);
existing.add(invoice);
final AccountInvoicesExp test = new AccountInvoicesExp(cutoffDate, null, existing);
final DefaultBillingEventSet billingEvents = new DefaultBillingEventSet(false, false, false);
billingEvents.add(createBillingEvent(startDate, BillingMode.IN_ARREAR, SubscriptionBaseTransitionType.CREATE));
test.filterProposedItems(proposedItems, billingEvents, internalCallContext);
Assert.assertEquals(proposedItems.size(), 1);
// Latest existing (P1M)
Assert.assertEquals(proposedItems.get(0).getStartDate(), new LocalDate(2021, 4, 1));
Assert.assertEquals(proposedItems.get(0).getEndDate(), cancelDate);
}
Aggregations