Search in sources :

Example 11 with DefaultProduct

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

the class TestCasePhase method testWildCardPhaseType.

@Test(groups = "fast")
public void testWildCardPhaseType() {
    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, BillingPeriod.MONTHLY, priceList, null, 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);
    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);
}
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 12 with DefaultProduct

use of org.killbill.billing.catalog.DefaultProduct 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 13 with DefaultProduct

use of org.killbill.billing.catalog.DefaultProduct 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 14 with DefaultProduct

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

the class TestXMLWriter method testAddPlan.

@Test(groups = "fast")
public void testAddPlan() throws Exception {
    final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class);
    final MutableStaticCatalog mutableCatalog = new DefaultMutableStaticCatalog(catalog);
    final DefaultProduct newProduct = new DefaultProduct();
    newProduct.setName("Dynamic");
    newProduct.setCatagory(ProductCategory.BASE);
    newProduct.initialize((StandaloneCatalog) mutableCatalog, new URI("dummy"));
    mutableCatalog.addProduct(newProduct);
    final DefaultPlanPhase trialPhase = new DefaultPlanPhase();
    trialPhase.setPhaseType(PhaseType.TRIAL);
    trialPhase.setDuration(new DefaultDuration().setUnit(TimeUnit.DAYS).setNumber(14));
    trialPhase.setFixed(new DefaultFixed().setFixedPrice(new DefaultInternationalPrice().setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.USD).setValue(BigDecimal.ZERO) })));
    final DefaultPlanPhase evergreenPhase = new DefaultPlanPhase();
    evergreenPhase.setPhaseType(PhaseType.EVERGREEN);
    evergreenPhase.setDuration(new DefaultDuration().setUnit(TimeUnit.MONTHS).setNumber(1));
    evergreenPhase.setRecurring(new DefaultRecurring().setBillingPeriod(BillingPeriod.MONTHLY).setRecurringPrice(new DefaultInternationalPrice().setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.USD).setValue(BigDecimal.TEN) })));
    final DefaultPlan newPlan = new DefaultPlan();
    newPlan.setName("dynamic-monthly");
    newPlan.setPriceListName(DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
    newPlan.setProduct(newProduct);
    newPlan.setInitialPhases(new DefaultPlanPhase[] { trialPhase });
    newPlan.setFinalPhase(evergreenPhase);
    // TODO Ordering breaks
    mutableCatalog.addPlan(newPlan);
    newPlan.initialize((StandaloneCatalog) mutableCatalog, new URI("dummy"));
    final String newCatalogStr = XMLWriter.writeXML((StandaloneCatalog) mutableCatalog, StandaloneCatalog.class);
    final StandaloneCatalog newCatalog = XMLLoader.getObjectFromStream(new URI("dummy"), new ByteArrayInputStream(newCatalogStr.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class);
    assertEquals(newCatalog.getCurrentPlans().size(), catalog.getCurrentPlans().size() + 1);
    final Plan plan = newCatalog.findCurrentPlan("dynamic-monthly");
    assertEquals(plan.getName(), "dynamic-monthly");
    assertEquals(plan.getPriceListName(), DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
    assertEquals(plan.getProduct().getName(), "Dynamic");
    assertEquals(plan.getProduct().getCategory(), ProductCategory.BASE);
    assertEquals(plan.getInitialPhases().length, 1);
    assertEquals(plan.getInitialPhases()[0].getName(), "dynamic-monthly-trial");
    assertEquals(plan.getInitialPhases()[0].getPhaseType(), PhaseType.TRIAL);
    assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices().length, 1);
    assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices()[0].getCurrency(), Currency.USD);
    assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices()[0].getValue(), BigDecimal.ZERO);
    assertEquals(plan.getFinalPhase().getName(), "dynamic-monthly-evergreen");
    assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
    assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 1);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getCurrency(), Currency.USD);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getValue(), BigDecimal.TEN);
}
Also used : DefaultPlanPhase(org.killbill.billing.catalog.DefaultPlanPhase) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultRecurring(org.killbill.billing.catalog.DefaultRecurring) DefaultInternationalPrice(org.killbill.billing.catalog.DefaultInternationalPrice) Plan(org.killbill.billing.catalog.api.Plan) DefaultPlan(org.killbill.billing.catalog.DefaultPlan) URI(java.net.URI) DefaultMutableStaticCatalog(org.killbill.billing.catalog.DefaultMutableStaticCatalog) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultPlan(org.killbill.billing.catalog.DefaultPlan) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) MutableStaticCatalog(org.killbill.billing.catalog.api.MutableStaticCatalog) DefaultMutableStaticCatalog(org.killbill.billing.catalog.DefaultMutableStaticCatalog) DefaultFixed(org.killbill.billing.catalog.DefaultFixed) DefaultDuration(org.killbill.billing.catalog.DefaultDuration) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) Test(org.testng.annotations.Test)

Example 15 with DefaultProduct

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

the class TestCase method testWildCardProductCategory.

@Test(groups = "fast")
public void testWildCardProductCategory() throws CatalogApiException {
    final MockCatalog cat = new MockCatalog();
    final DefaultProduct product = cat.getCurrentProduct(0);
    final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final DefaultCaseResult cr = new DefaultCaseResult(product, null, BillingPeriod.MONTHLY, 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.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);
}
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

DefaultProduct (org.killbill.billing.catalog.DefaultProduct)29 Test (org.testng.annotations.Test)27 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)26 MockCatalog (org.killbill.billing.catalog.MockCatalog)24 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)4 PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)4 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)2 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)2 IllegalPlanChange (org.killbill.billing.catalog.api.IllegalPlanChange)2 PlanChangeResult (org.killbill.billing.catalog.api.PlanChangeResult)2 Product (org.killbill.billing.catalog.api.Product)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URI (java.net.URI)1 DefaultDuration (org.killbill.billing.catalog.DefaultDuration)1 DefaultFixed (org.killbill.billing.catalog.DefaultFixed)1 DefaultInternationalPrice (org.killbill.billing.catalog.DefaultInternationalPrice)1 DefaultMutableStaticCatalog (org.killbill.billing.catalog.DefaultMutableStaticCatalog)1 DefaultPlan (org.killbill.billing.catalog.DefaultPlan)1 DefaultPlanPhase (org.killbill.billing.catalog.DefaultPlanPhase)1 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)1