@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
  }
  @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;
          }
        });
  }