@Test(groups = "slow", expectedExceptions = SubscriptionBaseApiException.class) public void testCancelSubscriptionWithInvalidRequestedDate() throws SubscriptionBaseApiException { final String prod = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME; // CREATE final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet); PlanPhase currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL); // MOVE TO NEXT PHASE testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN); final DateTime invalidDate = subscription.getBundleStartDate().minusDays(3); // CANCEL in EVERGREEN period with an invalid Date (prior to the Creation Date) subscription.cancelWithDate(invalidDate, callContext); }
@Test(groups = "slow") public void testInvalidChangesAcrossProductTypes() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; // CREATE BP final DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList); // MOVE CLOCK 14 DAYS LATER Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(14)); clock.addDeltaFromReality(it.toDurationMillis()); // Create AO final String aoProduct = "Laser-Scope"; final BillingPeriod aoTerm = BillingPeriod.MONTHLY; final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME; DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList); try { final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier(baseProduct, baseTerm, basePriceList); aoSubscription.changePlanWithDate(new DefaultEntitlementSpecifier(planPhaseSpecifier), clock.getUTCNow(), callContext); Assert.fail("Should not allow plan change across product type"); } catch (final SubscriptionBaseApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_INVALID.getCode()); } }
clock.addDeltaFromReality(it.toDurationMillis());
clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); currentPhase = subscription.getCurrentPhase(); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();
clock.addDeltaFromReality(it.toDurationMillis());
clock.addDeltaFromReality(it.toDurationMillis()); clock.addDeltaFromReality(it.toDurationMillis());
private void tChangePlanBundleAlignIMM(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet, final String toProd, final BillingPeriod toTerm, final String toPlanSet) throws SubscriptionBaseApiException { final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet); testListener.pushExpectedEvent(NextEvent.CHANGE); Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3)); clock.addDeltaFromReality(it.toDurationMillis()); // CHANGE PLAN IMM final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier(toProd, toTerm, toPlanSet); subscription.changePlan(new DefaultEntitlementSpecifier(planPhaseSpecifier), callContext); checkChangePlan(subscription, toProd, ProductCategory.BASE, toTerm, PhaseType.TRIAL); assertListenerStatus(); final PlanPhase currentPhase = subscription.getCurrentPhase(); final DateTime nextExpectedPhaseChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), currentPhase.getDuration()); testUtil.checkNextPhaseChange(subscription, 1, nextExpectedPhaseChange); // NEXT PHASE testListener.pushExpectedEvent(NextEvent.PHASE); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(30)); clock.addDeltaFromReality(it.toDurationMillis()); final DateTime futureNow = clock.getUTCNow(); assertTrue(futureNow.isAfter(nextExpectedPhaseChange)); assertListenerStatus(); }
testListener.pushExpectedEvent(NextEvent.PHASE); testListener.pushExpectedEvent(NextEvent.PHASE); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); clock.addDeltaFromReality(it.toDurationMillis());
clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();
@Test(groups = "slow") public void testCancelSubscriptionEOTWithNoChargeThroughDate() throws SubscriptionBaseApiException { final String prod = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME; // CREATE final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet); PlanPhase trialPhase = subscription.getCurrentPhase(); assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL); // NEXT PHASE final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration()); testUtil.checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange); // MOVE TO NEXT PHASE testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); trialPhase = subscription.getCurrentPhase(); assertEquals(trialPhase.getPhaseType(), PhaseType.EVERGREEN); testListener.pushExpectedEvent(NextEvent.CANCEL); // CANCEL subscription.cancel(callContext); assertListenerStatus(); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNull(currentPhase); testUtil.checkNextPhaseChange(subscription, 0, null); assertListenerStatus(); }
clock.addDeltaFromReality(it.toDurationMillis()); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();
clock.addDeltaFromReality(it.toDurationMillis()); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();
clock.addDeltaFromReality(it.toDurationMillis());
private void tChangePlanBundleAlignEOTWithNoChargeThroughDate(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet, final String toProd, final BillingPeriod toTerm, final String toPlanSet) { try { // CREATE final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet); // MOVE TO NEXT PHASE PlanPhase currentPhase = subscription.getCurrentPhase(); testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); final DateTime futureNow = clock.getUTCNow(); final DateTime nextExpectedPhaseChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), currentPhase.getDuration()); assertTrue(futureNow.isAfter(nextExpectedPhaseChange)); assertListenerStatus(); // CHANGE PLAN testListener.pushExpectedEvent(NextEvent.CHANGE); final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier(toProd, toTerm, toPlanSet); subscription.changePlan(new DefaultEntitlementSpecifier(planPhaseSpecifier), callContext); assertListenerStatus(); // CHECK CHANGE PLAN currentPhase = subscription.getCurrentPhase(); checkChangePlan(subscription, toProd, ProductCategory.BASE, toTerm, PhaseType.EVERGREEN); assertListenerStatus(); } catch (SubscriptionBaseApiException e) { Assert.fail(e.getMessage()); } }
clock.addDeltaFromReality(it.toDurationMillis());
clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); clock.addDeltaFromReality(it.toDurationMillis());
@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 { final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); subscription.changePlanWithDate(new DefaultEntitlementSpecifier(planPhaseSpecifier), clock.getUTCNow(), callContext); Assert.fail("Exception expected, error code: " + ErrorCode.SUB_CHANGE_FUTURE_CANCELLED); } catch (final SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_FUTURE_CANCELLED.getCode()); } assertListenerStatus(); }
currentTime = clock.getUTCNow(); Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); currentTime = clock.getUTCNow(); assertListenerStatus(); clock.addDeltaFromReality(it.toDurationMillis()); currentTime = clock.getUTCNow(); assertListenerStatus(); clock.addDeltaFromReality(it.toDurationMillis()); currentTime = clock.getUTCNow(); assertListenerStatus(); clock.addDeltaFromReality(it.toDurationMillis());
clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();
clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); PlanPhase currentPhase = subscription.getCurrentPhase(); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();