use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testWithExistingSplitRecurring.
@Test(groups = "fast")
public void testWithExistingSplitRecurring() {
final BigDecimal rate = new BigDecimal("40.00");
// We assume we have the right items for the period [2016, 9, 8; 2016, 10, 8] but split in pieces
final InvoiceItem recurring1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, new LocalDate(2016, 9, 8), new LocalDate(2016, 9, 9), new BigDecimal("2.0"), rate, currency);
final InvoiceItem recurring2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, new LocalDate(2016, 9, 9), new LocalDate(2016, 10, 8), new BigDecimal("38.0"), rate, currency);
final List<InvoiceItem> existingItems = new ArrayList<InvoiceItem>();
existingItems.add(recurring1);
existingItems.add(recurring2);
SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
for (InvoiceItem e : existingItems) {
tree.addItem(e);
}
tree.build();
tree.flatten(true);
// We generate the correct item for the period [2016, 9, 8; 2016, 10, 8]
final InvoiceItem proposedItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, new LocalDate(2016, 9, 8), new LocalDate(2016, 10, 8), rate, rate, currency);
tree.mergeProposedItem(proposedItem);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
expectedResult.add(proposedItem);
expectedResult.add(new RepairAdjInvoiceItem(invoiceId, accountId, recurring1.getStartDate(), recurring1.getEndDate(), recurring1.getAmount().negate(), currency, recurring1.getId()));
expectedResult.add(new RepairAdjInvoiceItem(invoiceId, accountId, recurring2.getStartDate(), recurring2.getEndDate(), recurring2.getAmount().negate(), currency, recurring2.getId()));
// We expect to see the repair for initail split items and the new full item
verifyResult(tree.getView(), expectedResult);
// Stage II: Try again.. with existing items
existingItems.addAll(tree.getView());
assertEquals(existingItems.size(), 5);
tree = new SubscriptionItemTree(subscriptionId, invoiceId);
for (InvoiceItem e : existingItems) {
tree.addItem(e);
}
tree.build();
tree.flatten(true);
// Regenerate proposedItem so it has a different id and Item#isSameKind correctly detect we are proposing the same kind
final InvoiceItem proposedItem2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, new LocalDate(2016, 9, 8), new LocalDate(2016, 10, 8), rate, rate, currency);
tree.mergeProposedItem(proposedItem2);
tree.buildForMerge();
// Nothing should be generated
Assert.assertTrue(tree.getView().isEmpty());
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testFullRepairPruneLogic2.
// Will test the case A from ItemsNodeInterval#prune logic (an item is left on the interval)
@Test(groups = "fast")
public void testFullRepairPruneLogic2() {
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 monthlyRateInit = new BigDecimal("12.00");
final BigDecimal monthlyAmountInit = monthlyRateInit;
final BigDecimal monthlyRateFinal = new BigDecimal("15.00");
final BigDecimal monthlyAmountFinal = monthlyRateFinal;
final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate1, endDate1, monthlyRateInit, monthlyAmountInit, currency);
final InvoiceItem monthly2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate2, endDate2, monthlyRateInit, monthlyAmountInit, currency);
final InvoiceItem repairMonthly2 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate2, endDate2, new BigDecimal("-12.00"), currency, monthly2.getId());
final InvoiceItem monthly2New = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate2, endDate2, monthlyRateFinal, monthlyAmountFinal, currency);
final InvoiceItem monthly3 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate3, endDate3, monthlyRateFinal, monthlyAmountFinal, currency);
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
expectedResult.add(monthly1);
expectedResult.add(monthly2New);
expectedResult.add(monthly3);
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
tree.addItem(monthly1);
tree.addItem(monthly2);
tree.addItem(repairMonthly2);
tree.addItem(monthly2New);
tree.addItem(monthly3);
tree.build();
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem 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.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceItemDao method testInvoiceItemCreation.
@Test(groups = "slow")
public void testInvoiceItemCreation() throws EntityPersistenceException {
final UUID accountId = account.getId();
final UUID invoiceId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final UUID subscriptionId = UUID.randomUUID();
final LocalDate startDate = new LocalDate(2011, 10, 1);
final LocalDate endDate = new LocalDate(2011, 11, 1);
final BigDecimal rate = new BigDecimal("20.00");
final RecurringInvoiceItem item = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test product", "test plan", "test phase", null, startDate, endDate, rate, rate, Currency.USD);
invoiceUtil.createInvoiceItem(item, context);
final InvoiceItemModelDao thisItem = invoiceUtil.getInvoiceItemById(item.getId(), context);
assertNotNull(thisItem);
assertEquals(thisItem.getId(), item.getId());
assertEquals(thisItem.getInvoiceId(), item.getInvoiceId());
assertEquals(thisItem.getSubscriptionId(), item.getSubscriptionId());
assertTrue(thisItem.getStartDate().compareTo(item.getStartDate()) == 0);
assertTrue(thisItem.getEndDate().compareTo(item.getEndDate()) == 0);
assertEquals(thisItem.getAmount().compareTo(item.getRate()), 0);
assertEquals(thisItem.getRate().compareTo(item.getRate()), 0);
assertEquals(thisItem.getCurrency(), item.getCurrency());
// created date is no longer set before persistence layer call
// assertEquals(thisItem.getCreatedDate().compareTo(item.getCreatedDate()), 0);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceItemDao method testGetInvoiceItemsBySubscriptionId.
@Test(groups = "slow")
public void testGetInvoiceItemsBySubscriptionId() throws EntityPersistenceException {
final UUID accountId = account.getId();
final UUID subscriptionId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final LocalDate startDate = new LocalDate(2011, 3, 1);
final BigDecimal rate = new BigDecimal("20.00");
for (int i = 0; i < 3; i++) {
final UUID invoiceId = UUID.randomUUID();
final RecurringInvoiceItem item = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test product", "test plan", "test phase", null, startDate.plusMonths(i), startDate.plusMonths(i + 1), rate, rate, Currency.USD);
invoiceUtil.createInvoiceItem(item, context);
}
final List<InvoiceItemModelDao> items = invoiceUtil.getInvoiceItemBySubscriptionId(subscriptionId, context);
assertEquals(items.size(), 3);
}
Aggregations