use of org.killbill.billing.catalog.api.SimplePlanDescriptor in project killbill by killbill.
the class TestCatalogUpdater method testAddExistingPlanWithNewCurrency.
@Test(groups = "fast")
public void testAddExistingPlanWithNewCurrency() throws Exception {
final StandaloneCatalog originalCatalog = getCatalog("SpyCarBasic.xml");
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1);
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName());
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3);
final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog);
final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of());
catalogUpdater.addSimplePlanDescriptor(desc);
final StandaloneCatalog catalog = catalogUpdater.getCatalog();
final Plan plan = catalog.findPlan("standard-monthly");
assertEquals(plan.getName(), "standard-monthly");
assertEquals(plan.getInitialPhases().length, 1);
assertEquals(plan.getInitialPhases()[0].getPhaseType(), PhaseType.TRIAL);
assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices().length, 0);
assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrice(Currency.EUR), BigDecimal.ZERO);
assertEquals(plan.getInitialPhases()[0].getName(), "standard-monthly-trial");
assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
assertNull(plan.getFinalPhase().getFixed());
assertEquals(plan.getFinalPhase().getName(), "standard-monthly-evergreen");
assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 3);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrice(Currency.EUR), BigDecimal.TEN);
}
use of org.killbill.billing.catalog.api.SimplePlanDescriptor in project killbill by killbill.
the class TestCatalogUpdater method testAddNoTrialPlanOnFirstCatalog.
@Test(groups = "fast")
public void testAddNoTrialPlanOnFirstCatalog() throws CatalogApiException {
final DateTime now = clock.getUTCNow();
final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
final CatalogUpdater catalogUpdater = new CatalogUpdater(now, desc.getCurrency());
catalogUpdater.addSimplePlanDescriptor(desc);
final StandaloneCatalog catalog = catalogUpdater.getCatalog();
assertEquals(catalog.getProducts().size(), 1);
final Product product = catalog.getProducts().iterator().next();
assertEquals(product.getName(), "Foo");
assertEquals(product.getCategory(), ProductCategory.BASE);
assertEquals(catalog.getPlans().size(), 1);
final Plan plan = catalog.findPlan("foo-monthly");
assertEquals(plan.getName(), "foo-monthly");
assertEquals(plan.getInitialPhases().length, 0);
assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
assertNull(plan.getFinalPhase().getFixed());
assertEquals(plan.getFinalPhase().getName(), "foo-monthly-evergreen");
assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 1);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getValue(), BigDecimal.TEN);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getCurrency(), Currency.EUR);
assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1);
final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0);
assertEquals(priceList.getName(), new PriceListDefault().getName());
assertEquals(priceList.getPlans().size(), 1);
assertEquals(priceList.getPlans().iterator().next().getName(), "foo-monthly");
}
use of org.killbill.billing.catalog.api.SimplePlanDescriptor in project killbill by killbill.
the class TestCatalogUpdater method testAddPlanOnExistingCatalog.
@Test(groups = "fast")
public void testAddPlanOnExistingCatalog() throws Exception {
final StandaloneCatalog originalCatalog = getCatalog("SpyCarBasic.xml");
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1);
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName());
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3);
final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog);
final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-annual", "Standard", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
catalogUpdater.addSimplePlanDescriptor(desc);
final StandaloneCatalog catalog = catalogUpdater.getCatalog();
final Plan plan = catalog.findPlan("standard-annual");
assertEquals(plan.getName(), "standard-annual");
assertEquals(plan.getInitialPhases().length, 0);
assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
assertNull(plan.getFinalPhase().getFixed());
assertEquals(plan.getFinalPhase().getName(), "standard-annual-evergreen");
assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 1);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getValue(), BigDecimal.TEN);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getCurrency(), Currency.USD);
assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1);
final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0);
assertEquals(priceList.getName(), new PriceListDefault().getName());
assertEquals(priceList.getPlans().size(), 4);
}
use of org.killbill.billing.catalog.api.SimplePlanDescriptor in project killbill by killbill.
the class TestCatalogUpdater method testInvalidPlanDescriptors.
@Test(groups = "fast")
public void testInvalidPlanDescriptors() throws Exception {
final StandaloneCatalog originalCatalog = enhanceOriginalCatalogForInvalidTestCases("org/killbill/billing/catalog/SpyCarBasic.xml");
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1);
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName());
assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 5);
CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog);
// Existing Plan has a 30 days trial => try with no TRIAL
SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.DAYS, ImmutableList.<String>of());
addBadSimplePlanDescriptor(catalogUpdater, desc);
// Existing Plan has a 30 days trial => try different trial length
desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
addBadSimplePlanDescriptor(catalogUpdater, desc);
// Existing Plan has a 30 days trial => try different trial unit
desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.MONTHS, ImmutableList.<String>of());
addBadSimplePlanDescriptor(catalogUpdater, desc);
// Existing Plan has a MONTHLY recurring => try with ANNUAL BillingPeriod
desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.ANNUAL, 30, TimeUnit.DAYS, ImmutableList.<String>of());
addBadSimplePlanDescriptor(catalogUpdater, desc);
// Existing Plan has a discount phase
desc = new DefaultSimplePlanDescriptor("dynamic-monthly", "Dynamic", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.MONTHS, ImmutableList.<String>of());
addBadSimplePlanDescriptor(catalogUpdater, desc);
// Existing Plan has final fixedterm phase
desc = new DefaultSimplePlanDescriptor("superdynamic-fixedterm", "SuperDynamic", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of());
addBadSimplePlanDescriptor(catalogUpdater, desc);
// Existing Plan a different recurring price ($100)
desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of());
addBadSimplePlanDescriptor(catalogUpdater, desc);
}
use of org.killbill.billing.catalog.api.SimplePlanDescriptor in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST.
@Test(groups = "slow")
public void testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST() throws Exception {
// Create a per-tenant catalog with one plan
final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("zoe-monthly", "Zoe", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
catalogUserApi.addSimplePlan(desc1, init, testCallContext);
StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
assertEquals(catalog.getPlans().size(), 1);
final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("zoe-14-monthly", "Zoe", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
catalogUserApi.addSimplePlan(desc2, init, testCallContext);
catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
assertEquals(catalog.getPlans().size(), 2);
try {
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Zoe", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), UUID.randomUUID().toString(), null, null, false, true, ImmutableList.<PluginProperty>of(), testCallContext);
fail("Creating entitlement should fail");
} catch (final EntitlementApiException e) {
assertEquals(e.getCode(), ErrorCode.CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST.getCode());
}
}
Aggregations