@Override public SubscriptionBase getBaseSubscription(final UUID bundleId, final InternalTenantContext context) { for (final SubscriptionBase cur : subscriptions) { if (cur.getBundleId().equals(bundleId) && cur.getCurrentPlan().getProduct().getCategory() == ProductCategory.BASE) { return buildSubscription((DefaultSubscriptionBase) cur, context); } } return null; }
@Test(groups = "fast") public void testChangeSubscriptionWithPolicy() throws Exception { final SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME); try { subscription.changePlanWithPolicy("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, BillingActionPolicy.ILLEGAL, callContext); Assert.fail(); } catch (SubscriptionBaseError error) { assertTrue(true); assertEquals(subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext).getCurrentPlan().getBillingPeriod(), BillingPeriod.ANNUAL); } // Assume the call takes less than a second assertEquals(DefaultClock.truncateMs(subscription.changePlanWithPolicy("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, BillingActionPolicy.IMMEDIATE, callContext)), DefaultClock.truncateMs(clock.getUTCNow())); assertEquals(subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext).getCurrentPlan().getBillingPeriod(), BillingPeriod.MONTHLY); }
@VisibleForTesting int calculateBcdForAlignment(final BillingAlignment alignment, final SubscriptionBaseBundle bundle, final SubscriptionBase subscription, final Account account, final Catalog catalog, final Plan plan, final InternalCallContext context) throws AccountApiException, SubscriptionBaseApiException, CatalogApiException { int result = 0; switch (alignment) { case ACCOUNT: result = account.getBillCycleDayLocal(); if (result == 0) { result = calculateBcdFromSubscription(subscription, plan, account, catalog, context); } break; case BUNDLE: final SubscriptionBase baseSub = subscriptionApi.getBaseSubscription(bundle.getId(), context); Plan basePlan = baseSub.getCurrentPlan(); if (basePlan == null) { // The BP has been cancelled basePlan = baseSub.getLastActivePlan(); } result = calculateBcdFromSubscription(baseSub, basePlan, account, catalog, context); break; case SUBSCRIPTION: result = calculateBcdFromSubscription(subscription, plan, account, catalog, context); break; } if (result == 0) { throw new CatalogApiException(ErrorCode.CAT_INVALID_BILLING_ALIGNMENT, alignment.toString()); } return result; }
assertEquals(subscriptions.size(), 2); final SubscriptionBase baseSubscription = (subscriptions.get(0).getCurrentPlan().getProduct().getCategory() == ProductCategory.BASE) ? subscriptions.get(0) : subscriptions.get(1); assertTrue(baseSubscription.getStartDate().compareTo(initalBPStart) == 0); assertEquals(baseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(baseSubscription.getState(), EntitlementState.ACTIVE); assertEquals(baseSubscription.getCurrentPlan().getName(), "shotgun-annual"); assertEquals(baseSubscription.getChargedThroughDate(), initalBPStart.plusYears(1)); final SubscriptionBase aoSubscription = (subscriptions.get(0).getCurrentPlan().getProduct().getCategory() == ProductCategory.ADD_ON) ? subscriptions.get(0) : subscriptions.get(1); assertEquals(aoSubscription.getCurrentPhase().getPhaseType(), PhaseType.DISCOUNT); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); assertEquals(aoSubscription.getCurrentPlan().getName(), "telescopic-scope-monthly"); assertEquals(aoSubscription.getChargedThroughDate(), initalAddonStart.plusMonths(1));
@Test(groups = "slow") public void testSingleBasePlan() throws SubscriptionBaseMigrationApiException { final DateTime startDate = clock.getUTCNow().minusMonths(2); final DateTime beforeMigration = clock.getUTCNow(); final AccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlan(startDate); final DateTime afterMigration = clock.getUTCNow(); testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT); migrationApi.migrate(toBeMigrated, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundles = subscriptionInternalApi.getBundlesForAccount(toBeMigrated.getAccountKey(), internalCallContext); assertEquals(bundles.size(), 1); final SubscriptionBaseBundle bundle = bundles.get(0); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(bundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1); final SubscriptionBase subscription = subscriptions.get(0); assertTrue(subscription.getStartDate().compareTo(startDate) == 0); assertEquals(subscription.getEndDate(), null); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "shotgun-annual"); assertEquals(subscription.getChargedThroughDate(), startDate.plusYears(1)); assertListenerStatus(); }
assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-monthly"); assertEquals(subscription.getChargedThroughDate(), trialDate.plusDays(30)); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-monthly"); assertEquals(subscription.getCurrentPhase().getName(), "assault-rifle-monthly-evergreen");
assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-annual"); assertEquals(subscription.getChargedThroughDate(), startDate.plusYears(1)); assertEquals(subscription.getCurrentPhase(), null); assertEquals(subscription.getState(), EntitlementState.CANCELLED); assertNull(subscription.getCurrentPlan());
assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-monthly"); assertEquals(subscription.getCurrentPlan().getName(), "shotgun-annual");
assertTrue(subscriptionInternalApi.getAllTransitions(newBaseSubscription, internalCallContext).get(1).getEffectiveTransitionTime().compareTo(evergreenPhaseDate) == 0); final Plan newPlan = newBaseSubscription.getCurrentPlan(); assertEquals(newPlan.getProduct().getName(), baseProduct); assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL);
assertTrue(subscriptionInternalApi.getAllTransitions(newBaseSubscription, internalCallContext).get(1).getEffectiveTransitionTime().compareTo(evergreenPhaseDate) == 0); final Plan newPlan = newBaseSubscription.getCurrentPlan(); assertEquals(newPlan.getProduct().getName(), baseProduct); assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL);
assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "shotgun-annual"); assertEquals(subscription.getChargedThroughDate(), startDate.plusYears(1));
final Plan newPlan = newBaseSubscription.getCurrentPlan(); assertEquals(newPlan.getProduct().getName(), baseProduct); assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN);
Plan currentPlan = baseSubscription.getCurrentPlan(); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), "Shotgun"); assertEquals(baseSubscription.getStartDate(), baseSubscription.getStartDate()); currentPlan = baseSubscription.getCurrentPlan(); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle");
Plan newPlan = newBaseSubscription.getCurrentPlan(); assertEquals(newPlan.getProduct().getName(), baseProduct); assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertListenerStatus(); newPlan = newBaseSubscription.getCurrentPlan(); assertEquals(newPlan.getProduct().getName(), newBaseProduct1); assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); newBaseSubscriptionWithCtd.changePlan(newBaseProduct2, newBaseTerm2, basePriceList, callContext); newPlan = newBaseSubscriptionWithCtd.getCurrentPlan(); assertEquals(newPlan.getProduct().getName(), newBaseProduct1); assertEquals(newBaseSubscriptionWithCtd.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN);
boolean foundAO2 = false; for (final SubscriptionBase cur : subscriptions) { final Plan curPlan = cur.getCurrentPlan(); final Product curProduct = curPlan.getProduct(); if (curProduct.getName().equals(baseProduct)) {