@LifecycleHandlerType(LifecycleLevel.LOAD_CATALOG) public synchronized void loadCatalog() throws ServiceException { if (!isInitialized) { try { // In multi-tenant mode, the property is not required if (config.getCatalogURI() != null && !config.getCatalogURI().isEmpty()) { catalogCache.loadDefaultCatalog(config.getCatalogURI()); log.info("Successfully loaded the default catalog {}", config.getCatalogURI()); } isInitialized = true; } catch (final Exception e) { throw new ServiceException(e); } } }
@Test(groups = "fast") public void testMissingDefaultCatalog() throws CatalogApiException { catalogCache.loadDefaultCatalog(null); Assert.assertEquals(catalogCache.getCatalog(true, true, false, internalCallContext).getCatalogName(), "EmptyCatalog"); }
catalogCache.loadDefaultCatalog(Resources.getResource("SpyCarBasic.xml").toExternalForm());
@Test(groups = "fast") public void testDefaultCatalog() throws CatalogApiException { catalogCache.loadDefaultCatalog(Resources.getResource("SpyCarBasic.xml").toExternalForm()); final DefaultVersionedCatalog result = catalogCache.getCatalog(true, true, false, internalCallContext); Assert.assertNotNull(result); final Collection<Product> products = result.getProducts(clock.getUTCNow()); Assert.assertEquals(products.size(), 3); // Verify the lookup with other contexts final DefaultVersionedCatalog resultForMultiTenantContext = new DefaultVersionedCatalog(result.getClock()); for (final StandaloneCatalog 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()); } }
@LifecycleHandlerType(LifecycleLevel.LOAD_CATALOG) public synchronized void loadCatalog() throws ServiceException { if (!isInitialized) { try { // In multi-tenant mode, the property is not required if (config.getCatalogURI() != null && !config.getCatalogURI().isEmpty()) { catalogCache.loadDefaultCatalog(config.getCatalogURI()); log.info("Successfully loaded the default catalog {}", config.getCatalogURI()); } isInitialized = true; } catch (final Exception e) { throw new ServiceException(e); } } }
@Test(groups = "fast") public void testMissingDefaultCatalog() throws CatalogApiException { catalogCache.loadDefaultCatalog(null); Assert.assertEquals(catalogCache.getCatalog(true, true, false, internalCallContext).getCatalogName(), "EmptyCatalog"); }
catalogCache.loadDefaultCatalog(Resources.getResource("SpyCarBasic.xml").toExternalForm());
@Test(groups = "fast") public void testDefaultCatalog() throws CatalogApiException { catalogCache.loadDefaultCatalog(Resources.getResource("SpyCarBasic.xml").toExternalForm()); final DefaultVersionedCatalog result = catalogCache.getCatalog(true, true, false, internalCallContext); Assert.assertNotNull(result); final Collection<Product> products = result.getProducts(clock.getUTCNow()); Assert.assertEquals(products.size(), 3); // Verify the lookup with other contexts final DefaultVersionedCatalog resultForMultiTenantContext = new DefaultVersionedCatalog(result.getClock()); for (final StandaloneCatalog 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()); } }