use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testWithEmptyEventSet.
@Test(groups = "fast")
public void testWithEmptyEventSet() throws InvoiceApiException {
final BillingEventSet events = new MockBillingEventSet();
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(), null, clock.getUTCToday(), Currency.USD, null, internalCallContext);
assertNull(invoiceWithMetadata.getInvoice());
}
use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testRegressionFor170.
// Regression test for #170 (see https://github.com/killbill/killbill/pull/173)
@Test(groups = "fast")
public void testRegressionFor170() throws EntityPersistenceException, InvoiceApiException, CatalogApiException {
final UUID accountId = account.getId();
final Currency currency = Currency.USD;
final SubscriptionBase subscription = createSubscription();
final MockInternationalPrice recurringPrice = new MockInternationalPrice(new DefaultPrice(new BigDecimal("2.9500"), Currency.USD));
final MockPlanPhase phase = new MockPlanPhase(recurringPrice, null);
final Plan plan = new MockPlan(phase);
final LocalDate targetDate = new LocalDate(2013, 10, 30);
final Invoice existingInvoice = new DefaultInvoice(UUID.randomUUID(), accountId, null, clock.getUTCToday(), targetDate, currency, false, InvoiceStatus.COMMITTED);
// Set the existing recurring invoice item 2013/06/15 - 2013/07/15
final LocalDate startDate = new LocalDate(2013, 06, 15);
final LocalDate endDate = new LocalDate(2013, 07, 15);
final InvoiceItem recurringInvoiceItem = new RecurringInvoiceItem(existingInvoice.getId(), accountId, subscription.getBundleId(), subscription.getId(), null, plan.getName(), phase.getName(), null, startDate, endDate, recurringPrice.getPrice(currency), recurringPrice.getPrice(currency), Currency.USD);
existingInvoice.addInvoiceItem(recurringInvoiceItem);
// Set an existing repair item
final LocalDate repairStartDate = new LocalDate(2013, 06, 21);
final LocalDate repairEndDate = new LocalDate(2013, 06, 26);
final BigDecimal repairAmount = new BigDecimal("0.4900").negate();
final InvoiceItem repairItem = new RepairAdjInvoiceItem(existingInvoice.getId(), accountId, repairStartDate, repairEndDate, repairAmount, currency, recurringInvoiceItem.getId());
existingInvoice.addInvoiceItem(repairItem);
// Create the billing event associated with the subscription creation
//
// Note : this is the interesting part of the test; it does not provide the blocking billing events, which force invoice
// to un repair what was previously repaired.
final BillingEventSet events = new MockBillingEventSet();
final BillingEvent event = invoiceUtil.createMockBillingEvent(null, subscription, new DateTime("2013-06-15", DateTimeZone.UTC), plan, phase, null, recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 15, BillingMode.IN_ADVANCE, "testEvent", 1L, SubscriptionBaseTransitionType.CREATE);
events.add(event);
final List<Invoice> existingInvoices = new LinkedList<Invoice>();
existingInvoices.add(existingInvoice);
// Generate a new invoice
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(null, null, existingInvoices), null, targetDate, currency, null, internalCallContext);
final Invoice invoice = invoiceWithMetadata.getInvoice();
assertEquals(invoice.getNumberOfItems(), 5);
assertEquals(invoice.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), new LocalDate(2013, 6, 21));
assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), new LocalDate(2013, 6, 26));
assertTrue(repairAmount.negate().compareTo(invoice.getInvoiceItems().get(0).getAmount()) == 0);
assertEquals(invoice.getInvoiceItems().get(1).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(invoice.getInvoiceItems().get(1).getStartDate(), new LocalDate(2013, 7, 15));
assertEquals(invoice.getInvoiceItems().get(1).getEndDate(), new LocalDate(2013, 8, 15));
assertEquals(invoice.getInvoiceItems().get(2).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(invoice.getInvoiceItems().get(2).getStartDate(), new LocalDate(2013, 8, 15));
assertEquals(invoice.getInvoiceItems().get(2).getEndDate(), new LocalDate(2013, 9, 15));
assertEquals(invoice.getInvoiceItems().get(3).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(invoice.getInvoiceItems().get(3).getStartDate(), new LocalDate(2013, 9, 15));
assertEquals(invoice.getInvoiceItems().get(3).getEndDate(), new LocalDate(2013, 10, 15));
assertEquals(invoice.getInvoiceItems().get(4).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(invoice.getInvoiceItems().get(4).getStartDate(), new LocalDate(2013, 10, 15));
assertEquals(invoice.getInvoiceItems().get(4).getEndDate(), new LocalDate(2013, 11, 15));
// Add newly generated invoice to existing invoices
existingInvoices.add(invoice);
// Generate next invoice (no-op)
final InvoiceWithMetadata newInvoiceWithMetdata = generator.generateInvoice(account, events, new AccountInvoices(null, null, existingInvoices), null, targetDate, currency, null, internalCallContext);
final Invoice newInvoice = newInvoiceWithMetdata.getInvoice();
assertNull(newInvoice);
}
use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testCancelEOTWithFullItemAdjustment.
@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/654")
public void testCancelEOTWithFullItemAdjustment() throws CatalogApiException, InvoiceApiException {
final BigDecimal rate = new BigDecimal("39.95");
final BillingEventSet events = new MockBillingEventSet();
final SubscriptionBase sub = createSubscription();
final LocalDate startDate = invoiceUtil.buildDate(2016, 10, 9);
final LocalDate endDate = invoiceUtil.buildDate(2016, 11, 9);
final Plan plan = new MockPlan();
final PlanPhase phase = createMockMonthlyPlanPhase(rate);
final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 9);
events.add(event);
final LocalDate targetDate = invoiceUtil.buildDate(2016, 10, 9);
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(), null, targetDate, Currency.USD, null, internalCallContext);
final Invoice invoice = invoiceWithMetadata.getInvoice();
assertNotNull(invoice);
assertEquals(invoice.getNumberOfItems(), 1);
assertEquals(invoice.getBalance(), KillBillMoney.of(rate, invoice.getCurrency()));
assertEquals(invoice.getInvoiceItems().get(0).getSubscriptionId(), sub.getId());
assertEquals(invoice.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), startDate);
assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), endDate);
// Cancel EOT and Add the item adjustment
final BillingEvent event2 = invoiceUtil.createMockBillingEvent(account, sub, endDate.toDateTimeAtStartOfDay(), plan, phase, ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 9, BillingMode.IN_ADVANCE, "Cancel", 2L, SubscriptionBaseTransitionType.CANCEL);
events.add(event2);
final InvoiceItem itemAdj = new ItemAdjInvoiceItem(invoice.getInvoiceItems().get(0), new LocalDate(2016, 10, 12), rate.negate(), Currency.USD);
invoice.addInvoiceItem(itemAdj);
final List<Invoice> existingInvoices = new ArrayList<Invoice>();
existingInvoices.add(invoice);
final InvoiceWithMetadata invoiceWithMetadata2 = generator.generateInvoice(account, events, new AccountInvoices(null, null, existingInvoices), null, targetDate, Currency.USD, null, internalCallContext);
final Invoice invoice2 = invoiceWithMetadata2.getInvoice();
assertNull(invoice2);
}
use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testWithSingleMonthlyEvent.
@Test(groups = "fast")
public void testWithSingleMonthlyEvent() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
final SubscriptionBase sub = createSubscription();
final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1);
final Plan plan = new MockPlan();
final BigDecimal rate1 = TEN;
final PlanPhase phase = createMockMonthlyPlanPhase(rate1);
final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 1);
events.add(event);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 10, 3);
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(), null, targetDate, Currency.USD, null, internalCallContext);
final Invoice invoice = invoiceWithMetadata.getInvoice();
assertNotNull(invoice);
assertEquals(invoice.getNumberOfItems(), 2);
assertEquals(invoice.getBalance(), KillBillMoney.of(TWENTY, invoice.getCurrency()));
assertEquals(invoice.getInvoiceItems().get(0).getSubscriptionId(), sub.getId());
assertEquals(invoice.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), new LocalDate(2011, 9, 1));
assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), new LocalDate(2011, 10, 1));
assertEquals(invoice.getInvoiceItems().get(1).getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(invoice.getInvoiceItems().get(1).getStartDate(), new LocalDate(2011, 10, 1));
assertEquals(invoice.getInvoiceItems().get(1).getEndDate(), new LocalDate(2011, 11, 1));
}
use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testWithNullEventSetAndNullInvoiceSet.
@Test(groups = "fast")
public void testWithNullEventSetAndNullInvoiceSet() throws InvoiceApiException {
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, null, new AccountInvoices(), null, clock.getUTCToday(), Currency.USD, null, internalCallContext);
assertNull(invoiceWithMetadata.getInvoice());
}
Aggregations