001: package org.dbbrowser.db.engine.updateengine;
002:
003: import junit.framework.TestCase;
004: import org.dbbrowser.db.engine.queryengine.Oracle9iDBQueryEngine;
005: import org.dbbrowser.db.engine.updateengine.GenericDBUpdateEngine;
006: import org.dbbrowser.db.engine.model.DBRow;
007: import org.dbbrowser.db.engine.model.DBTableCell;
008: import org.dbbrowser.db.engine.model.ColumnInfo;
009: import org.dbbrowser.db.engine.exception.DBEngineException;
010: import org.dbbrowser.drivermanager.ConnectionInfoSerializer;
011: import org.dbbrowser.drivermanager.ConnectionInfo;
012: import org.dbbrowser.drivermanager.DBBrowserDriverManager;
013: import org.dbbrowser.drivermanager.DriverManagerException;
014: import infrastructure.logging.Log;
015:
016: import java.util.List;
017: import java.util.Iterator;
018: import java.util.ArrayList;
019: import java.sql.Connection;
020: import java.sql.SQLException;
021: import java.sql.Types;
022: import java.io.IOException;
023:
024: public class GenericDBUpdateEngineTest extends TestCase {
025: private GenericDBUpdateEngine genericDBUpdateEngine = null;
026:
027: public GenericDBUpdateEngineTest(String name) {
028: super (name);
029: }
030:
031: public void setUp() {
032: try {
033: Log
034: .getInstance()
035: .debugMessage(
036: "*** Setting up connection for Oracle database *** ",
037: this .getClass().getName());
038:
039: //Get the connection info
040: List listOfConnectionInfo = ConnectionInfoSerializer
041: .deserialize();
042:
043: //Get the Oracle connection info
044: Iterator i = listOfConnectionInfo.iterator();
045: ConnectionInfo ci = null;
046: while (i.hasNext()) {
047: ConnectionInfo connectionInfo = (ConnectionInfo) i
048: .next();
049: if (connectionInfo.getName().equals("Oracle PPDB")) {
050: ci = connectionInfo;
051: break;
052: }
053: }
054:
055: //Get the connection if connection info is not null
056: if (ci != null) {
057: Connection conn = DBBrowserDriverManager.getInstance()
058: .getConnection(ci, null);
059:
060: //Setup the update engine
061: genericDBUpdateEngine = new GenericDBUpdateEngine(conn
062: .createStatement());
063: } else {
064: Log
065: .getInstance()
066: .fatalMessage(
067: "*** No Connection info found for Oracle database *** ",
068: this .getClass().getName());
069: fail("*** No Connection info found for Oracle database *** ");
070: }
071: } catch (ClassNotFoundException exc) {
072: Log.getInstance().fatalMessage(
073: "*** ClassNotFoundException *** "
074: + exc.getMessage(),
075: this .getClass().getName());
076: fail(exc.getMessage());
077: } catch (IOException exc) {
078: Log.getInstance().fatalMessage(
079: "*** IOException *** " + exc.getMessage(),
080: this .getClass().getName());
081: fail(exc.getMessage());
082: } catch (DriverManagerException exc) {
083: Log.getInstance().fatalMessage(
084: "*** DriverManagerException *** "
085: + exc.getMessage(),
086: this .getClass().getName());
087: fail(exc.getMessage());
088: } catch (SQLException exc) {
089: Log.getInstance().fatalMessage(
090: "*** DriverManagerException *** "
091: + exc.getMessage(),
092: this .getClass().getName());
093: fail(exc.getMessage());
094: }
095: }
096:
097: public void testUpdate() {
098: try {
099: ColumnInfo ci1 = new ColumnInfo("ID", "", "", new Integer(
100: 10), null, Boolean.FALSE, Boolean.TRUE,
101: Boolean.FALSE, new Integer(Types.NUMERIC));
102: DBTableCell dbTableCell1 = new DBTableCell(ci1,
103: new Integer(61), Boolean.FALSE);
104: ColumnInfo ci2 = new ColumnInfo("INDIVIDUAL_NAME", "", "",
105: new Integer(10), null, Boolean.FALSE,
106: Boolean.FALSE, Boolean.FALSE, new Integer(
107: Types.VARCHAR));
108: DBTableCell dbTableCell2 = new DBTableCell(ci2,
109: "Updated by JUnit", Boolean.TRUE);
110:
111: List listOfTableCells = new ArrayList();
112: listOfTableCells.add(dbTableCell1);
113: listOfTableCells.add(dbTableCell2);
114:
115: DBRow dbRow = new DBRow(listOfTableCells);
116: this .genericDBUpdateEngine.update("", "CLAIM_EXPERTS",
117: dbRow);
118: } catch (DBEngineException exc) {
119: Log.getInstance().fatalMessage(
120: "*** DBEngineException *** " + exc.getMessage(),
121: this .getClass().getName());
122: fail(exc.getMessage());
123: }
124: }
125:
126: public void testDeleteRow() {
127: try {
128: ColumnInfo ci1 = new ColumnInfo("ID", "", "", new Integer(
129: 10), null, Boolean.FALSE, Boolean.TRUE,
130: Boolean.FALSE, new Integer(Types.NUMERIC));
131: DBTableCell dbTableCell1 = new DBTableCell(ci1,
132: new Integer(100), Boolean.FALSE);
133:
134: List listOfTableCells = new ArrayList();
135: listOfTableCells.add(dbTableCell1);
136:
137: DBRow dbRow = new DBRow(listOfTableCells);
138: this .genericDBUpdateEngine.deleteRow("", "CLAIM_EXPERTS",
139: dbRow);
140: } catch (DBEngineException exc) {
141: Log.getInstance().fatalMessage(
142: "*** DBEngineException *** " + exc.getMessage(),
143: this.getClass().getName());
144: fail(exc.getMessage());
145: }
146: }
147: }
|