use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testZeroDollarEvents.
@Test(groups = "fast")
public void testZeroDollarEvents() throws InvoiceApiException, CatalogApiException {
final Plan plan = new MockPlan();
final PlanPhase planPhase = createMockMonthlyPlanPhase(ZERO);
final BillingEventSet events = new MockBillingEventSet();
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 1);
events.add(createBillingEvent(UUID.randomUUID(), UUID.randomUUID(), targetDate, plan, planPhase, 1));
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(), null, targetDate, Currency.USD, null, internalCallContext);
final Invoice invoice = invoiceWithMetadata.getInvoice();
assertNotNull(invoice);
assertEquals(invoice.getInvoiceItems().size(), 1);
assertEquals(invoice.getInvoiceItems().get(0).getAmount().compareTo(BigDecimal.ZERO), 0);
}
use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testOnePlan_ThreeMonthlyPhases_ChangeEOT.
@Test(groups = "fast")
public void testOnePlan_ThreeMonthlyPhases_ChangeEOT() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
final Plan plan1 = new MockPlan();
final BigDecimal rate1 = FIVE;
final PlanPhase phase1 = createMockMonthlyPlanPhase(rate1);
final SubscriptionBase sub = createSubscription();
final BillingEvent event1 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 9, 1), plan1, phase1, 1);
events.add(event1);
final BigDecimal rate2 = TEN;
final PlanPhase phase2 = createMockMonthlyPlanPhase(rate2);
final BillingEvent event2 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 10, 1), plan1, phase2, 1);
events.add(event2);
final BigDecimal rate3 = THIRTY;
final PlanPhase phase3 = createMockMonthlyPlanPhase(rate3);
final BillingEvent event3 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 11, 1), plan1, phase3, 1);
events.add(event3);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 12, 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(), 4);
assertEquals(invoice.getBalance(), KillBillMoney.of(rate1.add(rate2).add(TWO.multiply(rate3)), invoice.getCurrency()));
}
use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testAutoInvoiceDraftAccount.
@Test(groups = "fast")
public void testAutoInvoiceDraftAccount() throws Exception {
final MockBillingEventSet events = new MockBillingEventSet();
events.setAccountAutoInvoiceDraft(true);
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 UUID accountId = UUID.randomUUID();
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(), null, targetDate, Currency.USD, null, internalCallContext);
assertNotNull(invoiceWithMetadata.getInvoice());
assertEquals(invoiceWithMetadata.getInvoice().getStatus(), InvoiceStatus.DRAFT);
assertEquals(invoiceWithMetadata.getInvoice().getInvoiceItems().size(), 2);
}
use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testNullInvoiceGeneration.
private void testNullInvoiceGeneration(final BillingEventSet events, final List<Invoice> existingInvoices, final LocalDate targetDate) throws InvoiceApiException {
final Currency currency = Currency.USD;
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(null, null, existingInvoices), null, targetDate, currency, null, internalCallContext);
final Invoice invoice = invoiceWithMetadata.getInvoice();
assertNull(invoice);
}
use of org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testFixedModePlanChange.
@Test(groups = "fast")
public void testFixedModePlanChange() throws InvoiceApiException, CatalogApiException {
// create a SubscriptionBase with a fixed price and recurring price
final Plan plan1 = new MockPlan();
final BigDecimal fixedCost1 = TEN;
final BigDecimal fixedCost2 = TWENTY;
final PlanPhase phase1 = createMockMonthlyPlanPhase(null, fixedCost1, PhaseType.TRIAL);
final PlanPhase phase2 = createMockMonthlyPlanPhase(null, fixedCost2, PhaseType.EVERGREEN);
final BillingEventSet events = new MockBillingEventSet();
final UUID subscriptionId = UUID.randomUUID();
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final LocalDate startDate = new LocalDate(2011, 1, 1);
final BillingEvent event1 = createBillingEvent(subscriptionId, bundleId, startDate, plan1, phase1, 1);
events.add(event1);
// ensure that a single invoice item is generated for the fixed cost
final InvoiceWithMetadata invoiceWithMetadata1 = generator.generateInvoice(account, events, new AccountInvoices(), null, startDate, Currency.USD, null, internalCallContext);
final Invoice invoice1 = invoiceWithMetadata1.getInvoice();
assertNotNull(invoice1);
assertEquals(invoice1.getNumberOfItems(), 1);
assertEquals(invoice1.getBalance(), KillBillMoney.of(fixedCost1, invoice1.getCurrency()));
final List<Invoice> invoiceList = new ArrayList<Invoice>();
invoiceList.add(invoice1);
// move forward in time one billing period
final LocalDate phaseChangeDate = startDate.plusMonths(1);
final BillingEvent event2 = createBillingEvent(subscriptionId, bundleId, phaseChangeDate, plan1, phase2, 1);
events.add(event2);
// ensure that a single invoice item is generated for the fixed cost
final InvoiceWithMetadata invoiceWithMetadata2 = generator.generateInvoice(account, events, new AccountInvoices(null, null, invoiceList), null, phaseChangeDate, Currency.USD, null, internalCallContext);
final Invoice invoice2 = invoiceWithMetadata2.getInvoice();
assertEquals(invoice2.getNumberOfItems(), 1);
assertEquals(invoice2.getBalance(), KillBillMoney.of(fixedCost2, invoice2.getCurrency()));
}
Aggregations