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);
}
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);
}
Aggregations