use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class EventsStreamBuilder method buildForEntitlement.
public EventsStream buildForEntitlement(final UUID entitlementId, final InternalTenantContext internalTenantContext) throws EntitlementApiException {
final SubscriptionBaseBundle bundle;
final SubscriptionBase subscription;
final List<SubscriptionBase> allSubscriptionsForBundle;
final SubscriptionBase baseSubscription;
try {
subscription = subscriptionInternalApi.getSubscriptionFromId(entitlementId, internalTenantContext);
bundle = subscriptionInternalApi.getBundleFromId(subscription.getBundleId(), internalTenantContext);
allSubscriptionsForBundle = subscriptionInternalApi.getSubscriptionsForBundle(subscription.getBundleId(), null, internalTenantContext);
baseSubscription = findBaseSubscription(allSubscriptionsForBundle);
} catch (SubscriptionBaseApiException e) {
throw new EntitlementApiException(e);
}
final ImmutableAccountData account;
try {
account = accountInternalApi.getImmutableAccountDataById(bundle.getAccountId(), internalTenantContext);
} catch (AccountApiException e) {
throw new EntitlementApiException(e);
}
// Retrieve the blocking states
final List<BlockingState> blockingStatesForAccount = defaultBlockingStateDao.getBlockingAllForAccountRecordId(internalTenantContext);
final Map<UUID, Integer> bcdCache = new HashMap<UUID, Integer>();
return buildForEntitlement(blockingStatesForAccount, account, bundle, baseSubscription, subscription, allSubscriptionsForBundle, bcdCache, internalTenantContext);
}
use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class MockAccountModule method installInternalApi.
@Override
public void installInternalApi() {
final ImmutableAccountData immutableAccountData = Mockito.mock(ImmutableAccountData.class);
Mockito.when(immutableAccountData.getTimeZone()).thenReturn(DateTimeZone.UTC);
Mockito.when(immutableAccountData.getFixedOffsetTimeZone()).thenReturn(DateTimeZone.UTC);
final AccountInternalApi accountInternalApi = Mockito.mock(AccountInternalApi.class);
final ImmutableAccountInternalApi immutableAccountInternalApi = Mockito.mock(ImmutableAccountInternalApi.class);
bind(AccountInternalApi.class).toInstance(accountInternalApi);
bind(ImmutableAccountInternalApi.class).toInstance(immutableAccountInternalApi);
}
use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class TestBillCycleDayCalculator method verifyBCDCalculation.
private void verifyBCDCalculation(final DateTimeZone accountTimeZone, final DateTime startDateUTC, final int bcdLocal) throws AccountApiException, CatalogApiException {
final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class);
Mockito.when(subscription.getStartDate()).thenReturn(startDateUTC);
Mockito.when(subscription.getDateOfFirstRecurringNonZeroCharge()).thenReturn(startDateUTC);
final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class);
Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone);
final Integer bcd = BillCycleDayCalculator.calculateBcdForAlignment(new HashMap<UUID, Integer>(), subscription, subscription, BillingAlignment.SUBSCRIPTION, account.getTimeZone(), 0);
Assert.assertEquals(bcd, (Integer) bcdLocal);
}
use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class TestBillCycleDayCalculator method testCalculateBCDForAOWithBPCancelledBundleAligned.
@Test(groups = "fast")
public void testCalculateBCDForAOWithBPCancelledBundleAligned() throws Exception {
final DateTimeZone accountTimeZone = DateTimeZone.UTC;
final DateTime bpStartDateUTC = new DateTime(2012, 7, 16, 21, 0, 0, DateTimeZone.UTC);
final int expectedBCDUTC = 16;
// Create a Bundle associated with a subscription
final SubscriptionBaseBundle bundle = Mockito.mock(SubscriptionBaseBundle.class);
final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class);
Mockito.when(subscription.getStartDate()).thenReturn(bpStartDateUTC);
// Create a the base plan associated with that subscription
final Plan plan = Mockito.mock(Plan.class);
final Catalog catalog = Mockito.mock(Catalog.class);
Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), Mockito.<DateTime>any())).thenReturn(plan);
Mockito.when(subscription.getLastActivePlan()).thenReturn(plan);
Mockito.when(subscription.getDateOfFirstRecurringNonZeroCharge()).thenReturn(bpStartDateUTC);
final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class);
Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone);
final Integer billCycleDayLocal = BillCycleDayCalculator.calculateBcdForAlignment(new HashMap<UUID, Integer>(), subscription, subscription, BillingAlignment.BUNDLE, account.getTimeZone(), 0);
Assert.assertEquals(billCycleDayLocal, (Integer) expectedBCDUTC);
}
Aggregations