private void checkChangePlan(final DefaultSubscriptionBase subscription, final String expProduct, final ProductCategory expCategory, final BillingPeriod expBillingPeriod, final PhaseType expPhase) { final Plan currentPlan = subscription.getCurrentPlan(); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), expProduct); assertEquals(currentPlan.getProduct().getCategory(), expCategory); assertEquals(currentPlan.getBillingPeriod(), expBillingPeriod); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), expPhase); }
@Test(groups = "fast") public void testFromListing() throws Exception { final Product product = Mockito.mock(Product.class); Mockito.when(product.getName()).thenReturn(UUID.randomUUID().toString()); final InternationalPrice price = Mockito.mock(InternationalPrice.class); final PlanPhase planPhase = Mockito.mock(PlanPhase.class); Mockito.when(planPhase.getRecurringPrice()).thenReturn(price); final Plan plan = Mockito.mock(Plan.class); Mockito.when(plan.getProduct()).thenReturn(product); Mockito.when(plan.getName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(plan.getBillingPeriod()).thenReturn(BillingPeriod.QUARTERLY); Mockito.when(plan.getFinalPhase()).thenReturn(planPhase); final PriceList priceList = Mockito.mock(PriceList.class); Mockito.when(priceList.getName()).thenReturn(UUID.randomUUID().toString()); final Listing listing = Mockito.mock(Listing.class); Mockito.when(listing.getPlan()).thenReturn(plan); Mockito.when(listing.getPriceList()).thenReturn(priceList); final PlanDetailJson planDetailJason = new PlanDetailJson(listing); Assert.assertEquals(planDetailJason.getProductName(), plan.getProduct().getName()); Assert.assertEquals(planDetailJason.getPlanName(), plan.getName()); Assert.assertEquals(planDetailJason.getBillingPeriod(), plan.getBillingPeriod()); Assert.assertEquals(planDetailJason.getPriceListName(), priceList.getName()); Assert.assertEquals(planDetailJason.getFinalPhasePrice().size(), 0); } }
@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); }
public PlanDetailJson(final Listing listing) { final Plan plan = listing.getPlan(); if (plan == null) { this.productName = null; this.planName = null; this.billingPeriod = null; this.finalPhasePrice = ImmutableList.<PriceJson>of(); } else { this.productName = plan.getProduct() == null ? null : plan.getProduct().getName(); this.planName = plan.getName(); this.billingPeriod = plan.getBillingPeriod(); if (plan.getFinalPhase() == null || plan.getFinalPhase().getRecurringPrice() == null || plan.getFinalPhase().getRecurringPrice().getPrices() == null) { this.finalPhasePrice = ImmutableList.<PriceJson>of(); } else { this.finalPhasePrice = Lists.transform(ImmutableList.<Price>copyOf(plan.getFinalPhase().getRecurringPrice().getPrices()), new Function<Price, PriceJson>() { @Override public PriceJson apply(final Price price) { try { return new PriceJson(price); } catch (CurrencyValueNull e) { return new PriceJson(price.getCurrency().toString(), BigDecimal.ZERO); } } }); } } this.priceListName = listing.getPriceList() == null ? null : listing.getPriceList().getName(); }
@Override public Response doOperation(final CallContext ctx) throws EntitlementApiException, InterruptedException, TimeoutException, AccountApiException { final UUID uuid = UUID.fromString(subscriptionId); final Entitlement current = entitlementApi.getEntitlementForId(uuid, callContext); final LocalDate inputLocalDate = toLocalDate(current.getAccountId(), requestedDate, callContext); final Entitlement newEntitlement; if (requestedDate == null && policyString == null) { newEntitlement = current.changePlan(entitlement.getProductName(), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), ctx); } else if (policyString == null) { newEntitlement = current.changePlanWithDate(entitlement.getProductName(), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), inputLocalDate, ctx); } else { final BillingActionPolicy policy = BillingActionPolicy.valueOf(policyString.toUpperCase()); newEntitlement = current.changePlanOverrideBillingPolicy(entitlement.getProductName(), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), inputLocalDate, policy, ctx); } isImmediateOp = newEntitlement.getLastActiveProduct().getName().equals(entitlement.getProductName()) && newEntitlement.getLastActivePlan().getBillingPeriod() == BillingPeriod.valueOf(entitlement.getBillingPeriod()) && newEntitlement.getLastActivePriceList().getName().equals(entitlement.getPriceList()); return Response.status(Status.OK).build(); }
private SubscriptionEvent toSubscriptionEvent(final SubscriptionBaseTransition in, final SubscriptionEventType eventType, final DateTimeZone accountTimeZone) { return new DefaultSubscriptionEvent(in.getId(), in.getSubscriptionId(), in.getEffectiveTransitionTime(), in.getRequestedTransitionTime(), eventType, false, false, getServiceName(eventType), eventType.toString(), (in.getPreviousPlan() != null ? in.getPreviousPlan().getProduct() : null), in.getPreviousPlan(), in.getPreviousPhase(), in.getPreviousPriceList(), (in.getPreviousPlan() != null ? in.getPreviousPlan().getBillingPeriod() : null), (in.getNextPlan() != null ? in.getNextPlan().getProduct() : null), in.getNextPlan(), in.getNextPhase(), in.getNextPriceList(), (in.getNextPlan() != null ? in.getNextPlan().getBillingPeriod() : null), in.getCreatedDate(), accountTimeZone); }
assertEquals(currentPlan.getProduct().getName(), newBaseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(currentPlan.getProduct().getName(), newBaseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
@Test(groups = "slow") public void testCreateWithInitialPhase() throws SubscriptionBaseApiException { final DateTime init = clock.getUTCNow(); final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; testListener.pushExpectedEvent(NextEvent.CREATE); final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(bundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, PhaseType.EVERGREEN), clock.getUTCNow(), internalCallContext); assertNotNull(subscription); assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION); //assertEquals(subscription.getAccount(), account.getId()); assertEquals(subscription.getBundleId(), bundle.getId()); testUtil.assertDateWithin(subscription.getStartDate(), init, clock.getUTCNow()); testUtil.assertDateWithin(subscription.getBundleStartDate(), init, clock.getUTCNow()); final Plan currentPlan = subscription.getCurrentPlan(); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), productName); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN); assertListenerStatus(); }
assertEquals(currentPlan.getProduct().getName(), productName); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(currentPlan.getProduct().getName(), baseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(currentPlan.getProduct().getName(), baseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY); assertEquals(currentPlan.getProduct().getName(), newBaseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
this.productName = subscription.getLastActiveProduct().getName(); this.productCategory = subscription.getLastActiveProductCategory().name(); this.billingPeriod = subscription.getLastActivePlan().getBillingPeriod().toString(); this.priceList = subscription.getLastActivePriceList().getName(); this.cancelledDate = subscription.getEffectiveEndDate();
assertEquals(currentPlan.getProduct().getName(), baseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY); assertEquals(currentPlan.getProduct().getName(), newBaseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(currentPlan.getProduct().getName(), "Shotgun"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY); assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct); assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON); assertEquals(aoCurrentPlan.getBillingPeriod(), aoTerm); assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct); assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON); assertEquals(aoCurrentPlan.getBillingPeriod(), aoTerm);
assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.ANNUAL);
assertEquals(currentPlan.getProduct().getName(), "Laser-Scope"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.ADD_ON); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.ANNUAL); assertEquals(currentPlan.getProduct().getName(), "Pistol"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.ANNUAL); assertEquals(currentPlan.getProduct().getName(), "Pistol"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.ANNUAL);
assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.ANNUAL);