use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class TestXMLReader method testUsageConsumableInArrear.
@Test(groups = "fast")
public void testUsageConsumableInArrear() {
try {
final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("UsageExperimental.xml").toExternalForm(), StandaloneCatalog.class);
final Usage[] usages = getUsages(catalog, "consumable-in-arrear");
assertEquals(usages.length, 1);
final Usage usage = usages[0];
assertEquals(usage.getName(), "consumable-in-arrear-usage1");
assertEquals(usage.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(usage.getUsageType(), UsageType.CONSUMABLE);
assertEquals(usage.getBillingMode(), BillingMode.IN_ARREAR);
assertEquals(usage.getLimits().length, 0);
assertEquals(usage.getBlocks().length, 0);
assertEquals(usage.getTiers().length, 1);
assertEquals(usage.getTiers()[0].getTieredBlocks().length, 2);
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getUnit().getName(), "cell-phone-minutes");
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getSize(), new Double("1000"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getMax(), new Double("10000"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getPrice().getPrices().length, 1);
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getPrice().getPrices()[0].getCurrency(), Currency.BTC);
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getPrice().getPrices()[0].getValue(), new BigDecimal("0.5"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getUnit().getName(), "Mbytes");
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getSize(), new Double("512"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getMax(), new Double("512000"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getPrice().getPrices().length, 1);
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getPrice().getPrices()[0].getCurrency(), Currency.BTC);
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getPrice().getPrices()[0].getValue(), new BigDecimal("0.3"));
} catch (Exception e) {
Assert.fail(e.toString());
}
}
use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class TestXMLReader method testUsageCapacityInAdvance.
@Test(groups = "fast")
public void testUsageCapacityInAdvance() {
try {
final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("UsageExperimental.xml").toExternalForm(), StandaloneCatalog.class);
final Usage[] usages = getUsages(catalog, "capacity-in-advance-monthly");
assertEquals(usages.length, 1);
final Usage usage = usages[0];
assertEquals(usage.getName(), "capacity-in-advance-monthly-usage1");
assertEquals(usage.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(usage.getUsageType(), UsageType.CAPACITY);
assertEquals(usage.getBillingMode(), BillingMode.IN_ADVANCE);
assertEquals(usage.getBlocks().length, 0);
assertEquals(usage.getTiers().length, 0);
assertEquals(usage.getLimits().length, 1);
assertEquals(usage.getLimits()[0].getUnit().getName(), "members");
assertEquals(usage.getLimits()[0].getMax(), new Double("100"));
assertEquals(usage.getRecurringPrice().getPrices().length, 1);
assertEquals(usage.getRecurringPrice().getPrices()[0].getCurrency(), Currency.BTC);
assertEquals(usage.getRecurringPrice().getPrices()[0].getValue(), new BigDecimal("100.00"));
} catch (Exception e) {
Assert.fail(e.toString());
}
}
use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class TestXMLReader method testUsageConsumableInAdvancePrepayCredit.
@Test(groups = "fast")
public void testUsageConsumableInAdvancePrepayCredit() {
try {
final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("UsageExperimental.xml").toExternalForm(), StandaloneCatalog.class);
final Usage[] usages = getUsages(catalog, "consumable-in-advance-prepay-credit-monthly");
assertEquals(usages.length, 1);
final Usage usage = usages[0];
assertEquals(usage.getName(), "consumable-in-advance-prepay-credit-monthly-usage1");
assertEquals(usage.getBillingPeriod(), BillingPeriod.MONTHLY);
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(), "cell-phone-minutes");
assertEquals(usage.getBlocks()[0].getSize(), new Double("1000"));
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"));
} catch (Exception e) {
Assert.fail(e.toString());
}
}
use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class TestXMLWriter method testMarshallUnmarshall.
// Verify we can marshall/unmarshall a (fairly complex catalog) catalog and get back the same result (Required to support catalog update)
@Test(groups = "fast")
public void testMarshallUnmarshall() throws Exception {
final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class);
final String oldCatalogStr = XMLWriter.writeXML(catalog, StandaloneCatalog.class);
//System.err.println(oldCatalogStr);
final StandaloneCatalog oldCatalog = XMLLoader.getObjectFromStream(new URI("dummy"), new ByteArrayInputStream(oldCatalogStr.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class);
final String oldCatalogStr2 = XMLWriter.writeXML(oldCatalog, StandaloneCatalog.class);
assertEquals(oldCatalogStr2, oldCatalogStr);
}
use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class CatalogResource method getCatalogJson.
@TimedResource
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve the catalog as JSON", response = StaticCatalog.class)
@ApiResponses(value = {})
public Response getCatalogJson(@QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @javax.ws.rs.core.Context final HttpServletRequest request) throws Exception {
final TenantContext tenantContext = context.createContext(request);
final DateTime catalogDateVersion = requestedDate != null ? DATE_TIME_FORMATTER.parseDateTime(requestedDate).toDateTime(DateTimeZone.UTC) : null;
// Yack...
final VersionedCatalog catalog = (VersionedCatalog) catalogUserApi.getCatalog(catalogName, tenantContext);
final List<CatalogJson> result = new ArrayList<CatalogJson>();
if (catalogDateVersion != null) {
result.add(new CatalogJson(catalog, catalogDateVersion));
} else {
for (final StandaloneCatalog v : catalog.getVersions()) {
result.add(new CatalogJson(catalog, new DateTime(v.getEffectiveDate())));
}
}
return Response.status(Status.OK).entity(result).build();
}
Aggregations