@Test(groups = "fast") public void testCreateSubscriptionBPExists() throws SubscriptionBaseApiException { testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME); tCreateSubscriptionInternal(bundle.getId(), "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.SUB_CREATE_BP_EXISTS); }
@Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { //testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4)); clock.addDeltaFromReality(it.toDurationMillis()); //assertListenerStatus(); final DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, "Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final DateTime newCreateTime = baseSubscription.getStartDate().plusDays(3); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.TRIAL); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CREATE, newCreateTime, 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)); // FIRST ISSUE DRY RUN final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); final boolean dryRun = true; repairApi.repairBundle(bRepair, dryRun, callContext); } }, ErrorCode.SUB_REPAIR_BP_RECREATE_MISSING_AO);
@Override @BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); test = new TestWithException(); final DateTime startDate = clock.getUTCNow(); baseSubscription = testUtil.createSubscription(bundle, baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate); }
@Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4)); clock.addDeltaFromReality(it.toDurationMillis()); final DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); // MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4)); clock.addDeltaFromReality(it.toDurationMillis()); BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); // Quick check final SubscriptionBaseTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair); assertEquals(bpRepair.getExistingEvents().size(), 2); final SubscriptionBaseTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair); assertEquals(aoRepair.getExistingEvents().size(), 2); final List<DeletedEvent> des = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>(); //des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId())); final DateTime aoCancelDate = aoSubscription.getStartDate().plusDays(10); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CANCEL, aoCancelDate, null); final SubscriptionBaseTimeline saoRepair = testUtil.createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne)); bundleRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair)); final boolean dryRun = true; repairApi.repairBundle(bundleRepair, dryRun, callContext); } }, ErrorCode.SUB_REPAIR_NEW_EVENT_BEFORE_LAST_AO_REMAINING);
@Test(groups = "fast") public void testUncancelBadState() throws SubscriptionBaseApiException { final SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); try { subscription.uncancel(callContext); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_UNCANCEL_BAD_STATE.getCode()); } assertListenerStatus(); } }
@Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4)); clock.addDeltaFromReality(it.toDurationMillis()); final DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); // MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4)); clock.addDeltaFromReality(it.toDurationMillis()); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); // Quick check final SubscriptionBaseTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair); assertEquals(bpRepair.getExistingEvents().size(), 2); final SubscriptionBaseTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair); assertEquals(aoRepair.getExistingEvents().size(), 2); final List<DeletedEvent> des = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>(); des.add(testUtil.createDeletedEvent(aoRepair.getExistingEvents().get(0).getEventId())); des.add(testUtil.createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId())); final DateTime aoRecreateDate = aoSubscription.getStartDate().minusDays(5); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Telescopic-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.DISCOUNT); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CREATE, aoRecreateDate, spec); final SubscriptionBaseTimeline saoRepair = testUtil.createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair)); final boolean dryRun = true; repairApi.repairBundle(bRepair, dryRun, callContext); } }, ErrorCode.SUB_REPAIR_AO_CREATE_BEFORE_BP_START);
@Test(groups = "slow") public void testENT_REPAIR_VIEW_CHANGED_newEvent() throws Exception { final TestWithException test = new TestWithException(); final DateTime startDate = clock.getUTCNow(); final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate); test.withException(new TestWithExceptionCallback() { @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); }
final DateTime startDate = clock.getUTCNow(); final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
@Test(groups = "slow") public void testCreateCancelAddon() throws SubscriptionBaseApiException { 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(callContext); assertListenerStatus(); aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext); assertEquals(aoSubscription.getState(), EntitlementState.CANCELLED); assertListenerStatus(); }
@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()); } }
@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); }
final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList); final DateTime ctd = baseSubscription.getStartDate().plusDays(30);
final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList); final String aoProduct1 = "Telescopic-Scope"; final BillingPeriod aoTerm1 = BillingPeriod.MONTHLY; final DefaultSubscriptionBase aoSubscription1 = testUtil.createSubscription(bundle, aoProduct1, aoTerm1, basePriceList); assertEquals(aoSubscription1.getState(), EntitlementState.ACTIVE);
final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet); PlanPhase currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL);
final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
@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(); }
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); subscription.changePlan(toProd, toTerm, toPlanSet, callContext); assertListenerStatus(); // CHECK CHANGE PLAN currentPhase = subscription.getCurrentPhase(); checkChangePlan(subscription, toProd, ProductCategory.BASE, toTerm, PhaseType.EVERGREEN); assertListenerStatus(); } catch (SubscriptionBaseApiException e) { Assert.fail(e.getMessage()); } }
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 subscription.changePlan(toProd, toTerm, toPlanSet, 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(); }
@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(); }