Package de.nava.informa.core

Examples of de.nava.informa.core.ChannelGroupIF


   * Simple test of group creation. Creates group and checks the filling of data fields.
   *
   * @see PersistenceManagerIF#createGroup
   */
  public void testCreateGroup() {
    ChannelGroupIF group = null;

    try {
      // Create simple group and check how the fields are filled
      group = manager.createGroup(tuids1);
      assertNotNull("Group object should be returned.", group);

      assertTrue("ID should be initialized with some meaningful value.", -1 != group.getId());
      assertEquals("Title should be set.", tuids1, group.getTitle());

      final ChannelGroupIF group2 = findGroupById(group.getId());
      assertTrue("Manager should operate with the same objects.", group == group2);
    } catch (PersistenceManagerException e)
    {
      e.printStackTrace();
      fail();
View Full Code Here


   * Tests how group is deleted from storage.
   *
   * @see PersistenceManagerIF#deleteGroup
   */
  public void testDeleteGroup() {
    ChannelGroupIF group = null;

    try {
      // Create simple group
      group = manager.createGroup(tuids1);
      final long groupId = group.getId();
      manager.deleteGroup(group);

      assertEquals("Object ID should be turned back to -1.", -1, group.getId());
      final ChannelGroupIF group2 = findGroupById(groupId);
      assertNull("Object should be deleted from storage.", group2);
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail();
    }
View Full Code Here

   * Tests how groups with assigned channels are deleted.
   *
   * @see PersistenceManagerIF#deleteGroup
   */
  public void testDeleteGroupCascade() {
    ChannelGroupIF group = null;
    ChannelIF channel = null;

    try {
      // Create simple group with channel
      group = manager.createGroup(tuids1);
      channel = manager.createChannel(tuids1, url1);
      manager.addChannelToGroup(channel, group);

      final long groupId = group.getId();
      manager.deleteGroup(group);

      assertEquals("Object ID should be turned back to -1.", -1, group.getId());
      final ChannelGroupIF group2 = findGroupById(groupId);
      assertNull("Object should be deleted from storage.", group2);
      assertEquals("Group still has channels assigned.", 0, group.getAll().size());
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail();
View Full Code Here

   * are deleted as well.
   *
   * @see PersistenceManagerIF#deleteChannel
   */
  public void testDeleteChannelCascade() {
    ChannelGroupIF group = null;
    ChannelIF channel = null;
    ItemIF item1 = null;
    ItemIF item2 = null;

    try {
      // Create group and channel with two items
      group = manager.createGroup(tuids1);
      channel = manager.createChannel(tuids1, url1);
      item1 = manager.createItem(channel, tuids1);
      item2 = manager.createItem(channel, tuids2);

      // Put channel in group
      manager.addChannelToGroup(channel, group);

      // Delete channel
      manager.deleteChannel(channel);

      // Check that it was removed from parent group and all of its items gone too
      assertEquals("Group still has channels.", 0, group.getAll().size());
      assertEquals("Channel still has items.", 0, channel.getItems().size());
      assertEquals("Item still has initialized ID.", -1, item1.getId());
      assertEquals("Item still has initialized ID.", -1, item2.getId());
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail();
    } finally {
      // Delete channel, group and items
      try {
        if (item1 != null && item1.getId() != -1) manager.deleteItem(item1);
        if (item2 != null && item2.getId() != -1) manager.deleteItem(item2);
        if (channel != null && channel.getId() != -1) manager.deleteChannel(channel);
        if (group != null && group.getId() != -1) manager.deleteGroup(group);
      } catch (PersistenceManagerException e) {
        // We can do nothing here
      }
    }
  }
View Full Code Here

   *
   * @see PersistenceManagerIF#addChannelToGroup
   */
  public void testAddChannelToGroup() {
    ChannelIF channel = null;
    ChannelGroupIF group = null;

    try {
      // Create channel & group
      channel = manager.createChannel(tuids1, url1);
      group = manager.createGroup(tuids2);

      // Add channel to group
      manager.addChannelToGroup(channel, group);
      final Collection channels = group.getAll();
      assertEquals("Channel isn't added to group.", 1, channels.size());
      assertEquals("Wrong channel was added to group.", channel, channels.iterator().next());

      // Add duplicate channel to group
      manager.addChannelToGroup(channel, group);
      final Collection channels2 = group.getAll();
      assertEquals("Duplicate channel shouldn't be added to group.", 1, channels2.size());
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail();
    } finally {
      // Delete channel and group
      try {
        if (channel != null && channel.getId() != -1) manager.deleteChannel(channel);
        if (group != null && group.getId() != -1) manager.deleteGroup(group);
      } catch (PersistenceManagerException e) {
        // We can do nothing here.
      }
    }
  }
View Full Code Here

   *
   * @see PersistenceManagerIF#removeChannelFromGroup
   */
  public void testRemoveChannelFromGroup() {
    ChannelIF channel = null;
    ChannelGroupIF group = null;

    try {
      // Create channel & group
      channel = manager.createChannel(tuids1, url1);
      group = manager.createGroup(tuids2);

      // Add channel to group
      manager.addChannelToGroup(channel, group);

      // Remove channel from group
      manager.removeChannelFromGroup(channel, group);
      final Collection channels = group.getAll();
      assertEquals("Channel wasn't removed from group.", 0, channels.size());

      // Remove not-existing channel from group
      manager.removeChannelFromGroup(channel, group);
      final Collection channels2 = group.getAll();
      assertEquals("Channel wasn't removed from group.", 0, channels2.size());
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail();
    } finally {
View Full Code Here

   * Tests how the groups are merged.
   *
   * @see PersistenceManagerIF#mergeGroups
   */
  public void testMergeChannels() {
    ChannelGroupIF group1 = null;
    ChannelGroupIF group2 = null;
    ChannelIF channel1 = null;
    ChannelIF channel2 = null;
    ChannelIF channel3 = null;

    try {
      // Create 2 grops and 3 channels: 1 in first group and 2 in the second
      group1 = manager.createGroup(tuids1);
      group2 = manager.createGroup(tuids2);
      channel1 = manager.createChannel(tuids1, url1);
      channel2 = manager.createChannel(tuids2, url2);
      channel3 = manager.createChannel(tuids3, url3);

      final long group2Id = group2.getId();

      // Add channels to groups
      manager.addChannelToGroup(channel1, group1);
      manager.addChannelToGroup(channel2, group2);
      manager.addChannelToGroup(channel3, group2);

      // Move channels from second to first
      manager.mergeGroups(group1, group2);

      // Check the lists of channels in groups
      final Collection channels1 = group1.getAll();
      assertNotNull(channels1);
      assertEquals("Channels are incorrectly moved to first group.", 3, channels1.size());
      assertTrue("Order of channels is incorrect.", channels1.contains(channel1));
      assertTrue("Order of channels is incorrect.", channels1.contains(channel2));
      assertTrue("Order of channels is incorrect.", channels1.contains(channel3));
      assertEquals("ID of removed group is still in intialized state.", -1, group2.getId());
      assertNull("Second group still can be found in storage.", findGroupById(group2Id));
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail();
    } finally {
      // Delete groups and channels
      try {
        if (group1 != null) manager.deleteGroup(group1);
        if (group2 != null && group2.getId() != -1) manager.deleteGroup(group2);
        if (channel1 != null) manager.deleteChannel(channel1);
        if (channel2 != null) manager.deleteChannel(channel2);
        if (channel3 != null) manager.deleteChannel(channel3);
      } catch (PersistenceManagerException e) {
        // We can do nothing here.
View Full Code Here

   *
   * @throws PersistenceManagerException in cases of error.
   */
  private ChannelGroupIF findGroupById(long id)
    throws PersistenceManagerException {
    ChannelGroupIF result = null;

    final ChannelGroupIF[] groups = manager.getGroups();
    boolean found = false;
    int i = 0;
    while (i < groups.length && !found) {
      result = groups[i];
      found = result.getId() == id;
      i++;
    }

    return found ? result : null;
  }
View Full Code Here

    Transaction tx = null;
    int chId = -1;
    int chGrpId = -1;
    // our test objects
    ChannelIF channel;
    ChannelGroupIF grp1;
    // -- first create a channel with a category assigned
    try {
      tx = session.beginTransaction();
      String chanName = "Foo Test Channel";
      channel = builder.createChannel(chanName);
      channel.setDescription("Test Channel: " + chanName);
      channel.setLocation(new URL("http://nava.de/test/channelFoo"));
      session.saveOrUpdate(channel);
      grp1 = builder.createChannelGroup("group A");
      grp1.add(channel);
      session.saveOrUpdate(grp1);
      tx.commit();
      chId = (int) channel.getId();
      chGrpId = (int) grp1.getId();
    }
    catch (HibernateException he) {
      logger.warn("trying to rollback the transaction");
      if (tx != null) tx.rollback();
      throw he;
    }
    assertTrue("No valid channel created.", chId >= 0);
    assertTrue("No valid channel group created.", chGrpId >= 0);
    // -- try to retrieve channel and the assigned category
    try {
      logger.info("Searching for channel group " + chGrpId);
      Object result = session.get(ChannelGroup.class, new Long(chGrpId));
      assertNotNull(result);
      ChannelGroupIF cg = (ChannelGroupIF) result;
      logger.info("retrieved channel group --> " + cg);
      assertEquals(1, cg.getAll().size());
      ChannelIF c = (ChannelIF) cg.getAll().iterator().next();
      assertEquals("Foo Test Channel", c.getTitle());
      assertNull(cg.getParent());
    }
    catch (HibernateException he) {
      logger.warn("Error while querying for channel");
      throw he;
    }
View Full Code Here

*/
public class SpringPersistenceManager extends HibernateDaoSupport implements PersistenceManagerIF {


  public ChannelGroupIF createGroup(String title) throws PersistenceManagerException {
    ChannelGroupIF group = new ChannelGroup(title);
    getHibernateTemplate().save(group);
    return group;
  }
View Full Code Here

TOP

Related Classes of de.nava.informa.core.ChannelGroupIF

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.