From: Jeff M. <cus...@us...> - 2002-04-13 15:08:26
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql In directory usw-pr-cvs1:/tmp/cvs-serv12990/src/jdk/common/com/mockobjects/sql Added Files: ExpectationSqlRow.java MockConnection.java MockDriver.java MockMultiRowResultSet.java MockPreparedStatement.java MockResultSet.java MockSingleRowResultSet.java MockStatement.java Log Message: Move none core mocks out of the core area --- NEW FILE: ExpectationSqlRow.java --- package com.mockobjects.sql; import java.sql.SQLException; import java.util.Map; import java.util.Iterator; import com.mockobjects.*; import com.mockobjects.util.*; public class ExpectationSqlRow implements Verifiable { private ExpectationMap values; public ExpectationSqlRow(String name) { super(); values = new ExpectationMap(name); values.setExpectNothing(); } public ExpectationSqlRow(String name, Object[] indexedValues) { this(name); addExpectedIndexedValues(indexedValues); } public ExpectationSqlRow(String name, String[] columnNames, Object[] values) { this(name); addExpectedNamedValues(columnNames, values); } public void addExpectedIndexedValues(Object[] indexedValues) { for (int i = 0; i < indexedValues.length; ++i) { values.addExpected(new Integer(i + 1), indexedValues[i]); } } public void addExpectedNamedValues(Map map) { Iterator columnNames = map.keySet().iterator(); while (columnNames.hasNext()) { Object key = columnNames.next(); values.addExpected(key, map.get(key)); } } public void addExpectedNamedValues(String[] columnNames, Object[] someValues) { for (int i = 0; i < someValues.length; ++i) { values.addExpected(columnNames[i], someValues[i]); } } public Object get(int oneBasedIndex) throws SQLException { return get(new Integer(oneBasedIndex)); } public Object get(Object key) throws SQLException { Object result = values.get(key); if (result instanceof SQLException) { throw (SQLException)result; } return result; } public void verify() { values.verify(); } } --- NEW FILE: MockConnection.java --- package com.mockobjects.sql; import java.sql.*; import java.util.*; import com.mockobjects.*; public class MockConnection extends MockObject implements Connection { private ExpectationCounter myCommitCalls = new ExpectationCounter("MockConnection.commit"); private ExpectationCounter myRollbackCalls = new ExpectationCounter("MockConnection.rollback"); private ExpectationCounter myCloseCalls = new ExpectationCounter("MockConnection.close"); private ExpectationCollection myPreparedStatementStrings = new ExpectationList("MockConnection.preparedStatementString"); private ArrayList myPreparedStatements = new ArrayList(); private SQLException myStatementException = null; private ExpectationCounter myCreateStatementCalls = new ExpectationCounter("MockConnection.createStatement"); private ExpectationValue myAutoCommit = new ExpectationValue("MockConnection.setAutoCommit"); private Statement myStatement; private boolean myIsClosed; private SQLException myIsClosedException; private SQLException myCloseException; public MockConnection() { super(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setExpectedCommitCalls(int callCount) { myCommitCalls.setExpected(callCount); } public void setExpectedCreateStatementCalls(int calls) { myCreateStatementCalls.setExpected(calls); } public void addExpectedPreparedStatementString(String sql) { myPreparedStatementStrings.addExpected(sql); } public void setExpectedRollbackCalls(int callCount) { myRollbackCalls.setExpected(callCount); } public void setupAddPreparedStatement(PreparedStatement prepared) { myPreparedStatements.add(prepared); } public void setupStatement(Statement statement) { myStatement = statement; } public void setupThrowExceptionOnPrepareOrCreate(SQLException exception) { myStatementException = exception; } public void clearWarnings() throws SQLException { } public void setupCloseException(SQLException aCloseException){ myCloseException = aCloseException; } public void close() throws SQLException { if(myCloseException!=null){ throw myCloseException; } myCloseCalls.inc(); } public void commit() throws SQLException { myCommitCalls.inc(); } public Statement createStatement() throws SQLException { myCreateStatementCalls.inc(); throwStatementExceptionIfAny(); return myStatement; } public Statement createStatement( int resultSetType, int resultSetConcurrency) throws SQLException { throw new UnsupportedOperationException(); } public boolean getAutoCommit() throws SQLException { throw new UnsupportedOperationException(); } public String getCatalog() throws SQLException { throw new UnsupportedOperationException(); } public DatabaseMetaData getMetaData() throws SQLException { throw new UnsupportedOperationException(); } public int getTransactionIsolation() throws SQLException { throw new UnsupportedOperationException(); } public Map getTypeMap() throws SQLException { throw new UnsupportedOperationException(); } public SQLWarning getWarnings() throws SQLException { throw new UnsupportedOperationException(); } public void setupIsClosedException(SQLException aIsClosedException){ myIsClosedException = aIsClosedException; } public void setupIsClose(boolean aIsClosed){ myIsClosed = aIsClosed; } public boolean isClosed() throws SQLException { if(myIsClosedException!=null){ throw myIsClosedException; } return myIsClosed; } public boolean isReadOnly() throws SQLException { throw new UnsupportedOperationException(); } public String nativeSQL(String sql) throws SQLException { throw new UnsupportedOperationException(); } public CallableStatement prepareCall(String sql) throws SQLException { throw new UnsupportedOperationException(); } public CallableStatement prepareCall( String sql, int resultSetType, int resultSetConcurrency) throws SQLException { throw new UnsupportedOperationException(); } public PreparedStatement prepareStatement(String sql) throws SQLException { myPreparedStatementStrings.addActual(sql); throwStatementExceptionIfAny(); return (PreparedStatement) myPreparedStatements.remove(0); } public PreparedStatement prepareStatement( String sql, int resultSetType, int resultSetConcurrency) throws SQLException { throw new UnsupportedOperationException(); } public void rollback() throws SQLException { myRollbackCalls.inc(); } public void setExpectedAutoCommit(boolean autoCommit) { myAutoCommit.setExpected(autoCommit); } public void setAutoCommit(boolean autoCommit) throws SQLException { myAutoCommit.setActual(autoCommit); } public void setCatalog(String catalog) throws SQLException { throw new UnsupportedOperationException(); } public void setReadOnly(boolean readOnly) throws SQLException { throw new UnsupportedOperationException(); } public void setTransactionIsolation(int level) throws SQLException { throw new UnsupportedOperationException(); } public void setTypeMap(Map map) throws SQLException { throw new UnsupportedOperationException(); } private void throwStatementExceptionIfAny() throws SQLException { if (null != myStatementException) { throw myStatementException; } } } --- NEW FILE: MockDriver.java --- package com.mockobjects.sql; import java.sql.*; import java.util.*; public class MockDriver implements Driver{ public static MockDriver myDriver = new MockDriver(); private Connection myConnection; static{ try{ DriverManager.registerDriver(myDriver); }catch(SQLException e){ e.printStackTrace(); } } public void setupConnect(Connection aConnection){ this.myConnection = aConnection; } public boolean acceptsURL(String url){ return true; } public Connection connect(String url, Properties info){ return myConnection; } public int getMajorVersion(){ return 0; } public int getMinorVersion(){ return 0; } public DriverPropertyInfo[] getPropertyInfo(String url, Properties info){ return null; } public boolean jdbcCompliant(){ return false; } } --- NEW FILE: MockMultiRowResultSet.java --- package com.mockobjects.sql; import java.sql.*; import java.sql.Date; import java.util.*; import java.math.BigDecimal; import java.io.InputStream; import java.io.Reader; import junit.framework.Assert; import junit.framework.AssertionFailedError; import com.mockobjects.*; /** * This is a simple implementation of a MockResultSet. * It returns values for multiple rows. */ public class MockMultiRowResultSet extends MockResultSet { private Object[][] myRows = new Object[0][0]; private String[] myColumnNames; private int myRowOffset = -1; private SQLException myGetException = null; public MockMultiRowResultSet() { super(); } public void setupColumnNames(String[] columnNames) { myColumnNames = columnNames; } public void setupRows(Object[][] rows) { myRows = rows; } public void setupThrowExceptionOnGet(SQLException exception) { myGetException = exception; } public Object getObject(int columnIndex) throws SQLException { throwGetExceptionIfAny(); return myRows[myRowOffset][columnIndex - 1]; } public Object getObject(String columnName) throws SQLException { throwGetExceptionIfAny(); return getObject(findIndexForColumnName(columnName)); } public boolean next() throws SQLException { myNextCalls.inc(); if (myRowOffset + 1 >= myRows.length) { return false; } myRowOffset++; return true; } public int getRow() throws SQLException { return myRowOffset + 1; } private void throwGetExceptionIfAny() throws SQLException { if (null != myGetException) { throw myGetException; } } private int findIndexForColumnName(String columnName) throws SQLException { for (int i = 0; i < myColumnNames.length; ++i) { if (myColumnNames[i].equalsIgnoreCase(columnName)) { return i + 1; } } throw new SQLException("Column name not found"); } } --- NEW FILE: MockPreparedStatement.java --- package com.mockobjects.sql; import java.sql.*; import java.util.Calendar; import java.io.Reader; import java.math.BigDecimal; import com.mockobjects.*; public class MockPreparedStatement extends MockStatement implements PreparedStatement { private ExpectationSet mySetParameters = new ExpectationSet("MockPreparedStatement.setParameters"); private ExpectationCounter myClearParametersCalls = new ExpectationCounter("MockPreparedStatement.clearParameters() calls"); public MockPreparedStatement() { super(); } public void addExpectedSetParameter(int parameterIndex, int intValue) { addExpectedSetParameter(parameterIndex, new Integer(intValue)); } public void addExpectedSetParameter(int parameterIndex, Object parameterValue) { mySetParameters.addExpected(new MapEntry(new Integer(parameterIndex), parameterValue)); } public void addExpectedSetParameters(Object[] parameters) { for (int i = 0; i < parameters.length; ++i) { addExpectedSetParameter(i + 1, parameters[i]); } } public void clearParameters() throws SQLException { myClearParametersCalls.inc(); } public boolean execute() throws SQLException { innerExecute(); return false; } public void setExpectedClearParametersCalls(int callCount) { myClearParametersCalls.setExpected(callCount); } public void setExpectingNoSetParameters() { mySetParameters.setExpectNothing(); } public ResultSet executeQuery() throws SQLException { return executeQuery(""); } public int executeUpdate() throws SQLException { return executeUpdate(""); } public void setInt(int parameterIndex, int x) throws SQLException { setObject(parameterIndex, new Integer(x)); } public void setString(int parameterIndex, String x) throws SQLException { setObject(parameterIndex, x); } public void setTimestamp(int param, Timestamp timestamp) throws SQLException { setObject(param, timestamp); } public void setClob(int param, Clob clob) throws SQLException { setObject(param, clob); } public void setLong(int param, long aLong) throws SQLException { setObject(param, new Long(aLong)); } public void addBatch() throws SQLException { throw new UnsupportedOperationException(); } public void setNull(int param, int param1) throws SQLException { setObject(param, null); } public void setArray(int param, Array array) throws SQLException { setObject(param, array); } public void setShort(int param, short aShort) throws SQLException { setObject(param, new Short(aShort)); } public void setTime(int param, Time time, Calendar calendar) throws SQLException { setObject(param, time); } public void setObject(int param, Object obj, int targetSqlType, int scale) throws SQLException { throw new UnsupportedOperationException(); } public void setObject(int param, Object obj, int targetSqlType) throws SQLException { throw new UnsupportedOperationException(); } public void setRef(int param, Ref ref) throws SQLException { setObject(param, ref); } public void setDate(int param, Date date) throws SQLException { setObject(param, date); } public void setFloat(int param, float aFloat) throws SQLException { setObject(param, new Float(aFloat)); } public void setBlob(int param, Blob blob) throws SQLException { setObject(param, blob); } public void setCharacterStream(int param, Reader reader, int length) throws SQLException { throw new UnsupportedOperationException(); } public void setAsciiStream(int param, java.io.InputStream inputStream, int length) throws SQLException { throw new UnsupportedOperationException(); } public void setDate(int param, Date date, Calendar calendar) throws SQLException { setDate(param, date); } public void setBinaryStream(int param, java.io.InputStream inputStream, int length) throws SQLException { throw new UnsupportedOperationException(); } public void setUnicodeStream(int param, java.io.InputStream inputStream, int length) throws SQLException { throw new UnsupportedOperationException(); } public void setBytes(int param, byte[] values) throws SQLException { setObject(param, values); } public void setObject(int param, Object obj) throws SQLException { mySetParameters.addActual(new MapEntry(new Integer(param), obj)); } public void setByte(int param, byte aByte) throws SQLException { setObject(param, new Byte(aByte)); } public void setDouble(int param, double aDouble) throws SQLException { setObject(param, new Double(aDouble)); } public ResultSetMetaData getMetaData() throws SQLException { throw new UnsupportedOperationException(); } public void setTimestamp(int param, Timestamp timestamp, Calendar calendar) throws SQLException { throw new UnsupportedOperationException(); } public void setTime(int param, Time time) throws SQLException { setObject(param, time); } public void setBoolean(int param, boolean aBoolean) throws SQLException { setObject(param, new Boolean(aBoolean)); } public void setNull(int param, int param1, String typeName) throws SQLException { throw new UnsupportedOperationException(); } public void setBigDecimal(int param, BigDecimal bigDecimal) throws SQLException { setObject(param, bigDecimal); } } --- NEW FILE: MockResultSet.java --- package com.mockobjects.sql; import java.sql.*; import java.sql.Date; import java.util.*; import java.math.BigDecimal; import java.io.InputStream; import java.io.Reader; import junit.framework.Assert; import junit.framework.AssertionFailedError; import com.mockobjects.*; /** * This is the base implementation of a mock result set. * It manages converting objects from the current row into a other types. * Entries can be found by either column index or column name. * For basic java types (e.g. int, boolean), insert an instance of * the appropriate object (e.g. Integer, Boolean) * It also counts close() and next() calls * To force throwing a SQLException on a getter, set the corresponding value to be of type SQLException. */ abstract public class MockResultSet extends MockObject implements ResultSet { private ExpectationCounter myCloseCalls = new ExpectationCounter("MockResultSet.close"); protected ExpectationCounter myNextCalls = new ExpectationCounter("MockResultSet.next"); private ResultSetMetaData myMetaData; private Statement myStatement; public MockResultSet() { super(); } /** * Used as the base implementation for getting all types of object, * based on 1-based column index * @see java.sql.ResultSet#getObject(int) */ abstract public Object getObject(int columnIndex) throws SQLException; /** * Used as the base implementation for getting all types of object, * based on columnName * @see java.sql.ResultSet#getObject(int) */ abstract public Object getObject(String columnName) throws SQLException; abstract public boolean next() throws SQLException; abstract public int getRow() throws SQLException; public void setExpectedCloseCalls(int calls) { myCloseCalls.setExpected(calls); } public void setExpectedNextCalls(int calls) { myNextCalls.setExpected(calls); } public void setupMetaData(ResultSetMetaData metaData) { myMetaData = metaData; } public void setupStatement(Statement statement) { myStatement = statement; } public void close() throws SQLException { myCloseCalls.inc(); } public Array getArray(int i) throws SQLException { return (Array)getObject(i); } public Array getArray(String colName) throws SQLException { return (Array)getObject(colName); } public InputStream getAsciiStream(int columnIndex) throws SQLException { return (InputStream)getObject(columnIndex); } public InputStream getAsciiStream(String columnName) throws SQLException { return (InputStream)getObject(columnName); } public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { return getBigDecimal(columnName); } public BigDecimal getBigDecimal(int columnIndex) throws SQLException { return (BigDecimal)getObject(columnIndex); } public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { return (BigDecimal)getObject(columnIndex); } public BigDecimal getBigDecimal(String columnName) throws SQLException { return (BigDecimal)getObject(columnName); } public InputStream getBinaryStream(int columnIndex) throws SQLException { return (InputStream)getObject(columnIndex); } public InputStream getBinaryStream(String columnName) throws SQLException { return (InputStream)getObject(columnName); } public Blob getBlob(int i) throws SQLException { return (Blob)getObject(i); } public Blob getBlob(String colName) throws SQLException { return (Blob)getObject(colName); } public boolean getBoolean(int columnIndex) throws SQLException { return ((Boolean)getObject(columnIndex)).booleanValue(); } public boolean getBoolean(String columnName) throws SQLException { return ((Boolean)getObject(columnName)).booleanValue(); } public byte getByte(int columnIndex) throws SQLException { return ((Byte)getObject(columnIndex)).byteValue(); } public byte getByte(String columnName) throws SQLException { return ((Byte)getObject(columnName)).byteValue(); } public byte[] getBytes(int columnIndex) throws SQLException { return (byte[])getObject(columnIndex); } public byte[] getBytes(String columnName) throws SQLException { return (byte[])getObject(columnName); } public Reader getCharacterStream(int columnIndex) throws SQLException { return (Reader)getObject(columnIndex); } public Reader getCharacterStream(String columnName) throws SQLException { return (Reader)getObject(columnName); } public Clob getClob(int i) throws SQLException { return (Clob)getObject(i); } public Clob getClob(String colName) throws SQLException { return (Clob)getObject(colName); } public String getCursorName() throws SQLException { throw new AssertionFailedError("MockResultSet getCursorName not implemented"); } public int getConcurrency() throws SQLException { throw new AssertionFailedError("MockResultSet getConcurrency not implemented"); } public Date getDate(int columnIndex) throws SQLException { return (Date)getObject(columnIndex); } public Date getDate(String columnName) throws SQLException { return (Date)getObject(columnName); } public Date getDate(int columnIndex, Calendar cal) throws SQLException { return getDate(columnIndex); } public Date getDate(String columnName, Calendar cal) throws SQLException { return getDate(columnName); } public double getDouble(int columnIndex) throws SQLException { return ((Double)getObject(columnIndex)).doubleValue(); } public double getDouble(String columnName) throws SQLException { return ((Double)getObject(columnName)).doubleValue(); } public int getFetchDirection() throws SQLException { throw new AssertionFailedError("MockResultSet getFetchDirection not implemented"); } public int getFetchSize() throws SQLException { throw new AssertionFailedError("MockResultSet getFetchSize not implemented"); } public float getFloat(int columnIndex) throws SQLException { return ((Float)getObject(columnIndex)).floatValue(); } public float getFloat(String columnName) throws SQLException { return ((Float)getObject(columnName)).floatValue(); } public int getInt(int columnIndex) throws SQLException { return ((Integer) getObject(columnIndex)).intValue(); } public int getInt(String columnName) throws SQLException { return ((Integer) getObject(columnName)).intValue(); } public long getLong(int columnIndex) throws SQLException { return ((Long) getObject(columnIndex)).longValue(); } public long getLong(String columnName) throws SQLException { return ((Long) getObject(columnName)).longValue(); } public ResultSetMetaData getMetaData() throws SQLException { return myMetaData; } public Object getObject(int i, Map map) throws SQLException { throw new AssertionFailedError("MockResultSet getObject not implemented"); } public Object getObject(String colName, Map map) throws SQLException { throw new AssertionFailedError("MockResultSet getObject not implemented"); } public Ref getRef(int i) throws SQLException { return (Ref)getObject(i); } public Ref getRef(String colName) throws SQLException { return (Ref)getObject(colName); } public short getShort(String columnName) throws SQLException { return ((Short)getObject(columnName)).shortValue(); } public short getShort(int columnIndex) throws SQLException { return ((Short)getObject(columnIndex)).shortValue(); } public Statement getStatement() throws SQLException { return myStatement; } public String getString(int columnIndex) throws SQLException { return (String)getObject(columnIndex); } public String getString(String columnName) throws SQLException { return (String)getObject(columnName); } public Time getTime(int columnIndex) throws SQLException { return (Time)getObject(columnIndex); } public Time getTime(String columnName) throws SQLException { return (Time)getObject(columnName); } public Time getTime(int columnIndex, Calendar cal) throws SQLException { return getTime(columnIndex); } public Time getTime(String columnName, Calendar cal) throws SQLException { return getTime(columnName); } public Timestamp getTimestamp(int columnIndex) throws SQLException { return (Timestamp)getObject(columnIndex); } public Timestamp getTimestamp(String columnName) throws SQLException { return (Timestamp)getObject(columnName); } public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { return getTimestamp(columnIndex); } public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { return getTimestamp(columnName); } public int getType() throws SQLException { throw new AssertionFailedError("MockResultSet getType not implemented"); } public InputStream getUnicodeStream(int columnIndex) throws SQLException { return (InputStream)getObject(columnIndex); } public InputStream getUnicodeStream(String columnName) throws SQLException { return (InputStream)getObject(columnName); } public SQLWarning getWarnings() throws SQLException { throw new AssertionFailedError("MockResultSet getWarnings not implemented"); } public void clearWarnings() throws SQLException { throw new AssertionFailedError("MockResultSet clearWarnings not implemented"); } public int findColumn(String columnName) throws SQLException { throw new AssertionFailedError("MockResultSet findColumn not implemented"); } public boolean isBeforeFirst() throws SQLException { throw new AssertionFailedError("MockResultSet isBeforeFirst not implemented"); } public boolean isAfterLast() throws SQLException { throw new AssertionFailedError("MockResultSet getFetchSize not implemented"); } public boolean isFirst() throws SQLException { throw new AssertionFailedError("MockResultSet isFirst not implemented"); } public boolean isLast() throws SQLException { throw new AssertionFailedError("MockResultSet isLast not implemented"); } public void beforeFirst() throws SQLException { throw new AssertionFailedError("MockResultSet beforeFirst not implemented"); } public void afterLast() throws SQLException { throw new AssertionFailedError("MockResultSet afterLast not implemented"); } public boolean first() throws SQLException { throw new AssertionFailedError("MockResultSet first not implemented"); } public boolean last() throws SQLException { throw new AssertionFailedError("MockResultSet last not implemented"); } public boolean absolute(int row) throws SQLException { throw new AssertionFailedError("MockResultSet absolute not implemented"); } public boolean relative(int rows) throws SQLException { throw new AssertionFailedError("MockResultSet relative not implemented"); } public boolean previous() throws SQLException { throw new AssertionFailedError("MockResultSet previous not implemented"); } public void setFetchDirection(int direction) throws SQLException { throw new AssertionFailedError("MockResultSet setFetchDirection not implemented"); } public void setFetchSize(int rows) throws SQLException { throw new AssertionFailedError("MockResultSet setFetchSize not implemented"); } public boolean rowUpdated() throws SQLException { throw new AssertionFailedError("MockResultSet rowUpdated not implemented"); } public boolean rowInserted() throws SQLException { throw new AssertionFailedError("MockResultSet rowInserted not implemented"); } public boolean rowDeleted() throws SQLException { throw new AssertionFailedError("MockResultSet rowDeleted not implemented"); } public void updateNull(int columnIndex) throws SQLException { throw new AssertionFailedError("MockResultSet updateNull not implemented"); } public void updateBoolean(int columnIndex, boolean x) throws SQLException { throw new AssertionFailedError("MockResultSet updateBoolean not implemented"); } public void updateByte(int columnIndex, byte x) throws SQLException { throw new AssertionFailedError("MockResultSet updateByte not implemented"); } public void updateShort(int columnIndex, short x) throws SQLException { throw new AssertionFailedError("MockResultSet updateShort not implemented"); } public void updateInt(int columnIndex, int x) throws SQLException { throw new AssertionFailedError("MockResultSet updateInt not implemented"); } public void updateLong(int columnIndex, long x) throws SQLException { throw new AssertionFailedError("MockResultSet updateLong not implemented"); } public void updateFloat(int columnIndex, float x) throws SQLException { throw new AssertionFailedError("MockResultSet updateFloat not implemented"); } public void updateDouble(int columnIndex, double x) throws SQLException { throw new AssertionFailedError("MockResultSet updateDouble not implemented"); } public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { throw new AssertionFailedError("MockResultSet updateBigDecimal not implemented"); } public void updateString(int columnIndex, String x) throws SQLException { throw new AssertionFailedError("MockResultSet updateString not implemented"); } public void updateBytes(int columnIndex, byte x[]) throws SQLException { throw new AssertionFailedError("MockResultSet updateBytes not implemented"); } public void updateDate(int columnIndex, Date x) throws SQLException { throw new AssertionFailedError("MockResultSet updateDate not implemented"); } public void updateTime(int columnIndex, Time x) throws SQLException { throw new AssertionFailedError("MockResultSet updateTime not implemented"); } public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { throw new AssertionFailedError("MockResultSet updateTimestamp not implemented"); } public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { throw new AssertionFailedError("MockResultSet updateAsciiStream not implemented"); } public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { throw new AssertionFailedError("MockResultSet updateBinaryStream not implemented"); } public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { throw new AssertionFailedError("MockResultSet updateCharacterStream not implemented"); } public void updateObject(int columnIndex, Object x, int scale) throws SQLException { throw new AssertionFailedError("MockResultSet updateObject not implemented"); } public void updateObject(int columnIndex, Object x) throws SQLException { throw new AssertionFailedError("MockResultSet updateObject not implemented"); } public void updateNull(String columnName) throws SQLException { throw new AssertionFailedError("MockResultSet updateNull not implemented"); } public void updateBoolean(String columnName, boolean x) throws SQLException { throw new AssertionFailedError("MockResultSet updateBoolean not implemented"); } public void updateByte(String columnName, byte x) throws SQLException { throw new AssertionFailedError("MockResultSet updateByte not implemented"); } public void updateShort(String columnName, short x) throws SQLException { throw new AssertionFailedError("MockResultSet updateShort not implemented"); } public void updateInt(String columnName, int x) throws SQLException { throw new AssertionFailedError("MockResultSet updateInt not implemented"); } public void updateLong(String columnName, long x) throws SQLException { throw new AssertionFailedError("MockResultSet updateLong not implemented"); } public void updateFloat(String columnName, float x) throws SQLException { throw new AssertionFailedError("MockResultSet updateFloat not implemented"); } public void updateDouble(String columnName, double x) throws SQLException { throw new AssertionFailedError("MockResultSet updateDouble not implemented"); } public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { throw new AssertionFailedError("MockResultSet updateBigDecimal not implemented"); } public void updateString(String columnName, String x) throws SQLException { throw new AssertionFailedError("MockResultSet updateString not implemented"); } public void updateBytes(String columnName, byte x[]) throws SQLException { throw new AssertionFailedError("MockResultSet updateBytes not implemented"); } public void updateDate(String columnName, Date x) throws SQLException { throw new AssertionFailedError("MockResultSet updateDate not implemented"); } public void updateTime(String columnName, Time x) throws SQLException { throw new AssertionFailedError("MockResultSet updateTime not implemented"); } public void updateTimestamp(String columnName, Timestamp x) throws SQLException { throw new AssertionFailedError("MockResultSet updateTimestamp not implemented"); } public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException { throw new AssertionFailedError("MockResultSet updateAsciiStream not implemented"); } public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException { throw new AssertionFailedError("MockResultSet updateBinaryStream not implemented"); } public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException { throw new AssertionFailedError("MockResultSet updateCharacterStream not implemented"); } public void updateObject(String columnName, Object x, int scale) throws SQLException { throw new AssertionFailedError("MockResultSet updateObject not implemented"); } public void updateObject(String columnName, Object x) throws SQLException { throw new AssertionFailedError("MockResultSet updateObject not implemented"); } public void insertRow() throws SQLException { throw new AssertionFailedError("MockResultSet insertRow not implemented"); } public void updateRow() throws SQLException { throw new AssertionFailedError("MockResultSet updateRow not implemented"); } public void deleteRow() throws SQLException { throw new AssertionFailedError("MockResultSet deleteRow not implemented"); } public void refreshRow() throws SQLException { throw new AssertionFailedError("MockResultSet refreshRow not implemented"); } public void cancelRowUpdates() throws SQLException { throw new AssertionFailedError("MockResultSet cancelRowUpdates not implemented"); } public void moveToInsertRow() throws SQLException { throw new AssertionFailedError("MockResultSet moveToInsertRow not implemented"); } public void moveToCurrentRow() throws SQLException { throw new AssertionFailedError("MockResultSet moveToCurrentRow not implemented"); } public boolean wasNull() throws SQLException { throw new AssertionFailedError("MockResultSet wasNull not implemented"); } } --- NEW FILE: MockSingleRowResultSet.java --- package com.mockobjects.sql; import java.sql.SQLException; import java.util.*; /** * This is a simple implementation of a MockResultSet. * It verifies that the values fed to it have been retrieved. * These can be found by either column index or column name. * For basic java types (e.g. int, boolean), insert an instance of * the appropriate object (e.g. Integer, Boolean) * To force throwing a SQLException on a getter, set the corresponding value to be of type SQLException. */ public class MockSingleRowResultSet extends MockResultSet { private ExpectationSqlRow myRow = new ExpectationSqlRow("single row"); private int myNextCallCount = 0; public MockSingleRowResultSet() { super(); } public MockSingleRowResultSet(Object[] values) { this(); addExpectedIndexedValues(values); } public MockSingleRowResultSet(String[] names, Object[] values) { this(); addExpectedNamedValues(names, values); } public MockSingleRowResultSet(Map map) { this(); addExpectedNamedValues(map); } public void addExpectedIndexedValues(Object[] values) { myRow.addExpectedIndexedValues(values); } public void addExpectedNamedValues(String[] names, Object[] values) { myRow.addExpectedNamedValues(names, values); } public void addExpectedNamedValues(Map map) { myRow.addExpectedNamedValues(map); } public boolean next() throws SQLException { myNextCalls.inc(); myNextCallCount++; return myNextCallCount == 1; } public int getRow() throws SQLException { return myNextCallCount; } public Object getObject(int columnIndex) throws SQLException { return myRow.get(columnIndex); } public Object getObject(String columnName) throws SQLException { return myRow.get(columnName); } } --- NEW FILE: MockStatement.java --- package com.mockobjects.sql; import java.sql.*; import junit.framework.*; import com.mockobjects.*; public class MockStatement extends MockObject implements Statement { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockStatement.closeCalls"); protected ExpectationCounter myExecuteCalls = new ExpectationCounter("MockStatement.executeCalls"); protected ExpectationValue myQueryString = new ExpectationValue("MockStatement.queryString"); protected MockResultSet myResultSet; private int myUpdateCount = 0; private SQLException myExecuteException = null; public MockStatement() { super(); } public void setExpectedExecuteCalls(int callCount) { myExecuteCalls.setExpected(callCount); } public void setExpectedQueryString(String queryString) { myQueryString.setExpected(queryString); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setupResultSet(MockResultSet aResultSet) { myResultSet = aResultSet; } public void setupThrowExceptionOnExecute(SQLException exception) { myExecuteException = exception; } public void setupUpdateCount(int updateCount) { myUpdateCount = updateCount; } protected void innerExecute() throws SQLException { myExecuteCalls.inc(); if (null != myExecuteException) { throw myExecuteException; } } public void close() throws SQLException { myCloseCalls.inc(); } public boolean execute(String sql) throws SQLException { throw new UnsupportedOperationException(); } public ResultSet executeQuery(String sql) throws SQLException { myQueryString.setActual(sql); innerExecute(); return myResultSet; } public int executeUpdate(String sql) throws SQLException { myQueryString.setActual(sql); innerExecute(); return myUpdateCount; } public int getMaxFieldSize() throws SQLException { throw new UnsupportedOperationException(); } public void setMaxFieldSize(int max) throws SQLException { throw new UnsupportedOperationException(); } public int getMaxRows() throws SQLException { throw new UnsupportedOperationException(); } public void setMaxRows(int max) throws SQLException { throw new UnsupportedOperationException(); } public void setEscapeProcessing(boolean enable) throws SQLException { throw new UnsupportedOperationException(); } public int getQueryTimeout() throws SQLException { throw new UnsupportedOperationException(); } public void setQueryTimeout(int seconds) throws SQLException { throw new UnsupportedOperationException(); } public void cancel() throws SQLException { throw new UnsupportedOperationException(); } public SQLWarning getWarnings() throws SQLException { throw new UnsupportedOperationException(); } public void clearWarnings() throws SQLException { throw new UnsupportedOperationException(); } public void setCursorName(String name) throws SQLException { throw new UnsupportedOperationException(); } public ResultSet getResultSet() throws SQLException { throw new UnsupportedOperationException(); } public int getUpdateCount() throws SQLException { return myUpdateCount; } public boolean getMoreResults() throws SQLException { throw new UnsupportedOperationException(); } public void setFetchDirection(int direction) throws SQLException { throw new UnsupportedOperationException(); } public int getFetchDirection() throws SQLException { throw new UnsupportedOperationException(); } public void setFetchSize(int rows) throws SQLException { throw new UnsupportedOperationException(); } public int getFetchSize() throws SQLException { throw new UnsupportedOperationException(); } public int getResultSetConcurrency() throws SQLException { throw new UnsupportedOperationException(); } public int getResultSetType() throws SQLException { throw new UnsupportedOperationException(); } public void addBatch(String sql) throws SQLException { throw new UnsupportedOperationException(); } public void clearBatch() throws SQLException { throw new UnsupportedOperationException(); } public int[] executeBatch() throws SQLException { throw new UnsupportedOperationException(); } public Connection getConnection() throws SQLException { throw new UnsupportedOperationException(); } } |