1
2
3
4
5
6
7
8
9
10 package com.sri.emo.dbobj;
11
12 import com.jcorporate.expresso.core.db.DBConnection;
13 import com.jcorporate.expresso.core.db.DBConnectionPool;
14 import com.jcorporate.expresso.core.db.DBException;
15 import com.jcorporate.expresso.core.dbobj.DBObject;
16 import com.jcorporate.expresso.core.dbobj.Schema;
17 import com.jcorporate.expresso.core.utility.DBToolTests;
18 import com.jcorporate.expresso.ext.dbobj.SingleDBUserInfo;
19 import com.jcorporate.expresso.services.dbobj.DefaultUserInfo;
20 import com.jcorporate.expresso.services.test.TestSystemInitializer;
21 import com.sri.emo.EmoSchema;
22 import junit.framework.TestSuite;
23
24 import java.util.Enumeration;
25 import java.util.TreeSet;
26
27
28 /***
29 * This class validates the schema by automatically creating it
30 * Base Class Tests from DBToolTests perform the actual work.
31 */
32 public class TestSchema
33 extends DBToolTests {
34 public TestSchema(String testName)
35 throws Exception {
36 super(testName);
37 }
38
39 public static junit.framework.Test suite()
40 throws Exception {
41
42
43 TestSuite ts = new TestSuite("Schema Verification Tests");
44 ts.addTest(new TestSchema("testCreate"));
45 ts.addTest(new TestSchema("testAddingSchemas"));
46 ts.addTest(new TestSchema("testSetupSecurity"));
47 ts.addTest(new TestSchema("testPopulateTables"));
48 ts.addTest(new TestSchema("testOtherSetups"));
49 ts.addTest(new TestSchema("testVerify"));
50 return ts;
51 }
52
53 protected void setUp()
54 throws Exception {
55 super.setUp();
56
57
58 schemaList.add(new EmoSchema());
59 }
60
61 public void testVerify() {
62 TreeSet tableNames = new TreeSet();
63 DBConnectionPool myPool = null;
64 DBConnection myConnection = null;
65
66 try {
67 if (!isFailedOnce()) {
68 assertTrue("schemaList.size() > 0", schemaList.size() > 0);
69
70 Schema thisSchema = null;
71
72 for (Enumeration als = schemaList.elements();
73 als.hasMoreElements();) {
74 thisSchema = (Schema) als.nextElement();
75 System.out.println("Verifying Schema " +
76 thisSchema.getClass().getName());
77
78 DBObject oneObject = null;
79
80 for (Enumeration dbo = thisSchema.getMembers();
81 dbo.hasMoreElements();) {
82 oneObject = (DBObject) dbo.nextElement();
83 oneObject.setDataContext(TestSystemInitializer.getTestContext());
84
85
86 if (tableNames.contains(oneObject.getJDBCMetaData().getTargetTable())) {
87
88
89
90
91
92
93 String objName = oneObject.getClass().getName();
94 if (objName.equals(DefaultUserInfo.class.getName())
95 || objName.equals(SingleDBUserInfo.class.getName())
96 || objName.equals(com.sri.common.util.PermGroup.class.getName())) {
97 } else {
98 fail("Table name: " +
99 oneObject.getJDBCMetaData().getTargetTable() +
100 " already exists due to another DBObject. Offending DBObject" +
101 oneObject.getClass().getName());
102 }
103 } else {
104 tableNames.add(oneObject.getJDBCMetaData().getTargetTable());
105 }
106
107 try {
108 oneObject.verify();
109 } catch (DBException de) {
110 myPool.release(myConnection);
111 System.out.println(de.getMessage());
112 de.printStackTrace();
113 fail("Error in object " + oneObject.getJDBCMetaData().getName() +
114 ":" + de.getMessage());
115 }
116 }
117
118
119 }
120 } else {
121 fail();
122 }
123 } catch (Exception e) {
124 System.out.println(e.getMessage());
125 e.printStackTrace();
126 setFailedOnce(true);
127
128 if (myPool != null && myConnection != null) {
129 myPool.release(myConnection);
130 }
131
132 fail(e.getMessage());
133 }
134
135 }
136
137
138 public static void main(String[] args)
139 throws Exception {
140
141
142 junit.textui.TestRunner.run(suite());
143 }
144 }