private DefaultPriceList toDefaultPriceList(@Nullable final PriceList input) { if (input == null) { return null; } DefaultPriceList result = tmpDefaultPriceListMap.get(input.getName()); if (result == null) { result = new DefaultPriceList(); result.setName(input.getName()); result.setPlans(toFilterDefaultPlans(input.getName())); tmpDefaultPriceListMap.put(input.getName(), result); } return result; }
@Test(groups = "fast") public void testAddPlanOnExistingCatalog() throws Exception { final StandaloneCatalog originalCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3); final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-annual", "Standard", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of()); catalogUpdater.addSimplePlanDescriptor(desc); final StandaloneCatalog catalog = catalogUpdater.getCatalog(); final Plan plan = catalog.findCurrentPlan("standard-annual"); assertEquals(plan.getName(), "standard-annual"); assertEquals(plan.getInitialPhases().length, 0); assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); assertNull(plan.getFinalPhase().getFixed()); assertEquals(plan.getFinalPhase().getName(), "standard-annual-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.USD); assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1); final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0); assertEquals(priceList.getName(), new PriceListDefault().getName()); assertEquals(priceList.getPlans().size(), 4); }
@Override public List<Listing> getAvailableAddOnListings(final String baseProductName, @Nullable final String priceListName) { final List<Listing> availAddons = new ArrayList<Listing>(); try { final Product product = findCurrentProduct(baseProductName); if (product != null) { for (final Product availAddon : product.getAvailable()) { for (final BillingPeriod billingPeriod : BillingPeriod.values()) { for (final PriceList priceList : getPriceLists().getAllPriceLists()) { if (priceListName == null || priceListName.equals(priceList.getName())) { final Collection<Plan> addonInList = priceList.findPlans(availAddon, billingPeriod); for (final Plan cur : addonInList) { availAddons.add(new DefaultListing(cur, priceList)); } } } } } } } catch (final CatalogApiException e) { // No such product - just return an empty list } return availAddons; }
@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; }
@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; }
@Override public boolean apply(final PriceList input) { return input.getName().equals(priceListName); } });
@Test(groups = "fast") public void testInvalidPlanDescriptors() throws Exception { final StandaloneCatalog originalCatalog = enhanceOriginalCatalogForInvalidTestCases("SpyCarBasic.xml"); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 5); CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); // Existing Plan has a 30 days trial => try with no TRIAL SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.DAYS, ImmutableList.<String>of()); addBadSimplePlanDescriptor(catalogUpdater, desc); // Existing Plan has a 30 days trial => try different trial length desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of()); addBadSimplePlanDescriptor(catalogUpdater, desc); // Existing Plan has a 30 days trial => try different trial unit desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.MONTHS, ImmutableList.<String>of()); addBadSimplePlanDescriptor(catalogUpdater, desc); // Existing Plan has a MONTHLY recurring => try with ANNUAL BillingPeriod desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.ANNUAL, 30, TimeUnit.DAYS, ImmutableList.<String>of()); addBadSimplePlanDescriptor(catalogUpdater, desc); // Existing Plan has a discount phase desc = new DefaultSimplePlanDescriptor("dynamic-monthly", "Dynamic", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.MONTHS, ImmutableList.<String>of()); addBadSimplePlanDescriptor(catalogUpdater, desc); // Existing Plan has final fixedterm phase desc = new DefaultSimplePlanDescriptor("superdynamic-fixedterm", "SuperDynamic", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of()); addBadSimplePlanDescriptor(catalogUpdater, desc); // Existing Plan a different recurring price ($100) desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of()); addBadSimplePlanDescriptor(catalogUpdater, desc); }
@Override public List<Listing> getAvailableAddOnListings(final String baseProductName, @Nullable final String priceListName) { final List<Listing> availAddons = new ArrayList<Listing>(); try { final Product product = findCurrentProduct(baseProductName); if (product != null) { for (final Product availAddon : product.getAvailable()) { for (final BillingPeriod billingPeriod : BillingPeriod.values()) { for (final PriceList priceList : getPriceLists().getAllPriceLists()) { if (priceListName == null || priceListName.equals(priceList.getName())) { final Collection<Plan> addonInList = priceList.findPlans(availAddon, billingPeriod); for (final Plan cur : addonInList) { availAddons.add(new DefaultListing(cur, priceList)); } } } } } } } catch (final CatalogApiException e) { // No such product - just return an empty list } return availAddons; }
cur.getCurrentPhase().getPhaseType(), cur.getCurrentPlan().getRecurringBillingPeriod(), cur.getCurrentPriceList().getName(), reason); result.add(status);
@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"); }
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);
@Test(groups = "fast") public void testAddExistingPlanWithNewCurrency() throws Exception { final StandaloneCatalog originalCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3); final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of()); catalogUpdater.addSimplePlanDescriptor(desc); final StandaloneCatalog catalog = catalogUpdater.getCatalog(); final Plan plan = catalog.findCurrentPlan("standard-monthly"); assertEquals(plan.getName(), "standard-monthly"); assertEquals(plan.getInitialPhases().length, 1); assertEquals(plan.getInitialPhases()[0].getPhaseType(), PhaseType.TRIAL); assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices().length, 0); assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrice(Currency.EUR), BigDecimal.ZERO); assertEquals(plan.getInitialPhases()[0].getName(), "standard-monthly-trial"); assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); assertNull(plan.getFinalPhase().getFixed()); assertEquals(plan.getFinalPhase().getName(), "standard-monthly-evergreen"); assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY); assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 3); assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrice(Currency.EUR), BigDecimal.TEN); }
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_INCLUDED_IN_NEW_PLAN);
public DefaultSubscriptionEvent(final SubscriptionBaseTransitionData in, final DateTime startDate, final Long searchKey1, final Long searchKey2, final UUID userToken) { this(in.getId(), in.getSubscriptionId(), in.getBundleId(), in.getBundleExternalKey(), in.getEffectiveTransitionTime(), in.getEffectiveTransitionTime(), in.getPreviousState(), (in.getPreviousPlan() != null) ? in.getPreviousPlan().getName() : null, (in.getPreviousPhase() != null) ? in.getPreviousPhase().getName() : null, (in.getPreviousPriceList() != null) ? in.getPreviousPriceList().getName() : null, in.getPreviousBillingCycleDayLocal(), in.getNextState(), (in.getNextPlan() != null) ? in.getNextPlan().getName() : null, (in.getNextPhase() != null) ? in.getNextPhase().getName() : null, (in.getNextPriceList() != null) ? in.getNextPriceList().getName() : null, in.getNextBillingCycleDayLocal(), in.getTotalOrdering(), in.getTransitionType(), in.getRemainingEventsForUserOperation(), startDate, searchKey1, searchKey2, userToken); }
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);
@Test(groups = "fast") public void testAddPlanOnExistingCatalog() throws Exception { final StandaloneCatalog originalCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3); final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-annual", "Standard", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of()); catalogUpdater.addSimplePlanDescriptor(desc); final StandaloneCatalog catalog = catalogUpdater.getCatalog(); final Plan plan = catalog.findCurrentPlan("standard-annual"); assertEquals(plan.getName(), "standard-annual"); assertEquals(plan.getInitialPhases().length, 0); assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); assertNull(plan.getFinalPhase().getFixed()); assertEquals(plan.getFinalPhase().getName(), "standard-annual-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.USD); assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1); final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0); assertEquals(priceList.getName(), new PriceListDefault().getName()); assertEquals(priceList.getPlans().size(), 4); }