@Test public void updateCatalogEntry_updateVisibleInCatalog() throws Exception { Assert.assertEquals(voCatalogEntry.isVisibleInCatalog(), catalogEntry.isVisibleInCatalog()); voCatalogEntry.setVisibleInCatalog(!catalogEntry.isVisibleInCatalog()); assertFalse(voCatalogEntry.isVisibleInCatalog() == catalogEntry.isVisibleInCatalog()); CatalogEntry entry = CatalogEntryAssembler.updateCatalogEntry(catalogEntry, voCatalogEntry); Assert.assertEquals(voCatalogEntry.isVisibleInCatalog(), entry.isVisibleInCatalog()); }
@Test public void updateCatalogEntry() throws Exception { CatalogEntry entry = CatalogEntryAssembler.updateCatalogEntry(catalogEntry, voCatalogEntry); assertNotNull(entry); assertEquals(voCatalogEntry.getKey(), entry.getKey()); assertEquals(PRODUCT_KEY, entry.getProduct().getKey()); assertEquals(voCatalogEntry.getVersion(), entry.getVersion()); }
@Before public void setUp() { LocalizerServiceStub localizerServiceStub = new LocalizerServiceStub() { @Override public String getLocalizedTextFromDatabase( String localeString, long objectKey, LocalizedObjectTypes objectType) { return localizedText; } }; facade = new LocalizerFacade(localizerServiceStub, Locale.GERMAN.getLanguage()); // server side entries Product product = new Product(); product.setKey(PRODUCT_KEY); product.setTechnicalProduct(new TechnicalProduct()); product.setAutoAssignUserEnabled(false); ProductFeedback feedback = new ProductFeedback(); feedback.setAverageRating(new BigDecimal("2.5")); product.setProductFeedback(feedback); mp = new Marketplace(); mp.setKey(1); mp.setMarketplaceId(MP_ID); mp.setOrganization(new Organization()); catalogEntry = new CatalogEntry(); catalogEntry.setKey(1); catalogEntry.setProduct(product); catalogEntry.setMarketplace(mp); catalogEntry.setAnonymousVisible(true); catalogEntry.setVisibleInCatalog(true); catalogEntry2 = new CatalogEntry(); catalogEntry2.setKey(2); catalogEntry3 = new CatalogEntry(); catalogEntry3.setKey(3); VOMarketplace voMp = new VOMarketplace(); voMp.setMarketplaceId(MP_ID); // incoming entries voCatalogEntry = new VOCatalogEntry(); voCatalogEntry.setKey(1); voCatalogEntry.setVersion(0); voCatalogEntry.setMarketplace(voMp); voCatalogEntry.setAnonymousVisible(true); voCatalogEntry.setVisibleInCatalog(true); voCatalogEntry2 = new VOCatalogEntry(); voCatalogEntry2.setKey(2); voCatalogEntry3 = new VOCatalogEntry(); voCatalogEntry3.setKey(3); }
@Test public void toVOCatalogEntry_ForListing() throws Exception { // when VOCatalogEntry voCe = CatalogEntryAssembler.toVOCatalogEntry( catalogEntry, facade, PerformanceHint.ONLY_FIELDS_FOR_LISTINGS); // then assertEquals(catalogEntry.getProduct().getKey(), voCe.getService().getKey()); }
@Test(expected = ConcurrentModificationException.class) public void saveRevenueShareModelsForProduct_concurrentExecution() throws Exception { // given Product product = createProductForSave(tpSup, true, "mp", "tp", "productA", "pm"); final long productKey = product.getKey(); CatalogEntry catalogEntryOfProduct = getCatalogEntryForProduct(productKey); final RevenueShareModel brokerRevenueShare = new RevenueShareModel(); brokerRevenueShare.setKey(catalogEntryOfProduct.getBrokerPriceModel().getKey()); brokerRevenueShare.setRevenueShare(new BigDecimal("100.00")); final RevenueShareModel resellerRevenueShare = new RevenueShareModel(); resellerRevenueShare.setKey(catalogEntryOfProduct.getResellerPriceModel().getKey()); resellerRevenueShare.setRevenueShare(new BigDecimal("100.00")); // when container.login(poUserKey, ROLE_PLATFORM_OPERATOR); runTX( new Callable<Void>() { public Void call() throws Exception { localService.saveRevenueShareModelsForProduct( productKey, brokerRevenueShare, resellerRevenueShare, 0, 0); return null; } }); runTX( new Callable<Void>() { public Void call() throws Exception { localService.saveRevenueShareModelsForProduct( productKey, brokerRevenueShare, resellerRevenueShare, 0, 0); return null; } }); fail(); // then a ConcurrentModificationException occurs }
/** domain object -> value object */ @Test public void toVOCatalogEntry() { List<CategoryToCatalogEntry> categoryToCatalogEntry = new ArrayList<CategoryToCatalogEntry>(); CategoryToCatalogEntry ctc = new CategoryToCatalogEntry(); ctc.setCatalogEntry(catalogEntry); Category category = new Category(); category.setCategoryId("categoryId"); category.setMarketplaceKey(mp.getKey()); category.setMarketplace(mp); category.setKey(3333); ctc.setCategory(category); ctc.setKey(2222); categoryToCatalogEntry.add(ctc); catalogEntry.setCategoryToCatalogEntry(categoryToCatalogEntry); catalogEntry.getProduct().setVendor(new Organization()); VOCatalogEntry voEntry = CatalogEntryAssembler.toVOCatalogEntry(catalogEntry, facade); assertNotNull(voEntry); assertEquals(catalogEntry.getKey(), voEntry.getKey()); assertEquals(catalogEntry.getProduct().getKey(), voEntry.getService().getKey()); assertEquals(catalogEntry.getVersion(), voEntry.getVersion()); Assert.assertEquals(catalogEntry.isAnonymousVisible(), voEntry.isAnonymousVisible()); Assert.assertEquals(catalogEntry.isVisibleInCatalog(), voEntry.isVisibleInCatalog()); if (catalogEntry.getMarketplace() != null || voEntry.getMarketplace() != null) { assertNotNull(catalogEntry.getMarketplace()); assertNotNull(voEntry.getMarketplace()); assertEquals( catalogEntry.getMarketplace().getMarketplaceId(), voEntry.getMarketplace().getMarketplaceId()); } assertNotNull(voEntry.getCategories()); assertEquals(1, voEntry.getCategories().size()); assertEquals(category.getCategoryId(), voEntry.getCategories().get(0).getCategoryId()); }
@Test public void toCatalogEntry() throws ValidationException { // given VOService service = new VOService(); service.setServiceId("sId"); voCatalogEntry.setService(service); // when CatalogEntry ce = CatalogEntryAssembler.toCatalogEntry(voCatalogEntry); // then assertEquals(voCatalogEntry.getKey(), ce.getKey()); assertEquals(voCatalogEntry.isAnonymousVisible(), ce.isAnonymousVisible()); assertEquals(voCatalogEntry.isVisibleInCatalog(), ce.isVisibleInCatalog()); assertNotNull(ce.getMarketplace()); assertEquals( voCatalogEntry.getMarketplace().getMarketplaceId(), ce.getMarketplace().getMarketplaceId()); }
@Test public void saveRevenueShareModelsForProduct_UpdateRevenueShares() throws Exception { // given Product product = createProductForSave(tpSup, true, "mp", "tp", "productA", "pm"); final long productKey = product.getKey(); CatalogEntry catalogEntryOfProduct = getCatalogEntryForProduct(productKey); final RevenueShareModel brokerRevenueShare = new RevenueShareModel(); brokerRevenueShare.setKey(catalogEntryOfProduct.getBrokerPriceModel().getKey()); brokerRevenueShare.setRevenueShare(new BigDecimal("100.00")); final RevenueShareModel resellerRevenueShare = new RevenueShareModel(); resellerRevenueShare.setKey(catalogEntryOfProduct.getResellerPriceModel().getKey()); resellerRevenueShare.setRevenueShare(new BigDecimal("100.00")); // when container.login(poUserKey, ROLE_PLATFORM_OPERATOR); Map<RevenueShareModelType, RevenueShareModel> revenueShares = runTX( new Callable<Map<RevenueShareModelType, RevenueShareModel>>() { public Map<RevenueShareModelType, RevenueShareModel> call() throws Exception { return localService.saveRevenueShareModelsForProduct( productKey, brokerRevenueShare, resellerRevenueShare, 0, 0); } }); // then assertEquals( new BigDecimal("100.00"), revenueShares.get(RevenueShareModelType.BROKER_REVENUE_SHARE).getRevenueShare()); assertEquals( new BigDecimal("100.00"), revenueShares.get(RevenueShareModelType.RESELLER_REVENUE_SHARE).getRevenueShare()); // validate stored values in the database runTX( new Callable<Void>() { public Void call() throws Exception { Product result = ds.getReference(Product.class, productKey); List<CatalogEntry> entries = result.getCatalogEntries(); assertEquals(1, entries.size()); CatalogEntry ce = entries.get(0); RevenueShareModel brokerRevenueShare = ce.getBrokerPriceModel(); assertNotNull(brokerRevenueShare); assertEquals(new BigDecimal("100.00"), brokerRevenueShare.getRevenueShare()); RevenueShareModel resellerRevenueShare = ce.getBrokerPriceModel(); assertNotNull(resellerRevenueShare); assertEquals(new BigDecimal("100.00"), resellerRevenueShare.getRevenueShare()); List<DomainHistoryObject<?>> brokerRevenueHistories = ds.findHistory(brokerRevenueShare); assertEquals(2, brokerRevenueHistories.size()); assertEquals(ModificationType.MODIFY, brokerRevenueHistories.get(1).getModtype()); List<DomainHistoryObject<?>> resellerRevenueHistories = ds.findHistory(resellerRevenueShare); assertEquals(2, resellerRevenueHistories.size()); assertEquals(ModificationType.MODIFY, resellerRevenueHistories.get(1).getModtype()); return null; } }); }