1 package de.nava.informa.impl.hibernate; 2 3 28 29 31 import java.net.URL ; 32 import java.util.List ; 33 34 import net.sf.hibernate.Hibernate; 35 import net.sf.hibernate.HibernateException; 36 import net.sf.hibernate.Transaction; 37 38 import org.apache.commons.logging.Log; 39 import org.apache.commons.logging.LogFactory; 40 41 import de.nava.informa.core.ChannelGroupIF; 42 import de.nava.informa.core.ChannelIF; 43 import de.nava.informa.utils.InformaHibernateTestCase; 44 45 51 public class TestChannelGroup extends InformaHibernateTestCase { 52 53 private static Log logger = LogFactory.getLog(TestChannelGroup.class); 54 55 public TestChannelGroup(String name) { 56 super("TestChannelGroup", name); 57 } 58 59 public void testChannelGroups() throws Exception { 60 ChannelBuilder builder = new ChannelBuilder(session); 61 Transaction tx = null; 62 int chId = -1; 63 int chGrpId = -1; 64 ChannelIF channel; 66 ChannelGroupIF grp1; 67 try { 69 tx = session.beginTransaction(); 70 String chanName = "Foo Test Channel"; 71 channel = builder.createChannel(chanName); 72 channel.setDescription("Test Channel: " + chanName); 73 channel.setLocation(new URL ("http://nava.de/test/channelFoo")); 74 session.saveOrUpdate(channel); 75 grp1 = builder.createChannelGroup("group A"); 76 grp1.add(channel); 77 session.saveOrUpdate(grp1); 78 tx.commit(); 79 chId = (int) channel.getId(); 80 chGrpId = (int) grp1.getId(); 81 } 82 catch (HibernateException he) { 83 logger.warn("trying to rollback the transaction"); 84 if (tx != null) tx.rollback(); 85 throw he; 86 } 87 assertTrue("No valid channel created.", chId >= 0); 88 assertTrue("No valid channel group created.", chGrpId >= 0); 89 try { 91 logger.info("Searching for channel group " + chGrpId); 92 List result = session.find("from ChannelGroup as grp where grp.id = ?", 93 new Integer (chGrpId), Hibernate.INTEGER); 94 assertEquals(1, result.size()); 95 ChannelGroupIF cg = (ChannelGroupIF) result.iterator().next(); 96 logger.info("retrieved channel group --> " + cg); 97 assertEquals(1, cg.getAll().size()); 98 ChannelIF c = (ChannelIF) cg.getAll().iterator().next(); 99 assertEquals("Foo Test Channel", c.getTitle()); 100 assertNull(cg.getParent()); 101 } 102 catch (HibernateException he) { 103 logger.warn("Error while querying for channel"); 104 throw he; 105 } 106 try { 108 tx = session.beginTransaction(); 109 session.delete(grp1); 110 session.delete(channel); 111 tx.commit(); 112 } 113 catch (HibernateException he) { 114 logger.warn("trying to rollback the transaction"); 115 if (tx != null) tx.rollback(); 116 throw he; 117 } 118 } 119 120 } 121 | Popular Tags |