use of org.killbill.billing.catalog.DefaultVersionedCatalog in project killbill by killbill.
the class TestDefaultCatalogCache 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("org/killbill/billing/catalog/SpyCarBasic.xml").toExternalForm());
final VersionedCatalog result = catalogCache.getCatalog(true, true, false, internalCallContext);
Assert.assertNotNull(result);
final StaticCatalog catalogVersion = result.getVersions().get(result.getVersions().size() - 1);
final Collection<Product> products = catalogVersion.getProducts();
Assert.assertEquals(products.size(), 3);
// Verify the lookup with other contexts
final DefaultVersionedCatalog resultForMultiTenantContext = new DefaultVersionedCatalog();
for (final StaticCatalog cur : result.getVersions()) {
resultForMultiTenantContext.add(new StandaloneCatalogWithPriceOverride(cur, priceOverride, multiTenantContext.getTenantRecordId(), internalCallContextFactory));
}
Assert.assertEquals(catalogCache.getCatalog(true, true, false, multiTenantContext).getCatalogName(), resultForMultiTenantContext.getCatalogName());
Assert.assertEquals(catalogCache.getCatalog(true, true, false, multiTenantContext).getVersions().size(), resultForMultiTenantContext.getVersions().size());
for (int i = 0; i < catalogCache.getCatalog(true, true, false, multiTenantContext).getVersions().size(); i++) {
Assert.assertEquals(((StandaloneCatalogWithPriceOverride) catalogCache.getCatalog(true, true, false, multiTenantContext).getVersions().get(i)).getTenantRecordId(), ((StandaloneCatalogWithPriceOverride) resultForMultiTenantContext.getVersions().get(i)).getTenantRecordId());
}
}
use of org.killbill.billing.catalog.DefaultVersionedCatalog in project killbill by killbill.
the class TestDefaultSubscriptionTransferApi method beforeMethod.
@Override
@BeforeMethod(groups = "fast")
public void beforeMethod() throws Exception {
super.beforeMethod();
final SubscriptionDao dao = Mockito.mock(SubscriptionDao.class);
final DefaultVersionedCatalog versionedCatalog = new DefaultVersionedCatalog();
final MockCatalog mockCatalog = new MockCatalog();
versionedCatalog.add(mockCatalog);
final CatalogService catalogService = new MockCatalogService(versionedCatalog);
final CatalogInternalApi catalogInternalApiWithMockCatalogService = new DefaultCatalogInternalApi(catalogService);
final SubscriptionCatalogApi subscriptionCatalogInternalApiWithMockCatalogService = new DefaultSubscriptionCatalogApi(catalogInternalApiWithMockCatalogService, clock);
final SubscriptionBaseApiService apiService = Mockito.mock(SubscriptionBaseApiService.class);
final SubscriptionBaseTimelineApi timelineApi = Mockito.mock(SubscriptionBaseTimelineApi.class);
transferApi = new DefaultSubscriptionBaseTransferApi(clock, dao, timelineApi, subscriptionCatalogInternalApiWithMockCatalogService, subscriptionInternalApi, apiService, internalCallContextFactory);
// Overrride catalog with our MockCatalog
this.catalog = DefaultSubscriptionCatalogApi.wrapCatalog(versionedCatalog, clock);
}
use of org.killbill.billing.catalog.DefaultVersionedCatalog in project killbill by killbill.
the class VersionedCatalogLoader method loadDefaultCatalog.
@Override
public VersionedCatalog loadDefaultCatalog(final String uriString) throws CatalogApiException {
try {
final List<URI> xmlURIs;
if (uriString.endsWith(XML_EXTENSION)) {
// Assume its an xml file
xmlURIs = new ArrayList<URI>();
xmlURIs.add(new URI(uriString));
} else {
// Assume its a directory
final URL url = getURLFromString(uriString);
final String directoryContents = UriAccessor.accessUriAsString(uriString);
xmlURIs = findXmlReferences(directoryContents, url);
}
final DefaultVersionedCatalog result = new DefaultVersionedCatalog();
for (final URI u : xmlURIs) {
final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(u, StandaloneCatalog.class);
result.add(new StandaloneCatalogWithPriceOverride(catalog, priceOverride, InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, internalCallContextFactory));
}
// Perform initialization and validation for VersionedCatalog
XMLLoader.initializeAndValidate(result);
return result;
} catch (final ValidationException e) {
logger.warn("Failed to load default catalog", e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_DEFAULT, uriString);
} catch (final JAXBException e) {
logger.warn("Failed to load default catalog", e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_DEFAULT, uriString);
} catch (IllegalArgumentException e) {
logger.warn("Failed to load default catalog", e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_DEFAULT, uriString);
} catch (Exception e) {
logger.warn("Failed to load default catalog", e);
throw new IllegalStateException(e);
}
}
use of org.killbill.billing.catalog.DefaultVersionedCatalog in project killbill by killbill.
the class VersionedCatalogLoader method load.
public VersionedCatalog load(final Collection<String> catalogXMLs, final boolean filterTemplateCatalog, final Long tenantRecordId) throws CatalogApiException {
try {
final Collection<Future<StandaloneCatalog>> catalogs = new ArrayList<Future<StandaloneCatalog>>(catalogXMLs.size());
for (final String cur : catalogXMLs) {
catalogs.add(executorService.submit(new Callable<StandaloneCatalog>() {
@Override
public StandaloneCatalog call() throws Exception {
final InputStream curCatalogStream = new ByteArrayInputStream(cur.getBytes());
final StandaloneCatalog catalog = XMLLoader.getObjectFromStream(curCatalogStream, StandaloneCatalog.class);
if (!filterTemplateCatalog || !catalog.isTemplateCatalog()) {
return new StandaloneCatalogWithPriceOverride(catalog, priceOverride, tenantRecordId, internalCallContextFactory);
}
return null;
}
}));
}
final DefaultVersionedCatalog result = new DefaultVersionedCatalog();
for (final Future<StandaloneCatalog> standaloneCatalogFuture : catalogs) {
final StandaloneCatalog catalog = standaloneCatalogFuture.get();
if (catalog != null) {
result.add(catalog);
}
}
XMLLoader.initializeAndValidate(result);
return result;
} catch (final ValidationException e) {
logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
for (final ValidationError ve : e.getErrors()) {
logger.warn(ve.toString());
}
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, tenantRecordId);
} catch (final InterruptedException e) {
logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, tenantRecordId);
} catch (final ExecutionException e) {
logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, tenantRecordId);
}
}
use of org.killbill.billing.catalog.DefaultVersionedCatalog 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 = getCatalog("SpyCarAdvanced.xml");
final DefaultVersionedCatalog versionedCatalog = new DefaultVersionedCatalog();
versionedCatalog.add(catalog);
final Class serializableClass = versionedCatalog.getClass();
final String newCatalogStr = XMLWriter.writeXML(versionedCatalog, serializableClass);
// System.err.println(newCatalogStr);
}
Aggregations