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);
}
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);
}
}
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);
}
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());
}
}
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());
}
}
Aggregations