Search in sources :

Example 6 with VersionedCatalog

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

the class TestEhCacheCatalogCache method testDefaultCatalog.

//
// Verify CatalogCache returns default catalog when system property has been set (and CatalogCache has been initialized)
//
@Test(groups = "fast")
public void testDefaultCatalog() throws CatalogApiException {
    catalogCache.loadDefaultCatalog(Resources.getResource("SpyCarBasic.xml").toExternalForm());
    final VersionedCatalog result = catalogCache.getCatalog(true, true, internalCallContext);
    Assert.assertNotNull(result);
    final Collection<Product> products = result.getProducts(clock.getUTCNow());
    Assert.assertEquals(products.size(), 3);
    // Verify the lookup with other contexts
    final VersionedCatalog resultForMultiTenantContext = new VersionedCatalog(result.getClock());
    for (final StandaloneCatalog cur : result.getVersions()) {
        resultForMultiTenantContext.add(new StandaloneCatalogWithPriceOverride(cur, priceOverride, multiTenantContext.getTenantRecordId(), internalCallContextFactory));
    }
    Assert.assertEquals(catalogCache.getCatalog(true, true, multiTenantContext).getCatalogName(), resultForMultiTenantContext.getCatalogName());
    Assert.assertEquals(catalogCache.getCatalog(true, true, multiTenantContext).getVersions().size(), resultForMultiTenantContext.getVersions().size());
    for (int i = 0; i < catalogCache.getCatalog(true, true, multiTenantContext).getVersions().size(); i++) {
        Assert.assertEquals(((StandaloneCatalogWithPriceOverride) catalogCache.getCatalog(true, true, multiTenantContext).getVersions().get(i)).getTenantRecordId(), ((StandaloneCatalogWithPriceOverride) resultForMultiTenantContext.getVersions().get(i)).getTenantRecordId());
    }
}
Also used : StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride) VersionedCatalog(org.killbill.billing.catalog.VersionedCatalog) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) Product(org.killbill.billing.catalog.api.Product) Test(org.testng.annotations.Test)

Example 7 with VersionedCatalog

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

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

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

the class TestVersionedCatalogLoader method testLoadCatalogFromInsideResourceFolder.

@Test(groups = "fast")
public void testLoadCatalogFromInsideResourceFolder() throws CatalogApiException, URISyntaxException, IOException {
    final VersionedCatalog c = loader.loadDefaultCatalog("com/acme/SpyCarCustom.xml");
    Assert.assertEquals(c.size(), 1);
    final DateTime dt = new DateTime("2015-10-04T00:00:00+00:00");
    Assert.assertEquals(c.getEffectiveDate(), dt.toDate());
    Assert.assertEquals(c.getCatalogName(), "SpyCarCustom");
}
Also used : VersionedCatalog(org.killbill.billing.catalog.VersionedCatalog) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 10 with VersionedCatalog

use of org.killbill.billing.catalog.VersionedCatalog 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

VersionedCatalog (org.killbill.billing.catalog.VersionedCatalog)12 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)8 Test (org.testng.annotations.Test)7 StandaloneCatalogWithPriceOverride (org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)5 URI (java.net.URI)4 DateTime (org.joda.time.DateTime)4 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 URISyntaxException (java.net.URISyntaxException)3 JAXBException (javax.xml.bind.JAXBException)3 TransformerException (javax.xml.transform.TransformerException)3 InvalidConfigException (org.killbill.billing.catalog.api.InvalidConfigException)3 ValidationException (org.killbill.xmlloader.ValidationException)3 SAXException (org.xml.sax.SAXException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)2 Product (org.killbill.billing.catalog.api.Product)2 PriceOverride (org.killbill.billing.catalog.override.PriceOverride)2