use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testWithNewFixedItem.
@Test(groups = "fast")
public void testWithNewFixedItem() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate endDate = new LocalDate(2014, 2, 1);
final BigDecimal monthlyRate = new BigDecimal("12.00");
final BigDecimal monthlyAmount = monthlyRate;
final BigDecimal fixedAmount = new BigDecimal("5.00");
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
final InvoiceItem monthly = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyAmount, monthlyRate, currency);
tree.addItem(monthly);
tree.flatten(true);
final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyAmount, monthlyRate, currency);
final InvoiceItem fixed = new FixedPriceInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, fixedAmount, currency);
tree.mergeProposedItem(proposed1);
tree.mergeProposedItem(fixed);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
expectedResult.add(fixed);
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem 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, productName, planName, phaseName, null, 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-product", "other-plan", "other-plan", null, 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\",\"fullyAdjusted\":false}]},[{\"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\",\"fullyAdjusted\":false},{\"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\",\"fullyAdjusted\":false}]}]]";
assertEquals(json, expectedJson);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testMergeWithNoExisting.
@Test(groups = "fast")
public void testMergeWithNoExisting() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
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);
tree.flatten(true);
final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyAmount, monthlyRate, currency);
tree.mergeProposedItem(proposed1);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
expectedResult.add(proposed1);
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testRepairWithLargeItemAdjustment.
@Test(groups = "fast")
public void testRepairWithLargeItemAdjustment() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate itemAdjDate = new LocalDate(2014, 1, 2);
final LocalDate endDate = new LocalDate(2014, 2, 1);
final LocalDate cancelDate = new LocalDate(2014, 1, 23);
final BigDecimal rate1 = new BigDecimal("12.00");
final BigDecimal amount1 = rate1;
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
final InvoiceItem initial = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, amount1, rate1, currency);
final InvoiceItem itemAdj = new ItemAdjInvoiceItem(initial, itemAdjDate, new BigDecimal("-10.00"), currency);
tree.addItem(initial);
tree.addItem(itemAdj);
tree.flatten(true);
final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, cancelDate, amount1, rate1, currency);
tree.mergeProposedItem(proposed1);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
final InvoiceItem repair1 = new RepairAdjInvoiceItem(invoiceId, accountId, cancelDate, endDate, new BigDecimal("-2.00"), currency, initial.getId());
expectedResult.add(repair1);
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testMultipleLevels.
@Test(groups = "fast", description = "Complex multi-level tree, mostly used to test the tree printer")
public void testMultipleLevels() throws Exception {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate endDate = new LocalDate(2014, 2, 1);
final LocalDate startRepairDate1 = new LocalDate(2014, 1, 10);
final LocalDate endRepairDate1 = new LocalDate(2014, 1, 15);
final LocalDate startRepairDate11 = new LocalDate(2014, 1, 10);
final LocalDate endRepairDate12 = new LocalDate(2014, 1, 12);
final LocalDate startRepairDate2 = new LocalDate(2014, 1, 20);
final LocalDate endRepairDate2 = new LocalDate(2014, 1, 25);
final LocalDate startRepairDate21 = new LocalDate(2014, 1, 22);
final LocalDate endRepairDate22 = new LocalDate(2014, 1, 23);
final BigDecimal rate = BigDecimal.TEN;
final BigDecimal amount = rate;
final InvoiceItem initial = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, amount, rate, currency);
final InvoiceItem newItem1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startRepairDate1, endRepairDate1, amount, rate, currency);
final InvoiceItem repair1 = new RepairAdjInvoiceItem(invoiceId, accountId, startRepairDate1, endRepairDate1, amount.negate(), currency, initial.getId());
final InvoiceItem newItem11 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startRepairDate11, endRepairDate12, amount, rate, currency);
final InvoiceItem repair12 = new RepairAdjInvoiceItem(invoiceId, accountId, startRepairDate11, endRepairDate12, amount.negate(), currency, newItem1.getId());
final InvoiceItem newItem2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startRepairDate2, endRepairDate2, amount, rate, currency);
final InvoiceItem repair2 = new RepairAdjInvoiceItem(invoiceId, accountId, startRepairDate2, endRepairDate2, amount.negate(), currency, initial.getId());
final InvoiceItem newItem21 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startRepairDate21, endRepairDate22, amount, rate, currency);
final InvoiceItem repair22 = new RepairAdjInvoiceItem(invoiceId, accountId, startRepairDate21, endRepairDate22, amount.negate(), currency, newItem2.getId());
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
tree.addItem(initial);
tree.addItem(newItem1);
tree.addItem(repair1);
tree.addItem(newItem11);
tree.addItem(repair12);
tree.addItem(newItem2);
tree.addItem(repair2);
tree.addItem(newItem21);
tree.addItem(repair22);
tree.build();
// printTree(tree);
tree.flatten(true);
// printTree(tree);
}
Aggregations