Search in sources :

Example 76 with RecurringInvoiceItem

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);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ParentInvoiceItem(org.killbill.billing.invoice.model.ParentInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) Tag(org.killbill.billing.util.tag.Tag) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) Test(org.testng.annotations.Test)

Example 77 with RecurringInvoiceItem

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);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ParentInvoiceItem(org.killbill.billing.invoice.model.ParentInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) Test(org.testng.annotations.Test)

Example 78 with RecurringInvoiceItem

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);
}
Also used : RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 79 with RecurringInvoiceItem

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;
}
Also used : RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate)

Example 80 with RecurringInvoiceItem

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());
    }
}
Also used : InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Aggregations

RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)98 Test (org.testng.annotations.Test)90 LocalDate (org.joda.time.LocalDate)89 BigDecimal (java.math.BigDecimal)82 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)73 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)69 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)69 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)65 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)39 Invoice (org.killbill.billing.invoice.api.Invoice)38 UUID (java.util.UUID)34 MockPlan (org.killbill.billing.catalog.MockPlan)16 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)16 Plan (org.killbill.billing.catalog.api.Plan)16 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)16 AccountInvoices (org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices)16 BillingEventSet (org.killbill.billing.junction.BillingEventSet)16 HashMap (java.util.HashMap)15 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)15 BillingEvent (org.killbill.billing.junction.BillingEvent)15