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 MySQLGenericRawSQLEngineAutoCommitOnTest extends TestCase {
019: private GenericRawSQLEngine genericRawSQLEngine = null;
020: private Connection conn = null;
021:
022: public MySQLGenericRawSQLEngineAutoCommitOnTest(String name) {
023: super (name);
024: }
025:
026: public void setUp() {
027: try {
028: Log
029: .getInstance()
030: .debugMessage(
031: "*** Setting up connection for MySQL 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("HWW on MySQL")) {
045: ci = connectionInfo;
046: break;
047: }
048: }
049:
050: //Get the connection if connection info is not null
051: if (ci != null) {
052: Connection conn = DBBrowserDriverManager.getInstance()
053: .getConnection(ci, null);
054:
055: //Setup the update engine
056: genericRawSQLEngine = new GenericRawSQLEngine(conn
057: .createStatement());
058: } else {
059: Log
060: .getInstance()
061: .fatalMessage(
062: "*** No Connection info found for MySQL database *** ",
063: this .getClass().getName());
064: fail("*** No Connection info found for MySQL database *** ");
065: }
066: } catch (ClassNotFoundException exc) {
067: Log.getInstance().fatalMessage(
068: "*** ClassNotFoundException *** "
069: + exc.getMessage(),
070: this .getClass().getName());
071: fail(exc.getMessage());
072: } catch (IOException exc) {
073: Log.getInstance().fatalMessage(
074: "*** IOException *** " + exc.getMessage(),
075: this .getClass().getName());
076: fail(exc.getMessage());
077: } catch (DriverManagerException exc) {
078: Log.getInstance().fatalMessage(
079: "*** DriverManagerException *** "
080: + exc.getMessage(),
081: this .getClass().getName());
082: fail(exc.getMessage());
083: } catch (SQLException exc) {
084: Log.getInstance().fatalMessage(
085: "*** SQLException *** " + exc.getMessage(),
086: this .getClass().getName());
087: fail(exc.getMessage());
088: }
089: }
090:
091: public void testRunRawSelectSQLStatement() {
092: try {
093: Log
094: .getInstance()
095: .debugMessage(
096: "*** MySQLGenericRawSQLEngineAutoCommitOnTest.testRunRawSelectSQLStatement *** ",
097: this .getClass().getName());
098:
099: DBTable dbTable = this .genericRawSQLEngine
100: .runRawSQL("select count(*) from claim_experts");
101: assertTrue("Number of rows should be 1", dbTable
102: .getNumberOfRowsInTable().intValue() == 1);
103: } catch (DBEngineException exc) {
104: Log.getInstance().fatalMessage(
105: "*** DBEngineException *** " + exc.getMessage(),
106: this .getClass().getName());
107: fail(exc.getMessage());
108: }
109: }
110:
111: public void testRunRawInsertSQLStatement() {
112: try {
113: Log
114: .getInstance()
115: .debugMessage(
116: "*** MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawInsertSQLStatement *** ",
117: this .getClass().getName());
118:
119: String sql = "insert into hww.customer (pk_customerid, last_updated_at, last_updated_by "
120: + ") values ( 3, '2005-10-21', 'JUnit')";
121: DBTable dbTable = this .genericRawSQLEngine.runRawSQL(sql);
122: assertTrue("DBTable should be null", dbTable == null);
123: } catch (DBEngineException exc) {
124: Log.getInstance().fatalMessage(
125: "*** DBEngineException *** " + exc.getMessage(),
126: this .getClass().getName());
127: fail(exc.getMessage());
128: }
129: }
130:
131: public void testRunRawUpdateSQLStatement() {
132: try {
133: Log
134: .getInstance()
135: .debugMessage(
136: "*** MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawUpdateSQLStatement *** ",
137: this .getClass().getName());
138:
139: DBTable dbTable = this .genericRawSQLEngine
140: .runRawSQL("update hww.customer set firstname = 'JUnit' where pk_customerid=3");
141: assertTrue(
142: "MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawUpdateSQLStatement should be null",
143: dbTable == null);
144: } catch (DBEngineException exc) {
145: Log.getInstance().fatalMessage(
146: "*** DBEngineException *** " + exc.getMessage(),
147: this .getClass().getName());
148: fail(exc.getMessage());
149: }
150: }
151:
152: public void testRunRawDeleteSQLStatement() {
153: try {
154: Log
155: .getInstance()
156: .debugMessage(
157: "*** MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawDeleteSQLStatement *** ",
158: this .getClass().getName());
159:
160: DBTable dbTable = this .genericRawSQLEngine
161: .runRawSQL("delete from hww.customer where pk_customerid=3");
162: assertTrue(
163: "MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawDeleteSQLStatement should be null",
164: dbTable == null);
165: } catch (DBEngineException exc) {
166: Log.getInstance().fatalMessage(
167: "*** DBEngineException *** " + exc.getMessage(),
168: this .getClass().getName());
169: fail(exc.getMessage());
170: }
171: }
172:
173: public void testRunRawAddColumnSQLStatement() {
174: try {
175: Log
176: .getInstance()
177: .debugMessage(
178: "*** MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawAddColumnSQLStatement *** ",
179: this .getClass().getName());
180:
181: DBTable dbTable = this .genericRawSQLEngine
182: .runRawSQL("alter table hww.customer add test_column varchar(10)");
183: assertTrue(
184: "MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawAlterTableSQLStatement should be null",
185: dbTable == null);
186: } catch (DBEngineException exc) {
187: Log.getInstance().fatalMessage(
188: "*** DBEngineException *** " + exc.getMessage(),
189: this .getClass().getName());
190: fail(exc.getMessage());
191: }
192: }
193:
194: public void testRunRawDropColumnSQLStatement() {
195: try {
196: Log
197: .getInstance()
198: .debugMessage(
199: "*** MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawDropColumnSQLStatement *** ",
200: this .getClass().getName());
201:
202: DBTable dbTable = this .genericRawSQLEngine
203: .runRawSQL("alter table hww.customer drop column test_column");
204: assertTrue(
205: "MySQLGenericRawSQLEngineAutoCommitOffTest.testRunRawAlterTableSQLStatement should be null",
206: dbTable == null);
207: } catch (DBEngineException exc) {
208: Log.getInstance().fatalMessage(
209: "*** DBEngineException *** " + exc.getMessage(),
210: this .getClass().getName());
211: fail(exc.getMessage());
212: }
213: }
214:
215: public void testStripComments() {
216: Log
217: .getInstance()
218: .debugMessage(
219: "*** MySQLGenericRawSQLEngineAutoCommitOffTest.testStripComments *** ",
220: this .getClass().getName());
221:
222: String sql = this .genericRawSQLEngine
223: .stripComments("alter table CLAIM_EXPERTS /*Test comments*/drop column test_column");
224: assertTrue(
225: "GenericRawSQLEngineTest.testStripComments sql is incorrect",
226: "alter table CLAIM_EXPERTS drop column test_column"
227: .equals(sql));
228: }
229: }
|