@Override public String apply(final Product input) { return input.getName(); } });
private Iterable<Product> toDefaultProducts(final Iterable<Product> input) { if (tmpDefaultProducts == null) { final Map<String, Product> map = new HashMap<String, Product>(); for (final Product product : input) map.put(product.getName(), toDefaultProduct(product)); tmpDefaultProducts = map; } return tmpDefaultProducts.values(); }
public boolean isAddonAvailable(final Product baseProduct, final Plan targetAddOnPlan) { final Product targetAddonProduct = targetAddOnPlan.getProduct(); final Collection<Product> availableAddOns = baseProduct.getAvailable(); for (final Product curAv : availableAddOns) { if (curAv.getName().equals(targetAddonProduct.getName())) { return true; } } return false; }
public boolean isAddonIncluded(final Product baseProduct, final Plan targetAddOnPlan) { final Product targetAddonProduct = targetAddOnPlan.getProduct(); final Collection<Product> includedAddOns = baseProduct.getIncluded(); for (final Product curAv : includedAddOns) { if (curAv.getName().equals(targetAddonProduct.getName())) { return true; } } return false; }
@Override public boolean apply(final Product input) { return input.getName().equals(productName); } });
private Product toDefaultProduct(@Nullable final Product input) { if (input == null) { return null; } if (tmpDefaultProducts != null) { final Product existingProduct = tmpDefaultProducts.get(input.getName()); if (existingProduct == null) throw new IllegalStateException("Unknown product " + input.getName()); return existingProduct; } final DefaultProduct result = new DefaultProduct(); result.setCatalogName(catalogName); result.setCatagory(input.getCategory()); result.setName(input.getName()); result.setPrettyName(input.getPrettyName()); return result; }
public Plan getPlanFrom(final Product product, final BillingPeriod period, final String priceListName) throws CatalogApiException { Collection<Plan> plans = null; final DefaultPriceList pl = findPriceListFrom(priceListName); if (pl != null) { plans = pl.findPlans(product, period); } if (plans.size() == 0) { plans = defaultPricelist.findPlans(product, period); } switch (plans.size()) { case 0: return null; case 1: return plans.iterator().next(); default: throw new CatalogApiException(ErrorCode.CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST, priceListName, product.getName(), period); } }
@Override public List<Listing> getAvailableBasePlanListings() { final List<Listing> availBasePlans = new ArrayList<Listing>(); for (final Plan plan : getCurrentPlans()) { if (plan.getProduct().getCategory().equals(ProductCategory.BASE)) { for (final PriceList priceList : getPriceLists().getAllPriceLists()) { for (final Plan priceListPlan : priceList.getPlans()) { if (priceListPlan.getName().equals(plan.getName()) && priceListPlan.getProduct().getName().equals(plan.getProduct().getName())) { availBasePlans.add(new DefaultListing(priceListPlan, priceList)); } } } } } return availBasePlans; }
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.getRecurringBillingPeriod(), expBillingPeriod); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), expPhase); }
public void checkAddonCreationRights(final SubscriptionBase baseSubscription, final Plan targetAddOnPlan, final DateTime requestedDate, final InternalTenantContext context) throws SubscriptionBaseApiException { if (baseSubscription.getState() == EntitlementState.CANCELLED || (baseSubscription.getState() == EntitlementState.PENDING && context.toLocalDate(baseSubscription.getStartDate()).compareTo(context.toLocalDate(requestedDate)) < 0)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_BP_NON_ACTIVE, targetAddOnPlan.getName()); } final Plan currentOrPendingPlan = baseSubscription.getCurrentOrPendingPlan(); final Product baseProduct = currentOrPendingPlan.getProduct(); if (isAddonIncluded(baseProduct, targetAddOnPlan)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_ALREADY_INCLUDED, targetAddOnPlan.getName(), currentOrPendingPlan.getProduct().getName()); } if (!isAddonAvailable(baseProduct, targetAddOnPlan)) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_NOT_AVAILABLE, targetAddOnPlan.getName(), currentOrPendingPlan.getProduct().getName()); } }
@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; final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, PhaseType.EVERGREEN, null); assertNotNull(subscription); assertEquals(subscription.getBundleExternalKey(), bundle.getExternalKey()); 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.getRecurringBillingPeriod(), BillingPeriod.MONTHLY); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN); assertListenerStatus(); }
@Test(groups = "fast") public void testAddNoTrialPlanOnFirstCatalog() throws CatalogApiException { final DateTime now = clock.getUTCNow(); final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of()); final CatalogUpdater catalogUpdater = new CatalogUpdater(now, desc.getCurrency()); catalogUpdater.addSimplePlanDescriptor(desc); final StandaloneCatalog catalog = catalogUpdater.getCatalog(); assertEquals(catalog.getCurrentProducts().size(), 1); final Product product = catalog.getCurrentProducts().iterator().next(); assertEquals(product.getName(), "Foo"); assertEquals(product.getCategory(), ProductCategory.BASE); assertEquals(catalog.getCurrentPlans().size(), 1); final Plan plan = catalog.findCurrentPlan("foo-monthly"); assertEquals(plan.getName(), "foo-monthly"); assertEquals(plan.getInitialPhases().length, 0); assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); assertNull(plan.getFinalPhase().getFixed()); assertEquals(plan.getFinalPhase().getName(), "foo-monthly-evergreen"); assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY); assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 1); assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getValue(), BigDecimal.TEN); assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getCurrency(), Currency.EUR); assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1); final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0); assertEquals(priceList.getName(), new PriceListDefault().getName()); assertEquals(priceList.getPlans().size(), 1); assertEquals(priceList.getPlans().iterator().next().getName(), "foo-monthly"); }
testListener.pushExpectedEvent(NextEvent.CANCEL); assertEquals(subscription.getLastActiveProduct().getName(), prod); assertEquals(subscription.getLastActivePriceList().getName(), planSet); assertEquals(subscription.getLastActiveBillingPeriod(), term); assertListenerStatus(); assertEquals(subscription.getLastActiveProduct().getName(), prod); assertEquals(subscription.getLastActivePriceList().getName(), planSet); assertEquals(subscription.getLastActiveBillingPeriod(), term);
assertEquals(currentPlan.getProduct().getName(), productName); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getRecurringBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(newPlan.getProduct().getName(), baseProduct); assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL);
assertEquals(product.getName(), "Foo"); assertEquals(product.getCategory(), ProductCategory.BASE);
assertEquals(newPlan.getProduct().getName(), baseProduct); assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN);
assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getRecurringBillingPeriod(), BillingPeriod.ANNUAL);
public StandaloneCatalog toStandaloneCatalog(final StandalonePluginCatalog pluginCatalog) { final StandaloneCatalog result = new StandaloneCatalog(); result.setCatalogName(catalogName); result.setEffectiveDate(pluginCatalog.getEffectiveDate().toDate()); result.setProducts(toDefaultProducts(pluginCatalog.getProducts())); result.setPlans(toDefaultPlans(result, pluginCatalog.getPlans())); result.setPriceLists(toDefaultPriceListSet(pluginCatalog.getDefaultPriceList(), pluginCatalog.getChildrenPriceList())); result.setSupportedCurrencies(toArray(pluginCatalog.getCurrencies())); result.setUnits(toDefaultUnits(pluginCatalog.getUnits())); result.setPlanRules(toDefaultPlanRules(pluginCatalog.getPlanRules())); for (final Product cur : pluginCatalog.getProducts()) { final Product target = result.getCatalogEntityCollectionProduct().findByName(cur.getName()); if (target != null) { ((DefaultProduct) target).setAvailable(toFilteredDefaultProduct(cur.getAvailable())); ((DefaultProduct) target).setIncluded(toFilteredDefaultProduct(cur.getIncluded())); } } result.initialize(result); return result; }
assertEquals(currentPlan.getProduct().getName(), prod); currentPhase = subscription.getCurrentPhase(); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);