Search in sources :

Example 21 with StandaloneCatalog

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

the class TestXMLWriter method testVersionedCatalog.

// Verifies we can generate the XML associated with a VersionedCatalog
@Test(groups = "fast")
public void testVersionedCatalog() throws Exception {
    final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class);
    final VersionedCatalog versionedCatalog = new VersionedCatalog(clock);
    versionedCatalog.add(catalog);
    final String newCatalogStr = XMLWriter.writeXML(versionedCatalog, VersionedCatalog.class);
//System.err.println(newCatalogStr);
}
Also used : VersionedCatalog(org.killbill.billing.catalog.VersionedCatalog) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) Test(org.testng.annotations.Test)

Example 22 with StandaloneCatalog

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

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

the class TestCatalogPluginMapping method testMappingFromExistingCatalog.

@Test(groups = "fast")
public void testMappingFromExistingCatalog() throws Exception {
    final StandaloneCatalog inputCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class);
    final StandalonePluginCatalog pluginCatalog = buildStandalonePluginCatalog(inputCatalog);
    final StandaloneCatalogMapper mapper = new StandaloneCatalogMapper(inputCatalog.getCatalogName(), inputCatalog.getRecurringBillingMode());
    final StandaloneCatalog output = mapper.toStandaloneCatalog(pluginCatalog, inputCatalog.getCatalogURI());
    Assert.assertEquals(output, inputCatalog);
}
Also used : StandalonePluginCatalog(org.killbill.billing.catalog.plugin.api.StandalonePluginCatalog) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) Test(org.testng.annotations.Test)

Example 24 with StandaloneCatalog

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

the class TestVersionedCatalogLoader method testLoad.

@Test(groups = "fast")
public void testLoad() throws IOException, SAXException, InvalidConfigException, JAXBException, TransformerException, URISyntaxException, CatalogApiException {
    final VersionedCatalog c = loader.loadDefaultCatalog(Resources.getResource("versionedCatalog").toString());
    Assert.assertEquals(c.size(), 3);
    final Iterator<StandaloneCatalog> it = c.iterator();
    DateTime dt = new DateTime("2011-01-01T00:00:00+00:00");
    Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate());
    dt = new DateTime("2011-02-02T00:00:00+00:00");
    Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate());
    dt = new DateTime("2011-03-03T00:00:00+00:00");
    Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate());
}
Also used : VersionedCatalog(org.killbill.billing.catalog.VersionedCatalog) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)24 Test (org.testng.annotations.Test)15 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)11 BigDecimal (java.math.BigDecimal)8 VersionedCatalog (org.killbill.billing.catalog.VersionedCatalog)8 URI (java.net.URI)6 DateTime (org.joda.time.DateTime)5 StandaloneCatalogWithPriceOverride (org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)5 Usage (org.killbill.billing.catalog.api.Usage)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Plan (org.killbill.billing.catalog.api.Plan)4 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 JAXBException (javax.xml.bind.JAXBException)3 TransformerException (javax.xml.transform.TransformerException)3 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)3 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)3 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)3 InvalidConfigException (org.killbill.billing.catalog.api.InvalidConfigException)3 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)3