1 64 65 package com.jcorporate.expresso.core.security.tests; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.services.dbobj.GroupNest; 69 import com.jcorporate.expresso.services.dbobj.UserGroup; 70 import com.jcorporate.expresso.services.test.TestSystemInitializer; 71 import junit.framework.Test; 72 import junit.framework.TestCase; 73 import junit.framework.TestSuite; 74 import org.apache.log4j.Logger; 75 76 77 81 public class UserGroupTest 82 extends TestCase { 83 private static Logger log = Logger.getLogger(UserGroupTest.class); 84 85 90 public UserGroupTest(String name) { 91 super(name); 92 } 93 94 95 99 protected void tearDown() 100 throws Exception { 101 try { 102 GroupNest gn = new GroupNest(); 103 gn.setDataContext(TestSystemInitializer.getTestContext()); 104 gn.setField("GroupName", "Test1"); 105 gn.setField("MemberOf", "Test2"); 106 107 if (gn.find()) { 108 gn.delete(); 109 } 110 111 UserGroup oneGroup = new UserGroup(); 112 oneGroup.setDataContext(TestSystemInitializer.getTestContext()); 113 oneGroup.setField("GroupName", "Test1"); 114 115 if (oneGroup.find()) { 116 oneGroup.delete(); 117 } 118 119 oneGroup.clear(); 120 oneGroup.setField("GroupName", "Test2"); 121 122 if (oneGroup.find()) { 123 oneGroup.delete(); 124 } 125 } catch (DBException de) { 126 log.error(de); 127 fail("Unable to clean up test tables"); 128 } 129 } 130 131 132 135 public void testAdd() { 136 try { 137 UserGroup oneGroup = new UserGroup(); 138 oneGroup.setDataContext(TestSystemInitializer.getTestContext()); 139 oneGroup.clear(); 140 oneGroup.setDataContext(TestSystemInitializer.getTestContext()); 141 oneGroup.setField("GroupName", "Test1"); 142 143 if (!oneGroup.find()) { 144 oneGroup.setField("Descrip", "Test1 Group"); 145 oneGroup.add(); 146 log.info("Added 'Test1' user group"); 147 } 148 149 oneGroup.clear(); 150 oneGroup.setDataContext(TestSystemInitializer.getTestContext()); 151 oneGroup.setField("GroupName", "Test2"); 152 153 if (!oneGroup.find()) { 154 oneGroup.setField("Descrip", "Test2 Group"); 155 oneGroup.add(); 156 log.info("Added 'Test2' user group"); 157 } 158 159 GroupNest gn = new GroupNest(); 160 gn.setDataContext(TestSystemInitializer.getTestContext()); 161 gn.setField("GroupName", "Test1"); 162 gn.setField("MemberOf", "Test2"); 163 164 if (!gn.find()) { 165 gn.add(); 166 log.info("Added 'Test2' as nested group of 'Test1'"); 167 } 168 } catch (DBException ce) { 169 log.error(ce); 170 fail("DB exception occurred - see log"); 171 } 172 } 173 174 179 public static Test suite() { 180 TestSuite suite = new TestSuite(UserGroupTest.class); 181 182 return suite; 183 } 184 185 } 186 | Popular Tags |