use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testOnePlan_TwoMonthlyPhases_ChangeImmediate.
@Test(groups = "fast")
public void testOnePlan_TwoMonthlyPhases_ChangeImmediate() 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, 15), plan1, phase2, 15);
events.add(event2);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 12, 3);
final UUID accountId = UUID.randomUUID();
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);
final BigDecimal numberOfCyclesEvent1;
numberOfCyclesEvent1 = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
final BigDecimal numberOfCyclesEvent2 = TWO;
BigDecimal expectedValue;
expectedValue = numberOfCyclesEvent1.multiply(rate1);
expectedValue = expectedValue.add(numberOfCyclesEvent2.multiply(rate2));
expectedValue = KillBillMoney.of(expectedValue, invoice.getCurrency());
assertEquals(invoice.getBalance(), expectedValue);
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class TestDefaultSubscriptionBundleTimeline method createEntitlement.
private Entitlement createEntitlement(final UUID entitlementId, final List<SubscriptionBaseTransition> allTransitions, final Collection<BlockingState> blockingStates) {
final DefaultEntitlement result = Mockito.mock(DefaultEntitlement.class);
Mockito.when(result.getId()).thenReturn(entitlementId);
final EventsStream eventsStream = Mockito.mock(EventsStream.class);
Mockito.when(eventsStream.getBlockingStates()).thenReturn(blockingStates);
Mockito.when(result.getEventsStream()).thenReturn(eventsStream);
final SubscriptionBase base = Mockito.mock(SubscriptionBase.class);
Mockito.when(base.getAllTransitions()).thenReturn(allTransitions);
Mockito.when(result.getSubscriptionBase()).thenReturn(base);
Mockito.when(result.getSubscriptionBase().getStartDate()).thenReturn(new DateTime(DateTimeZone.UTC));
return result;
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class EventsStreamBuilder method buildForBundle.
public List<EventsStream> buildForBundle(final UUID bundleId, final InternalTenantContext internalTenantContext) throws EntitlementApiException {
final SubscriptionBaseBundle bundle;
final List<SubscriptionBase> subscriptionsForBundle;
try {
bundle = subscriptionInternalApi.getBundleFromId(bundleId, internalTenantContext);
subscriptionsForBundle = subscriptionInternalApi.getSubscriptionsForBundle(bundleId, null, internalTenantContext);
} catch (final SubscriptionBaseApiException e) {
throw new EntitlementApiException(e);
}
final List<EventsStream> eventsStreams = new LinkedList<EventsStream>();
for (final SubscriptionBase subscription : subscriptionsForBundle) {
eventsStreams.add(buildForEntitlement(bundle, subscription, subscriptionsForBundle, internalTenantContext));
}
return eventsStreams;
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class EventsStreamBuilder method buildForBaseSubscription.
public EventsStream buildForBaseSubscription(final UUID bundleId, final TenantContext tenantContext) throws EntitlementApiException {
final SubscriptionBase baseSubscription;
try {
final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(bundleId, ObjectType.BUNDLE, tenantContext);
baseSubscription = subscriptionInternalApi.getBaseSubscription(bundleId, internalTenantContext);
} catch (final SubscriptionBaseApiException e) {
throw new EntitlementApiException(e);
}
return buildForEntitlement(baseSubscription.getId(), tenantContext);
}
use of org.killbill.billing.subscription.api.SubscriptionBase in project killbill by killbill.
the class EventsStreamBuilder method buildForEntitlement.
private EventsStream buildForEntitlement(final SubscriptionBase subscription, final InternalTenantContext internalTenantContext) throws EntitlementApiException {
final SubscriptionBaseBundle bundle;
final List<SubscriptionBase> subscriptionsForBundle;
try {
bundle = subscriptionInternalApi.getBundleFromId(subscription.getBundleId(), internalTenantContext);
subscriptionsForBundle = subscriptionInternalApi.getSubscriptionsForBundle(subscription.getBundleId(), null, internalTenantContext);
} catch (final SubscriptionBaseApiException e) {
throw new EntitlementApiException(e);
}
return buildForEntitlement(bundle, subscription, subscriptionsForBundle, internalTenantContext);
}
Aggregations