use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class SubscriptionChecker method checkSubscriptionCreated.
public SubscriptionBase checkSubscriptionCreated(final UUID subscriptionId, final InternalCallContext context) throws SubscriptionBaseApiException {
final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT, objectIdCacheController);
final CallContext callContext = context.toCallContext(null, tenantId);
final SubscriptionBase subscription = subscriptionApi.getSubscriptionFromId(subscriptionId, context);
Assert.assertNotNull(subscription);
auditChecker.checkSubscriptionCreated(subscription.getBundleId(), subscriptionId, callContext);
List<SubscriptionBaseTransition> subscriptionEvents = getSubscriptionEvents(subscription);
Assert.assertTrue(subscriptionEvents.size() >= 1);
auditChecker.checkSubscriptionEventCreated(subscription.getBundleId(), ((SubscriptionBaseTransitionData) subscriptionEvents.get(0)).getId(), callContext);
auditChecker.checkBundleCreated(subscription.getBundleId(), callContext);
return subscription;
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testSingleEventWithExistingInvoice.
@Test(groups = "fast")
public void testSingleEventWithExistingInvoice() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
final SubscriptionBase sub = createSubscription();
final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1);
final Plan plan1 = new MockPlan();
final BigDecimal rate = FIVE;
final PlanPhase phase1 = createMockMonthlyPlanPhase(rate);
final BillingEvent event1 = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan1, phase1, 1);
events.add(event1);
LocalDate targetDate = invoiceUtil.buildDate(2011, 12, 1);
final InvoiceWithMetadata invoiceWithMetadata1 = generator.generateInvoice(account, events, new AccountInvoices(), null, targetDate, Currency.USD, null, internalCallContext);
final List<Invoice> existingInvoices = new ArrayList<Invoice>();
final Invoice invoice1 = invoiceWithMetadata1.getInvoice();
existingInvoices.add(invoice1);
targetDate = invoiceUtil.buildDate(2011, 12, 3);
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.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestDefaultInvoiceGenerator method createSubscription.
private SubscriptionBase createSubscription(final UUID subscriptionId, final UUID bundleId) {
final SubscriptionBase sub = Mockito.mock(SubscriptionBase.class);
Mockito.when(sub.getId()).thenReturn(subscriptionId);
Mockito.when(sub.getBundleId()).thenReturn(bundleId);
return sub;
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testWithSingleMonthlyEventWithLeadingProRation.
@Test(groups = "fast")
public void testWithSingleMonthlyEventWithLeadingProRation() 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 rate = TEN;
final PlanPhase phase = createMockMonthlyPlanPhase(rate);
final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 15);
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);
final BigDecimal expectedNumberOfBillingCycles;
expectedNumberOfBillingCycles = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
final BigDecimal expectedAmount = KillBillMoney.of(expectedNumberOfBillingCycles.multiply(rate), invoice.getCurrency());
assertEquals(invoice.getBalance(), expectedAmount);
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestDefaultInvoiceGenerator method createBillingEvent.
private BillingEvent createBillingEvent(final UUID subscriptionId, final UUID bundleId, final LocalDate startDate, final Plan plan, final PlanPhase planPhase, final int billCycleDayLocal) throws CatalogApiException {
final SubscriptionBase sub = createSubscription(subscriptionId, bundleId);
final Currency currency = Currency.USD;
return invoiceUtil.createMockBillingEvent(null, sub, startDate.toDateTimeAtStartOfDay(), plan, planPhase, planPhase.getFixed().getPrice() == null ? null : planPhase.getFixed().getPrice().getPrice(currency), planPhase.getRecurring().getRecurringPrice() == null ? null : planPhase.getRecurring().getRecurringPrice().getPrice(currency), currency, planPhase.getRecurring().getBillingPeriod(), billCycleDayLocal, BillingMode.IN_ADVANCE, "Test", totalOrdering++, SubscriptionBaseTransitionType.CREATE);
}
Aggregations