use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDaoHelper method testPopulateChildrenWith_WRITTEN_OFF.
@Test(groups = "slow")
public void testPopulateChildrenWith_WRITTEN_OFF() throws Exception {
final UUID accountId = account.getId();
final Invoice inputInvoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final InvoiceItem invoiceItem = new RecurringInvoiceItem(inputInvoice.getId(), accountId, UUID.randomUUID(), UUID.randomUUID(), "test", "test-plan", "test-phase", null, today, today, BigDecimal.TEN, BigDecimal.TEN, Currency.USD);
inputInvoice.addInvoiceItem(invoiceItem);
invoiceUtil.createInvoice(inputInvoice, internalAccountContext);
final List<Tag> tags = ImmutableList.of(new DefaultControlTag(ControlTagType.WRITTEN_OFF, ObjectType.INVOICE, inputInvoice.getId(), clock.getUTCNow()));
final InvoiceModelDao invoice1 = getRawInvoice(inputInvoice.getId(), internalAccountContext);
populateChildrenByInvoiceId(invoice1, tags);
final InvoiceModelDao invoice2 = getRawInvoice(inputInvoice.getId(), internalAccountContext);
populateChildrenByAccountRecordId(invoice2, tags);
Assert.assertEquals(invoice1, invoice2);
Assert.assertEquals((new DefaultInvoice(invoice1)).getBalance().compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals((new DefaultInvoice(invoice2)).getBalance().compareTo(BigDecimal.ZERO), 0);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDaoHelper method testPopulateChildrenWithTrackingIds.
@Test(groups = "slow")
public void testPopulateChildrenWithTrackingIds() throws Exception {
final UUID accountId = account.getId();
final Invoice inputInvoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final InvoiceItem invoiceItem = new RecurringInvoiceItem(inputInvoice.getId(), accountId, UUID.randomUUID(), UUID.randomUUID(), "test", "test-plan", "test-phase", null, today, today, BigDecimal.TEN, BigDecimal.TEN, Currency.USD);
inputInvoice.addInvoiceItem(invoiceItem);
invoiceUtil.createInvoice(inputInvoice, internalAccountContext);
final InvoiceTrackingSqlDao trackingSqlDao = dbi.onDemand(InvoiceTrackingSqlDao.class);
trackingSqlDao.create(ImmutableList.of(new InvoiceTrackingModelDao("12345", inputInvoice.getId(), UUID.randomUUID(), "foo", today)), internalAccountContext);
final List<Tag> tags = ImmutableList.of();
final InvoiceModelDao invoice1 = getRawInvoice(inputInvoice.getId(), internalAccountContext);
populateChildrenByInvoiceId(invoice1, tags);
final InvoiceModelDao invoice2 = getRawInvoice(inputInvoice.getId(), internalAccountContext);
populateChildrenByAccountRecordId(invoice2, tags);
Assert.assertEquals(new DefaultInvoice(invoice1).getTrackingIds().size(), 1);
Assert.assertEquals(new DefaultInvoice(invoice2).getTrackingIds().size(), 1);
Assert.assertEquals(invoice1, invoice2);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceItemDao method testGetInvoiceItemsByAccountId.
@Test(groups = "slow")
public void testGetInvoiceItemsByAccountId() throws EntityPersistenceException {
final UUID accountId = account.getId();
final UUID bundleId = UUID.randomUUID();
final LocalDate targetDate = new LocalDate(2011, 5, 23);
final DefaultInvoice invoice = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate, Currency.USD);
invoiceUtil.createInvoice(invoice, context);
final UUID invoiceId = invoice.getId();
final LocalDate startDate = new LocalDate(2011, 3, 1);
final BigDecimal rate = new BigDecimal("20.00");
final UUID subscriptionId = UUID.randomUUID();
final RecurringInvoiceItem item = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test product", "test plan", "test phase", null, startDate, startDate.plusMonths(1), rate, rate, Currency.USD);
invoiceUtil.createInvoiceItem(item, context);
final List<InvoiceItemModelDao> items = invoiceUtil.getInvoiceItemByAccountId(context);
assertEquals(items.size(), 1);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceMigrationApi method createAndCheckMigrationInvoice.
private UUID createAndCheckMigrationInvoice(final UUID accountId) throws InvoiceApiException {
final InvoiceItem recurringItem = new RecurringInvoiceItem(null, accountId, null, null, "productName", "planName", "phaseName", null, new LocalDate(2016, 2, 1), new LocalDate(2016, 3, 1), MIGRATION_INVOICE_AMOUNT, MIGRATION_INVOICE_AMOUNT, MIGRATION_INVOICE_CURRENCY);
final UUID migrationInvoiceId = invoiceUserApi.createMigrationInvoice(accountId, date_migrated, ImmutableList.of(recurringItem), callContext);
Assert.assertNotNull(migrationInvoiceId);
// Double check it was created and values are correct
final InvoiceModelDao invoice = invoiceDao.getById(migrationInvoiceId, internalCallContext);
Assert.assertNotNull(invoice);
Assert.assertEquals(invoice.getAccountId(), accountId);
// temp to avoid tz test artifact
Assert.assertEquals(invoice.getTargetDate().compareTo(date_migrated), 0);
// Assert.assertEquals(invoice.getTargetDate(),now);
Assert.assertEquals(invoice.getInvoiceItems().size(), 1);
Assert.assertEquals(invoice.getInvoiceItems().get(0).getAmount().compareTo(MIGRATION_INVOICE_AMOUNT), 0);
Assert.assertEquals(invoice.getInvoiceItems().get(0).getType(), InvoiceItemType.RECURRING);
Assert.assertEquals(InvoiceModelDaoHelper.getRawBalanceForRegularInvoice(invoice).compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(invoice.getCurrency(), MIGRATION_INVOICE_CURRENCY);
Assert.assertTrue(invoice.isMigrated());
return migrationInvoiceId;
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestFixedAndRecurringInvoiceItemGenerator method testTooManyRecurringInvoiceItemsForGivenSubscriptionAndServicePeriodPostMerge.
// Simulate a bug in the generator where two recurring items for the same service period and subscription end up in the resulting items
@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/664")
public void testTooManyRecurringInvoiceItemsForGivenSubscriptionAndServicePeriodPostMerge() throws InvoiceApiException {
final Multimap<UUID, LocalDate> createdItemsPerDayPerSubscription = LinkedListMultimap.<UUID, LocalDate>create();
final LocalDate startDate = new LocalDate("2016-01-01");
final Collection<InvoiceItem> resultingItems = new LinkedList<InvoiceItem>();
final InvoiceItem recurringInvoiceItem = new RecurringInvoiceItem(UUID.randomUUID(), clock.getUTCNow(), null, account.getId(), subscription.getBundleId(), subscription.getId(), null, "planName", "phaseName", null, startDate, startDate.plusMonths(1), BigDecimal.ONE, BigDecimal.ONE, account.getCurrency());
resultingItems.add(recurringInvoiceItem);
resultingItems.add(recurringInvoiceItem);
try {
fixedAndRecurringInvoiceItemGenerator.safetyBounds(resultingItems, createdItemsPerDayPerSubscription, internalCallContext);
fail();
} catch (final InvoiceApiException e) {
assertEquals(e.getCode(), ErrorCode.UNEXPECTED_ERROR.getCode());
}
resultingItems.clear();
for (int i = 0; i < 2; i++) {
resultingItems.add(new RecurringInvoiceItem(UUID.randomUUID(), clock.getUTCNow(), null, account.getId(), subscription.getBundleId(), subscription.getId(), null, "planName", "phaseName", null, startDate, startDate.plusMonths(1), // Amount shouldn't have any effect
BigDecimal.TEN, BigDecimal.ONE, account.getCurrency()));
}
try {
fixedAndRecurringInvoiceItemGenerator.safetyBounds(resultingItems, createdItemsPerDayPerSubscription, internalCallContext);
fail();
} catch (final InvoiceApiException e) {
assertEquals(e.getCode(), ErrorCode.UNEXPECTED_ERROR.getCode());
}
}
Aggregations