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); }
public IllegalPlanChange(final Throwable cause, final PlanPhaseSpecifier from, final PlanSpecifier to) { super(cause, ErrorCode.CAT_ILLEGAL_CHANGE_REQUEST, from.getProductName(), from.getBillingPeriod(), from.getPriceListName(), to.getProductName(), to.getBillingPeriod(), to.getPriceListName()); }
/** * @return the {@code PlanSpecifier} */ public PlanSpecifier toPlanSpecifier() { return new PlanSpecifier(productName, productCategory, billingPeriod, priceListName); } }
private DefaultPriceList findPriceList(final PlanSpecifier specifier, final StandaloneCatalog catalog) throws CatalogApiException { DefaultPriceList result = Case.getResult(priceListCase, specifier, catalog); if (result == null) { result = catalog.findCurrentPriceList(specifier.getPriceListName()); } return result; }
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; }
@Override public boolean canCreatePlan(final PlanSpecifier specifier) throws CatalogApiException { final Product product = findCurrentProduct(specifier.getProductName()); final Plan plan = findCurrentPlan(specifier.getProductName(), specifier.getBillingPeriod(), specifier.getPriceListName()); final DefaultPriceList priceList = findCurrentPriceList(specifier.getPriceListName()); return (!product.isRetired()) && (!plan.isRetired()) && (!priceList.isRetired()); }
protected boolean satisfiesCase(final PlanSpecifier planPhase, final StandaloneCatalog c) throws CatalogApiException { return (getProduct() == null || getProduct().equals(c.findCurrentProduct(planPhase.getProductName()))) && (getProductCategory() == null || getProductCategory().equals(planPhase.getProductCategory())) && (getBillingPeriod() == null || getBillingPeriod().equals(planPhase.getBillingPeriod())) && (getPriceList() == null || getPriceList().equals(c.findCurrentPriceList(planPhase.getPriceListName()))); }
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)); } }
public BillingActionPolicy getPlanChangePolicy(final PlanPhaseSpecifier from, final PlanSpecifier to, final StandaloneCatalog catalog) throws CatalogApiException { if (from.getProductName().equals(to.getProductName()) && from.getBillingPeriod() == to.getBillingPeriod() && from.getPriceListName().equals(to.getPriceListName())) { return BillingActionPolicy.ILLEGAL; } //Plan toPlan = catalog.findPlan() return CaseChange.getResult(changeCase, from, to, catalog); }
public T getResult(final PlanPhaseSpecifier from, final PlanSpecifier to, final StandaloneCatalog catalog) throws CatalogApiException { if ( (phaseType == null || from.getPhaseType() == phaseType) && (fromProduct == null || fromProduct.equals(catalog.findCurrentProduct(from.getProductName()))) && (fromProductCategory == null || fromProductCategory.equals(from.getProductCategory())) && (fromBillingPeriod == null || fromBillingPeriod.equals(from.getBillingPeriod())) && (toProduct == null || toProduct.equals(catalog.findCurrentProduct(to.getProductName()))) && (toProductCategory == null || toProductCategory.equals(to.getProductCategory())) && (toBillingPeriod == null || toBillingPeriod.equals(to.getBillingPeriod())) && (fromPriceList == null || fromPriceList.equals(catalog.findCurrentPriceList(from.getPriceListName()))) && (toPriceList == null || toPriceList.equals(catalog.findCurrentPriceList(to.getPriceListName()))) ) { return getResult(); } return null; }
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)); }
public IllegalPlanChange(final PlanPhaseSpecifier from, final PlanSpecifier to) { super(ErrorCode.CAT_ILLEGAL_CHANGE_REQUEST, from.getProductName(), from.getBillingPeriod(), from.getPriceListName(), to.getProductName(), to.getBillingPeriod(), to.getPriceListName()); }
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); } }
@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 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); }