@Test(groups = "slow") public void testCreateCancelAddon() { try { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.ANNUAL; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList); final String aoProduct = "Telescopic-Scope"; final BillingPeriod aoTerm = BillingPeriod.MONTHLY; final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME; DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); testListener.pushExpectedEvent(NextEvent.CANCEL); final DateTime now = clock.getUTCNow(); aoSubscription.cancel(now, callContext); assertTrue(testListener.isCompleted(5000)); aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( aoSubscription.getId(), internalCallContext); assertEquals(aoSubscription.getState(), EntitlementState.CANCELLED); assertListenerStatus(); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Test(groups = "slow") public void testCreateCancelAddonAndThenBP() { try { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.ANNUAL; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList); final String aoProduct = "Telescopic-Scope"; final BillingPeriod aoTerm = BillingPeriod.MONTHLY; final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME; DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); // Move clock after a month Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1)); testListener.pushExpectedEvent(NextEvent.PHASE); testListener.pushExpectedEvent(NextEvent.PHASE); clock.addDeltaFromReality(it.toDurationMillis()); assertTrue(testListener.isCompleted(5000)); // SET CTD TO CANCEL IN FUTURE final DateTime now = clock.getUTCNow(); final Duration aoCtd = testUtil.getDurationMonth(1); final DateTime newAOChargedThroughDate = TestSubscriptionHelper.addDuration(now, aoCtd); subscriptionInternalApi.setChargedThroughDate( aoSubscription.getId(), newAOChargedThroughDate, internalCallContext); final Duration bpCtd = testUtil.getDurationMonth(11); final DateTime newBPChargedThroughDate = TestSubscriptionHelper.addDuration(now, bpCtd); subscriptionInternalApi.setChargedThroughDate( baseSubscription.getId(), newBPChargedThroughDate, internalCallContext); baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( baseSubscription.getId(), internalCallContext); aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( aoSubscription.getId(), internalCallContext); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(1)); clock.addDeltaFromReality(it.toDurationMillis()); // CANCEL AO aoSubscription.cancel(clock.getUTCNow(), callContext); aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( aoSubscription.getId(), internalCallContext); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); assertTrue(aoSubscription.isSubscriptionFutureCancelled()); // CANCEL BASE NOW baseSubscription.cancel(clock.getUTCNow(), callContext); baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( baseSubscription.getId(), internalCallContext); assertEquals(baseSubscription.getState(), EntitlementState.ACTIVE); assertTrue(baseSubscription.isSubscriptionFutureCancelled()); aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( aoSubscription.getId(), internalCallContext); List<SubscriptionBaseTransition> aoTransitions = aoSubscription.getAllTransitions(); assertEquals(aoTransitions.size(), 3); assertEquals(aoTransitions.get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE); assertEquals(aoTransitions.get(1).getTransitionType(), SubscriptionBaseTransitionType.PHASE); assertEquals(aoTransitions.get(2).getTransitionType(), SubscriptionBaseTransitionType.CANCEL); assertTrue(aoSubscription.getFutureEndDate().compareTo(newAOChargedThroughDate) == 0); testListener.pushExpectedEvent(NextEvent.UNCANCEL); aoSubscription.uncancel(callContext); assertTrue(testListener.isCompleted(5000)); aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( aoSubscription.getId(), internalCallContext); aoTransitions = aoSubscription.getAllTransitions(); assertEquals(aoTransitions.size(), 3); assertEquals(aoTransitions.get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE); assertEquals(aoTransitions.get(1).getTransitionType(), SubscriptionBaseTransitionType.PHASE); assertEquals(aoTransitions.get(2).getTransitionType(), SubscriptionBaseTransitionType.CANCEL); assertTrue(aoSubscription.getFutureEndDate().compareTo(newBPChargedThroughDate) == 0); assertListenerStatus(); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Test(groups = "slow") public void testCancelUncancelBPWithAddon() { try { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; // CREATE BP DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList); final String aoProduct = "Telescopic-Scope"; final BillingPeriod aoTerm = BillingPeriod.MONTHLY; final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME; DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList); testListener.reset(); testListener.pushExpectedEvent(NextEvent.PHASE); testListener.pushExpectedEvent(NextEvent.PHASE); // MOVE CLOCK AFTER TRIAL + AO DISCOUNT Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(2)); clock.addDeltaFromReality(it.toDurationMillis()); assertTrue(testListener.isCompleted(5000)); // SET CTD TO CANCEL IN FUTURE final DateTime now = clock.getUTCNow(); final Duration ctd = testUtil.getDurationMonth(1); // Why not just use clock.getUTCNow().plusMonths(1) ? final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(now, ctd); subscriptionInternalApi.setChargedThroughDate( baseSubscription.getId(), newChargedThroughDate, internalCallContext); baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( baseSubscription.getId(), internalCallContext); // FUTURE CANCELLATION baseSubscription.cancel(now, callContext); // REFETCH AO SUBSCRIPTION AND CHECK THIS IS ACTIVE aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( aoSubscription.getId(), internalCallContext); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); assertTrue(aoSubscription.isSubscriptionFutureCancelled()); testListener.reset(); testListener.pushExpectedEvent(NextEvent.UNCANCEL); baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( baseSubscription.getId(), internalCallContext); baseSubscription.uncancel(callContext); assertTrue(testListener.isCompleted(5000)); aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( aoSubscription.getId(), internalCallContext); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); assertFalse(aoSubscription.isSubscriptionFutureCancelled()); // CANCEL AGAIN it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(1)); clock.addDeltaFromReality(it.toDurationMillis()); baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( baseSubscription.getId(), internalCallContext); baseSubscription.cancel(clock.getUTCNow(), callContext); baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( baseSubscription.getId(), internalCallContext); assertEquals(baseSubscription.getState(), EntitlementState.ACTIVE); assertTrue(baseSubscription.isSubscriptionFutureCancelled()); aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId( aoSubscription.getId(), internalCallContext); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); assertTrue(aoSubscription.isSubscriptionFutureCancelled()); assertListenerStatus(); } catch (Exception e) { Assert.fail(e.getMessage()); } }