/**
   * Test subscribe.
   *
   * @throws Exception - if something is wrong this exception is thrown.
   */
  @Test
  public void testSubscribe() throws Exception {
    User user = getUser(userDao, "subuser1");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
    CollectionItem collection = getCollection(root, "subcoll1");
    Ticket ticket = generateTicket(collection, user);

    CollectionSubscription sub1 = new HibCollectionSubscription();
    sub1.setDisplayName("sub1");
    sub1.setCollection(collection);
    sub1.setTicket(ticket);
    user.addSubscription(sub1);
    userDao.updateUser(user);

    clearSession();

    user = getUser(userDao, "subuser1");

    Assert.assertFalse("no subscriptions saved", user.getCollectionSubscriptions().isEmpty());

    CollectionSubscription querySub = user.getSubscription("sub1");
    Assert.assertNotNull("sub1 not found", querySub);
    Assert.assertEquals("sub1 not same subscriber", user.getUid(), querySub.getOwner().getUid());
    Assert.assertEquals(
        "sub1 not same collection", collection.getUid(), querySub.getCollectionUid());
    Assert.assertEquals("sub1 not same ticket", ticket.getKey(), querySub.getTicketKey());

    querySub.setDisplayName("sub2");
    userDao.updateUser(user);

    clearSession();

    user = getUser(userDao, "subuser1");

    querySub = user.getSubscription("sub1");
    Assert.assertNull("sub1 mistakenly found", querySub);

    querySub = user.getSubscription("sub2");
    Assert.assertNotNull("sub2 not found", querySub);

    user.removeSubscription(querySub);
    userDao.updateUser(user);

    clearSession();

    user = getUser(userDao, "subuser1");

    querySub = user.getSubscription("sub1");
    Assert.assertNull("sub1 mistakenly found", querySub);

    querySub = user.getSubscription("sub2");
    Assert.assertNull("sub2 mistakenly found", querySub);
  }
 /**
  * Gets collection.
  *
  * @param parent The parent.
  * @param name The name.
  * @return The collection item.
  * @throws Exception - if something is wrong this exception is thrown.
  */
 private CollectionItem getCollection(CollectionItem parent, String name) throws Exception {
   for (Item child : (Set<Item>) parent.getChildren()) {
     if (child.getName().equals(name)) {
       return (CollectionItem) child;
     }
   }
   CollectionItem collection = new HibCollectionItem();
   collection.setName(name);
   collection.setDisplayName(name);
   collection.setOwner(parent.getOwner());
   return contentDao.createCollection(parent, collection);
 }