Search in sources :

Example 6 with AccountInvoicesExp

use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp 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);
}
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 AccountInvoicesExp

use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp 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);
}
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 AccountInvoicesExp

use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp 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 9 with AccountInvoicesExp

use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp 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 10 with AccountInvoicesExp

use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp 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)

Aggregations

LocalDate (org.joda.time.LocalDate)13 Invoice (org.killbill.billing.invoice.api.Invoice)13 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)13 AccountInvoicesExp (org.killbill.billing.invoice.optimizer.InvoiceOptimizerExp.AccountInvoicesExp)13 Test (org.testng.annotations.Test)13 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)12 ArrayList (java.util.ArrayList)10 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)10 DefaultBillingEventSet (org.killbill.billing.junction.plumbing.billing.DefaultBillingEventSet)10 BigDecimal (java.math.BigDecimal)6 UUID (java.util.UUID)3 DateTime (org.joda.time.DateTime)3 Period (org.joda.time.Period)3 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)3 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)3 MockPlan (org.killbill.billing.catalog.MockPlan)3 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)3 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)3 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)3 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)3