@Override public DateTime changePlanWithDate(final String productName, final BillingPeriod term, final String priceList, final DateTime requestedDate, final CallContext context) throws SubscriptionBaseApiException { return sub.changePlanWithDate(productName, term, priceList, requestedDate, context); }
@Test(groups = "fast") public void testChangeSubscriptionNonActive() throws SubscriptionBaseApiException { final SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME); testListener.pushExpectedEvent(NextEvent.CANCEL); subscription.cancelWithDate(clock.getUTCNow(), callContext); try { subscription.changePlanWithDate("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, clock.getUTCNow(), callContext); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_NON_ACTIVE.getCode()); } }
@Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final List<DeletedEvent> des = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>(); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId())); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId())); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); testListener.pushExpectedEvent(NextEvent.CHANGE); final DateTime changeTime = clock.getUTCNow(); baseSubscription.changePlanWithDate("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, changeTime, callContext); assertListenerStatus(); repairApi.repairBundle(bRepair, true, callContext); assertListenerStatus(); } }, ErrorCode.SUB_REPAIR_VIEW_CHANGED);
@Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3)); clock.addDeltaFromReality(it.toDurationMillis()); testListener.pushExpectedEvent(NextEvent.CHANGE); final DateTime changeTime = clock.getUTCNow(); baseSubscription.changePlanWithDate("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, changeTime, callContext); assertListenerStatus(); // MOVE AFTER TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(40)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final DeletedEvent de = testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_INVALID_DELETE_SET);
@Override public Entitlement changePlanWithDate(final String productName, final BillingPeriod billingPeriod, final String priceList, final LocalDate localDate, final CallContext callContext) throws EntitlementApiException { // Get the latest state from disk refresh(callContext); if (!eventsStream.isEntitlementActive()) { throw new EntitlementApiException(ErrorCode.SUB_CHANGE_NON_ACTIVE, getId(), getState()); } final InternalCallContext context = internalCallContextFactory.createInternalCallContext(getAccountId(), callContext); try { checker.checkBlockedChange(getSubscriptionBase(), context); } catch (BlockingApiException e) { throw new EntitlementApiException(e, e.getCode(), e.getMessage()); } final DateTime effectiveChangeDate = dateHelper.fromLocalDateAndReferenceTime(localDate, getSubscriptionBase().getStartDate(), context); try { getSubscriptionBase().changePlanWithDate(productName, billingPeriod, priceList, effectiveChangeDate, callContext); } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } blockAddOnsIfRequired(effectiveChangeDate, callContext, context); return entitlementApi.getEntitlementForId(getId(), callContext); }
@Test(groups = "fast") public void testChangeSubscriptionFutureCancelled() throws SubscriptionBaseApiException { SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); final PlanPhase trialPhase = subscription.getCurrentPhase(); // MOVE TO NEXT PHASE final PlanPhase currentPhase = subscription.getCurrentPhase(); testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); // SET CTD TO CANCEL IN FUTURE final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration()); final Duration ctd = testUtil.getDurationMonth(1); final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(expectedPhaseTrialChange, ctd); subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext); subscription = subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); subscription.cancelWithPolicy(BillingActionPolicy.END_OF_TERM, callContext); try { subscription.changePlanWithDate("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, clock.getUTCNow(), callContext); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_FUTURE_CANCELLED.getCode()); } assertListenerStatus(); }