use of org.killbill.billing.catalog.api.MutableStaticCatalog in project killbill by killbill.
the class TestCatalogUpdater method enhanceOriginalCatalogForInvalidTestCases.
private StandaloneCatalog enhanceOriginalCatalogForInvalidTestCases(final String catalogName) throws Exception {
final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource(catalogName).toExternalForm(), StandaloneCatalog.class);
final MutableStaticCatalog mutableCatalog = new DefaultMutableStaticCatalog(catalog);
final DefaultProduct newProduct1 = new DefaultProduct();
newProduct1.setName("Dynamic");
newProduct1.setCatagory(ProductCategory.BASE);
newProduct1.initialize((StandaloneCatalog) mutableCatalog);
mutableCatalog.addProduct(newProduct1);
final DefaultPlanPhase discountPhase1 = new DefaultPlanPhase();
discountPhase1.setPhaseType(PhaseType.DISCOUNT);
discountPhase1.setDuration(new DefaultDuration().setUnit(TimeUnit.DAYS).setNumber(14));
discountPhase1.setRecurring(new DefaultRecurring().setBillingPeriod(BillingPeriod.MONTHLY).setRecurringPrice(new DefaultInternationalPrice().setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.USD).setValue(BigDecimal.TEN) })));
final DefaultPlanPhase evergreenPhase1 = new DefaultPlanPhase();
evergreenPhase1.setPhaseType(PhaseType.EVERGREEN);
evergreenPhase1.setDuration(new DefaultDuration().setUnit(TimeUnit.UNLIMITED));
evergreenPhase1.setRecurring(new DefaultRecurring().setBillingPeriod(BillingPeriod.MONTHLY).setRecurringPrice(new DefaultInternationalPrice().setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.USD).setValue(BigDecimal.TEN) })));
// Add a Plan with a DISCOUNT phase
final DefaultPlan newPlan1 = new DefaultPlan();
newPlan1.setName("dynamic-monthly");
newPlan1.setPriceListName(DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
newPlan1.setProduct(newProduct1);
newPlan1.setInitialPhases(new DefaultPlanPhase[] { discountPhase1 });
newPlan1.setFinalPhase(evergreenPhase1);
newPlan1.initialize((StandaloneCatalog) mutableCatalog);
mutableCatalog.addPlan(newPlan1);
final DefaultProduct newProduct2 = new DefaultProduct();
newProduct2.setName("SuperDynamic");
newProduct2.setCatagory(ProductCategory.BASE);
newProduct2.initialize((StandaloneCatalog) mutableCatalog);
mutableCatalog.addProduct(newProduct2);
// Add a Plan with a FIXEDTERM phase
final DefaultPlanPhase fixedterm2 = new DefaultPlanPhase();
fixedterm2.setPhaseType(PhaseType.FIXEDTERM);
fixedterm2.setDuration(new DefaultDuration().setUnit(TimeUnit.MONTHS).setNumber(3));
fixedterm2.setRecurring(new DefaultRecurring().setBillingPeriod(BillingPeriod.MONTHLY).setRecurringPrice(new DefaultInternationalPrice().setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.USD).setValue(BigDecimal.TEN) })));
final DefaultPlan newPlan2 = new DefaultPlan();
newPlan2.setName("superdynamic-fixedterm");
newPlan2.setPriceListName(DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
newPlan2.setProduct(newProduct2);
newPlan2.setFinalPhase(fixedterm2);
newPlan2.initialize((StandaloneCatalog) mutableCatalog);
mutableCatalog.addPlan(newPlan2);
final String newCatalogStr = XMLWriter.writeXML((StandaloneCatalog) mutableCatalog, StandaloneCatalog.class);
return XMLLoader.getObjectFromStream(new ByteArrayInputStream(newCatalogStr.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class);
}
use of org.killbill.billing.catalog.api.MutableStaticCatalog in project killbill by killbill.
the class TestXMLWriter method testAddPlan.
@Test(groups = "fast")
public void testAddPlan() throws Exception {
final StandaloneCatalog catalog = getCatalog("SpyCarBasic.xml");
final MutableStaticCatalog mutableCatalog = new DefaultMutableStaticCatalog(catalog);
final DefaultProduct newProduct = new DefaultProduct();
newProduct.setName("Dynamic");
newProduct.setCatagory(ProductCategory.BASE);
newProduct.initialize((StandaloneCatalog) mutableCatalog);
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.UNLIMITED));
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);
newPlan.setRecurringBillingMode(BillingMode.IN_ADVANCE);
newPlan.initialize((StandaloneCatalog) mutableCatalog);
mutableCatalog.addPlan(newPlan);
final String newCatalogStr = XMLWriter.writeXML((StandaloneCatalog) mutableCatalog, StandaloneCatalog.class);
final StandaloneCatalog newCatalog = XMLLoader.getObjectFromStream(new ByteArrayInputStream(newCatalogStr.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class);
assertEquals(newCatalog.getPlans().size(), catalog.getPlans().size() + 1);
final Plan plan = newCatalog.findPlan("dynamic-monthly");
assertEquals(plan.getName(), "dynamic-monthly");
assertEquals(plan.getPriceList().getName(), 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);
}
use of org.killbill.billing.catalog.api.MutableStaticCatalog in project killbill by killbill.
the class TestCatalogUpdater method testPlanWithNonFinalFixedTermPhase.
@Test(groups = "fast")
public void testPlanWithNonFinalFixedTermPhase() throws Exception {
final StandaloneCatalog catalog = getCatalog("SpyCarBasic.xml");
final MutableStaticCatalog mutableCatalog = new DefaultMutableStaticCatalog(catalog);
final DefaultProduct newProduct = new DefaultProduct();
newProduct.setName("Something");
newProduct.setCatagory(ProductCategory.BASE);
newProduct.initialize((StandaloneCatalog) mutableCatalog);
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) })));
// Add a Plan with a FIXEDTERM phase
final DefaultPlanPhase fixedTermPhase = new DefaultPlanPhase();
fixedTermPhase.setPhaseType(PhaseType.FIXEDTERM);
fixedTermPhase.setDuration(new DefaultDuration().setUnit(TimeUnit.MONTHS).setNumber(3));
fixedTermPhase.setRecurring(new DefaultRecurring().setBillingPeriod(BillingPeriod.MONTHLY).setRecurringPrice(new DefaultInternationalPrice().setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.USD).setValue(BigDecimal.TEN) })));
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("something-with-fixed-term");
newPlan.setPriceListName(DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
newPlan.setProduct(newProduct);
newPlan.setInitialPhases(new DefaultPlanPhase[] { trialPhase, fixedTermPhase });
newPlan.setFinalPhase(fixedTermPhase);
newPlan.initialize((StandaloneCatalog) mutableCatalog);
mutableCatalog.addPlan(newPlan);
final String newCatalogStr = XMLWriter.writeXML((StandaloneCatalog) mutableCatalog, StandaloneCatalog.class);
final StandaloneCatalog newCatalog = XMLLoader.getObjectFromStream(new ByteArrayInputStream(newCatalogStr.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class);
final DefaultPlan targetPlan = newCatalog.findPlan("something-with-fixed-term");
Assert.assertEquals(targetPlan.getInitialPhases().length, 2);
Assert.assertEquals(targetPlan.getInitialPhases()[1].getPhaseType(), PhaseType.FIXEDTERM);
}
Aggregations