@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); } }
private DateTime createSubscriptionCreationEvent(final Plan nextPlan, final PlanPhase nextPhase) throws CatalogApiException { final DateTime now = clock.getUTCNow(); final DateTime then = now.minusDays(1); final PriceList nextPriceList = catalog.findPriceList(PriceListSet.DEFAULT_PRICELIST_NAME, now); final EffectiveSubscriptionInternalEvent t = new MockEffectiveSubscriptionEvent( eventId, subId, bunId, then, now, null, null, null, null, EntitlementState.ACTIVE, nextPlan.getName(), nextPhase.getName(), nextPriceList.getName(), 1L, SubscriptionBaseTransitionType.CREATE, 1, null, 1L, 2L, null); effectiveSubscriptionTransitions.add(t); return now; } }
/** * For unit tests only. * <p/> * You can't really use this constructor in real life because the start date is likely not the one you want (you likely * want the phase start date). * * @param subscription Subscription to use as a model * @param currency ACCOUNT currency * @param catalog Catalog to use */ BusinessSubscription(final Subscription subscription, final Currency currency, final Catalog catalog) { this(subscription.getCurrentPriceList() == null ? null : subscription.getCurrentPriceList().getName(), subscription.getCurrentPlan().getName(), subscription.getCurrentPhase().getName(), currency, subscription.getStartDate(), subscription.getState(), catalog); }
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(); }
@Test(groups = "slow") public void testSingleBasePlan() throws SubscriptionBaseMigrationApiException { final DateTime startDate = clock.getUTCNow().minusMonths(2); final DateTime beforeMigration = clock.getUTCNow(); final AccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlan(startDate); final DateTime afterMigration = clock.getUTCNow(); testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT); migrationApi.migrate(toBeMigrated, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundles = subscriptionInternalApi.getBundlesForAccount(toBeMigrated.getAccountKey(), internalCallContext); assertEquals(bundles.size(), 1); final SubscriptionBaseBundle bundle = bundles.get(0); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(bundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1); final SubscriptionBase subscription = subscriptions.get(0); assertTrue(subscription.getStartDate().compareTo(startDate) == 0); assertEquals(subscription.getEndDate(), null); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "shotgun-annual"); assertEquals(subscription.getChargedThroughDate(), startDate.plusYears(1)); assertListenerStatus(); }
assertTrue(baseSubscription.getStartDate().compareTo(initalBPStart) == 0); assertEquals(baseSubscription.getEndDate(), null); assertEquals(baseSubscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(baseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(baseSubscription.getState(), EntitlementState.ACTIVE); assertEquals(aoSubscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(aoSubscription.getCurrentPhase().getPhaseType(), PhaseType.DISCOUNT); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE);
assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE);
assertEquals(subscription.getLastActivePriceList().getName(), planSet); assertEquals(subscription.getLastActiveBillingPeriod(), term); assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE); assertEquals(subscription.getLastActivePriceList().getName(), planSet); assertEquals(subscription.getLastActiveBillingPeriod(), term); assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE);
final SubscriptionBase subscription = subscriptions.get(0); assertTrue(subscription.getStartDate().compareTo(startDate) == 0); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase(), null); assertEquals(subscription.getState(), EntitlementState.CANCELLED);
this.productCategory = subscription.getLastActiveProductCategory().name(); this.billingPeriod = subscription.getLastActivePlan().getBillingPeriod().toString(); this.priceList = subscription.getLastActivePriceList().getName(); this.cancelledDate = subscription.getEffectiveEndDate(); this.chargedThroughDate = subscription.getChargedThroughDate(); cur.getEffectiveDate(), product != null ? product.getName() : null, priceList != null ? priceList.getName() : null, cur.getSubscriptionEventType().toString(), phase != null ? phase.getName() : null,
assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
testUtil.assertDateWithin(subscription.getStartDate(), beforeMigration.minusMonths(2), afterMigration.minusMonths(2)); assertEquals(subscription.getEndDate(), null); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE);
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_INCLUDED_IN_NEW_PLAN);
assertEquals(subscription.getLastActivePriceList().getName(), planSet); assertEquals(subscription.getLastActiveBillingPeriod(), term); assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE); assertEquals(subscription.getLastActivePriceList().getName(), planSet); assertEquals(subscription.getLastActiveBillingPeriod(), term); assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE); assertEquals(subscription.getLastActivePriceList().getName(), planSet); assertEquals(subscription.getLastActiveBillingPeriod(), term); assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE);
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);