Search in sources :

Example 46 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testMergeUpgradeWithFinalRepair.

@Test(groups = "fast")
public void testMergeUpgradeWithFinalRepair() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate upgradeDate = new LocalDate(2014, 1, 25);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final BigDecimal monthlyRate1 = new BigDecimal("12.00");
    final BigDecimal monthlyAmount1 = monthlyRate1;
    final BigDecimal monthlyRate2 = new BigDecimal("20.00");
    final BigDecimal monthlyAmount2 = monthlyRate1;
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount1, monthlyRate1, currency);
    tree.addItem(monthly1);
    tree.flatten(true);
    final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, upgradeDate, monthlyAmount1, monthlyRate1, currency);
    final InvoiceItem proposed2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "foo", "foo", upgradeDate, endDate, monthlyAmount2, monthlyRate2, currency);
    tree.mergeProposedItem(proposed1);
    tree.mergeProposedItem(proposed2);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, upgradeDate, endDate, new BigDecimal("-2.71"), currency, monthly1.getId());
    expectedResult.add(proposed2);
    expectedResult.add(repair);
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 47 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testFullRepairPruneLogic1.

// Will test the case A from ItemsNodeInterval#prune logic (when we delete a node while walking the tree)
@Test(groups = "fast")
public void testFullRepairPruneLogic1() {
    final LocalDate startDate1 = new LocalDate(2015, 1, 1);
    final LocalDate endDate1 = new LocalDate(2015, 2, 1);
    final LocalDate startDate2 = endDate1;
    final LocalDate endDate2 = new LocalDate(2015, 3, 1);
    final LocalDate startDate3 = endDate2;
    final LocalDate endDate3 = new LocalDate(2015, 4, 1);
    final BigDecimal monthlyRate = new BigDecimal("12.00");
    final BigDecimal monthlyAmount = monthlyRate;
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate1, endDate1, monthlyAmount, monthlyRate, currency);
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate2, endDate2, monthlyAmount, monthlyRate, currency);
    final InvoiceItem repairMonthly2 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate2, endDate2, new BigDecimal("-12.00"), currency, monthly2.getId());
    final InvoiceItem monthly3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate3, endDate3, monthlyAmount, monthlyRate, currency);
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(monthly1);
    expectedResult.add(monthly3);
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.addItem(repairMonthly2);
    tree.addItem(monthly3);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 48 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testAnnualFullRepairFollowedByMonthly.

@Test(groups = "fast")
public void testAnnualFullRepairFollowedByMonthly() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate firstMonthlyEndDate = new LocalDate(2014, 2, 1);
    final LocalDate secondMonthlyEndDate = new LocalDate(2014, 3, 1);
    final LocalDate endDate = new LocalDate(2015, 2, 1);
    final BigDecimal rate1 = new BigDecimal("120.00");
    final BigDecimal amount1 = rate1;
    final BigDecimal rate2 = new BigDecimal("10.00");
    final BigDecimal amount2 = rate2;
    final InvoiceItem annual = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency);
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, endDate, amount1.negate(), currency, annual.getId());
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "someelse", "someelse", startDate, firstMonthlyEndDate, amount2, rate2, currency);
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "someelse", "someelse", firstMonthlyEndDate, secondMonthlyEndDate, amount2, rate2, currency);
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(monthly1);
    expectedResult.add(monthly2);
    SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(annual);
    tree.addItem(repair);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
    tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(repair);
    tree.addItem(annual);
    tree.addItem(monthly2);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
    tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.addItem(annual);
    tree.addItem(repair);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 49 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testFullRepairByPartsPruneLogic2.

// Will test the case A and B from ItemsNodeInterval#prune logic
@Test(groups = "fast")
public void testFullRepairByPartsPruneLogic2() {
    final LocalDate startDate = new LocalDate(2015, 2, 1);
    final LocalDate intermediate1 = new LocalDate(2015, 2, 8);
    final LocalDate intermediate2 = new LocalDate(2015, 2, 16);
    final LocalDate intermediate3 = new LocalDate(2015, 2, 24);
    final LocalDate endDate = new LocalDate(2015, 3, 1);
    final BigDecimal monthlyRate = new BigDecimal("12.00");
    final BigDecimal monthlyAmount = monthlyRate;
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
    final InvoiceItem repair11 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, endDate, new BigDecimal("-12.00"), currency, monthly1.getId());
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
    final InvoiceItem repair21 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, intermediate1, new BigDecimal("3.00"), currency, monthly2.getId());
    final InvoiceItem repair22 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate1, intermediate2, new BigDecimal("3.00"), currency, monthly2.getId());
    final InvoiceItem repair23 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate2, intermediate3, new BigDecimal("3.00"), currency, monthly2.getId());
    final InvoiceItem repair24 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate3, endDate, new BigDecimal("3.00"), currency, monthly2.getId());
    final InvoiceItem monthly3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(monthly3);
    // First test with items in order
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(repair11);
    tree.addItem(monthly2);
    tree.addItem(repair21);
    tree.addItem(repair22);
    tree.addItem(repair23);
    tree.addItem(repair24);
    tree.addItem(monthly3);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 50 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testSimpleRepair.

@Test(groups = "fast")
public void testSimpleRepair() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final LocalDate repairDate = new LocalDate(2014, 1, 23);
    final BigDecimal rate1 = new BigDecimal("12.00");
    final BigDecimal amount1 = rate1;
    final BigDecimal rate2 = new BigDecimal("14.85");
    final BigDecimal amount2 = rate2;
    final InvoiceItem initial = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency);
    final InvoiceItem newItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "someelse", "someelse", repairDate, endDate, amount2, rate2, currency);
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, repairDate, endDate, amount1.negate(), currency, initial.getId());
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem expected1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, repairDate, new BigDecimal("8.52"), rate1, currency);
    expectedResult.add(expected1);
    final InvoiceItem expected2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "someelse", "someelse", repairDate, endDate, amount2, rate2, currency);
    expectedResult.add(expected2);
    // First test with items in order
    SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(initial);
    tree.addItem(newItem);
    tree.addItem(repair);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
    tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(repair);
    tree.addItem(newItem);
    tree.addItem(initial);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
    tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(repair);
    tree.addItem(initial);
    tree.addItem(newItem);
    tree.build();
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Aggregations

RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)50 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)48 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)48 Test (org.testng.annotations.Test)47 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)46 BigDecimal (java.math.BigDecimal)45 LocalDate (org.joda.time.LocalDate)45 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)45 UUID (java.util.UUID)19 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)19 Invoice (org.killbill.billing.invoice.api.Invoice)18 LinkedList (java.util.LinkedList)11 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)11 BillingEventSet (org.killbill.billing.junction.BillingEventSet)11 SubscriptionFutureNotificationDates (org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates)10 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)9 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)9 MockPlan (org.killbill.billing.catalog.MockPlan)9 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)9 Plan (org.killbill.billing.catalog.api.Plan)9