@Override protected void configure() { final Catalog catalog = Mockito.mock(Catalog.class); final CatalogService catalogService = Mockito.mock(CatalogService.class); Mockito.when(catalogService.getCurrentCatalog()).thenReturn(new MockCatalog()); Mockito.when(catalogService.getFullCatalog()).thenReturn(catalog); bind(CatalogService.class).toInstance(catalogService); } }
@Override public BillingAlignment billingAlignment(final PlanPhaseSpecifier planPhase, final DateTime requestedDate) throws CatalogApiException { return billingAlignment(planPhase); }
@Override public boolean canCreatePlan(final PlanSpecifier specifier, final DateTime requestedDate) throws CatalogApiException { return canCreatePlan(specifier); }
@Test(groups = "fast") public void testOrder() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); final DefaultProduct product1 = cat.getCurrentProducts()[0]; final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultProduct product2 = cat.getCurrentProducts()[2]; final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
@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 testWildCardProduct() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); final DefaultProduct product = cat.getCurrentProducts()[0]; final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final CaseResult cr = new CaseResult( null, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertion(Result.FOO, cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, product.getName(), ProductCategory.ADD_ON, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), cat); assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat); }
@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 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); } }
@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 testFindPhase() throws CatalogApiException { final DefaultPlanPhase phaseTrial1 = new MockPlanPhase().setPhaseType(PhaseType.TRIAL); final DefaultPlanPhase phaseTrial2 = new MockPlanPhase().setPhaseType(PhaseType.TRIAL); final DefaultPlanPhase phaseDiscount1 = new MockPlanPhase().setPhaseType(PhaseType.DISCOUNT); final DefaultPlanPhase phaseDiscount2 = new MockPlanPhase().setPhaseType(PhaseType.DISCOUNT); final DefaultPlan plan1 = new MockPlan().setName("TestPlan1").setFinalPhase(phaseDiscount1).setInitialPhases(new DefaultPlanPhase[]{phaseTrial1}); final DefaultPlan plan2 = new MockPlan().setName("TestPlan2").setFinalPhase(phaseDiscount2).setInitialPhases(new DefaultPlanPhase[]{phaseTrial2}); phaseTrial1.setPlan(plan1); phaseTrial2.setPlan(plan2); phaseDiscount1.setPlan(plan1); phaseDiscount2.setPlan(plan2); final StandaloneCatalog cat = new MockCatalog().setPlans(new DefaultPlan[]{plan1, plan2}); Assert.assertEquals(cat.findCurrentPhase("TestPlan1-discount"), phaseDiscount1); Assert.assertEquals(cat.findCurrentPhase("TestPlan2-discount"), phaseDiscount2); Assert.assertEquals(cat.findCurrentPhase("TestPlan1-trial"), phaseTrial1); Assert.assertEquals(cat.findCurrentPhase("TestPlan2-trial"), phaseTrial2); } }
@Test(groups = "fast") public void testBillingEventsBundleAligned() throws CatalogApiException, AccountApiException { final Plan nextPlan = catalog.findPlan("Horn1USD", clock.getUTCNow()); final PlanPhase nextPhase = nextPlan.getAllPhases()[0]; final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(1); catalog.setBillingAlignment(BillingAlignment.BUNDLE); ((MockSubscription) subscription).setPlan(catalog.findPlan("PickupTrialEvergreen10USD", now)); final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); // The expected BCD is when the subscription started checkFirstEvent(events, nextPlan, subscription.getStartDate().getDayOfMonth(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString()); }
@Test(groups = "fast") public void testBillingEventsAutoInvoicingOffBundle() throws CatalogApiException, AccountApiException, TagApiException { final Plan nextPlan = catalog.findPlan("PickupTrialEvergreen10USD", clock.getUTCNow()); final PlanPhase nextPhase = nextPlan.getAllPhases()[1]; createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(32); tagInternalApi.addTag(bunId, ObjectType.BUNDLE, ControlTagType.AUTO_INVOICING_OFF.getId(), internalCallContext); final BillingEventSet events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); assertEquals(events.getSubscriptionIdsWithAutoInvoiceOff().size(), 1); assertEquals(events.getSubscriptionIdsWithAutoInvoiceOff().get(0), subId); assertEquals(events.size(), 0); }
@Override public Plan findPlan(final String productName, final BillingPeriod term, final String priceListName, final DateTime requestedDate, final DateTime subscriptionStartDate) throws CatalogApiException { return findCurrentPlan(productName, term, priceListName); }
@Override public Product findProduct(final String name, final DateTime requestedDate) throws CatalogApiException { return findCurrentProduct(name); }
@Override public PlanPhase findPhase(final String name, final DateTime requestedDate, final DateTime subscriptionStartDate) throws CatalogApiException { return findCurrentPhase(name); }
@Override public PriceList findPriceList(final String name, final DateTime requestedDate) throws CatalogApiException { return findCurrentPricelist(name); }
@Test(groups = "fast") public void testWildcardFromProduct() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); final DefaultProduct product1 = cat.getCurrentProducts()[0]; final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultProduct product2 = cat.getCurrentProducts()[2]; final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1]; cat.getCurrentProducts()[1].getName(), product2.getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, product1.getName(), cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.ANNUAL, BillingPeriod.MONTHLY, ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, cat.getCurrentProducts()[1].getName(), priceList2.getName(), PhaseType.EVERGREEN, cat); ProductCategory.BASE, ProductCategory.BASE, BillingPeriod.MONTHLY, BillingPeriod.MONTHLY, priceList1.getName(), cat.getCurrentProducts()[1].getName(), PhaseType.EVERGREEN, cat);
@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); }
@Test(groups = "fast") public void testWildCardPriceList() throws CatalogApiException { final MockCatalog cat = new MockCatalog(); final DefaultProduct product = cat.getCurrentProducts()[0]; final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME); final CaseResult cr = new CaseResult( product, ProductCategory.BASE, BillingPeriod.MONTHLY, null, Result.FOO); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, cat.getCurrentProducts()[1].getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, product.getName(), ProductCategory.ADD_ON, BillingPeriod.MONTHLY, priceList.getName(), cat); assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), cat); assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat); }
@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); }