private StandaloneCatalog getCurrentStandaloneCatalogForTenant(final InternalTenantContext internalTenantContext) throws CatalogApiException { final DefaultVersionedCatalog versionedCatalog = catalogService.getFullCatalog(false, false, internalTenantContext); if (versionedCatalog != null && !versionedCatalog.getVersions().isEmpty()) { final StandaloneCatalog standaloneCatalogWithPriceOverride = versionedCatalog.getVersions().get(versionedCatalog.getVersions().size() - 1); return standaloneCatalogWithPriceOverride; } else { return null; } }
@Test(groups = "fast") public void testLoad() throws CatalogApiException { final DefaultVersionedCatalog c = loader.loadDefaultCatalog(Resources.getResource("versionedCatalog").toString()); Assert.assertEquals(c.getVersions().size(), 4); DateTime dt = new DateTime("2011-01-01T00:00:00+00:00"); Assert.assertEquals(c.getVersions().get(0).getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-02-02T00:00:00+00:00"); Assert.assertEquals(c.getVersions().get(1).getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-02-03T00:00:00+00:00"); Assert.assertEquals(c.getVersions().get(2).getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-03-03T00:00:00+00:00"); Assert.assertEquals(c.getVersions().get(3).getEffectiveDate(), dt.toDate()); }
@Test(groups = "fast") public void testLoadCatalogFromInsideResourceFolder() throws CatalogApiException { final DefaultVersionedCatalog c = loader.loadDefaultCatalog("com/acme/SpyCarCustom.xml"); Assert.assertEquals(c.getVersions().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"); }
private void initializeCatalog(final DefaultVersionedCatalog tenantCatalog) { tenantCatalog.initialize(defaultCatalog.getClock(), tenantCatalog); for (final StandaloneCatalog cur : tenantCatalog.getVersions()) { if (cur instanceof StandaloneCatalogWithPriceOverride) { ((StandaloneCatalogWithPriceOverride) cur).initialize(cur, priceOverride, internalCallContextFactory); } else { cur.initialize(cur); } } }
@Test(groups = "fast") public void testStandaloneCatalogExternalizable() throws IOException { final Codec codec = new SerializationCodec(); final ByteBuf byteBuf = codec.getValueEncoder().encode(vc.getVersions().get(0)); final StandaloneCatalog standaloneCatalog = (StandaloneCatalog) codec.getValueDecoder().decode(byteBuf, null); Assert.assertEquals(standaloneCatalog, vc.getVersions().get(0)); } }
@Override public VersionedCatalog<? extends StaticCatalog> getCatalog(final String catalogName, @Nullable final DateTime catalogDateVersion, final TenantContext tenantContext) throws CatalogApiException { final InternalTenantContext internalTenantContext; if (tenantContext.getAccountId() != null) { internalTenantContext = internalCallContextFactory.createInternalTenantContext(tenantContext.getAccountId(), tenantContext); } else { internalTenantContext = createInternalTenantContext(tenantContext); } final DefaultVersionedCatalog fullCatalog = catalogService.getFullCatalog(true, true, internalTenantContext); if (catalogDateVersion == null) { return fullCatalog; } else { final DefaultVersionedCatalog filteredCatalog = new DefaultVersionedCatalog(clock); for (final StandaloneCatalog v : fullCatalog.getVersions()) { if (v.getEffectiveDate().compareTo(catalogDateVersion.toDate()) >= 0) { filteredCatalog.add(v); break; } } return filteredCatalog; } }
@Test(groups = "fast") public void testDefaultPlanRulesExternalizable() throws IOException { final Codec codec = new SerializationCodec(); final ByteBuf byteBuf = codec.getValueEncoder().encode(vc.getVersions().get(0).getPlanRules()); final DefaultPlanRules planRules = (DefaultPlanRules) codec.getValueDecoder().decode(byteBuf, null); Assert.assertEquals(planRules, vc.getVersions().get(0).getPlanRules()); }
@Test(groups = "fast") public void testCatalogEntityCollectionProductExternalizable() throws IOException { final Codec codec = new SerializationCodec(); final ByteBuf byteBuf = codec.getValueEncoder().encode(vc.getVersions().get(0).getCatalogEntityCollectionProduct()); final Collection products = (CatalogEntityCollection) codec.getValueDecoder().decode(byteBuf, null); Assert.assertEquals(products, vc.getVersions().get(0).getCatalogEntityCollectionProduct()); }
@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()); } }
@Test(groups = "fast") public void testProductExternalizable() throws IOException { final Codec codec = new SerializationCodec(); for (final Product product : vc.getVersions().get(0).getCatalogEntityCollectionProduct().getEntries()) { final ByteBuf byteBuf = codec.getValueEncoder().encode(product); final Product product2 = (Product) codec.getValueDecoder().decode(byteBuf, null); Assert.assertEquals(product2, product); } }
for (StandaloneCatalog c : versionedCatalog.getVersions()) { if (c.getEffectiveDate().compareTo(newCatalogVersion.getEffectiveDate()) == 0) { final ValidationErrors errors = new ValidationErrors();
for (final StandaloneCatalog cur : defaultCatalog.getVersions()) { final StandaloneCatalogWithPriceOverride curWithOverride = new StandaloneCatalogWithPriceOverride(cur, priceOverride, tenantContext.getTenantRecordId(), internalCallContextFactory); tenantCatalog.add(curWithOverride);
private StandaloneCatalog getCurrentStandaloneCatalogForTenant(final InternalTenantContext internalTenantContext) throws CatalogApiException { final DefaultVersionedCatalog versionedCatalog = catalogService.getFullCatalog(false, false, internalTenantContext); if (versionedCatalog != null && !versionedCatalog.getVersions().isEmpty()) { final StandaloneCatalog standaloneCatalogWithPriceOverride = versionedCatalog.getVersions().get(versionedCatalog.getVersions().size() - 1); return standaloneCatalogWithPriceOverride; } else { return null; } }
@Test(groups = "fast") public void testLoadCatalogFromInsideResourceFolder() throws CatalogApiException { final DefaultVersionedCatalog c = loader.loadDefaultCatalog("com/acme/SpyCarCustom.xml"); Assert.assertEquals(c.getVersions().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"); }
private void initializeCatalog(final DefaultVersionedCatalog tenantCatalog) { tenantCatalog.initialize(defaultCatalog.getClock(), tenantCatalog); for (final StandaloneCatalog cur : tenantCatalog.getVersions()) { if (cur instanceof StandaloneCatalogWithPriceOverride) { ((StandaloneCatalogWithPriceOverride) cur).initialize(cur, priceOverride, internalCallContextFactory); } else { cur.initialize(cur); } } }
@Test(groups = "fast") public void testStandaloneCatalogExternalizable() throws IOException { final Codec codec = new SerializationCodec(); final ByteBuf byteBuf = codec.getValueEncoder().encode(vc.getVersions().get(0)); final StandaloneCatalog standaloneCatalog = (StandaloneCatalog) codec.getValueDecoder().decode(byteBuf, null); Assert.assertEquals(standaloneCatalog, vc.getVersions().get(0)); } }
@Test(groups = "fast") public void testDefaultPlanRulesExternalizable() throws IOException { final Codec codec = new SerializationCodec(); final ByteBuf byteBuf = codec.getValueEncoder().encode(vc.getVersions().get(0).getPlanRules()); final DefaultPlanRules planRules = (DefaultPlanRules) codec.getValueDecoder().decode(byteBuf, null); Assert.assertEquals(planRules, vc.getVersions().get(0).getPlanRules()); }
@Test(groups = "fast") public void testCatalogEntityCollectionProductExternalizable() throws IOException { final Codec codec = new SerializationCodec(); final ByteBuf byteBuf = codec.getValueEncoder().encode(vc.getVersions().get(0).getCatalogEntityCollectionProduct()); final Collection products = (CatalogEntityCollection) codec.getValueDecoder().decode(byteBuf, null); Assert.assertEquals(products, vc.getVersions().get(0).getCatalogEntityCollectionProduct()); }
@Override public VersionedPluginCatalog getVersionedPluginCatalog(final Iterable<PluginProperty> properties, final TenantContext tenantContext) { nbVersionedPluginCatalogApiCalls++; Assert.assertNotNull(versionedCatalog, "test did not initialize plugin catalog"); return new TestModelVersionedPluginCatalog(versionedCatalog.getCatalogName(), toStandalonePluginCatalogs(versionedCatalog.getVersions())); }
@Test(groups = "fast") public void testProductExternalizable() throws IOException { final Codec codec = new SerializationCodec(); for (final Product product : vc.getVersions().get(0).getCatalogEntityCollectionProduct().getEntries()) { final ByteBuf byteBuf = codec.getValueEncoder().encode(product); final Product product2 = (Product) codec.getValueDecoder().decode(byteBuf, null); Assert.assertEquals(product2, product); } }