Search in sources :

Example 6 with StandaloneCatalog

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

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());
    }
}
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 8 with StandaloneCatalog

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());
    }
}
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 9 with StandaloneCatalog

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 10 with StandaloneCatalog

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();
}
Also used : VersionedCatalog(org.killbill.billing.catalog.VersionedCatalog) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) CatalogJson(org.killbill.billing.jaxrs.json.CatalogJson) DateTime(org.joda.time.DateTime) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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