Exemplo n.º 1
0
  private void testAddonCreateInternal(
      final String aoProduct,
      final BillingPeriod aoTerm,
      final String aoPriceList,
      final PlanAlignmentCreate expAlignement) {
    try {
      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 ADDON
      final DateTime beforeAOCreation = clock.getUTCNow();
      DefaultSubscriptionBase aoSubscription =
          testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
      final DateTime afterAOCreation = clock.getUTCNow();

      // CHECK EVERYTHING
      Plan aoCurrentPlan = aoSubscription.getCurrentPlan();
      assertNotNull(aoCurrentPlan);
      assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct);
      assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON);
      assertEquals(aoCurrentPlan.getBillingPeriod(), aoTerm);

      PlanPhase aoCurrentPhase = aoSubscription.getCurrentPhase();
      assertNotNull(aoCurrentPhase);
      assertEquals(aoCurrentPhase.getPhaseType(), PhaseType.DISCOUNT);

      testUtil.assertDateWithin(aoSubscription.getStartDate(), beforeAOCreation, afterAOCreation);
      assertEquals(aoSubscription.getBundleStartDate(), baseSubscription.getBundleStartDate());

      // CHECK next AO PHASE EVENT IS INDEED A MONTH AFTER BP STARTED => BUNDLE ALIGNMENT
      SubscriptionBaseTransition aoPendingTranstion = aoSubscription.getPendingTransition();
      if (expAlignement == PlanAlignmentCreate.START_OF_BUNDLE) {
        assertEquals(
            aoPendingTranstion.getEffectiveTransitionTime(),
            baseSubscription.getStartDate().plusMonths(1));
      } else {
        assertEquals(
            aoPendingTranstion.getEffectiveTransitionTime(),
            aoSubscription.getStartDate().plusMonths(1));
      }

      // ADD TWO PHASE EVENTS (BP + AO)
      testListener.reset();
      testListener.pushExpectedEvent(NextEvent.PHASE);
      testListener.pushExpectedEvent(NextEvent.PHASE);

      // MOVE THROUGH TIME TO GO INTO EVERGREEN
      it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(33));
      clock.addDeltaFromReality(it.toDurationMillis());
      assertTrue(testListener.isCompleted(5000));

      // CHECK EVERYTHING AGAIN
      aoSubscription =
          (DefaultSubscriptionBase)
              subscriptionInternalApi.getSubscriptionFromId(
                  aoSubscription.getId(), internalCallContext);

      aoCurrentPlan = aoSubscription.getCurrentPlan();
      assertNotNull(aoCurrentPlan);
      assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct);
      assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON);
      assertEquals(aoCurrentPlan.getBillingPeriod(), aoTerm);

      aoCurrentPhase = aoSubscription.getCurrentPhase();
      assertNotNull(aoCurrentPhase);
      assertEquals(aoCurrentPhase.getPhaseType(), PhaseType.EVERGREEN);

      aoSubscription =
          (DefaultSubscriptionBase)
              subscriptionInternalApi.getSubscriptionFromId(
                  aoSubscription.getId(), internalCallContext);
      aoPendingTranstion = aoSubscription.getPendingTransition();
      assertNull(aoPendingTranstion);
    } catch (SubscriptionBaseApiException e) {
      Assert.fail(e.getMessage());
    }
  }
Exemplo n.º 2
0
  @Test(groups = "slow")
  public void testChangeBPWithAddonNonAvailable() {
    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);
      final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(now, ctd);
      subscriptionInternalApi.setChargedThroughDate(
          baseSubscription.getId(), newChargedThroughDate, internalCallContext);
      baseSubscription =
          (DefaultSubscriptionBase)
              subscriptionInternalApi.getSubscriptionFromId(
                  baseSubscription.getId(), internalCallContext);

      // CHANGE IMMEDIATELY WITH TO BP WITH NON AVAILABLE ADDON
      final String newBaseProduct = "Pistol";
      final BillingPeriod newBaseTerm = BillingPeriod.MONTHLY;
      final String newBasePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;

      final List<EntitlementAOStatusDryRun> aoStatus =
          subscriptionInternalApi.getDryRunChangePlanStatus(
              baseSubscription.getId(), newBaseProduct, now, internalCallContext);
      assertEquals(aoStatus.size(), 1);
      assertEquals(aoStatus.get(0).getId(), aoSubscription.getId());
      assertEquals(aoStatus.get(0).getProductName(), aoProduct);
      assertEquals(aoStatus.get(0).getBillingPeriod(), aoTerm);
      assertEquals(aoStatus.get(0).getPhaseType(), aoSubscription.getCurrentPhase().getPhaseType());
      assertEquals(aoStatus.get(0).getPriceList(), aoSubscription.getCurrentPriceList().getName());
      assertEquals(aoStatus.get(0).getReason(), DryRunChangeReason.AO_NOT_AVAILABLE_IN_NEW_PLAN);

      baseSubscription.changePlan(newBaseProduct, newBaseTerm, newBasePriceList, 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());

      // MOVE AFTER CHANGE
      testListener.reset();
      testListener.pushExpectedEvent(NextEvent.CHANGE);
      testListener.pushExpectedEvent(NextEvent.CANCEL);
      it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
      clock.addDeltaFromReality(it.toDurationMillis());
      assertTrue(testListener.isCompleted(5000));

      // REFETCH AO SUBSCRIPTION AND CHECK THIS CANCELLED
      aoSubscription =
          (DefaultSubscriptionBase)
              subscriptionInternalApi.getSubscriptionFromId(
                  aoSubscription.getId(), internalCallContext);
      assertEquals(aoSubscription.getState(), EntitlementState.CANCELLED);

      assertListenerStatus();
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }