001: package org.contineo.core.security.dao;
002:
003: import java.util.Collection;
004:
005: import org.apache.commons.logging.Log;
006: import org.apache.commons.logging.LogFactory;
007: import org.contineo.core.AbstractCoreTestCase;
008: import org.contineo.core.security.Group;
009: import org.contineo.core.security.dao.GroupDAO;
010:
011: /**
012: * Test case for <code>HibernateGroupDAOTest</code>
013: *
014: * @author Alessandro Gasparini
015: * @since 3.0
016: */
017: public class HibernateGroupDAOTest extends AbstractCoreTestCase {
018:
019: protected static Log log = LogFactory
020: .getLog(HibernateGroupDAOTest.class);
021:
022: // Instance under test
023: private GroupDAO dao;
024:
025: public HibernateGroupDAOTest(String name) {
026: super (name);
027: }
028:
029: protected void setUp() throws Exception {
030: super .setUp();
031:
032: // Retrieve the instance under test from spring context. Make sure that
033: // it is an HibernateGroupDAO
034: dao = (GroupDAO) context.getBean("GroupDAO");
035: }
036:
037: public void testDelete() {
038: assertTrue(dao.exists("testGroup"));
039:
040: assertTrue(dao.delete("testGroup"));
041: assertFalse(dao.exists("testGroup"));
042:
043: // Delete a BIG group with associated MenuGroups and UserGroups
044: assertTrue(dao.delete("admin"));
045: assertFalse(dao.exists("admin"));
046: }
047:
048: public void testExists() {
049: assertTrue(dao.exists("admin"));
050: assertFalse(dao.exists("unexistent"));
051: assertFalse(dao.exists("xxxxo"));
052: }
053:
054: public void testFindByPrimaryKey() {
055: Group group = dao.findByPrimaryKey("admin");
056: assertNotNull(group);
057: assertEquals("admin", group.getGroupName());
058:
059: // Try with unexisting username
060: group = dao.findByPrimaryKey("xxxx");
061: assertNull(group);
062: }
063:
064: public void testFindAllGroupNames() {
065: Collection groupNames = dao.findAllGroupNames();
066: assertNotNull(groupNames);
067: assertFalse(groupNames.isEmpty());
068: assertTrue(groupNames.contains("admin"));
069: assertTrue(groupNames.contains("testGroup"));
070: }
071:
072: public void testStore() {
073: assertFalse(dao.exists("LogicalObjects"));
074:
075: Group group = new Group();
076: group.setGroupName("LogicalObjects");
077: group.setGroupDesc("Test group for store method");
078:
079: boolean result = dao.store(group);
080: assertTrue(dao.exists("LogicalObjects"));
081: assertTrue(result);
082:
083: Group group2 = dao.findByPrimaryKey("LogicalObjects");
084: assertEquals(group, group2);
085: }
086:
087: public void testInsert() {
088: assertFalse(dao.exists("parentNone"));
089:
090: Group group = new Group();
091: group.setGroupName("parentNone");
092: group
093: .setGroupDesc("Test group for insert method parent = none");
094:
095: assertTrue(dao.insert(group, null));
096: assertTrue(dao.exists("parentNone"));
097:
098: // Test with parentGroup Not Empty
099: assertFalse(dao.exists("parentNotEmpty"));
100:
101: group = new Group();
102: group.setGroupName("parentNotEmpty");
103: group
104: .setGroupDesc("Test group for insertX method parentGroup Not Empty");
105:
106: assertTrue(dao.insert(group, "parentNone"));
107: assertTrue(dao.exists("parentNotEmpty"));
108: }
109: }
|