/** * @return the {@code PlanSpecifier} */ public PlanSpecifier toPlanSpecifier() { return new PlanSpecifier(productName, productCategory, billingPeriod, priceListName); } }
public T getResult(final PlanPhaseSpecifier specifier, final StandaloneCatalog c) throws CatalogApiException { if ((phaseType == null || specifier.getPhaseType() == phaseType) && satisfiesCase(new PlanSpecifier(specifier), c) ) { return getResult(); } return null; }
protected void assertion(final Result result, final CaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final StandaloneCatalog cat) throws CatalogApiException { Assert.assertEquals(result, cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat)); } }
protected void assertionNull(final CaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final StandaloneCatalog cat) throws CatalogApiException { Assert.assertNull(cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat)); }
@Test(groups = "fast") public void test() throws Exception { final URI uri = new URI(Resources.getResource("WeaponsHireSmall.xml").toExternalForm()); final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(uri, StandaloneCatalog.class); Assert.assertNotNull(catalog); final PlanRules rules = catalog.getPlanRules(); final PlanSpecifier specifier = new PlanSpecifier("Laser-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, "DEFAULT"); final PlanAlignmentCreate alignment = rules.getPlanCreateAlignment(specifier, catalog); Assert.assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION); final PlanSpecifier specifier2 = new PlanSpecifier("Extra-Ammo", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, "DEFAULT"); final PlanAlignmentCreate alignment2 = rules.getPlanCreateAlignment(specifier2, catalog); Assert.assertEquals(alignment2, PlanAlignmentCreate.START_OF_BUNDLE); } }
protected void assertionNull(final CaseChangeResult cr, final String fromProductName, final String toProductName, final ProductCategory fromProductCategory, final ProductCategory toProductCategory, final BillingPeriod fromBp, final BillingPeriod toBp, final String fromPriceListName, final String toPriceListName, final PhaseType phaseType, final StandaloneCatalog cat) { try { Assert.assertNull(cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType), new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName), cat)); } catch (CatalogApiException e) { Assert.fail("", e); } }
protected void assertion(final Result result, final CaseChangeResult cr, final String fromProductName, final String toProductName, final ProductCategory fromProductCategory, final ProductCategory toProductCategory, final BillingPeriod fromBp, final BillingPeriod toBp, final String fromPriceListName, final String toPriceListName, final PhaseType phaseType, final StandaloneCatalog cat) { try { Assert.assertEquals(result, cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType), new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName), cat)); } catch (CatalogApiException e) { Assert.fail("", e); } } }
protected void assertionException(final CaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final StandaloneCatalog cat) { try { cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat); Assert.fail("Expecting an exception"); } catch (CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_PRICE_LIST_NOT_FOUND.getCode()); } }
protected void assertionException(final CaseChangeResult cr, final String fromProductName, final String toProductName, final ProductCategory fromProductCategory, final ProductCategory toProductCategory, final BillingPeriod fromBp, final BillingPeriod toBp, final String fromPriceListName, final String toPriceListName, final PhaseType phaseType, final StandaloneCatalog cat) { try { cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType), new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName), cat); Assert.fail("Expecting an exception"); } catch (CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_PRICE_LIST_NOT_FOUND.getCode()); } }
@Test(groups = "slow") public void testAddonCreateWithBundleAlign() throws CatalogApiException, SubscriptionBaseApiException { final String aoProduct = "Telescopic-Scope"; final BillingPeriod aoTerm = BillingPeriod.MONTHLY; final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME; // This is just to double check our test catalog gives us what we want before we start the test final PlanSpecifier planSpecifier = new PlanSpecifier(aoProduct, ProductCategory.ADD_ON, aoTerm, aoPriceList); final PlanAlignmentCreate alignement = catalog.planCreateAlignment(planSpecifier, clock.getUTCNow()); assertEquals(alignement, PlanAlignmentCreate.START_OF_BUNDLE); testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignement); assertListenerStatus(); }
@Test(groups = "slow") public void testAddonCreateWithSubscriptionAlign() throws SubscriptionBaseApiException, CatalogApiException { final String aoProduct = "Laser-Scope"; final BillingPeriod aoTerm = BillingPeriod.MONTHLY; final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME; // This is just to double check our test catalog gives us what we want before we start the test final PlanSpecifier planSpecifier = new PlanSpecifier(aoProduct, ProductCategory.ADD_ON, aoTerm, aoPriceList); final PlanAlignmentCreate alignement = catalog.planCreateAlignment(planSpecifier, clock.getUTCNow()); assertEquals(alignement, PlanAlignmentCreate.START_OF_SUBSCRIPTION); testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignement); assertListenerStatus(); }
@Test(groups = "fast") public void testExistingPriceListIsKept() throws CatalogApiException { final DefaultProduct product1 = cat.getCurrentProducts()[0]; final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN); final PlanSpecifier to = new PlanSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.ANNUAL, priceList1.getName()); 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(), priceList1); }
@Test(groups = "fast") public void testCannotChangeToSamePlan() throws CatalogApiException { final DefaultProduct product1 = cat.getCurrentProducts()[0]; final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN); final PlanSpecifier to = new PlanSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName()); try { cat.getPlanRules().planChange(from, to, cat); Assert.fail("We did not see an exception when trying to change plan to the same plan"); } catch (IllegalPlanChange e) { // Correct - cannot change to the same plan } catch (CatalogApiException e) { Assert.fail("", e); } }
@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); } }
public PlanChangeResult planChange(final PlanPhaseSpecifier from, PlanSpecifier to, final StandaloneCatalog catalog) throws CatalogApiException { final DefaultPriceList toPriceList; if (to.getPriceListName() == null) { // Pricelist may be null because it is unspecified this is the principal use-case toPriceList = findPriceList(from.toPlanSpecifier(), catalog); to = new PlanSpecifier(to.getProductName(), to.getProductCategory(), to.getBillingPeriod(), toPriceList.getName()); } else { toPriceList = catalog.findCurrentPriceList(to.getPriceListName()); } final BillingActionPolicy policy = getPlanChangePolicy(from, to, catalog); if (policy == BillingActionPolicy.ILLEGAL) { throw new IllegalPlanChange(from, to); } final PlanAlignmentChange alignment = getPlanChangeAlignment(from, to, catalog); return new PlanChangeResult(toPriceList, policy, alignment); }
new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName()), cat); Assert.assertEquals(r1, Result.FOO); new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName()), cat); Assert.assertEquals(r2, Result.DIPSY);
new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.MONTHLY, priceList2.getName()), cat); new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.ANNUAL, priceList2.getName()), cat);