use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestInvoiceItemDao method testExternalChargeInvoiceSqlDao.
@Test(groups = "slow")
public void testExternalChargeInvoiceSqlDao() throws Exception {
final UUID invoiceId = UUID.randomUUID();
final UUID accountId = account.getId();
final UUID bundleId = UUID.randomUUID();
final String description = UUID.randomUUID().toString();
final LocalDate startDate = new LocalDate(2012, 4, 1);
final LocalDate endDate = new LocalDate(2012, 5, 1);
final InvoiceItem externalChargeInvoiceItem = new ExternalChargeInvoiceItem(invoiceId, accountId, bundleId, description, startDate, endDate, TEN, Currency.USD, null);
invoiceUtil.createInvoiceItem(externalChargeInvoiceItem, context);
final InvoiceItemModelDao savedItem = invoiceUtil.getInvoiceItemById(externalChargeInvoiceItem.getId(), context);
assertSameInvoiceItem(externalChargeInvoiceItem, savedItem);
}
use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestInvoiceItemDao method createAndVerifyExternalCharge.
private void createAndVerifyExternalCharge(final BigDecimal amount, final Currency currency) throws EntityPersistenceException {
final InvoiceItem externalChargeInvoiceItem = new ExternalChargeInvoiceItem(UUID.randomUUID(), account.getId(), UUID.randomUUID(), UUID.randomUUID().toString(), new LocalDate(2012, 4, 1), new LocalDate(2012, 5, 1), amount, currency, null);
invoiceUtil.createInvoiceItem(externalChargeInvoiceItem, context);
final InvoiceItemModelDao savedItem = invoiceUtil.getInvoiceItemById(externalChargeInvoiceItem.getId(), context);
assertSameInvoiceItem(externalChargeInvoiceItem, savedItem);
Assert.assertEquals(externalChargeInvoiceItem.getAmount().compareTo(amount), 0);
}
use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceUserApi method testPostExternalChargeForBundle.
@Test(groups = "slow")
public void testPostExternalChargeForBundle() throws Exception {
final Account account = invoiceUtil.createAccount(callContext);
final UUID accountId = account.getId();
final UUID invoiceId = invoiceUtil.generateRegularInvoice(account, null, callContext);
// Post an external charge
final BigDecimal externalChargeAmount = BigDecimal.TEN;
final UUID bundleId = UUID.randomUUID();
final InvoiceItem externalCharge = new ExternalChargeInvoiceItem(null, accountId, bundleId, UUID.randomUUID().toString(), clock.getUTCToday(), null, externalChargeAmount, accountCurrency, null);
final InvoiceItem externalChargeInvoiceItem = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge), true, null, callContext).get(0);
Assert.assertEquals(externalChargeInvoiceItem.getBundleId(), bundleId);
}
use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceUserApi method testDeleteUserGeneratedCredit.
@Test(groups = "slow")
public void testDeleteUserGeneratedCredit() throws Exception {
final Account account = invoiceUtil.createAccount(callContext);
final UUID accountId = account.getId();
// Invoice created in DRAFT state so we can add credit items on top of it
final InvoiceItem externalCharge1 = new ExternalChargeInvoiceItem(null, accountId, null, "description", clock.getUTCToday(), clock.getUTCToday(), new BigDecimal("100.00"), accountCurrency, null);
final List<InvoiceItem> items1 = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge1), false, null, callContext);
assertEquals(items1.size(), 1);
final Invoice invoice1 = invoiceUserApi.getInvoice(items1.get(0).getInvoiceId(), callContext);
final InvoiceItem creditItemInput = new CreditAdjInvoiceItem(invoice1.getId(), accountId, clock.getUTCToday(), "something", new BigDecimal("200.00"), accountCurrency, null);
final List<InvoiceItem> itemCredits = invoiceUserApi.insertCredits(accountId, clock.getUTCToday(), ImmutableList.of(creditItemInput), true, null, callContext);
final InvoiceItem itemCredit = itemCredits.get(0);
// No credit as invoice is still in DRAFT
final BigDecimal accountBalance = invoiceUserApi.getAccountBalance(accountId, callContext);
final BigDecimal accountCBA = invoiceUserApi.getAccountCBA(accountId, callContext);
Assert.assertEquals(accountBalance.compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(accountCBA.compareTo(BigDecimal.ZERO), 0);
// Create new invoice (COMMITTED)
final InvoiceItem externalCharge2 = new ExternalChargeInvoiceItem(null, accountId, null, "description", clock.getUTCToday(), clock.getUTCToday(), new BigDecimal("50.00"), accountCurrency, null);
final List<InvoiceItem> items2 = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge2), true, null, callContext);
assertEquals(items2.size(), 1);
final Invoice invoice2 = invoiceUserApi.getInvoice(items2.get(0).getInvoiceId(), callContext);
// Verify balance and credit only reflect invoice2
final BigDecimal accountBalance2 = invoiceUserApi.getAccountBalance(accountId, callContext);
final BigDecimal accountCBA2 = invoiceUserApi.getAccountCBA(accountId, callContext);
Assert.assertEquals(accountBalance2.compareTo(new BigDecimal("50")), 0);
Assert.assertEquals(accountCBA2.compareTo(BigDecimal.ZERO), 0);
// Commit invoice 1
invoiceUserApi.commitInvoice(invoice1.getId(), callContext);
final BigDecimal accountBalance3 = invoiceUserApi.getAccountBalance(accountId, callContext);
final BigDecimal accountCBA3 = invoiceUserApi.getAccountCBA(accountId, callContext);
Assert.assertEquals(accountBalance3.compareTo(new BigDecimal("-50")), 0);
Assert.assertEquals(accountCBA3.compareTo(new BigDecimal("50")), 0);
// Void invoice1 where we initially generated the credit -> fails because there was credit generated on it
try {
invoiceUserApi.voidInvoice(invoice1.getId(), callContext);
Assert.fail("Should not allow to void invoice with credit");
} catch (final Exception ignore) {
// No check because of https://github.com/killbill/killbill/issues/1501
}
Invoice latestInvoice1 = invoiceUserApi.getInvoice(items1.get(0).getInvoiceId(), callContext);
final InvoiceItem creditGenItem = Iterables.tryFind(latestInvoice1.getInvoiceItems(), new Predicate<InvoiceItem>() {
@Override
public boolean apply(final InvoiceItem invoiceItem) {
return InvoiceItemType.CBA_ADJ == invoiceItem.getInvoiceItemType() && invoiceItem.getAmount().compareTo(BigDecimal.ZERO) > 0;
}
}).get();
// Delete the credit generation
invoiceUserApi.deleteCBA(accountId, invoice1.getId(), creditGenItem.getId(), callContext);
latestInvoice1 = invoiceUserApi.getInvoice(items1.get(0).getInvoiceId(), callContext);
Assert.assertEquals(latestInvoice1.getBalance().compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(latestInvoice1.getInvoiceItems().size(), 3);
Assert.assertNotNull(Iterables.tryFind(latestInvoice1.getInvoiceItems(), new Predicate<InvoiceItem>() {
@Override
public boolean apply(final InvoiceItem invoiceItem) {
return InvoiceItemType.CBA_ADJ == invoiceItem.getInvoiceItemType() && invoiceItem.getAmount().compareTo(BigDecimal.ZERO) == 0;
}
}).orNull());
Assert.assertNotNull(Iterables.tryFind(latestInvoice1.getInvoiceItems(), new Predicate<InvoiceItem>() {
@Override
public boolean apply(final InvoiceItem invoiceItem) {
return InvoiceItemType.CREDIT_ADJ == invoiceItem.getInvoiceItemType() && // Original credit amount - CBA gen (we just deleted)
invoiceItem.getAmount().compareTo(new BigDecimal("-100.00")) == 0;
}
}).orNull());
final BigDecimal accountBalance4 = invoiceUserApi.getAccountBalance(accountId, callContext);
final BigDecimal accountCBA4 = invoiceUserApi.getAccountCBA(accountId, callContext);
Assert.assertEquals(accountBalance4.compareTo(new BigDecimal("50.0")), 0);
Assert.assertEquals(accountCBA4.compareTo(BigDecimal.ZERO), 0);
}
use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testSimpleInvoiceRun.
@Test(groups = "slow")
public void testSimpleInvoiceRun() throws Exception {
final UUID accountId = account.getId();
final InvoiceModelDao invoiceForExternalCharge = new InvoiceModelDao(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD, false);
final InvoiceItemModelDao externalCharge1 = new InvoiceItemModelDao(new ExternalChargeInvoiceItem(invoiceForExternalCharge.getId(), accountId, UUID.randomUUID(), UUID.randomUUID().toString(), clock.getUTCToday(), clock.getUTCToday(), new BigDecimal("15.0"), Currency.USD, null));
final InvoiceItemModelDao externalCharge2 = new InvoiceItemModelDao(new ExternalChargeInvoiceItem(invoiceForExternalCharge.getId(), accountId, UUID.randomUUID(), UUID.randomUUID().toString(), clock.getUTCToday(), clock.getUTCToday(), new BigDecimal("17.0"), Currency.USD, null));
invoiceForExternalCharge.addInvoiceItem(externalCharge1);
invoiceForExternalCharge.addInvoiceItem(externalCharge2);
invoiceDao.createInvoice(invoiceForExternalCharge, null, ImmutableSet.<InvoiceTrackingModelDao>of(), new FutureAccountNotifications(), new ExistingInvoiceMetadata(ImmutableList.<Invoice>of()), context);
final Invoice invoice = invoiceUserApi.getInvoice(invoiceForExternalCharge.getId(), callContext);
invoiceUtil.checkInvoicesEqual(invoiceForExternalCharge, invoice);
}
Aggregations