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