Search in sources :

Example 1 with DefaultPriceList

use of org.killbill.billing.catalog.DefaultPriceList in project killbill by killbill.

the class DefaultPlanRules method planChange.

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);
}
Also used : BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) IllegalPlanChange(org.killbill.billing.catalog.api.IllegalPlanChange) PlanAlignmentChange(org.killbill.billing.catalog.api.PlanAlignmentChange) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Example 2 with DefaultPriceList

use of org.killbill.billing.catalog.DefaultPriceList in project killbill by killbill.

the class TestCase method testWildCardProduct.

@Test(groups = "fast")
public void testWildCardProduct() throws CatalogApiException {
    final MockCatalog cat = new MockCatalog();
    final DefaultProduct product = cat.getCurrentProduct(0);
    final DefaultPriceList priceList = (DefaultPriceList) cat.findPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final DefaultCaseResult cr = new DefaultCaseResult(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.getCurrentProduct(1).getName(), ProductCategory.BASE, 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);
}
Also used : MockCatalog(org.killbill.billing.catalog.MockCatalog) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) Test(org.testng.annotations.Test)

Example 3 with DefaultPriceList

use of org.killbill.billing.catalog.DefaultPriceList in project killbill by killbill.

the class TestCase method testWildCardBillingPeriod.

@Test(groups = "fast")
public void testWildCardBillingPeriod() throws CatalogApiException {
    final MockCatalog cat = new MockCatalog();
    final DefaultProduct product = cat.getCurrentProduct(0);
    final DefaultPriceList priceList = (DefaultPriceList) cat.findPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final DefaultCaseResult cr = new DefaultCaseResult(product, ProductCategory.BASE, null, priceList, Result.FOO);
    assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
    assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), cat);
    assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.ANNUAL, priceList.getName(), cat);
    assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat);
}
Also used : MockCatalog(org.killbill.billing.catalog.MockCatalog) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) Test(org.testng.annotations.Test)

Example 4 with DefaultPriceList

use of org.killbill.billing.catalog.DefaultPriceList in project killbill by killbill.

the class TestCase method testCaseOrder.

@Test
public void testCaseOrder() throws CatalogApiException {
    final MockCatalog cat = new MockCatalog();
    final DefaultProduct product = cat.getCurrentProduct(0);
    final DefaultPriceList priceList = (DefaultPriceList) cat.findPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final DefaultCaseResult cr0 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, Result.FOO);
    final DefaultCaseResult cr1 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, Result.BAR);
    final DefaultCaseResult cr2 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.ANNUAL, priceList, Result.DIPSY);
    final DefaultCaseResult cr3 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.ANNUAL, priceList, Result.LALA);
    final Result r1 = DefaultCase.getResult(new DefaultCaseResult[] { cr0, cr1, cr2, cr3 }, new PlanSpecifier(product.getName(), BillingPeriod.MONTHLY, priceList.getName()), cat);
    Assert.assertEquals(r1, Result.FOO);
    final Result r2 = DefaultCase.getResult(new DefaultCaseResult[] { cr0, cr1, cr2 }, new PlanSpecifier(product.getName(), BillingPeriod.ANNUAL, priceList.getName()), cat);
    Assert.assertEquals(r2, Result.DIPSY);
}
Also used : MockCatalog(org.killbill.billing.catalog.MockCatalog) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 5 with DefaultPriceList

use of org.killbill.billing.catalog.DefaultPriceList in project killbill by killbill.

the class TestCasePhase method testWildCardBillingPeriod.

@Test(groups = "fast")
public void testWildCardBillingPeriod() {
    final MockCatalog cat = new MockCatalog();
    final DefaultProduct product = cat.getCurrentProduct(0);
    final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
    final DefaultCaseResult cr = new DefaultCaseResult(product, ProductCategory.BASE, null, priceList, PhaseType.EVERGREEN, Result.FOO);
    assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat);
    assertionNull(cr, cat.getCurrentProduct(1).getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN, cat);
    assertion(Result.FOO, 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);
}
Also used : MockCatalog(org.killbill.billing.catalog.MockCatalog) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) Test(org.testng.annotations.Test)

Aggregations

DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)32 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)26 Test (org.testng.annotations.Test)26 MockCatalog (org.killbill.billing.catalog.MockCatalog)25 PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)6 IllegalPlanChange (org.killbill.billing.catalog.api.IllegalPlanChange)4 PlanChangeResult (org.killbill.billing.catalog.api.PlanChangeResult)4 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)4 BillingActionPolicy (org.killbill.billing.catalog.api.BillingActionPolicy)2 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)2 PlanAlignmentChange (org.killbill.billing.catalog.api.PlanAlignmentChange)2 BeforeMethod (org.testng.annotations.BeforeMethod)1