use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testMergeCancellationWithTwoMiddleRepair.
@Test(groups = "fast")
public void testMergeCancellationWithTwoMiddleRepair() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate blockDate1 = new LocalDate(2014, 1, 7);
final LocalDate unblockDate1 = new LocalDate(2014, 1, 13);
final LocalDate blockDate2 = new LocalDate(2014, 1, 17);
final LocalDate unblockDate2 = new LocalDate(2014, 1, 25);
final LocalDate endDate = new LocalDate(2014, 2, 1);
final BigDecimal monthlyRate = new BigDecimal("12.00");
final BigDecimal monthlyAmount = monthlyRate;
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
final InvoiceItem monthly = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
tree.addItem(monthly);
tree.flatten(true);
final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, blockDate1, monthlyAmount, monthlyRate, currency);
final InvoiceItem proposed2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, unblockDate1, blockDate2, monthlyAmount, monthlyRate, currency);
final InvoiceItem proposed3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, unblockDate2, endDate, monthlyAmount, monthlyRate, currency);
tree.mergeProposedItem(proposed1);
tree.mergeProposedItem(proposed2);
tree.mergeProposedItem(proposed3);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
final InvoiceItem repair1 = new RepairAdjInvoiceItem(invoiceId, accountId, blockDate1, unblockDate1, new BigDecimal("-2.32"), currency, monthly.getId());
final InvoiceItem repair2 = new RepairAdjInvoiceItem(invoiceId, accountId, blockDate2, unblockDate2, new BigDecimal("-3.10"), currency, monthly.getId());
expectedResult.add(repair1);
expectedResult.add(repair2);
verifyResult(tree.getView(), expectedResult);
// Dot it again but with proposed items out of order
final SubscriptionItemTree treeAgain = new SubscriptionItemTree(subscriptionId, invoiceId);
final InvoiceItem monthlyAgain = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
treeAgain.addItem(monthlyAgain);
treeAgain.flatten(true);
final InvoiceItem proposed2Again = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, unblockDate1, blockDate2, monthlyAmount, monthlyRate, currency);
final InvoiceItem proposed1Again = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, blockDate1, monthlyAmount, monthlyRate, currency);
final InvoiceItem proposed3Again = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, unblockDate2, endDate, monthlyAmount, monthlyRate, currency);
treeAgain.mergeProposedItem(proposed1Again);
treeAgain.mergeProposedItem(proposed2Again);
treeAgain.mergeProposedItem(proposed3Again);
treeAgain.buildForMerge();
verifyResult(treeAgain.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testFullRepairByPartsPruneLogic1.
// Will test the case B from ItemsNodeInterval#prune logic
@Test(groups = "fast")
public void testFullRepairByPartsPruneLogic1() {
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, intermediate1, new BigDecimal("3.00"), currency, monthly1.getId());
final InvoiceItem repair12 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate1, intermediate2, new BigDecimal("3.00"), currency, monthly1.getId());
final InvoiceItem repair13 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate2, intermediate3, new BigDecimal("3.00"), currency, monthly1.getId());
final InvoiceItem repair14 = new RepairAdjInvoiceItem(invoiceId, accountId, intermediate3, endDate, new BigDecimal("3.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(repair12);
tree.addItem(repair13);
tree.addItem(repair14);
tree.addItem(monthly2);
tree.addItem(repair21);
tree.addItem(repair22);
tree.addItem(repair23);
tree.addItem(repair24);
tree.addItem(monthly3);
tree.build();
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testMultipleRepair.
@Test(groups = "fast")
public void testMultipleRepair() {
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 BigDecimal rate3 = new BigDecimal("19.23");
final BigDecimal amount3 = rate3;
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, repairDate1, endDate, amount1.negate(), currency, initial.getId());
final InvoiceItem newItem2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, repairDate2, endDate, amount3, rate3, currency);
final InvoiceItem repair2 = new RepairAdjInvoiceItem(invoiceId, accountId, repairDate2, endDate, amount2.negate(), currency, newItem1.getId());
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
final InvoiceItem expected1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, repairDate1, new BigDecimal("8.52"), rate1, currency);
expectedResult.add(expected1);
final InvoiceItem expected2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, repairDate1, repairDate2, new BigDecimal("4.95"), rate2, currency);
expectedResult.add(expected2);
final InvoiceItem expected3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, repairDate2, endDate, amount3, rate3, currency);
expectedResult.add(expected3);
// First test with items in order
SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
tree.addItem(initial);
tree.addItem(newItem1);
tree.addItem(repair1);
tree.addItem(newItem2);
tree.addItem(repair2);
tree.build();
verifyResult(tree.getView(), expectedResult);
tree = new SubscriptionItemTree(subscriptionId, invoiceId);
tree.addItem(repair2);
tree.addItem(newItem1);
tree.addItem(newItem2);
tree.addItem(repair1);
tree.addItem(initial);
tree.build();
verifyResult(tree.getView(), expectedResult);
tree = new SubscriptionItemTree(subscriptionId, invoiceId);
tree.addItem(repair1);
tree.addItem(newItem1);
tree.addItem(initial);
tree.addItem(repair2);
tree.addItem(newItem2);
tree.build();
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testMergeMonthlyToAnnualWithNoProRation.
@Test(groups = "fast")
public void testMergeMonthlyToAnnualWithNoProRation() {
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);
// First test with items in order
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
tree.addItem(monthly1);
tree.addItem(monthly2);
tree.flatten(true);
final InvoiceItem proposed = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, switchToAnnualDate, endDate, yearlyAmount, yearlyRate, currency);
final InvoiceItem proposedMonthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endMonthly1, monthlyAmount, monthlyRate, currency);
tree.mergeProposedItem(proposedMonthly1);
final InvoiceItem proRatedmonthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endMonthly1, switchToAnnualDate, monthlyAmount, monthlyRate, currency);
tree.mergeProposedItem(proRatedmonthly2);
tree.mergeProposedItem(proposed);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, switchToAnnualDate, endMonthly2, new BigDecimal("-2.57"), currency, monthly2.getId());
expectedResult.add(proposed);
expectedResult.add(repair);
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testMergeCancellationWithFinalRepair.
@Test(groups = "fast")
public void testMergeCancellationWithFinalRepair() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate cancelDate = 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, startDate, cancelDate, monthlyAmount1, monthlyRate1, currency);
tree.mergeProposedItem(proposed1);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, cancelDate, endDate, new BigDecimal("-2.71"), currency, monthly1.getId());
expectedResult.add(repair);
verifyResult(tree.getView(), expectedResult);
}
Aggregations