@Test
  public void testAddToCollection() {
    final UserModel user = userService.getUserForUID("ahertz");
    List<CockpitObjectAbstractCollectionModel> collections =
        cockpitCollectionService.getCollectionsForUser(user);
    CockpitObjectAbstractCollectionModel collection = null;
    for (final CockpitObjectAbstractCollectionModel coll : collections) {
      if ("testA".equals(coll.getQualifier())) {
        collection = coll;
        break;
      }
    }

    assertThat(collection.getElements().size()).isEqualTo(2);

    final CatalogVersionModel catalogVersion =
        catalogService.getCatalogVersion("testCatalog", "Online");
    final List<ItemModel> elements = new ArrayList<ItemModel>();
    elements.add(productService.getProductForCode(catalogVersion, "testProduct4"));

    final int n = cockpitCollectionService.addToCollection(collection, elements);

    collections = cockpitCollectionService.getCollectionsForUser(user);
    CockpitObjectAbstractCollectionModel changedCollection = null;
    for (final CockpitObjectAbstractCollectionModel coll : collections) {
      if ("testA".equals(coll.getQualifier())) {
        changedCollection = coll;
        break;
      }
    }

    assertThat(changedCollection.getElements().size()).isEqualTo(3);
    assertThat(n).isEqualTo(1);
  }
  @Test
  public void testRemoveFromCollection() {
    final UserModel user = userService.getUserForUID("ahertz");
    List<CockpitObjectAbstractCollectionModel> collections =
        cockpitCollectionService.getCollectionsForUser(user);
    CockpitObjectAbstractCollectionModel collection = null;

    for (final CockpitObjectAbstractCollectionModel coll : collections) {
      if ("testA".equals(coll.getQualifier())) {
        collection = coll;
        break;
      }
    }

    assertThat(collection.getElements().size()).isEqualTo(2);

    final CatalogVersionModel catalogVersion =
        catalogService.getCatalogVersion("testCatalog", "Online");
    final List<ItemModel> elements = new ArrayList<ItemModel>();
    elements.add(productService.getProductForCode(catalogVersion, "testProduct4"));

    int n = cockpitCollectionService.removeFromCollection(collection, elements);

    collections = cockpitCollectionService.getCollectionsForUser(user);
    CockpitObjectAbstractCollectionModel changedCollection = null;
    for (final CockpitObjectAbstractCollectionModel coll : collections) {
      if ("testA".equals(coll.getQualifier())) {
        changedCollection = coll;
        break;
      }
    }
    // should not change, before we tried to remove the element that does not exist in the
    // collection
    assertThat(changedCollection.getElements().size()).isEqualTo(2);
    assertThat(n).isEqualTo(0);

    elements.clear();
    elements.add(productService.getProductForCode(catalogVersion, "testProduct0"));

    n = cockpitCollectionService.removeFromCollection(collection, elements);

    collections = cockpitCollectionService.getCollectionsForUser(user);
    changedCollection = null;
    for (final CockpitObjectAbstractCollectionModel coll : collections) {
      if ("testA".equals(coll.getQualifier())) {
        changedCollection = coll;
        break;
      }
    }
    assertThat(changedCollection.getElements().size()).isEqualTo(1);
    assertThat(n).isEqualTo(1);
  }