use of org.killbill.billing.catalog.MockPlan in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testAutoInvoiceOffAccount.
@Test(groups = "fast")
public void testAutoInvoiceOffAccount() throws Exception {
final MockBillingEventSet events = new MockBillingEventSet();
events.setAccountInvoiceOff(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, null, targetDate, Currency.USD, internalCallContext);
assertNull(invoiceWithMetadata.getInvoice());
}
use of org.killbill.billing.catalog.MockPlan in project killbill by killbill.
the class TestDefaultBillingEvent method createEvent.
private BillingEvent createEvent(final SubscriptionBase sub, final DateTime effectiveDate, final SubscriptionBaseTransitionType type, final long totalOrdering) {
final int billCycleDay = 1;
final Plan shotgun = new MockPlan();
final PlanPhase shotgunMonthly = createMockMonthlyPlanPhase(null, BigDecimal.ZERO, PhaseType.TRIAL);
final Account account = new MockAccountBuilder().build();
return new DefaultBillingEvent(sub, effectiveDate, true, shotgun, shotgunMonthly, BigDecimal.ZERO, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, billCycleDay, "Test Event 1", totalOrdering, type, DateTimeZone.UTC, null, false);
}
use of org.killbill.billing.catalog.MockPlan in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testSimpleWithTimeZone.
@Test(groups = "fast")
public void testSimpleWithTimeZone() throws InvoiceApiException, CatalogApiException {
final SubscriptionBase sub = createSubscription();
final Plan plan = new MockPlan();
final BigDecimal rate = TEN;
final PlanPhase phase = createMockMonthlyPlanPhase(rate);
// Start date was the 16 local, but was the 17 UTC
final int bcdLocal = 16;
final LocalDate startDate = invoiceUtil.buildDate(2012, 7, bcdLocal);
final BillingEventSet events = new MockBillingEventSet();
final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, bcdLocal);
events.add(event);
// Target date is the next BCD, in local time
final LocalDate targetDate = invoiceUtil.buildDate(2012, 8, bcdLocal);
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.getInvoiceItems().get(0).getStartDate(), invoiceUtil.buildDate(2012, 7, 16));
assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), invoiceUtil.buildDate(2012, 8, 16));
assertEquals(invoice.getInvoiceItems().get(1).getStartDate(), invoiceUtil.buildDate(2012, 8, 16));
assertEquals(invoice.getInvoiceItems().get(1).getEndDate(), invoiceUtil.buildDate(2012, 9, 16));
}
use of org.killbill.billing.catalog.MockPlan in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testFixedPriceLifeCycle.
@Test(groups = "fast")
public void testFixedPriceLifeCycle() throws InvoiceApiException {
final SubscriptionBase subscription = createSubscription();
final Plan plan = new MockPlan("plan 1");
final MockInternationalPrice zeroPrice = new MockInternationalPrice(new DefaultPrice(ZERO, Currency.USD));
final MockInternationalPrice cheapPrice = new MockInternationalPrice(new DefaultPrice(ONE, Currency.USD));
final PlanPhase phase1 = new MockPlanPhase(null, zeroPrice, BillingPeriod.NO_BILLING_PERIOD, PhaseType.TRIAL);
final PlanPhase phase2 = new MockPlanPhase(cheapPrice, null, BillingPeriod.MONTHLY, PhaseType.DISCOUNT);
final DateTime changeDate = new DateTime("2012-04-1");
final BillingEventSet events = new MockBillingEventSet();
final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, subscription, new DateTime("2012-01-1"), plan, phase1, ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Test Event 1", 1L, SubscriptionBaseTransitionType.CREATE);
final BillingEvent event2 = invoiceUtil.createMockBillingEvent(null, subscription, changeDate, plan, phase2, ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Test Event 2", 2L, SubscriptionBaseTransitionType.PHASE);
events.add(event2);
events.add(event1);
final InvoiceWithMetadata invoiceWithMetadata1 = generator.generateInvoice(account, events, new AccountInvoices(), null, new LocalDate("2012-02-01"), Currency.USD, null, internalCallContext);
final Invoice invoice1 = invoiceWithMetadata1.getInvoice();
assertNotNull(invoice1);
assertEquals(invoice1.getNumberOfItems(), 1);
final List<Invoice> invoiceList = new ArrayList<Invoice>();
invoiceList.add(invoice1);
final InvoiceWithMetadata invoiceWithMetadata2 = generator.generateInvoice(account, events, new AccountInvoices(null, null, invoiceList), null, new LocalDate("2012-04-05"), Currency.USD, null, internalCallContext);
final Invoice invoice2 = invoiceWithMetadata2.getInvoice();
assertNotNull(invoice2);
assertEquals(invoice2.getNumberOfItems(), 1);
final FixedPriceInvoiceItem item = (FixedPriceInvoiceItem) invoice2.getInvoiceItems().get(0);
assertEquals(item.getStartDate(), changeDate.toLocalDate());
}
use of org.killbill.billing.catalog.MockPlan in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testMixedModeLifeCycle.
@Test(groups = "fast")
public void testMixedModeLifeCycle() throws InvoiceApiException, CatalogApiException {
// create a SubscriptionBase with a fixed price and recurring price
final Plan plan1 = new MockPlan();
final BigDecimal monthlyRate = FIVE;
final BigDecimal fixedCost = TEN;
final PlanPhase phase1 = createMockMonthlyPlanPhase(monthlyRate, fixedCost, PhaseType.TRIAL);
final BillingEventSet events = new MockBillingEventSet();
final UUID subscriptionId = 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 both components are invoiced
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(), 2);
assertEquals(invoice1.getBalance(), KillBillMoney.of(FIFTEEN, invoice1.getCurrency()));
final List<Invoice> invoiceList = new ArrayList<Invoice>();
invoiceList.add(invoice1);
// move forward in time one billing period
final LocalDate currentDate = startDate.plusMonths(1);
// ensure that only the recurring price is invoiced
final InvoiceWithMetadata invoiceWithMetadata2 = generator.generateInvoice(account, events, new AccountInvoices(null, null, invoiceList), null, currentDate, Currency.USD, null, internalCallContext);
final Invoice invoice2 = invoiceWithMetadata2.getInvoice();
assertNotNull(invoice2);
assertEquals(invoice2.getNumberOfItems(), 1);
assertEquals(invoice2.getBalance(), KillBillMoney.of(FIVE, invoice2.getCurrency()));
}
Aggregations