Search in sources :

Example 6 with DefaultBillingEventSet

use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.

the class TestInvoiceOptimizerExp method testInAdvanceLateP1M.

@Test(groups = "fast")
public void testInAdvanceLateP1M() {
    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)));
    // P1M
    final LocalDate cutoffDate = targetDate.minusMonths(1);
    // Existing: empty
    // Existing (filtered)  empty
    final List<Invoice> existing = new ArrayList<Invoice>();
    final Invoice invoice = createInvoice(cutoffDate);
    final InvoiceItem newItem = createItem(invoice.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 4, 1), new LocalDate(2021, 5, 1));
    invoice.addInvoiceItem(newItem);
    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(), 2);
    // Latest existing (P1M) - this would be regenerated, we would catch up for one period
    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));
}
Also used : RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) ArrayList(java.util.ArrayList) DefaultBillingEventSet(org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet) LocalDate(org.joda.time.LocalDate) AccountInvoicesExp(org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp) Test(org.testng.annotations.Test)

Example 7 with DefaultBillingEventSet

use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.

the class TestInvoiceOptimizerExp method testInAdvanceWithCancellationP1M.

@Test(groups = "fast")
public void testInAdvanceWithCancellationP1M() {
    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, new BigDecimal("9.88"), new LocalDate(2021, 4, 1), cancelDate));
    // P0M
    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), cancelDate);
    invoice.addInvoiceItem(newItem);
    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(), 1);
    // Latest existing (P1M)
    Assert.assertEquals(proposedItems.get(0).getStartDate(), new LocalDate(2021, 4, 1));
    Assert.assertEquals(proposedItems.get(0).getEndDate(), cancelDate);
}
Also used : RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) ArrayList(java.util.ArrayList) DefaultBillingEventSet(org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountInvoicesExp(org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp) Test(org.testng.annotations.Test)

Example 8 with DefaultBillingEventSet

use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.

the class TestInvoiceOptimizerExp method testInAdvanceP1M.

@Test(groups = "fast")
public void testInAdvanceP1M() {
    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)));
    // P1M
    final LocalDate cutoffDate = targetDate.minusMonths(1);
    // Existing: invoice from 2021-2-1 -> 2021-5-1
    // Existing (filtered)  2021-4-1 ->  2021-5-1
    final List<Invoice> existing = new ArrayList<Invoice>();
    final Invoice invoice = createInvoice(cutoffDate);
    final InvoiceItem newItem = createItem(invoice.getId(), BigDecimal.TEN, BigDecimal.TEN, new LocalDate(2021, 4, 1), new LocalDate(2021, 5, 1));
    invoice.addInvoiceItem(newItem);
    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(), 2);
    // Latest existing (P1M) - this would be filtered out by the tree later on
    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));
}
Also used : RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) ArrayList(java.util.ArrayList) DefaultBillingEventSet(org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet) LocalDate(org.joda.time.LocalDate) AccountInvoicesExp(org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp) Test(org.testng.annotations.Test)

Example 9 with DefaultBillingEventSet

use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.

the class TestInvoiceOptimizerExp method testInArrearWithCancellationP0M.

@Test(groups = "fast")
public void testInArrearWithCancellationP0M() {
    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)));
    proposedItems.add(createItem(proposed.getId(), BigDecimal.TEN, new BigDecimal("9.88"), 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);
    final AccountInvoicesExp test = new AccountInvoicesExp(cutoffDate, null, existing);
    // 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_ARREAR, SubscriptionBaseTransitionType.CREATE));
    test.filterProposedItems(proposedItems, billingEvents, internalCallContext);
    Assert.assertEquals(proposedItems.size(), 0);
}
Also used : RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) ArrayList(java.util.ArrayList) DefaultBillingEventSet(org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountInvoicesExp(org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp) Test(org.testng.annotations.Test)

Example 10 with DefaultBillingEventSet

use of org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet in project killbill by killbill.

the class TestInvoiceOptimizerExp method testInArrearP1M.

@Test(groups = "fast")
public void testInArrearP1M() {
    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
    final LocalDate cutoffDate = targetDate.minusMonths(1);
    // Existing: invoice from 2021-2-1 -> 2021-5-1
    // Existing (filtered) 2021-4-1 -> 2021-5-1
    final List<Invoice> existing = new ArrayList<Invoice>();
    final Invoice invoice = createInvoice(cutoffDate);
    final InvoiceItem newItem = createItem(invoice.getId(), BigDecimal.TEN, BigDecimal.TEN, cutoffDate.minusMonths(1), cutoffDate);
    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(), 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));
}
Also used : RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) ArrayList(java.util.ArrayList) DefaultBillingEventSet(org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet) LocalDate(org.joda.time.LocalDate) AccountInvoicesExp(org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)10 LocalDate (org.joda.time.LocalDate)10 Invoice (org.killbill.billing.invoice.api.Invoice)10 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)10 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)10 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)10 AccountInvoicesExp (org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp)10 DefaultBillingEventSet (org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet)10 Test (org.testng.annotations.Test)10 BigDecimal (java.math.BigDecimal)3