@Test(expected = CatalogEntryRemovedException.class)
 public void consolidateCatalogEntries_TwoEntriesWithSameKey() throws Exception {
   voCatalogEntry2.setKey(voCatalogEntry.getKey());
   CatalogEntryAssembler.consolidateCatalogEntries(
       new HashSet<VOCatalogEntry>(Arrays.asList(voCatalogEntry, voCatalogEntry2)),
       Arrays.asList(catalogEntry, catalogEntry2));
 }
 @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());
 }
  @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
  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());
  }
  @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(expected = ConcurrentModificationException.class)
 public void consolidateCatalogEntries_WrongVersion() throws Exception {
   voCatalogEntry.setVersion(-1);
   CatalogEntryAssembler.consolidateCatalogEntries(
       Collections.singleton(voCatalogEntry), Arrays.asList(catalogEntry));
 }
 @Test(expected = ConcurrentModificationException.class)
 public void updateCatalogEntry_conflictingVersions() throws Exception {
   voCatalogEntry.setVersion(-1);
   CatalogEntryAssembler.updateCatalogEntry(catalogEntry, voCatalogEntry);
 }
 @Test(expected = SaaSSystemException.class)
 public void updateCatalogEntry_conflictingKeys() throws Exception {
   voCatalogEntry.setKey(2);
   CatalogEntryAssembler.updateCatalogEntry(catalogEntry, voCatalogEntry);
 }
  /** 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());
  }