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