Search in sources :

Example 16 with StandaloneCatalog

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

the class TestCatalogOverrideDao method testOverrideTwoOutOfThreePhases.

@Test(groups = "slow")
public void testOverrideTwoOutOfThreePhases() throws Exception {
    final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class);
    final Plan plan = catalog.findCurrentPlan("discount-standard-monthly");
    final PlanPhasePriceOverride[] resolvedOverrides = new PlanPhasePriceOverride[plan.getAllPhases().length];
    resolvedOverrides[0] = new DefaultPlanPhasePriceOverride(plan.getAllPhases()[0].getName(), Currency.USD, BigDecimal.TEN, null);
    resolvedOverrides[1] = null;
    resolvedOverrides[2] = new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), Currency.USD, null, new BigDecimal("348.64"));
    final CatalogOverridePlanDefinitionModelDao newPlan = catalogOverrideDao.getOrCreateOverridePlanDefinition(plan.getName(), new DateTime(catalog.getEffectiveDate()), resolvedOverrides, internalCallContext);
    assertEquals(newPlan.getParentPlanName(), "discount-standard-monthly");
    assertTrue(newPlan.getIsActive());
    final List<CatalogOverridePhaseDefinitionModelDao> phases = catalogOverrideDao.getOverriddenPlanPhases(newPlan.getRecordId(), internalCallContext);
    assertEquals(phases.size(), 2);
}
Also used : DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) Plan(org.killbill.billing.catalog.api.Plan) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) Test(org.testng.annotations.Test)

Example 17 with StandaloneCatalog

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

the class VersionedCatalogLoader method load.

public VersionedCatalog load(final Iterable<String> catalogXMLs, final boolean filterTemplateCatalog, final Long tenantRecordId) throws CatalogApiException {
    final VersionedCatalog result = new VersionedCatalog(clock);
    final URI uri;
    try {
        uri = new URI("/tenantCatalog");
        for (final String cur : catalogXMLs) {
            final InputStream curCatalogStream = new ByteArrayInputStream(cur.getBytes());
            final StandaloneCatalog catalog = XMLLoader.getObjectFromStream(uri, curCatalogStream, StandaloneCatalog.class);
            if (!filterTemplateCatalog || !catalog.isTemplateCatalog()) {
                result.add(new StandaloneCatalogWithPriceOverride(catalog, priceOverride, tenantRecordId, internalCallContextFactory));
            }
        }
        // Perform initialization and validation for VersionedCatalog
        XMLLoader.initializeAndValidate(uri, result);
        return result;
    } catch (final ValidationException e) {
        logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
        throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, tenantRecordId);
    } catch (final JAXBException e) {
        logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
        throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, tenantRecordId);
    } catch (final IOException e) {
        logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
        throw new IllegalStateException(e);
    } catch (final TransformerException e) {
        logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
        throw new IllegalStateException(e);
    } catch (final URISyntaxException e) {
        logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
        throw new IllegalStateException(e);
    } catch (final SAXException e) {
        logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
        throw new IllegalStateException(e);
    } catch (final InvalidConfigException e) {
        logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
        throw new IllegalStateException(e);
    }
}
Also used : StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride) ValidationException(org.killbill.xmlloader.ValidationException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) InvalidConfigException(org.killbill.billing.catalog.api.InvalidConfigException) URI(java.net.URI) SAXException(org.xml.sax.SAXException) VersionedCatalog(org.killbill.billing.catalog.VersionedCatalog) ByteArrayInputStream(java.io.ByteArrayInputStream) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) TransformerException(javax.xml.transform.TransformerException)

Example 18 with StandaloneCatalog

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

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

the class TestXMLReader method testUsageConsumableInAdvanceTopUp.

@Test(groups = "fast")
public void testUsageConsumableInAdvanceTopUp() {
    try {
        final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("UsageExperimental.xml").toExternalForm(), StandaloneCatalog.class);
        final Usage[] usages = getUsages(catalog, "consumable-in-advance-topup");
        assertEquals(usages.length, 1);
        final Usage usage = usages[0];
        assertEquals(usage.getName(), "consumable-in-advance-topup-usage1");
        assertEquals(usage.getBillingPeriod(), BillingPeriod.NO_BILLING_PERIOD);
        assertEquals(usage.getUsageType(), UsageType.CONSUMABLE);
        assertEquals(usage.getBillingMode(), BillingMode.IN_ADVANCE);
        assertEquals(usage.getLimits().length, 0);
        assertEquals(usage.getTiers().length, 0);
        assertEquals(usage.getBlocks().length, 1);
        assertEquals(usage.getBlocks()[0].getUnit().getName(), "fastrack-tokens");
        assertEquals(usage.getBlocks()[0].getSize(), new Double("10"));
        assertEquals(usage.getBlocks()[0].getPrice().getPrices().length, 1);
        assertEquals(usage.getBlocks()[0].getPrice().getPrices()[0].getCurrency(), Currency.BTC);
        assertEquals(usage.getBlocks()[0].getPrice().getPrices()[0].getValue(), new BigDecimal("0.10"));
        assertEquals(usage.getBlocks()[0].getMinTopUpCredit(), new Double("5"));
    } catch (Exception e) {
        Assert.fail(e.toString());
    }
}
Also used : Usage(org.killbill.billing.catalog.api.Usage) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) BigDecimal(java.math.BigDecimal) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) Test(org.testng.annotations.Test)

Example 20 with StandaloneCatalog

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

the class TestXMLReader method testUsageCapacityInArrear.

@Test(groups = "fast")
public void testUsageCapacityInArrear() {
    try {
        final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("UsageExperimental.xml").toExternalForm(), StandaloneCatalog.class);
        final Usage[] usages = getUsages(catalog, "capacity-in-arrear");
        assertEquals(usages.length, 1);
        final Usage usage = usages[0];
        assertEquals(usage.getName(), "capacity-in-arrear-usage1");
        assertEquals(usage.getBillingPeriod(), BillingPeriod.MONTHLY);
        assertEquals(usage.getUsageType(), UsageType.CAPACITY);
        assertEquals(usage.getBillingMode(), BillingMode.IN_ARREAR);
        assertEquals(usage.getLimits().length, 0);
        assertEquals(usage.getBlocks().length, 0);
        assertEquals(usage.getTiers().length, 2);
        assertEquals(usage.getTiers()[0].getLimits().length, 2);
        assertEquals(usage.getTiers()[0].getLimits()[0].getUnit().getName(), "bandwith-meg-sec");
        assertEquals(usage.getTiers()[0].getLimits()[0].getMax(), new Double("100"));
        assertEquals(usage.getTiers()[0].getLimits()[1].getUnit().getName(), "members");
        assertEquals(usage.getTiers()[0].getLimits()[1].getMax(), new Double("500"));
        assertEquals(usage.getTiers()[0].getFixedPrice().getPrices().length, 1);
        assertEquals(usage.getTiers()[0].getFixedPrice().getPrices()[0].getCurrency(), Currency.BTC);
        assertEquals(usage.getTiers()[0].getFixedPrice().getPrices()[0].getValue(), new BigDecimal("0.007"));
        assertEquals(usage.getTiers()[0].getRecurringPrice().getPrices().length, 1);
        assertEquals(usage.getTiers()[0].getRecurringPrice().getPrices()[0].getCurrency(), Currency.BTC);
        assertEquals(usage.getTiers()[0].getRecurringPrice().getPrices()[0].getValue(), new BigDecimal("0.8"));
        assertEquals(usage.getTiers()[1].getLimits()[0].getUnit().getName(), "bandwith-meg-sec");
        assertEquals(usage.getTiers()[1].getLimits()[0].getMax(), new Double("100"));
        assertEquals(usage.getTiers()[1].getLimits()[1].getUnit().getName(), "members");
        assertEquals(usage.getTiers()[1].getLimits()[1].getMax(), new Double("1000"));
        assertEquals(usage.getTiers()[1].getFixedPrice().getPrices().length, 1);
        assertEquals(usage.getTiers()[1].getFixedPrice().getPrices()[0].getCurrency(), Currency.BTC);
        assertEquals(usage.getTiers()[1].getFixedPrice().getPrices()[0].getValue(), new BigDecimal("0.4"));
        assertEquals(usage.getTiers()[1].getRecurringPrice().getPrices().length, 1);
        assertEquals(usage.getTiers()[1].getRecurringPrice().getPrices()[0].getCurrency(), Currency.BTC);
        assertEquals(usage.getTiers()[1].getRecurringPrice().getPrices()[0].getValue(), new BigDecimal("1.2"));
    } catch (Exception e) {
        Assert.fail(e.toString());
    }
}
Also used : Usage(org.killbill.billing.catalog.api.Usage) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) BigDecimal(java.math.BigDecimal) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) 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