Search in sources :

Example 11 with CreditBalanceAdjInvoiceItem

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

the class TestInvoiceItemDao method testCreditBalanceInvoiceSqlDao.

@Test(groups = "slow")
public void testCreditBalanceInvoiceSqlDao() throws EntityPersistenceException {
    final UUID invoiceId = UUID.randomUUID();
    final UUID accountId = account.getId();
    final LocalDate creditDate = new LocalDate(2012, 4, 1);
    final InvoiceItem creditInvoiceItem = new CreditBalanceAdjInvoiceItem(invoiceId, accountId, creditDate, TEN, Currency.USD);
    invoiceUtil.createInvoiceItem(creditInvoiceItem, context);
    final InvoiceItemModelDao savedItem = invoiceUtil.getInvoiceItemById(creditInvoiceItem.getId(), context);
    assertSameInvoiceItem(creditInvoiceItem, savedItem);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) TaxInvoiceItem(org.killbill.billing.invoice.model.TaxInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 12 with CreditBalanceAdjInvoiceItem

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

the class TestInvoiceDao method testCantDeleteSystemGeneratedCredit.

@Test(groups = "slow")
public void testCantDeleteSystemGeneratedCredit() throws Exception {
    final UUID accountId = account.getId();
    // Create invoice 1
    // Scenario:
    // * $-10 repair
    // * $10 generated CBA
    final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
    final RepairAdjInvoiceItem repairAdjInvoiceItem = new RepairAdjInvoiceItem(invoice1.getId(), invoice1.getAccountId(), invoice1.getInvoiceDate(), invoice1.getInvoiceDate(), BigDecimal.TEN.negate(), invoice1.getCurrency(), UUID.randomUUID());
    final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem1 = new CreditBalanceAdjInvoiceItem(invoice1.getId(), invoice1.getAccountId(), invoice1.getInvoiceDate(), repairAdjInvoiceItem.getAmount().negate(), invoice1.getCurrency());
    invoiceUtil.createInvoice(invoice1, context);
    invoiceUtil.createInvoiceItem(repairAdjInvoiceItem, context);
    invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem1, context);
    // Verify scenario
    Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 10.00);
    invoiceUtil.verifyInvoice(invoice1.getId(), 0.00, 10.00, context);
    // Delete the CBA on invoice 1
    try {
        invoiceDao.deleteCBA(accountId, invoice1.getId(), creditBalanceAdjInvoiceItem1.getId(), context);
        Assert.fail();
    } catch (IllegalStateException e) {
        Assert.assertEquals(e.getMessage(), "Cannot delete system generated credit");
    }
    // Verify the result
    Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 10.00);
    invoiceUtil.verifyInvoice(invoice1.getId(), 0.00, 10.00, context);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Aggregations

CreditBalanceAdjInvoiceItem (org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem)12 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)11 UUID (java.util.UUID)10 Invoice (org.killbill.billing.invoice.api.Invoice)10 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)10 Test (org.testng.annotations.Test)10 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)9 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)8 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)7 CreditAdjInvoiceItem (org.killbill.billing.invoice.model.CreditAdjInvoiceItem)7 LocalDate (org.joda.time.LocalDate)6 DefaultInvoicePayment (org.killbill.billing.invoice.model.DefaultInvoicePayment)6 BigDecimal (java.math.BigDecimal)5 ExternalChargeInvoiceItem (org.killbill.billing.invoice.model.ExternalChargeInvoiceItem)5 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)4 ParentInvoiceItem (org.killbill.billing.invoice.model.ParentInvoiceItem)4 DateTime (org.joda.time.DateTime)3 InvoicePayment (org.killbill.billing.invoice.api.InvoicePayment)3 HashMap (java.util.HashMap)2 InvoiceFormatter (org.killbill.billing.invoice.api.formatters.InvoiceFormatter)2