use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testMergeCancellationWithMiddleRepair.
@Test(groups = "fast")
public void testMergeCancellationWithMiddleRepair() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate blockDate = new LocalDate(2014, 1, 13);
final LocalDate unblockDate = 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, blockDate, monthlyAmount1, monthlyRate1, currency);
final InvoiceItem proposed2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, unblockDate, endDate, monthlyAmount1, monthlyRate1, currency);
tree.mergeProposedItem(proposed1);
tree.mergeProposedItem(proposed2);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, blockDate, unblockDate, new BigDecimal("-4.65"), currency, monthly1.getId());
expectedResult.add(repair);
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method verifyJson.
@Test(groups = "fast")
public void verifyJson() throws IOException {
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
final UUID id1 = UUID.fromString("e8ba6ce7-9bd4-417d-af53-70951ecaa99f");
final InvoiceItem yearly1 = new RecurringInvoiceItem(id1, new DateTime(), invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, new LocalDate("2014-01-01"), new LocalDate("2015-01-01"), BigDecimal.TEN, BigDecimal.TEN, currency);
tree.addItem(yearly1);
final UUID id2 = UUID.fromString("48db1317-9a6e-4666-bcc5-fc7d3d0defc8");
final InvoiceItem newItem = new RecurringInvoiceItem(id2, new DateTime(), invoiceId, accountId, bundleId, subscriptionId, "other-plan", "other-plan", new LocalDate("2014-08-01"), new LocalDate("2015-01-01"), BigDecimal.ONE, BigDecimal.ONE, currency);
tree.addItem(newItem);
final UUID id3 = UUID.fromString("02ec57f5-2723-478b-86ba-ebeaedacb9db");
final InvoiceItem repair = new RepairAdjInvoiceItem(id3, new DateTime(), invoiceId, accountId, new LocalDate("2014-08-01"), new LocalDate("2015-01-01"), BigDecimal.TEN.negate(), currency, yearly1.getId());
tree.addItem(repair);
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
tree.getRoot().jsonSerializeTree(new ObjectMapper(), outputStream);
final String json = outputStream.toString("UTF-8");
final String expectedJson = "[{\"start\":\"2014-01-01\",\"end\":\"2015-01-01\",\"items\":[{\"id\":\"e8ba6ce7-9bd4-417d-af53-70951ecaa99f\",\"startDate\":\"2014-01-01\",\"endDate\":\"2015-01-01\",\"amount\":10.00,\"currency\":\"USD\",\"linkedId\":null,\"action\":\"ADD\"}]},[{\"start\":\"2014-08-01\",\"end\":\"2015-01-01\",\"items\":[{\"id\":\"48db1317-9a6e-4666-bcc5-fc7d3d0defc8\",\"startDate\":\"2014-08-01\",\"endDate\":\"2015-01-01\",\"amount\":1.00,\"currency\":\"USD\",\"linkedId\":null,\"action\":\"ADD\"},{\"id\":\"02ec57f5-2723-478b-86ba-ebeaedacb9db\",\"startDate\":\"2014-08-01\",\"endDate\":\"2015-01-01\",\"amount\":10.00,\"currency\":\"USD\",\"linkedId\":\"e8ba6ce7-9bd4-417d-af53-70951ecaa99f\",\"action\":\"CANCEL\"}]}]]";
assertEquals(json, expectedJson);
}
use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem 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.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testBlockAcrossPeriod.
@Test(groups = "fast")
public void testBlockAcrossPeriod() {
final LocalDate startDate1 = new LocalDate(2014, 1, 1);
final LocalDate blockDate = new LocalDate(2014, 1, 25);
final LocalDate startDate2 = new LocalDate(2014, 2, 1);
final LocalDate unblockDate = new LocalDate(2014, 2, 7);
final LocalDate endDate = new LocalDate(2014, 3, 1);
final BigDecimal rate1 = new BigDecimal("12.00");
final BigDecimal amount1 = rate1;
final InvoiceItem first = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate1, startDate2, amount1, rate1, currency);
final InvoiceItem second = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate2, endDate, amount1, rate1, currency);
final InvoiceItem block1 = new RepairAdjInvoiceItem(invoiceId, accountId, blockDate, startDate2, amount1.negate(), currency, first.getId());
final InvoiceItem block2 = new RepairAdjInvoiceItem(invoiceId, accountId, startDate2, unblockDate, amount1.negate(), currency, first.getId());
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
final InvoiceItem expected1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate1, blockDate, new BigDecimal("9.29"), rate1, currency);
final InvoiceItem expected2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, unblockDate, endDate, new BigDecimal("9.43"), rate1, currency);
expectedResult.add(expected1);
expectedResult.add(expected2);
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
tree.addItem(first);
tree.addItem(second);
tree.addItem(block1);
tree.addItem(block2);
tree.build();
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RepairAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testMergeTwoDifferentItems.
@Test(groups = "fast")
public void testMergeTwoDifferentItems() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate endDate = new LocalDate(2014, 2, 1);
final BigDecimal monthlyRate1 = new BigDecimal("12.00");
final BigDecimal monthlyAmount1 = monthlyRate1;
final BigDecimal monthlyRate2 = new BigDecimal("15.00");
final BigDecimal monthlyAmount2 = monthlyRate2;
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, endDate, monthlyAmount2, monthlyRate2, currency);
tree.mergeProposedItem(proposed1);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, endDate, monthlyAmount1.negate(), currency, monthly1.getId());
expectedResult.add(proposed1);
expectedResult.add(repair);
verifyResult(tree.getView(), expectedResult);
}
Aggregations