001: package org.dbbrowser.db.engine.rawsqlengine;
002:
003: import junit.framework.TestCase;
004: import org.dbbrowser.db.engine.exception.DBEngineException;
005: import org.dbbrowser.db.engine.model.DBTable;
006: import org.dbbrowser.db.engine.rawsqlengine.GenericRawSQLEngine;
007: import org.dbbrowser.drivermanager.ConnectionInfoSerializer;
008: import org.dbbrowser.drivermanager.ConnectionInfo;
009: import org.dbbrowser.drivermanager.DBBrowserDriverManager;
010: import org.dbbrowser.drivermanager.DriverManagerException;
011: import infrastructure.logging.Log;
012: import java.util.List;
013: import java.util.Iterator;
014: import java.sql.Connection;
015: import java.sql.SQLException;
016: import java.io.IOException;
017:
018: public class OracleGenericRawSQLEngineAutoCommitOnTest extends TestCase {
019: private GenericRawSQLEngine genericRawSQLEngine = null;
020:
021: public OracleGenericRawSQLEngineAutoCommitOnTest(String name) {
022: super (name);
023: }
024:
025: public void setUp() {
026: try {
027: Log
028: .getInstance()
029: .debugMessage(
030: "*** Setting up connection for Oracle database *** ",
031: this .getClass().getName());
032:
033: //Get the connection info
034: List listOfConnectionInfo = ConnectionInfoSerializer
035: .deserialize();
036:
037: //Get the Oracle connection info
038: Iterator i = listOfConnectionInfo.iterator();
039: ConnectionInfo ci = null;
040: while (i.hasNext()) {
041: ConnectionInfo connectionInfo = (ConnectionInfo) i
042: .next();
043: if (connectionInfo.getName().equals("Oracle PPDB")) {
044: ci = connectionInfo;
045: break;
046: }
047: }
048:
049: //Get the connection if connection info is not null
050: if (ci != null) {
051: Connection conn = DBBrowserDriverManager.getInstance()
052: .getConnection(ci, null);
053:
054: //Setup the update engine
055: genericRawSQLEngine = new GenericRawSQLEngine(conn
056: .createStatement());
057: } else {
058: Log
059: .getInstance()
060: .fatalMessage(
061: "*** No Connection info found for Oracle database *** ",
062: this .getClass().getName());
063: fail("*** No Connection info found for Oracle database *** ");
064: }
065: } catch (ClassNotFoundException exc) {
066: Log.getInstance().fatalMessage(
067: "*** ClassNotFoundException *** "
068: + exc.getMessage(),
069: this .getClass().getName());
070: fail(exc.getMessage());
071: } catch (IOException exc) {
072: Log.getInstance().fatalMessage(
073: "*** IOException *** " + exc.getMessage(),
074: this .getClass().getName());
075: fail(exc.getMessage());
076: } catch (DriverManagerException exc) {
077: Log.getInstance().fatalMessage(
078: "*** DriverManagerException *** "
079: + exc.getMessage(),
080: this .getClass().getName());
081: fail(exc.getMessage());
082: } catch (SQLException exc) {
083: Log.getInstance().fatalMessage(
084: "*** SQLException *** " + exc.getMessage(),
085: this .getClass().getName());
086: fail(exc.getMessage());
087: }
088: }
089:
090: public void testRunRawSelectSQLStatement() {
091: try {
092: Log
093: .getInstance()
094: .debugMessage(
095: "*** GenericRawSQLEngineTest.testRunRawSelectSQLStatement *** ",
096: this .getClass().getName());
097:
098: DBTable dbTable = this .genericRawSQLEngine
099: .runRawSQL("select count(*) from claim_experts");
100: assertTrue("Number of rows should be 1", dbTable
101: .getNumberOfRowsInTable().intValue() == 1);
102: } catch (DBEngineException exc) {
103: Log.getInstance().fatalMessage(
104: "*** DBEngineException *** " + exc.getMessage(),
105: this .getClass().getName());
106: fail(exc.getMessage());
107: }
108: }
109:
110: public void testRunRawInsertSQLStatement() {
111: try {
112: Log
113: .getInstance()
114: .debugMessage(
115: "*** GenericRawSQLEngineTest.testRunRawInsertSQLStatement *** ",
116: this .getClass().getName());
117:
118: String sql = "insert into CLAIM_EXPERTS (ID, CLAIM_ID, EXPERT_ID) "
119: + "values ( CLAIM_EXPERTS_SEQ.nextval, 4, 15)";
120: DBTable dbTable = this .genericRawSQLEngine.runRawSQL(sql);
121: assertTrue("DBTable should be null", dbTable == null);
122: } catch (DBEngineException exc) {
123: Log.getInstance().fatalMessage(
124: "*** DBEngineException *** " + exc.getMessage(),
125: this .getClass().getName());
126: fail(exc.getMessage());
127: }
128: }
129:
130: public void testRunRawUpdateSQLStatement() {
131: try {
132: Log
133: .getInstance()
134: .debugMessage(
135: "*** GenericRawSQLEngineTest.testRunRawUpdateSQLStatement *** ",
136: this .getClass().getName());
137:
138: DBTable dbTable = this .genericRawSQLEngine
139: .runRawSQL("update CLAIM_EXPERTS set individual_name = 'Updated by JUnit' where CLAIM_ID=534");
140: assertTrue(
141: "GenericRawSQLEngineTest.testRunRawUpdateSQLStatement should be null",
142: dbTable == null);
143: } catch (DBEngineException exc) {
144: Log.getInstance().fatalMessage(
145: "*** DBEngineException *** " + exc.getMessage(),
146: this .getClass().getName());
147: fail(exc.getMessage());
148: }
149: }
150:
151: public void testRunRawDeleteSQLStatement() {
152: try {
153: Log
154: .getInstance()
155: .debugMessage(
156: "*** GenericRawSQLEngineTest.testRunRawDeleteSQLStatement *** ",
157: this .getClass().getName());
158:
159: DBTable dbTable = this .genericRawSQLEngine
160: .runRawSQL("delete from CLAIM_EXPERTS where CLAIM_ID=534");
161: assertTrue(
162: "GenericRawSQLEngineTest.testRunRawDeleteSQLStatement should be null",
163: dbTable == null);
164: } catch (DBEngineException exc) {
165: Log.getInstance().fatalMessage(
166: "*** DBEngineException *** " + exc.getMessage(),
167: this .getClass().getName());
168: fail(exc.getMessage());
169: }
170: }
171:
172: public void testRunRawAddColumnSQLStatement() {
173: try {
174: Log
175: .getInstance()
176: .debugMessage(
177: "*** GenericRawSQLEngineTest.testRunRawAddColumnSQLStatement *** ",
178: this .getClass().getName());
179:
180: DBTable dbTable = this .genericRawSQLEngine
181: .runRawSQL("alter table CLAIM_EXPERTS add test_column varchar(10)");
182: assertTrue(
183: "GenericRawSQLEngineTest.testRunRawAlterTableSQLStatement should be null",
184: dbTable == null);
185: } catch (DBEngineException exc) {
186: Log.getInstance().fatalMessage(
187: "*** DBEngineException *** " + exc.getMessage(),
188: this .getClass().getName());
189: fail(exc.getMessage());
190: }
191: }
192:
193: public void testRunRawDropColumnSQLStatement() {
194: try {
195: Log
196: .getInstance()
197: .debugMessage(
198: "*** GenericRawSQLEngineTest.testRunRawDropColumnSQLStatement *** ",
199: this .getClass().getName());
200:
201: DBTable dbTable = this .genericRawSQLEngine
202: .runRawSQL("alter table CLAIM_EXPERTS drop column test_column");
203: assertTrue(
204: "GenericRawSQLEngineTest.testRunRawAlterTableSQLStatement should be null",
205: dbTable == null);
206: } catch (DBEngineException exc) {
207: Log.getInstance().fatalMessage(
208: "*** DBEngineException *** " + exc.getMessage(),
209: this .getClass().getName());
210: fail(exc.getMessage());
211: }
212: }
213:
214: public void testStripComments() {
215: Log.getInstance().debugMessage(
216: "*** GenericRawSQLEngineTest.testStripComments *** ",
217: this .getClass().getName());
218:
219: String sql = this .genericRawSQLEngine
220: .stripComments("alter table CLAIM_EXPERTS /*Test comments*/drop column test_column");
221: assertTrue(
222: "GenericRawSQLEngineTest.testStripComments sql is incorrect",
223: "alter table CLAIM_EXPERTS drop column test_column"
224: .equals(sql));
225: }
226: }
|