@Override public PlanAlignmentCreate planCreateAlignment(final PlanSpecifier specifier) throws CatalogApiException { return planRules.getPlanCreateAlignment(specifier, this); }
@Override public PlanChangeResult planChange(final PlanPhaseSpecifier from, final PlanSpecifier to) throws CatalogApiException { return planRules.planChange(from, to, this); }
@Override public BillingAlignment billingAlignment(final PlanPhaseSpecifier planPhase) throws CatalogApiException { return planRules.getBillingAlignment(planPhase, this); }
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); }
@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}); }
@Override public BillingActionPolicy planChangePolicy(final PlanPhaseSpecifier from, final PlanSpecifier to) throws CatalogApiException { return planRules.getPlanChangePolicy(from, to, this); }
@Override public BillingActionPolicy planCancelPolicy(final PlanPhaseSpecifier planPhase) throws CatalogApiException { return planRules.getPlanCancelPolicy(planPhase, this); }
@Override public PlanAlignmentChange planChangeAlignment(final PlanPhaseSpecifier from, final PlanSpecifier to) throws CatalogApiException { return planRules.getPlanChangeAlignment(from, to, this); }
public void populateRules() { setPlanRules(new PlanRules()); }
@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); } }
@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 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); } }
@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); } }