Search in sources :

Example 16 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestStandaloneCatalogWithPriceOverride method testCreatePlanNoProduct.

@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());
    }
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 17 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestLoadRules method test.

@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);
}
Also used : StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) URI(java.net.URI) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 18 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestPlanRules method testExistingPriceListIsKept.

@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);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) IllegalPlanChange(org.killbill.billing.catalog.api.IllegalPlanChange) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 19 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestPlanRules method testBaseCase.

@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);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) IllegalPlanChange(org.killbill.billing.catalog.api.IllegalPlanChange) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 20 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestCase method assertionException.

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());
    }
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Aggregations

PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)39 Test (org.testng.annotations.Test)28 DateTime (org.joda.time.DateTime)16 Interval (org.joda.time.Interval)11 LocalDate (org.joda.time.LocalDate)9 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)8 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)7 Duration (org.killbill.billing.catalog.api.Duration)7 Account (org.killbill.billing.account.api.Account)6 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)6 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)6 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)5 Plan (org.killbill.billing.catalog.api.Plan)5 ArrayList (java.util.ArrayList)4 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)4 PlanAlignmentCreate (org.killbill.billing.catalog.api.PlanAlignmentCreate)4 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)4 BigDecimal (java.math.BigDecimal)3 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)3