001: package org.dbbrowser.db.engine.queryengine;
002:
003: import infrastructure.logging.Log;
004: import java.io.IOException;
005: import java.sql.Connection;
006: import java.sql.SQLException;
007: import java.util.Iterator;
008: import java.util.List;
009: import org.dbbrowser.db.engine.exception.DBEngineException;
010: import org.dbbrowser.db.engine.model.DBTable;
011: import org.dbbrowser.drivermanager.ConnectionInfo;
012: import org.dbbrowser.drivermanager.ConnectionInfoSerializer;
013: import org.dbbrowser.drivermanager.DBBrowserDriverManager;
014: import org.dbbrowser.drivermanager.DriverManagerException;
015: import junit.framework.TestCase;
016:
017: public class Oracle9iDBQueryEngineTest extends TestCase {
018: private Oracle9iDBQueryEngine oracle9iDBQueryEngine = null;
019: private static final String SCHEMA_NAME = "XCSSYS";
020: private static final String TABLE_NAME = "CLAIM";
021:
022: public Oracle9iDBQueryEngineTest(String name) {
023: super (name);
024: }
025:
026: public void setUp() {
027: try {
028: Log
029: .getInstance()
030: .debugMessage(
031: "*** Setting up connection for Oracle database *** ",
032: this .getClass().getName());
033:
034: //Get the connection info
035: List listOfConnectionInfo = ConnectionInfoSerializer
036: .deserialize();
037:
038: //Get the Oracle connection info
039: Iterator i = listOfConnectionInfo.iterator();
040: ConnectionInfo ci = null;
041: while (i.hasNext()) {
042: ConnectionInfo connectionInfo = (ConnectionInfo) i
043: .next();
044: if (connectionInfo.getName().equals(
045: "XCSSYS for Data Migration")) {
046: ci = connectionInfo;
047: break;
048: }
049: }
050:
051: //Get the connection if connection info is not null
052: if (ci != null) {
053: Connection conn = DBBrowserDriverManager.getInstance()
054: .getConnection(ci, null);
055:
056: //Setup the query engine
057: oracle9iDBQueryEngine = new Oracle9iDBQueryEngine(conn
058: .createStatement());
059: } else {
060: Log
061: .getInstance()
062: .fatalMessage(
063: "*** No Connection info found for Oracle database *** ",
064: this .getClass().getName());
065: fail("*** No Connection info found for Oracle database *** ");
066: }
067: } catch (ClassNotFoundException exc) {
068: Log.getInstance().fatalMessage(
069: "*** ClassNotFoundException *** "
070: + exc.getMessage(),
071: this .getClass().getName());
072: fail(exc.getMessage());
073: } catch (IOException exc) {
074: Log.getInstance().fatalMessage(
075: "*** IOException *** " + exc.getMessage(),
076: this .getClass().getName());
077: fail(exc.getMessage());
078: } catch (DriverManagerException exc) {
079: Log.getInstance().fatalMessage(
080: "*** DriverManagerException *** "
081: + exc.getMessage(),
082: this .getClass().getName());
083: fail(exc.getMessage());
084: } catch (SQLException exc) {
085: Log.getInstance().fatalMessage(
086: "*** SQLException *** " + exc.getMessage(),
087: this .getClass().getName());
088: fail(exc.getMessage());
089: }
090: }
091:
092: public void testGetAllDataInATable() {
093: try {
094: Log.getInstance().debugMessage(
095: "*** testCountNumberOfRows for Oracle DBMS *** ",
096: this .getClass().getName());
097:
098: //Get the number of rows in a table
099: Integer rowCount = oracle9iDBQueryEngine.getRowCount(
100: SCHEMA_NAME, TABLE_NAME);
101:
102: assertTrue("Number of rows in " + TABLE_NAME + " is "
103: + rowCount.intValue(), rowCount.intValue() == 663);
104: } catch (DBEngineException exc) {
105: Log.getInstance().fatalMessage(
106: "*** DriverManagerException *** "
107: + exc.getMessage(),
108: this .getClass().getName());
109: fail(exc.getMessage());
110: }
111: }
112:
113: public void testListIndexes() {
114: try {
115: Log.getInstance().debugMessage(
116: "*** testListIndexes for Oracle DBMS *** ",
117: this .getClass().getName());
118:
119: //Get the number of rows in a table
120: DBTable table = oracle9iDBQueryEngine.listIndexes();
121:
122: assertTrue("Number of indexes is "
123: + table.getListOfRows().size(), table
124: .getListOfRows().size() == 52);
125: } catch (DBEngineException exc) {
126: Log.getInstance().fatalMessage(
127: "*** DriverManagerException *** "
128: + exc.getMessage(),
129: this .getClass().getName());
130: fail(exc.getMessage());
131: }
132: }
133:
134: public void testCountNumberOfRows() {
135: try {
136: Log.getInstance().debugMessage(
137: "*** testCountNumberOfRows for Oracle DBMS *** ",
138: this .getClass().getName());
139:
140: //Get the number of rows in a table
141: Integer rowCount = oracle9iDBQueryEngine.getRowCount(
142: SCHEMA_NAME, TABLE_NAME);
143:
144: assertTrue("Number of rows in " + TABLE_NAME + " is "
145: + rowCount.intValue(), rowCount.intValue() == 663);
146: } catch (DBEngineException exc) {
147: Log.getInstance().fatalMessage(
148: "*** DriverManagerException *** "
149: + exc.getMessage(),
150: this .getClass().getName());
151: fail(exc.getMessage());
152: }
153: }
154:
155: public void testListSchemas() {
156: try {
157: Log.getInstance().debugMessage(
158: "*** testListSchemas for Oracle DBMS *** ",
159: this .getClass().getName());
160:
161: //Get the list of table spaces
162: List listOfSchemas = oracle9iDBQueryEngine.listSchemas();
163:
164: assertTrue("Schema " + SCHEMA_NAME + " found",
165: listOfSchemas.contains(SCHEMA_NAME));
166: } catch (DBEngineException exc) {
167: Log.getInstance().fatalMessage(
168: "*** DriverManagerException *** "
169: + exc.getMessage(),
170: this .getClass().getName());
171: fail(exc.getMessage());
172: }
173: }
174:
175: public void testListConstraints() {
176: try {
177: Log.getInstance().debugMessage(
178: "*** testListConstraints for Oracle DBMS *** ",
179: this .getClass().getName());
180:
181: //Get the list of table spaces
182: DBTable tableForConstraints = oracle9iDBQueryEngine
183: .listConstraints();
184:
185: assertTrue("Number of constraints in " + SCHEMA_NAME
186: + " is "
187: + tableForConstraints.getListOfRows().size(),
188: tableForConstraints.getListOfRows().size() == 203);
189: } catch (DBEngineException exc) {
190: Log.getInstance().fatalMessage(
191: "*** DriverManagerException *** "
192: + exc.getMessage(),
193: this .getClass().getName());
194: fail(exc.getMessage());
195: }
196: }
197:
198: public void testListTablesInSchema() {
199: try {
200: Log.getInstance().debugMessage(
201: "*** testListTablesInSchema for Oracle DBMS *** ",
202: this .getClass().getName());
203:
204: //Get the list of tables
205: List listOfTables = oracle9iDBQueryEngine
206: .listTablesInSchema(SCHEMA_NAME);
207:
208: assertTrue("Table " + TABLE_NAME + " found in schema "
209: + SCHEMA_NAME, listOfTables.contains(TABLE_NAME));
210: } catch (DBEngineException exc) {
211: Log.getInstance().fatalMessage(
212: "*** DriverManagerException *** "
213: + exc.getMessage(),
214: this .getClass().getName());
215: fail(exc.getMessage());
216: }
217: }
218:
219: /*public void testGetAllFilteredDataInATable()
220: {
221: try
222: {
223: Log.getInstance().debugMessage("*** testGetAllFilteredDataInATable for Oracle DBMS *** ", this.getClass().getName());
224:
225: //Build the filters
226: ColumnInfo ci1 = new ColumnInfo("UCR", ColumnInfo.COLUMN_TYPE_VARCHAR, "java.lang.String", new Integer(17), ColumnInfo.COLUMN_NULLABLE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, null);
227: DBTableCell dbTableCell1 = new DBTableCell(ci1, "B0423LINKED1", Boolean.FALSE);
228: ColumnInfo ci2 = new ColumnInfo("client_name", ColumnInfo.COLUMN_TYPE_VARCHAR, "java.lang.String", new Integer(17), ColumnInfo.COLUMN_NULLABLE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, null);
229: DBTableCell dbTableCell2 = new DBTableCell(ci2, "Ascot", Boolean.FALSE);
230:
231: List listOfFilters = new ArrayList();
232: listOfFilters.add( dbTableCell1 );
233: listOfFilters.add( dbTableCell2 );
234:
235: //Get the data in the form of a dbtable
236: DBTable dbTable = oracle9iDBQueryEngine.testGetAllFilteredDataInATable(SCHEMA_NAME, TABLE_NAME, listOfFilters);
237: Log.getInstance().debugMessage("List of rows size is: " + dbTable.getListOfRows().size(), this.getClass().getName());
238:
239: assertTrue("Should return 1 record", dbTable.getListOfRows().size() == 1);
240: }
241: catch(DBEngineException exc)
242: {
243: Log.getInstance().fatalMessage("*** DBEngineException *** " + exc.getMessage(), this.getClass().getName());
244: fail(exc.getMessage());
245: }
246: }*/
247:
248: public void testGetPrimaryKeyColumnNames() {
249: try {
250: Log
251: .getInstance()
252: .debugMessage(
253: "*** testGetPrimaryKeyColumnNames for Oracle DBMS *** ",
254: this .getClass().getName());
255:
256: //Get the primary keys for the table
257: List listOfPrimaryKeyColumnNames = oracle9iDBQueryEngine
258: .getPrimaryKeyColumnNames(SCHEMA_NAME, TABLE_NAME);
259: assertTrue("List of primary key in table " + TABLE_NAME
260: + " should be 1", listOfPrimaryKeyColumnNames
261: .size() == 1);
262: } catch (DBEngineException exc) {
263: Log.getInstance().fatalMessage(
264: "*** DBEngineException *** " + exc.getMessage(),
265: this .getClass().getName());
266: fail(exc.getMessage());
267: }
268: }
269:
270: public void testListColumnsInATable() {
271: try {
272: Log.getInstance().debugMessage(
273: "*** testListColumnsInATable for Oracle DBMS *** ",
274: this .getClass().getName());
275:
276: //Get the list of columns in the table
277: List listColumnInfos = oracle9iDBQueryEngine
278: .listColumnsInATable(SCHEMA_NAME, TABLE_NAME);
279: assertTrue("List of columns in table " + TABLE_NAME
280: + " should be 52", listColumnInfos.size() == 55);
281: } catch (DBEngineException exc) {
282: Log.getInstance().fatalMessage(
283: "*** DBEngineException *** " + exc.getMessage(),
284: this.getClass().getName());
285: fail(exc.getMessage());
286: }
287: }
288: }
|