Search in sources :

Example 16 with ItemAdjInvoiceItem

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

the class TestSubscriptionItemTree method testWithWrongInitialItem.

@Test(groups = "fast")
public void testWithWrongInitialItem() throws IOException {
    final LocalDate wrongStartDate = new LocalDate(2016, 9, 9);
    final LocalDate correctStartDate = new LocalDate(2016, 9, 8);
    final LocalDate endDate = new LocalDate(2016, 10, 8);
    final BigDecimal rate = new BigDecimal("12.00");
    final BigDecimal amount = rate;
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    final InvoiceItem wrongInitialItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, wrongStartDate, endDate, amount, rate, currency);
    tree.addItem(wrongInitialItem);
    final InvoiceItem itemAdj = new ItemAdjInvoiceItem(wrongInitialItem, new LocalDate(2016, 10, 2), amount.negate(), currency);
    tree.addItem(itemAdj);
    final InvoiceItem correctInitialItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, correctStartDate, endDate, amount, rate, currency);
    tree.flatten(true);
    tree.mergeProposedItem(correctInitialItem);
    tree.buildForMerge();
    final InvoiceItem expected = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, correctStartDate, wrongStartDate, new BigDecimal("0.40"), rate, currency);
    final List<InvoiceItem> expectedResult = ImmutableList.<InvoiceItem>of(expected);
    verifyResult(tree.getView(), expectedResult);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)16 BigDecimal (java.math.BigDecimal)15 LocalDate (org.joda.time.LocalDate)15 Test (org.testng.annotations.Test)15 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)14 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)14 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)13 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)12 Invoice (org.killbill.billing.invoice.api.Invoice)8 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)7 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)6 AccountInvoices (org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices)6 BillingEventSet (org.killbill.billing.junction.BillingEventSet)6 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 MockPlan (org.killbill.billing.catalog.MockPlan)4 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)4 Plan (org.killbill.billing.catalog.api.Plan)4 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)4 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)4