@Override public List<SubscriptionBundle> call() throws Exception { return subscriptionApi.getSubscriptionBundlesForAccountId(accountId, tenantContext); } };
subscriptionApi.getSubscriptionBundlesForAccountId(accountId, tenantContext);
protected List<SubscriptionBundle> getSubscriptionBundlesForAccount(final UUID accountId, final TenantContext context) throws OSGIServiceNotAvailable { final SubscriptionApi subscriptionApi = getSubscriptionApi(); try { return subscriptionApi.getSubscriptionBundlesForAccountId(accountId, context); } catch (final SubscriptionApiException e) { logService.log(LogService.LOG_WARNING, "Error retrieving bundles for account id " + accountId, e); throw new OSGIServiceNotAvailable(e); } }
final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForAccountId(accountId, callContext); final Iterable<Subscription> subscriptions = Iterables.concat(Iterables.transform(bundles, new Function<SubscriptionBundle, List<Subscription>>() { @Override
@Test(groups = "slow", description = "Verify behavior with or without ENT_STARTED event works as expected") public void testRegressionForNew_ENT_STARTED_event() throws Exception { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); // Start the entitlement yesterday (does not m,ake sense, but we want to check later different of behavior) final LocalDate entitlementEffectiveDate = initialDate.minusDays(1); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); final EntitlementSpecifier spec = new DefaultEntitlementSpecifier(planPhaseSpecifier); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), spec, UUID.randomUUID().toString(), entitlementEffectiveDate, null, false, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); // Because of the BlockingState event ENT_STARTED, the entitlement date should be correctly set Assert.assertEquals(entitlement.getEffectiveStartDate(), entitlementEffectiveDate); final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForAccountId(account.getId(), callContext); Assert.assertEquals(bundles.size(), 1); subscriptionBundleChecker(bundles, initialDate, entitlement, 0); // Let's do some surgery and inactivate the ENT_STARTED BlockingState final List<BlockingState> blockingStates = blockingStateDao.getBlockingState(entitlement.getId(), BlockingStateType.SUBSCRIPTION, clock.getUTCNow(), internalCallContext); assertEquals(blockingStates.size(), 1); assertEquals(blockingStates.get(0).getStateName(), DefaultEntitlementApi.ENT_STATE_START); blockingStateDao.unactiveBlockingState(blockingStates.get(0).getId(), internalCallContext); final Entitlement oldSchoolEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); // Because the ENT_STARTED BlockingState has been invalidated, the startDate should now default to the billingDate Assert.assertEquals(oldSchoolEntitlement.getEffectiveStartDate(), initialDate); final List<SubscriptionBundle> oldSchoolBundles = subscriptionApi.getSubscriptionBundlesForAccountId(account.getId(), callContext); Assert.assertEquals(oldSchoolBundles.size(), 1); subscriptionBundleChecker(oldSchoolBundles, initialDate, oldSchoolEntitlement, 0); }
@Test(groups = "slow", description = "Verify blocking states are exposed in SubscriptionBundle") public void testBlockingStatesInTimelineApi() throws Exception { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID entitlement1Id = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), UUID.randomUUID().toString(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement entitlement1 = entitlementApi.getEntitlementForId(entitlement1Id, callContext); // Move the clock 1.5 sec so the (truncated) created date are apart from each other and ordering in the bundle does not default on the UUID which is random. clock.addDeltaFromReality(1500); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID entitlement2Id = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), UUID.randomUUID().toString(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement2Id, callContext); testListener.pushExpectedEvents(NextEvent.BLOCK); entitlementUtils.setBlockingStateAndPostBlockingTransitionEvent(new DefaultBlockingState(account.getId(), BlockingStateType.ACCOUNT, "stateName", "service", false, false, false, clock.getUTCNow()), internalCallContextFactory.createInternalCallContext(account.getId(), callContext)); assertListenerStatus(); final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForAccountId(account.getId(), callContext); Assert.assertEquals(bundles.size(), 2); // This will test the ordering as well subscriptionBundleChecker(bundles, initialDate, entitlement1, 0); subscriptionBundleChecker(bundles, initialDate, entitlement2, 1); }