public PlanRequestWrapper(final String planName) { this(new PlanSpecifier(planName)); }
protected void assertion(final Result result, final DefaultCaseResult 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, bp, priceListName), cat)); } }
public T getResult(final PlanPhaseSpecifier specifier, final StaticCatalog c) throws CatalogApiException { if ((phaseType == null || specifier.getPhaseType() == phaseType) && satisfiesCase(new PlanSpecifier(specifier), c)) { return getResult(); } return null; }
protected void assertionNull(final DefaultCaseResult 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, bp, priceListName), cat)); }
private List<TimedPhase> getTimedPhaseOnCreate(final DateTime subscriptionStartDate, final DateTime bundleStartDate, final Plan plan, @Nullable final PhaseType initialPhase, final Catalog catalog, final DateTime catalogEffectiveDate, final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException { final PlanSpecifier planSpecifier = new PlanSpecifier(plan.getName()); final DateTime planStartDate; final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, catalogEffectiveDate, subscriptionStartDate); switch (alignment) { case START_OF_SUBSCRIPTION: planStartDate = subscriptionStartDate; break; case START_OF_BUNDLE: planStartDate = bundleStartDate; break; default: throw new SubscriptionBaseError(String.format("Unknown PlanAlignmentCreate %s", alignment)); } return getPhaseAlignments(plan, initialPhase, planStartDate); }
protected void assertionNull(final DefaultCaseChangeResult 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, fromBp, fromPriceListName, phaseType), new PlanSpecifier(toProductName, toBp, toPriceListName), cat)); } catch (CatalogApiException e) { Assert.fail("", e); } }
protected void assertion(final Result result, final DefaultCaseChangeResult cr, final String fromProductName, final String toProductName, 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, fromBp, fromPriceListName, phaseType), new PlanSpecifier(toProductName, 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 DefaultPlanRules rules = catalog.getPlanRules(); final PlanSpecifier specifier = new PlanSpecifier("Laser-Scope", BillingPeriod.MONTHLY, "DEFAULT"); final PlanAlignmentCreate alignment = rules.getPlanCreateAlignment(specifier, catalog); Assert.assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION); final PlanSpecifier specifier2 = new PlanSpecifier("Extra-Ammo", BillingPeriod.MONTHLY, "DEFAULT"); final PlanAlignmentCreate alignment2 = rules.getPlanCreateAlignment(specifier2, catalog); Assert.assertEquals(alignment2, PlanAlignmentCreate.START_OF_BUNDLE); } }
protected void assertionException(final DefaultCaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final StandaloneCatalog cat) { try { cr.getResult(new PlanSpecifier(productName, bp, priceListName), 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, aoTerm, aoPriceList); final DateTime utcNow = clock.getUTCNow(); final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, utcNow, utcNow); assertEquals(alignment, PlanAlignmentCreate.START_OF_BUNDLE); testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignment); }
@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, aoTerm, aoPriceList); final DateTime utcNow = clock.getUTCNow(); final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, utcNow, utcNow); assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION); testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignment); }
protected void assertionException(final DefaultCaseChangeResult cr, final String fromProductName, final String toProductName, final BillingPeriod fromBp, final BillingPeriod toBp, final String fromPriceListName, final String toPriceListName, final PhaseType phaseType, final StandaloneCatalog cat) { try { cr.getResult(new PlanPhaseSpecifier(fromProductName, fromBp, fromPriceListName, phaseType), new PlanSpecifier(toProductName, 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 testCreatePlanInvalidProduct() throws Exception { final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class); final StaticCatalog standaloneCatalogWithPriceOverride = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalCallContext.getTenantRecordId(), internalCallContextFactory); try { final PlanSpecifier specWithNullProduct = new PlanSpecifier("INVALID", BillingPeriod.ANNUAL, "DEFAULT"); standaloneCatalogWithPriceOverride.createOrFindCurrentPlan(specWithNullProduct, null); Assert.fail(); } catch (final CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PRODUCT.getCode()); } } }
@Test(groups = "slow") public void testCreatePlanNoProduct() throws Exception { final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class); final StaticCatalog standaloneCatalogWithPriceOverride = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalCallContext.getTenantRecordId(), internalCallContextFactory); try { final PlanSpecifier specWithNullProduct = new PlanSpecifier(null, BillingPeriod.ANNUAL, "DEFAULT"); standaloneCatalogWithPriceOverride.createOrFindCurrentPlan(specWithNullProduct, null); Assert.fail(); } catch (final CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_NULL_PRODUCT_NAME.getCode()); } }
private enum WhichPhase { CURRENT, NEXT }
final PlanSpecifier spec = new PlanSpecifier("standard-monthly-67890"); final PlanPhasePriceOverridesWithCallContext overrides = Mockito.mock(PlanPhasePriceOverridesWithCallContext.class); Mockito.when(overrides.getCallContext()).thenReturn(callContext);
@Test(groups = "fast") public void testExistingPriceListIsKept() throws CatalogApiException { final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN); final PlanSpecifier to = new PlanSpecifier(product1.getName(), 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 testBaseCase() throws CatalogApiException { final DefaultProduct product1 = cat.getCurrentProduct(0); final DefaultProduct product2 = cat.getCurrentProduct(1); final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[0]; final PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN); final PlanSpecifier to = new PlanSpecifier(product2.getName(), 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, final PlanSpecifier to, final StaticCatalog catalog) throws CatalogApiException { final DefaultPriceList toPriceList = to.getPriceListName() != null ? (DefaultPriceList) catalog.findCurrentPricelist(to.getPriceListName()) : findPriceList(from, catalog); // If we use old scheme {product, billingPeriod, pricelist}, ensure pricelist is correct // (Pricelist may be null because if it is unspecified this is the principal use-case) final PlanSpecifier toWithPriceList = to.getPlanName() == null ? new PlanSpecifier(to.getProductName(), to.getBillingPeriod(), toPriceList.getName()) : to; final BillingActionPolicy policy = getPlanChangePolicy(from, toWithPriceList, catalog); if (policy == BillingActionPolicy.ILLEGAL) { throw new IllegalPlanChange(from, toWithPriceList); } final PlanAlignmentChange alignment = getPlanChangeAlignment(from, toWithPriceList, catalog); return new PlanChangeResult(toPriceList, policy, alignment); }
@Test(groups = "fast") public void testFindPlanWithDatesAndPlanSpecifier() throws Exception { final PlanSpecifier pistolMonthly = new PlanSpecifier("Pistol", BillingPeriod.MONTHLY, "DEFAULT"); final PlanSpecifier shotgunQuarterly = new PlanSpecifier("Shotgun", BillingPeriod.QUARTERLY, "DEFAULT");