1 64 65 package com.jcorporate.expresso.core.dbobj.tests; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.db.TableCreator; 69 import com.jcorporate.expresso.core.misc.ConfigManager; 70 import com.jcorporate.expresso.core.misc.ConfigurationException; 71 import com.jcorporate.expresso.services.test.TestSystemInitializer; 72 import junit.framework.Test; 73 import junit.framework.TestCase; 74 import junit.framework.TestSuite; 75 import org.apache.log4j.Logger; 76 77 import java.util.Enumeration ; 78 import java.util.Iterator ; 79 import java.util.Vector ; 80 81 82 85 public class OtherDBTest 86 extends TestCase { 87 private static Logger log = Logger.getLogger(OtherDBTest.class); 88 89 94 public OtherDBTest(String name) { 95 super(name); 96 } 97 98 103 public int countTestCases() { 104 return 1; 105 } 106 107 111 protected void setUp() 112 throws Exception { 113 TestSystemInitializer.setUp(); 114 try { 115 ConfigManager.getContext(TestSystemInitializer.getTestContext()); 116 } catch (ConfigurationException ce) { 117 fail("There is no 'test' db/context set up - cannot run db object tests without a test context"); 118 } 119 120 TestSchema ts = new TestSchema(); 121 Vector v = TableCreator.getInstance().createAsNeeded(ts, TestSystemInitializer.getTestContext()); 122 123 for (Enumeration ev = v.elements(); ev.hasMoreElements();) { 124 log.info((String ) ev.nextElement()); 125 } 126 } 127 128 129 133 protected void tearDown() 134 throws Exception { 135 try { 136 137 138 Test1 test1List = new Test1(); 139 test1List.setDataContext(TestSystemInitializer.getTestContext()); 140 141 Test1 oneTest1 = null; 142 143 for (Iterator i = test1List.searchAndRetrieveList().iterator(); 144 i.hasNext();) { 145 oneTest1 = (Test1) i.next(); 146 oneTest1.delete(); 147 } 148 149 Test2 test2List = new Test2(); 150 test2List.setDataContext(TestSystemInitializer.getTestContext()); 151 152 Test2 oneTest2 = null; 153 154 for (Iterator i = test1List.searchAndRetrieveList().iterator(); 155 i.hasNext();) { 156 oneTest2 = (Test2) i.next(); 157 oneTest2.delete(); 158 } 159 } catch (DBException de) { 160 log.error(de); 161 fail("Unable to clean up test object tables"); 162 } 163 } 164 165 166 169 public void testAdd() { 170 try { 171 172 173 Test1 oneTest = new Test1(); 174 oneTest.setDataContext(TestSystemInitializer.getTestContext()); 175 oneTest.setField("TestKey", "1"); 176 oneTest.add(); 177 } catch (DBException ce) { 178 log.error(ce); 179 fail("DB exception occurred - see log"); 180 } 181 182 try { 183 184 185 Test1 oneTest = new Test1(); 186 oneTest.setDataContext(TestSystemInitializer.getTestContext()); 187 oneTest.setField("TestKey", "1"); 188 oneTest.add(); 189 fail("Test add should have thrown exception on duplicate key here"); 190 } catch (DBException ce) { 191 192 193 } 194 try { 195 Test1 oneTest = new Test1(); 196 oneTest.setDataContext(TestSystemInitializer.getTestContext()); 197 oneTest.setField("TestKey", "1"); 198 oneTest.retrieve(); 199 } catch (DBException ce) { 200 log.error(ce); 201 fail("DB exception occurred on retrieve test - see log"); 202 } 203 try { 204 Test1 oneTest = new Test1(); 205 oneTest.setDataContext(TestSystemInitializer.getTestContext()); 206 oneTest.setField("TestKey", "1"); 207 208 if (!oneTest.find()) { 209 fail("DB exception occurred on retrieve test - see log"); 210 } 211 } catch (DBException ce) { 212 log.error(ce); 213 fail("DB exception occurred on find test - see log"); 214 } 215 } 216 217 222 public static Test suite() { 223 TestSuite suite = new TestSuite(OtherDBTest.class); 224 225 return suite; 226 } 227 228 } 229 230 | Popular Tags |