public List<PriceList> getAllPriceLists() { final List<PriceList> result = new ArrayList<PriceList>(childPriceLists.length + 1); result.add(getDefaultPricelist()); for (final PriceList list : getChildPriceLists()) { result.add(list); } return result; }
@Override public DefaultPlan findCurrentPlan(final String productName, final BillingPeriod period, final String priceListName) throws CatalogApiException { if (productName == null) { throw new CatalogApiException(ErrorCode.CAT_NULL_PRODUCT_NAME); } if (priceLists == null) { throw new CatalogApiException(ErrorCode.CAT_PRICE_LIST_NOT_FOUND, priceListName); } final Product product = findCurrentProduct(productName); final DefaultPlan result = priceLists.getPlanFrom(priceListName, product, period); if (result == null) { final String periodString = (period == null) ? "NULL" : period.toString(); throw new CatalogApiException(ErrorCode.CAT_PLAN_NOT_FOUND, productName, periodString, priceListName); } return result; }
public DefaultPriceList findCurrentPriceList(final String priceListName) throws CatalogApiException { return priceLists.findPriceListFrom(priceListName); }
@Test(groups = "fast") public void testBaseCase() throws CatalogApiException { final DefaultProduct product1 = cat.getCurrentProducts()[0]; final DefaultProduct product2 = cat.getCurrentProducts()[1]; final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[0]; final PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN); final PlanSpecifier to = new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.MONTHLY, null); PlanChangeResult result = null; try { result = cat.getPlanRules().planChange(from, to, cat); } catch (IllegalPlanChange e) { Assert.fail("We should not have triggered this error"); } catch (CatalogApiException e) { Assert.fail("", e); } Assert.assertEquals(result.getPolicy(), BillingActionPolicy.END_OF_TERM); Assert.assertEquals(result.getAlignment(), PlanAlignmentChange.START_OF_SUBSCRIPTION); Assert.assertEquals(result.getNewPriceList(), priceList2); } }
final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
@Test(groups = "fast") public void testOverriding() throws CatalogApiException { final DefaultProduct foo = new DefaultProduct("Foo", ProductCategory.BASE); final DefaultProduct bar = new DefaultProduct("Bar", ProductCategory.BASE); final DefaultPlan[] defaultPlans = new DefaultPlan[]{ new MockPlan().setName("plan-foo-monthly").setProduct(foo).setFinalPhase(new MockPlanPhase().setBillCycleDuration(MONTHLY).setPhaseType(EVERGREEN)), new MockPlan().setName("plan-bar-monthly").setProduct(bar).setFinalPhase(new MockPlanPhase().setBillCycleDuration(MONTHLY).setPhaseType(EVERGREEN)), new MockPlan().setName("plan-foo-annual").setProduct(foo).setFinalPhase(new MockPlanPhase().setBillCycleDuration(ANNUAL).setPhaseType(EVERGREEN)), new MockPlan().setName("plan-bar-annual").setProduct(bar).setFinalPhase(new MockPlanPhase().setBillCycleDuration(ANNUAL).setPhaseType(EVERGREEN)) }; final DefaultPlan[] childPlans = new DefaultPlan[]{ new MockPlan().setName("plan-foo").setProduct(foo).setFinalPhase(new MockPlanPhase().setBillCycleDuration(ANNUAL).setPhaseType(DISCOUNT)), new MockPlan().setName("plan-bar").setProduct(bar).setFinalPhase(new MockPlanPhase().setBillCycleDuration(ANNUAL).setPhaseType(DISCOUNT)) }; final PriceListDefault defaultPriceList = new PriceListDefault(defaultPlans); final DefaultPriceList[] childPriceLists = new DefaultPriceList[]{ new DefaultPriceList(childPlans, "child") }; final DefaultPriceListSet set = new DefaultPriceListSet(defaultPriceList, childPriceLists); Assert.assertEquals(set.getPlanFrom(PriceListSet.DEFAULT_PRICELIST_NAME, foo, BillingPeriod.ANNUAL).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); Assert.assertEquals(set.getPlanFrom(PriceListSet.DEFAULT_PRICELIST_NAME, foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); Assert.assertEquals(set.getPlanFrom("child", foo, BillingPeriod.ANNUAL).getFinalPhase().getPhaseType(), PhaseType.DISCOUNT); Assert.assertEquals(set.getPlanFrom("child", foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); }
@Override public List<Listing> getAvailableAddonListings(final String baseProductName) { final List<Listing> availAddons = new ArrayList<Listing>(); try { Product product = findCurrentProduct(baseProductName); if ( product != null ) { for ( Product availAddon : product.getAvailable() ) { for ( BillingPeriod billingPeriod : BillingPeriod.values()) { for( PriceList priceList : getPriceLists().getAllPriceLists()) { Plan addonInList = priceList.findPlan(availAddon, billingPeriod); if ( (addonInList != null) ) { availAddons.add(new DefaultListing(addonInList, priceList)); } } } } } } catch (CatalogApiException e) { // No such product - just return an empty list } return availAddons; }
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { validate(catalog, errors, products); validate(catalog, errors, plans); priceLists.validate(catalog, errors); planRules.validate(catalog, errors); return errors; }
@Override public void initialize(final StandaloneCatalog catalog, final URI sourceURI) { catalogURI = sourceURI; super.initialize(catalog, sourceURI); planRules.initialize(catalog, sourceURI); priceLists.initialize(catalog, sourceURI); for (final DefaultProduct p : products) { p.initialize(catalog, sourceURI); } for (final DefaultPlan p : plans) { p.initialize(catalog, sourceURI); } }
public void populatePriceLists() { final DefaultPlan[] plans = getCurrentPlans(); final DefaultPriceList[] priceList = new DefaultPriceList[plans.length - 1]; for (int i = 1; i < plans.length; i++) { priceList[i - 1] = new DefaultPriceList(new DefaultPlan[]{plans[i]}, plans[i].getName() + "-pl"); } final DefaultPriceListSet set = new DefaultPriceListSet(new PriceListDefault(new DefaultPlan[]{plans[0]}), priceList); setPriceLists(set); }
@BeforeMethod(groups = "fast") public void beforeMethod() { cat = new MockCatalog(); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[0]; final CaseChangePlanPolicy casePolicy = new CaseChangePlanPolicy().setPolicy(BillingActionPolicy.END_OF_TERM); final CaseChangePlanAlignment caseAlignment = new CaseChangePlanAlignment().setAlignment(PlanAlignmentChange.START_OF_SUBSCRIPTION); final CasePriceList casePriceList = new CasePriceList().setToPriceList(priceList2); cat.getPlanRules(). setChangeCase(new CaseChangePlanPolicy[]{casePolicy}). setChangeAlignmentCase(new CaseChangePlanAlignment[]{caseAlignment}). setPriceListCase(new CasePriceList[]{casePriceList}); }
@Test(groups = "fast") public void testWildCardPhaseType() { final MockCatalog cat = new MockCatalog(); final DefaultProduct product = cat.getCurrentProducts()[0]; final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final CaseResult cr = new CaseResult( product, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, null, Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.ADD_ON, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat); }
@Test(groups = "fast") public void testForNullBillingPeriod() throws CatalogApiException { final DefaultProduct foo = new DefaultProduct("Foo", ProductCategory.BASE); final DefaultProduct bar = new DefaultProduct("Bar", ProductCategory.BASE); final DefaultPlan[] defaultPlans = new DefaultPlan[]{ new MockPlan().setName("plan-foo-monthly").setProduct(foo).setFinalPhase(new MockPlanPhase().setBillCycleDuration(MONTHLY).setPhaseType(EVERGREEN)), new MockPlan().setName("plan-bar-monthly").setProduct(bar).setFinalPhase(new MockPlanPhase().setBillCycleDuration(MONTHLY).setPhaseType(EVERGREEN)), new MockPlan().setName("plan-foo-annual").setProduct(foo).setFinalPhase(new MockPlanPhase().setBillCycleDuration(null).setPhaseType(EVERGREEN)), new MockPlan().setName("plan-bar-annual").setProduct(bar).setFinalPhase(new MockPlanPhase().setBillCycleDuration(null).setPhaseType(EVERGREEN)) }; final DefaultPlan[] childPlans = new DefaultPlan[]{ new MockPlan().setName("plan-foo").setProduct(foo).setFinalPhase(new MockPlanPhase().setBillCycleDuration(ANNUAL).setPhaseType(DISCOUNT)), new MockPlan().setName("plan-bar").setProduct(bar).setFinalPhase(new MockPlanPhase().setBillCycleDuration(ANNUAL).setPhaseType(DISCOUNT)) }; final PriceListDefault defaultPriceList = new PriceListDefault(defaultPlans); final DefaultPriceList[] childPriceLists = new DefaultPriceList[]{ new DefaultPriceList(childPlans, "child") }; final DefaultPriceListSet set = new DefaultPriceListSet(defaultPriceList, childPriceLists); Assert.assertEquals(set.getPlanFrom("child", foo, BillingPeriod.ANNUAL).getFinalPhase().getPhaseType(), PhaseType.DISCOUNT); Assert.assertEquals(set.getPlanFrom("child", foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); Assert.assertEquals(set.getPlanFrom(PriceListSet.DEFAULT_PRICELIST_NAME, foo, BillingPeriod.ANNUAL).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); Assert.assertEquals(set.getPlanFrom(PriceListSet.DEFAULT_PRICELIST_NAME, foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); } }
@Override public List<Listing> getAvailableBasePlanListings() { final List<Listing> availBasePlans = new ArrayList<Listing>(); for (Plan plan : getCurrentPlans()) { if (plan.getProduct().getCategory().equals(ProductCategory.BASE)) { for (PriceList priceList : getPriceLists().getAllPriceLists()) { for (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; } }
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
@Test(groups = "fast") public void testBasic() { final MockCatalog cat = new MockCatalog(); final DefaultProduct product = cat.getCurrentProducts()[0]; final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final CaseResult cr = new CaseResult( product, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, PhaseType.EVERGREEN, Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.ADD_ON, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat); }
@Override public PriceList findCurrentPricelist(final String name) throws CatalogApiException { if (name == null || priceLists == null) { throw new CatalogApiException(ErrorCode.CAT_PRICE_LIST_NOT_FOUND, name); } return priceLists.findPriceListFrom(name); }
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
@Test(groups = "fast") public void testWildCardPriceList() { final MockCatalog cat = new MockCatalog(); final DefaultProduct product = cat.getCurrentProducts()[0]; final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist(); final CaseResult cr = new CaseResult( product, ProductCategory.BASE, BillingPeriod.MONTHLY, null, PhaseType.EVERGREEN, Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.ADD_ON, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN, cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", PhaseType.EVERGREEN, cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat); }
public DefaultPlan getPlanFrom(final String priceListName, final Product product, final BillingPeriod period) throws CatalogApiException { DefaultPlan result = null; final DefaultPriceList pl = findPriceListFrom(priceListName); if (pl != null) { result = pl.findPlan(product, period); } if (result != null) { return result; } return defaultPricelist.findPlan(product, period); }