Search in sources :

Example 96 with RecurringInvoiceItem

use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.

the class TestSubscriptionItemTree method testWithBCDChange2.

@Test(groups = "fast")
public void testWithBCDChange2() {
    final LocalDate existingItemStartPeriod = new LocalDate(2014, 6, 20);
    final LocalDate existingItemEndPeriod = new LocalDate(2014, 7, 20);
    final LocalDate proposedItem1StartPeriod = new LocalDate(2014, 6, 17);
    final LocalDate proposedItem1EndPeriod = new LocalDate(2014, 7, 17);
    final LocalDate proposedItem2StartPeriod = proposedItem1EndPeriod;
    final LocalDate proposedItem2EndPeriod = new LocalDate(2014, 8, 17);
    final BigDecimal monthlyRate = new BigDecimal("10.00");
    final BigDecimal fullAmount = monthlyRate;
    final InvoiceItem item1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, existingItemStartPeriod, existingItemEndPeriod, fullAmount, monthlyRate, currency);
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(item1);
    tree.build();
    tree.flatten(true);
    final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, proposedItem1StartPeriod, proposedItem1EndPeriod, fullAmount, monthlyRate, currency);
    final InvoiceItem proposed2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, proposedItem2StartPeriod, proposedItem2EndPeriod, fullAmount, monthlyRate, currency);
    tree.mergeProposedItem(proposed1);
    tree.mergeProposedItem(proposed2);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem expected1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, proposedItem1StartPeriod, existingItemStartPeriod, new BigDecimal("1"), monthlyRate, currency);
    expectedResult.add(expected1);
    final InvoiceItem expected2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, existingItemEndPeriod, proposedItem2EndPeriod, new BigDecimal("9.03"), monthlyRate, currency);
    expectedResult.add(expected2);
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 97 with RecurringInvoiceItem

use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.

the class TestSubscriptionItemTree method testWithBCDChange4.

@Test(groups = "fast")
public void testWithBCDChange4() {
    final LocalDate existingItem1StartPeriod = new LocalDate(2014, 5, 17);
    final LocalDate existingItem1EndPeriod = new LocalDate(2014, 5, 20);
    final LocalDate existingItem2StartPeriod = existingItem1EndPeriod;
    final LocalDate existingItem2EndPeriod = new LocalDate(2014, 6, 20);
    final LocalDate existingItem3StartPeriod = existingItem2EndPeriod;
    final LocalDate existingItem3EndPeriod = new LocalDate(2014, 7, 20);
    final LocalDate existingItem4StartPeriod = existingItem3EndPeriod;
    final LocalDate existingItem4EndPeriod = new LocalDate(2014, 8, 17);
    final LocalDate proposedItem1StartPeriod = new LocalDate(2014, 5, 17);
    final LocalDate proposedItem1EndPeriod = new LocalDate(2014, 6, 17);
    final LocalDate proposedItem2StartPeriod = proposedItem1EndPeriod;
    final LocalDate proposedItem2EndPeriod = new LocalDate(2014, 7, 17);
    final LocalDate proposedItem3StartPeriod = proposedItem2EndPeriod;
    final LocalDate proposedItem3EndPeriod = new LocalDate(2014, 8, 17);
    final BigDecimal monthlyRate = new BigDecimal("10.00");
    final BigDecimal fullAmount = monthlyRate;
    final InvoiceItem item1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, existingItem1StartPeriod, existingItem1EndPeriod, new BigDecimal("1"), monthlyRate, currency);
    final InvoiceItem item2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, existingItem2StartPeriod, existingItem2EndPeriod, fullAmount, monthlyRate, currency);
    final InvoiceItem item3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, existingItem3StartPeriod, existingItem3EndPeriod, fullAmount, monthlyRate, currency);
    final InvoiceItem item4 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, existingItem4StartPeriod, existingItem4EndPeriod, new BigDecimal("7"), monthlyRate, currency);
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(item1);
    tree.addItem(item2);
    tree.addItem(item3);
    tree.addItem(item4);
    tree.build();
    tree.flatten(true);
    final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, proposedItem1StartPeriod, proposedItem1EndPeriod, fullAmount, monthlyRate, currency);
    final InvoiceItem proposed2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, proposedItem2StartPeriod, proposedItem2EndPeriod, fullAmount, monthlyRate, currency);
    final InvoiceItem proposed3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, proposedItem3StartPeriod, proposedItem3EndPeriod, fullAmount, monthlyRate, currency);
    tree.mergeProposedItem(proposed1);
    tree.mergeProposedItem(proposed2);
    tree.mergeProposedItem(proposed3);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 98 with RecurringInvoiceItem

use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.

the class TestSubscriptionItemTree method testWithWrongInitialItem.

@Test(groups = "fast")
public void testWithWrongInitialItem() throws IOException {
    final LocalDate wrongStartDate = new LocalDate(2016, 9, 9);
    final LocalDate correctStartDate = new LocalDate(2016, 9, 8);
    final LocalDate endDate = new LocalDate(2016, 10, 8);
    final BigDecimal rate = new BigDecimal("12.00");
    final BigDecimal amount = rate;
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    final InvoiceItem wrongInitialItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, wrongStartDate, endDate, amount, rate, currency);
    tree.addItem(wrongInitialItem);
    final InvoiceItem itemAdj = new ItemAdjInvoiceItem(wrongInitialItem, new LocalDate(2016, 10, 2), amount.negate(), currency);
    tree.addItem(itemAdj);
    final InvoiceItem correctInitialItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, correctStartDate, endDate, amount, rate, currency);
    tree.flatten(true);
    tree.mergeProposedItem(correctInitialItem);
    tree.buildForMerge();
    final InvoiceItem expected = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, correctStartDate, wrongStartDate, new BigDecimal("0.40"), rate, currency);
    final List<InvoiceItem> expectedResult = ImmutableList.<InvoiceItem>of(expected);
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)98 Test (org.testng.annotations.Test)90 LocalDate (org.joda.time.LocalDate)89 BigDecimal (java.math.BigDecimal)82 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)73 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)69 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)69 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)65 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)39 Invoice (org.killbill.billing.invoice.api.Invoice)38 UUID (java.util.UUID)34 MockPlan (org.killbill.billing.catalog.MockPlan)16 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)16 Plan (org.killbill.billing.catalog.api.Plan)16 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)16 AccountInvoices (org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices)16 BillingEventSet (org.killbill.billing.junction.BillingEventSet)16 HashMap (java.util.HashMap)15 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)15 BillingEvent (org.killbill.billing.junction.BillingEvent)15