Search in sources :

Example 36 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testInvalidRepairCausingOverlappingRecurringV2.

@Test(groups = "fast")
public void testInvalidRepairCausingOverlappingRecurringV2() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final LocalDate repairDate1 = new LocalDate(2014, 1, 23);
    final LocalDate repairDate2 = new LocalDate(2014, 1, 26);
    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 newItem1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, repairDate1, endDate, amount2, rate2, currency);
    final InvoiceItem repair1 = new RepairAdjInvoiceItem(invoiceId, accountId, repairDate2, endDate, amount1.negate(), currency, initial.getId());
    // Out-of-order insertion to show ordering doesn't matter
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(repair1);
    tree.addItem(initial);
    tree.addItem(newItem1);
    try {
        tree.build();
        fail();
    } catch (final IllegalStateException e) {
    }
}
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 37 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testMergeCancellationWithInitialRepair.

@Test(groups = "fast")
public void testMergeCancellationWithInitialRepair() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate blockDate = 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 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, blockDate, endDate, monthlyAmount1, monthlyRate1, currency);
    tree.mergeProposedItem(proposed1);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, blockDate, new BigDecimal("-9.29"), currency, monthly1.getId());
    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 38 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testMonthlyToAnnualWithNoProRation.

@Test(groups = "fast")
public void testMonthlyToAnnualWithNoProRation() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate endMonthly1 = new LocalDate(2014, 2, 1);
    final LocalDate endMonthly2 = new LocalDate(2014, 3, 1);
    final LocalDate switchToAnnualDate = new LocalDate(2014, 2, 23);
    final LocalDate endDate = new LocalDate(2015, 2, 23);
    final BigDecimal monthlyRate = new BigDecimal("12.00");
    final BigDecimal monthlyAmount = monthlyRate;
    final BigDecimal yearlyRate = new BigDecimal("100.00");
    final BigDecimal yearlyAmount = yearlyRate;
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endMonthly1, monthlyAmount, monthlyRate, currency);
    final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endMonthly1, endMonthly2, monthlyAmount, monthlyRate, currency);
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, switchToAnnualDate, endMonthly2, monthlyAmount.negate(), currency, monthly2.getId());
    final InvoiceItem annual = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, switchToAnnualDate, endDate, yearlyAmount, yearlyRate, currency);
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(monthly1);
    final InvoiceItem monthly2Prorated = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endMonthly1, switchToAnnualDate, new BigDecimal("9.43"), monthlyRate, currency);
    expectedResult.add(monthly2Prorated);
    expectedResult.add(annual);
    // First test with items in order
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(monthly1);
    tree.addItem(monthly2);
    tree.addItem(repair);
    tree.addItem(annual);
    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 39 with RepairAdjInvoiceItem

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

the class TestSubscriptionItemTree method testMultipleBlockedBillings.

@Test(groups = "fast")
public void testMultipleBlockedBillings() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final LocalDate blockStart1 = new LocalDate(2014, 1, 8);
    final LocalDate unblockStart1 = new LocalDate(2014, 1, 10);
    final LocalDate blockStart2 = new LocalDate(2014, 1, 17);
    final LocalDate unblockStart2 = new LocalDate(2014, 1, 23);
    final BigDecimal rate1 = new BigDecimal("12.00");
    final BigDecimal amount1 = rate1;
    final InvoiceItem initial = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency);
    final InvoiceItem block1 = new RepairAdjInvoiceItem(invoiceId, accountId, blockStart1, unblockStart1, amount1.negate(), currency, initial.getId());
    final InvoiceItem block2 = new RepairAdjInvoiceItem(invoiceId, accountId, blockStart2, unblockStart2, amount1.negate(), currency, initial.getId());
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem expected1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, blockStart1, new BigDecimal("2.71"), rate1, currency);
    expectedResult.add(expected1);
    final InvoiceItem expected2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, unblockStart1, blockStart2, new BigDecimal("2.71"), rate1, currency);
    expectedResult.add(expected2);
    final InvoiceItem expected3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, unblockStart2, endDate, new BigDecimal("3.48"), rate1, currency);
    expectedResult.add(expected3);
    // First test with items in order
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.addItem(initial);
    tree.addItem(block1);
    tree.addItem(block2);
    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 40 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)

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