Source Code Cross Referenced for JDBCTestModule.java in  » Testing » mockrunner-0.4 » com » mockrunner » jdbc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » mockrunner 0.4 » com.mockrunner.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package com.mockrunner.jdbc;
0002:
0003:        import java.sql.CallableStatement;
0004:        import java.sql.PreparedStatement;
0005:        import java.sql.SQLException;
0006:        import java.util.ArrayList;
0007:        import java.util.Arrays;
0008:        import java.util.Iterator;
0009:        import java.util.List;
0010:        import java.util.Map;
0011:        import java.util.TreeMap;
0012:
0013:        import com.mockrunner.base.NestedApplicationException;
0014:        import com.mockrunner.base.VerifyFailedException;
0015:        import com.mockrunner.mock.jdbc.JDBCMockObjectFactory;
0016:        import com.mockrunner.mock.jdbc.MockCallableStatement;
0017:        import com.mockrunner.mock.jdbc.MockPreparedStatement;
0018:        import com.mockrunner.mock.jdbc.MockResultSet; //import com.mockrunner.mock.jdbc.MockSavepoint;
0019:        import com.mockrunner.mock.jdbc.MockStatement;
0020:        import com.mockrunner.util.common.StringUtil;
0021:
0022:        /**
0023:         * Module for JDBC tests.
0024:         */
0025:        public class JDBCTestModule {
0026:            private JDBCMockObjectFactory mockFactory;
0027:            private boolean caseSensitive = false;
0028:            private boolean exactMatch = false;
0029:            private boolean useRegularExpressions = false;
0030:
0031:            public JDBCTestModule(JDBCMockObjectFactory mockFactory) {
0032:                this .mockFactory = mockFactory;
0033:            }
0034:
0035:            /**
0036:             * Set if specified SQL statements should be handled case sensitive.
0037:             * Defaults to to <code>false</code>, i.e. <i>INSERT</i> is the same
0038:             * as <i>insert</i>. 
0039:             * Please note that this method controls SQL statement
0040:             * matching for this class, e.g. what statements the method
0041:             * {@link #getPreparedStatements(String)} returns or what statements
0042:             * are taken into account by the method {@link #verifySQLStatementExecuted(String)}.
0043:             * In contrast to {@link AbstractResultSetHandler#setCaseSensitive(boolean)} it does 
0044:             * not control the prepared results that are returned when the tested application
0045:             * executes a matching statement.
0046:             * @param caseSensitive enable or disable case sensitivity
0047:             */
0048:            public void setCaseSensitive(boolean caseSensitive) {
0049:                this .caseSensitive = caseSensitive;
0050:            }
0051:
0052:            /**
0053:             * Set if specified SQL statements must match exactly.
0054:             * Defaults to <code>false</code>, i.e. the SQL statement used
0055:             * to create a <code>PreparedStatement</code> must contain
0056:             * the specified SQL statement, but does not have to match
0057:             * exactly. If the original statement is <i>insert into mytable values(?, ?, ?)</i>
0058:             * <code>verifyPreparedStatementPresent("insert into mytable")</code>
0059:             * will pass.
0060:             * Please note that this method controls SQL statement
0061:             * matching for this class, e.g. what statements the method
0062:             * {@link #getPreparedStatements(String)} returns or what statements
0063:             * are taken into account by the method {@link #verifySQLStatementExecuted(String)}.
0064:             * In contrast to {@link AbstractResultSetHandler#setExactMatch(boolean)} it does 
0065:             * not control the prepared results that are returned when the tested application
0066:             * executes a matching statement.
0067:             * @param exactMatch enable or disable exact matching
0068:             */
0069:            public void setExactMatch(boolean exactMatch) {
0070:                this .exactMatch = exactMatch;
0071:            }
0072:
0073:            /**
0074:             * Set if regular expressions should be used when matching
0075:             * SQL statements. Irrelevant if <code>exactMatch</code> is
0076:             * <code>true</code>. Default is <code>false</code>, i.e. you
0077:             * cannot use regular expressions and matching is based
0078:             * on string comparison.
0079:             * Please note that this method controls SQL statement
0080:             * matching for the methods of this class, e.g. what statements the method
0081:             * {@link #getPreparedStatements(String)} returns or what statements
0082:             * are taken into account by the method {@link #verifySQLStatementExecuted(String)}.
0083:             * In contrast to {@link AbstractResultSetHandler#setUseRegularExpressions(boolean)} it does 
0084:             * not control the prepared results that are returned when the tested application
0085:             * executes a matching statement.
0086:             * @param useRegularExpressions should regular expressions be used
0087:             */
0088:            public void setUseRegularExpressions(boolean useRegularExpressions) {
0089:                this .useRegularExpressions = useRegularExpressions;
0090:            }
0091:
0092:            /**
0093:             * Returns the {@link StatementResultSetHandler}. 
0094:             * The {@link StatementResultSetHandler}
0095:             * contains methods that can be used to specify the 
0096:             * {@link com.mockrunner.mock.jdbc.MockResultSet} objects
0097:             * and update counts that a {@link com.mockrunner.mock.jdbc.MockStatement} 
0098:             * should return when executing an SQL statement.
0099:             * @return the {@link StatementResultSetHandler}
0100:             */
0101:            public StatementResultSetHandler getStatementResultSetHandler() {
0102:                return mockFactory.getMockConnection()
0103:                        .getStatementResultSetHandler();
0104:            }
0105:
0106:            /**
0107:             * Returns the {@link PreparedStatementResultSetHandler}.
0108:             * The {@link PreparedStatementResultSetHandler}
0109:             * contains methods that can be used to specify the 
0110:             * {@link com.mockrunner.mock.jdbc.MockResultSet} objects
0111:             * and update counts that a {@link com.mockrunner.mock.jdbc.MockPreparedStatement} 
0112:             * should return when executing an SQL statement.
0113:             * @return the {@link PreparedStatementResultSetHandler}
0114:             */
0115:            public PreparedStatementResultSetHandler getPreparedStatementResultSetHandler() {
0116:                return mockFactory.getMockConnection()
0117:                        .getPreparedStatementResultSetHandler();
0118:            }
0119:
0120:            /**
0121:             * Returns the {@link CallableStatementResultSetHandler}.
0122:             * The {@link CallableStatementResultSetHandler}
0123:             * contains methods that can be used to specify the 
0124:             * {@link com.mockrunner.mock.jdbc.MockResultSet} objects
0125:             * and update counts that a {@link com.mockrunner.mock.jdbc.MockCallableStatement} 
0126:             * should return when executing an SQL statement.
0127:             * @return the {@link CallableStatementResultSetHandler}
0128:             */
0129:            public CallableStatementResultSetHandler getCallableStatementResultSetHandler() {
0130:                return mockFactory.getMockConnection()
0131:                        .getCallableStatementResultSetHandler();
0132:            }
0133:
0134:            /**
0135:             * Returns a {@link com.mockrunner.mock.jdbc.MockStatement} by its index.
0136:             * @param index the index of the <code>Statement</code>
0137:             * @return the <code>Statement</code> or <code>null</code>, if there is no such
0138:             *         <code>Statement</code>
0139:             */
0140:            public MockStatement getStatement(int index) {
0141:                List statements = getStatements();
0142:                if (index < statements.size())
0143:                    return (MockStatement) statements.get(index);
0144:                return null;
0145:            }
0146:
0147:            /**
0148:             * Returns all {@link com.mockrunner.mock.jdbc.MockStatement} objects.
0149:             * @return the <code>List</code> of <code>Statement</code> objects
0150:             */
0151:            public List getStatements() {
0152:                return mockFactory.getMockConnection()
0153:                        .getStatementResultSetHandler().getStatements();
0154:            }
0155:
0156:            /**
0157:             * Returns a <code>List</code> of all SQL statements that were executed
0158:             * by calling an <code>execute</code> method of a {@link com.mockrunner.mock.jdbc.MockStatement},
0159:             * {@link com.mockrunner.mock.jdbc.MockPreparedStatement} or
0160:             * {@link com.mockrunner.mock.jdbc.MockCallableStatement}.
0161:             * @return the <code>List</code> of SQL statements
0162:             */
0163:            public List getExecutedSQLStatements() {
0164:                ArrayList list = new ArrayList();
0165:                list
0166:                        .addAll(mockFactory.getMockConnection()
0167:                                .getStatementResultSetHandler()
0168:                                .getExecutedStatements());
0169:                list.addAll(mockFactory.getMockConnection()
0170:                        .getPreparedStatementResultSetHandler()
0171:                        .getExecutedStatements());
0172:                list.addAll(mockFactory.getMockConnection()
0173:                        .getCallableStatementResultSetHandler()
0174:                        .getExecutedStatements());
0175:                return list;
0176:            }
0177:
0178:            /**
0179:             * @deprecated use {@link #getExecutedSQLStatementParameterMap}
0180:             */
0181:            public Map getExecutedSQLStatementParameter() {
0182:                return getExecutedSQLStatementParameterMap();
0183:            }
0184:
0185:            /**
0186:             * Returns a <code>Map</code> of all parameters that were used when
0187:             * executing a {@link com.mockrunner.mock.jdbc.MockPreparedStatement} or
0188:             * {@link com.mockrunner.mock.jdbc.MockCallableStatement}.
0189:             * The keys are the corresponding SQL statements. The values are the 
0190:             * {@link ParameterSets} objects.
0191:             * @return the <code>Map</code> of parameters
0192:             */
0193:            public Map getExecutedSQLStatementParameterMap() {
0194:                Map map = new TreeMap();
0195:                map.putAll(mockFactory.getMockConnection()
0196:                        .getPreparedStatementResultSetHandler()
0197:                        .getExecutedStatementParameterMap());
0198:                map.putAll(mockFactory.getMockConnection()
0199:                        .getCallableStatementResultSetHandler()
0200:                        .getExecutedStatementParameterMap());
0201:                return map;
0202:            }
0203:
0204:            /**
0205:             * Returns the {@link ParameterSets} object for the specified SQL statement.
0206:             * If more than one {@link ParameterSets} object is found, the first one
0207:             * will be returned.
0208:             * @param sql the the SQL statement
0209:             * @return the {@link ParameterSets} object or <code>null</code> if no
0210:             *         matching object is found
0211:             */
0212:            public ParameterSets getExecutedSQLStatementParameterSets(String sql) {
0213:                Map map = getExecutedSQLStatementParameterMap();
0214:                SQLStatementMatcher matcher = new SQLStatementMatcher(
0215:                        caseSensitive, exactMatch, useRegularExpressions);
0216:                List list = matcher.getMatchingObjects(map, sql, false, false);
0217:                if (list != null && list.size() > 0) {
0218:                    return (ParameterSets) list.get(0);
0219:                }
0220:                return null;
0221:            }
0222:
0223:            /**
0224:             * Returns the <code>ResultSet</code> objects with the specified id. 
0225:             * If there are more than one <code>ResultSet</code> objects with the
0226:             * specified id, the first one is returned. If there is no
0227:             * <code>ResultSet</code> with the specified id, this method
0228:             * returns <code>null</code>.
0229:             * Please also see {@link #getReturnedResultSets(String)}.
0230:             * @return the <code>ResultSet</code> with the specified id
0231:             */
0232:            public MockResultSet getReturnedResultSet(String id) {
0233:                List list = getReturnedResultSets(id);
0234:                if (list != null && list.size() > 0) {
0235:                    return (MockResultSet) list.get(0);
0236:                }
0237:                return null;
0238:            }
0239:
0240:            /**
0241:             * Returns a <code>List</code> of the <code>ResultSet</code> objects with
0242:             * the specified id. In contrast to {@link #getReturnedResultSets}, the
0243:             * returned <code>List</code> never contains <code>ResultSet[]</code> objects,
0244:             * only single result sets. If {@link #getReturnedResultSets} returns an
0245:             * array, every <code>ResultSet</code> is checked and added to the returned <code>List</code>,
0246:             * if the id matches.
0247:             * Please note that <code>ResultSet</code> objects are cloned when executing 
0248:             * statements. The <code>ResultSet</code> objects in the <code>List</code>
0249:             * returned by this method are really the instances the statement returned
0250:             * and not the instances you have used when preparing them.
0251:             * @return the <code>List</code> of <code>ResultSet</code> objects
0252:             */
0253:            public List getReturnedResultSets(String id) {
0254:                List list = getReturnedResultSets();
0255:                ArrayList resultList = new ArrayList();
0256:                for (int ii = 0; ii < list.size(); ii++) {
0257:                    Object object = list.get(ii);
0258:                    if (object instanceof  MockResultSet) {
0259:                        addIfIdMatches((MockResultSet) object, id, resultList);
0260:                    } else if (object instanceof  MockResultSet[]) {
0261:                        MockResultSet[] resultSets = (MockResultSet[]) object;
0262:                        for (int yy = 0; yy < resultSets.length; yy++) {
0263:                            addIfIdMatches(resultSets[yy], id, resultList);
0264:                        }
0265:                    }
0266:                }
0267:                return resultList;
0268:            }
0269:
0270:            private void addIfIdMatches(MockResultSet resultSet, String id,
0271:                    List resultList) {
0272:                if (null == id)
0273:                    return;
0274:                if (id.equals(resultSet.getId())) {
0275:                    resultList.add(resultSet);
0276:                }
0277:            }
0278:
0279:            /**
0280:             * Returns a <code>List</code> of all <code>ResultSet</code> objects that were returned
0281:             * by calling an <code>executeQuery</code> method of a {@link com.mockrunner.mock.jdbc.MockStatement},
0282:             * {@link com.mockrunner.mock.jdbc.MockPreparedStatement} or
0283:             * {@link com.mockrunner.mock.jdbc.MockCallableStatement}.
0284:             * Please note that the <code>List</code> may contain arrays of <code>ResultSet</code> objects,
0285:             * if a query returned multiple result sets. The <code>List</code> may
0286:             * contain <code>ResultSet</code> objects and <code>ResultSet[]</code> objects.
0287:             * If a query returned multiple result sets, the list will always contain
0288:             * the full array of <code>ResultSet</code> objects that were prepared, even
0289:             * if {@link com.mockrunner.mock.jdbc.MockStatement#getMoreResults()} was
0290:             * not called for all the result sets.
0291:             * Please note that <code>ResultSet</code> objects are cloned when executing 
0292:             * statements. The <code>ResultSet</code> objects in the <code>List</code>
0293:             * returned by this method are really the instances the statement returned
0294:             * and not the instances you have used when preparing them.
0295:             * @return the <code>List</code> of <code>ResultSet</code> or <code>ResultSet[]</code> objects
0296:             */
0297:            public List getReturnedResultSets() {
0298:                ArrayList list = new ArrayList();
0299:                list
0300:                        .addAll(mockFactory.getMockConnection()
0301:                                .getStatementResultSetHandler()
0302:                                .getReturnedResultSets());
0303:                list.addAll(mockFactory.getMockConnection()
0304:                        .getPreparedStatementResultSetHandler()
0305:                        .getReturnedResultSets());
0306:                list.addAll(mockFactory.getMockConnection()
0307:                        .getCallableStatementResultSetHandler()
0308:                        .getReturnedResultSets());
0309:                return list;
0310:            }
0311:
0312:            /**
0313:             * Returns a {@link com.mockrunner.mock.jdbc.MockPreparedStatement} that was 
0314:             * created using a {@link com.mockrunner.mock.jdbc.MockConnection} by its index.
0315:             * @param index the index of the <code>PreparedStatement</code>
0316:             * @return the <code>PreparedStatement</code> or <code>null</code>, if there is no such
0317:             *         <code>PreparedStatement</code>
0318:             */
0319:            public MockPreparedStatement getPreparedStatement(int index) {
0320:                List statements = getPreparedStatements();
0321:                if (index < statements.size())
0322:                    return (MockPreparedStatement) statements.get(index);
0323:                return null;
0324:            }
0325:
0326:            /**
0327:             * Returns a {@link com.mockrunner.mock.jdbc.MockPreparedStatement} that was 
0328:             * created using a {@link com.mockrunner.mock.jdbc.MockConnection} by its SQL statement.
0329:             * If there are more than one {@link com.mockrunner.mock.jdbc.MockPreparedStatement}
0330:             * objects with the specified SQL, the first one will be returned.
0331:             * Please note that you can modify the search parameters with 
0332:             * {@link #setCaseSensitive}, {@link #setExactMatch} and {@link #setUseRegularExpressions}.
0333:             * @param sql the SQL statement used to create the <code>PreparedStatement</code>
0334:             * @return the <code>PreparedStatement</code> or <code>null</code>, if there is no macth
0335:             */
0336:            public MockPreparedStatement getPreparedStatement(String sql) {
0337:                List list = getPreparedStatements(sql);
0338:                if (null != list && list.size() > 0) {
0339:                    return (MockPreparedStatement) list.get(0);
0340:                }
0341:                return null;
0342:            }
0343:
0344:            /**
0345:             * Returns all {@link com.mockrunner.mock.jdbc.MockPreparedStatement} objects.
0346:             * @return the <code>List</code> of <code>PreparedStatement</code> objects
0347:             */
0348:            public List getPreparedStatements() {
0349:                return mockFactory.getMockConnection()
0350:                        .getPreparedStatementResultSetHandler()
0351:                        .getPreparedStatements();
0352:            }
0353:
0354:            /**
0355:             * Returns all {@link com.mockrunner.mock.jdbc.MockPreparedStatement} objects with
0356:             * the specified SQL statement as a <code>List</code>. If there are no matches, an empty
0357:             * <code>List</code> will be returned.
0358:             * Please note that you can modify the search parameters with 
0359:             * {@link #setCaseSensitive}, {@link #setExactMatch} and {@link #setUseRegularExpressions}.
0360:             * @param sql the SQL statement used to create the <code>PreparedStatement</code>
0361:             * @return the <code>List</code> of <code>PreparedStatement</code> objects
0362:             */
0363:            public List getPreparedStatements(String sql) {
0364:                Map sqlStatements = mockFactory.getMockConnection()
0365:                        .getPreparedStatementResultSetHandler()
0366:                        .getPreparedStatementMap();
0367:                SQLStatementMatcher matcher = new SQLStatementMatcher(
0368:                        caseSensitive, exactMatch, useRegularExpressions);
0369:                return matcher.getMatchingObjects(sqlStatements, sql, true,
0370:                        false);
0371:            }
0372:
0373:            /**
0374:             * Returns a {@link com.mockrunner.mock.jdbc.MockCallableStatement} that was 
0375:             * created using a {@link com.mockrunner.mock.jdbc.MockConnection} by its index.
0376:             * @param index the index of the <code>CallableStatement</code>
0377:             * @return the <code>CallableStatement</code> or <code>null</code>, if there is no such
0378:             *         <code>CallableStatement</code>
0379:             */
0380:            public MockCallableStatement getCallableStatement(int index) {
0381:                List statements = getCallableStatements();
0382:                if (index < statements.size())
0383:                    return (MockCallableStatement) statements.get(index);
0384:                return null;
0385:            }
0386:
0387:            /**
0388:             * Returns a {@link com.mockrunner.mock.jdbc.MockCallableStatement} that was 
0389:             * created using a {@link com.mockrunner.mock.jdbc.MockConnection} by its SQL statement.
0390:             * If there are more than one {@link com.mockrunner.mock.jdbc.MockCallableStatement}
0391:             * objects with the specified SQL, the first one will be returned.
0392:             * Please note that you can modify the search parameters with 
0393:             * {@link #setCaseSensitive}, {@link #setExactMatch} and {@link #setUseRegularExpressions}.
0394:             * @param sql the SQL statement used to create the <code>CallableStatement</code>
0395:             * @return the <code>CallableStatement</code> or <code>null</code>, if there is no macth
0396:             */
0397:            public MockCallableStatement getCallableStatement(String sql) {
0398:                List list = getCallableStatements(sql);
0399:                if (null != list && list.size() > 0) {
0400:                    return (MockCallableStatement) list.get(0);
0401:                }
0402:                return null;
0403:            }
0404:
0405:            /**
0406:             * Returns all {@link com.mockrunner.mock.jdbc.MockCallableStatement} objects.
0407:             * @return the <code>List</code> of <code>CallableStatement</code> objects
0408:             */
0409:            public List getCallableStatements() {
0410:                return mockFactory.getMockConnection()
0411:                        .getCallableStatementResultSetHandler()
0412:                        .getCallableStatements();
0413:            }
0414:
0415:            /**
0416:             * Returns all {@link com.mockrunner.mock.jdbc.MockCallableStatement} objects with
0417:             * the specified SQL statement as a <code>List</code>. 
0418:             * If there are no matches, an empty <code>List</code> will be returned. 
0419:             * Please note that you can modify the search parameters with 
0420:             * {@link #setCaseSensitive}, {@link #setExactMatch} and {@link #setUseRegularExpressions}.
0421:             * @param sql the SQL statement used to create the <code>CallableStatement</code>
0422:             * @return the <code>List</code> of <code>CallableStatement</code> objects
0423:             */
0424:            public List getCallableStatements(String sql) {
0425:                Map sqlStatements = mockFactory.getMockConnection()
0426:                        .getCallableStatementResultSetHandler()
0427:                        .getCallableStatementMap();
0428:                SQLStatementMatcher matcher = new SQLStatementMatcher(
0429:                        caseSensitive, exactMatch, useRegularExpressions);
0430:                return matcher.getMatchingObjects(sqlStatements, sql, true,
0431:                        false);
0432:            }
0433:
0434:            /**
0435:             * Returns a parameter that was added to a <code>PreparedStatement</code>
0436:             * using its <code>set</code> methods. Simple data types are returned as
0437:             * the corresponsing wrapper type.
0438:             * @param statement the <code>PreparedStatement</code>
0439:             * @param indexOfParameter the index used to set the parameter
0440:             * @return the corresponding object
0441:             */
0442:            public Object getPreparedStatementParameter(
0443:                    PreparedStatement statement, int indexOfParameter) {
0444:                if (null == statement)
0445:                    return null;
0446:                return ((MockPreparedStatement) statement)
0447:                        .getParameter(indexOfParameter);
0448:            }
0449:
0450:            /**
0451:             * Returns a parameter that was added to a <code>PreparedStatement</code>
0452:             * using its <code>set</code> methods. Uses the first <code>PreparedStatement</code>
0453:             * with the specified SQL statement. Simple data types are returned as
0454:             * the corresponsing wrapper type.
0455:             * @param sql the SQL statement
0456:             * @param indexOfParameter the index used to set the object
0457:             * @return the corresponding object
0458:             */
0459:            public Object getPreparedStatementParameter(String sql,
0460:                    int indexOfParameter) {
0461:                return getPreparedStatementParameter(getPreparedStatement(sql),
0462:                        indexOfParameter);
0463:            }
0464:
0465:            /**
0466:             * Returns an object that was added to a <code>PreparedStatement</code>
0467:             * using its <code>set</code> methods. Simple data types are returned as
0468:             * the corresponsing wrapper type.
0469:             * @param indexOfStatement the index of the statement
0470:             * @param indexOfParameter the index used to set the object
0471:             * @return the corresponding object
0472:             */
0473:            public Object getPreparedStatementParameter(int indexOfStatement,
0474:                    int indexOfParameter) {
0475:                return getPreparedStatementParameter(
0476:                        getPreparedStatement(indexOfStatement),
0477:                        indexOfParameter);
0478:            }
0479:
0480:            /**
0481:             * Returns a parameter that was added to a <code>CallableStatement</code>
0482:             * using its <code>set</code> methods. Simple data types are returned as
0483:             * the corresponsing wrapper type.
0484:             * @param statement the <code>CallableStatement</code>
0485:             * @param indexOfParameter the index used to set the parameter
0486:             * @return the corresponding object
0487:             */
0488:            public Object getCallableStatementParameter(
0489:                    CallableStatement statement, int indexOfParameter) {
0490:                if (null == statement)
0491:                    return null;
0492:                return ((MockCallableStatement) statement)
0493:                        .getParameter(indexOfParameter);
0494:            }
0495:
0496:            /**
0497:             * Returns a parameter that was added to a <code>CallableStatement</code>
0498:             * using its <code>set</code> methods. Uses the first <code>CallableStatement</code>
0499:             * with the specified SQL statement. Simple data types are returned as
0500:             * the corresponsing wrapper type.
0501:             * @param sql the SQL statement
0502:             * @param indexOfParameter the index used to set the object
0503:             * @return the corresponding object
0504:             */
0505:            public Object getCallableStatementParameter(String sql,
0506:                    int indexOfParameter) {
0507:                return getCallableStatementParameter(getCallableStatement(sql),
0508:                        indexOfParameter);
0509:            }
0510:
0511:            /**
0512:             * Returns an object that was added to a <code>CallableStatement</code>
0513:             * using its <code>set</code> methods. Simple data types are returned as
0514:             * the corresponsing wrapper type.
0515:             * @param indexOfStatement the index of the statement
0516:             * @param indexOfParameter the index used to set the object
0517:             * @return the corresponding object
0518:             */
0519:            public Object getCallableStatementParameter(int indexOfStatement,
0520:                    int indexOfParameter) {
0521:                return getCallableStatementParameter(
0522:                        getCallableStatement(indexOfStatement),
0523:                        indexOfParameter);
0524:            }
0525:
0526:            /**
0527:             * Returns a parameter that was added to a <code>CallableStatement</code>
0528:             * using its <code>set</code> methods.
0529:             * @param statement the <code>CallableStatement</code>
0530:             * @param nameOfParameter the name of the parameter
0531:             * @return the corresponding object
0532:             */
0533:            public Object getCallableStatementParameter(
0534:                    CallableStatement statement, String nameOfParameter) {
0535:                if (null == statement)
0536:                    return null;
0537:                return ((MockCallableStatement) statement)
0538:                        .getParameter(nameOfParameter);
0539:            }
0540:
0541:            /**
0542:             * Returns a parameter that was added to a <code>CallableStatement</code>
0543:             * using its <code>set</code> methods. Uses the first <code>CallableStatement</code>
0544:             * with the specified SQL statement.
0545:             * @param sql the SQL statement
0546:             * @param nameOfParameter the name of the parameter
0547:             * @return the corresponding object
0548:             */
0549:            public Object getCallableStatementParameter(String sql,
0550:                    String nameOfParameter) {
0551:                return getCallableStatementParameter(getCallableStatement(sql),
0552:                        nameOfParameter);
0553:            }
0554:
0555:            /**
0556:             * Returns an object that was added to a <code>CallableStatement</code>
0557:             * using its <code>set</code> methods.
0558:             * @param indexOfStatement the index of the statement
0559:             * @param nameOfParameter the name of the parameter
0560:             * @return the corresponding object
0561:             */
0562:            public Object getCallableStatementParameter(int indexOfStatement,
0563:                    String nameOfParameter) {
0564:                return getCallableStatementParameter(
0565:                        getCallableStatement(indexOfStatement), nameOfParameter);
0566:            }
0567:
0568:            /**
0569:             * Returns a list of all <code>Savepoint</code> objects.
0570:             * @return the <code>List</code> of {@link com.mockrunner.mock.jdbc.MockSavepoint} objects
0571:             */
0572:            /*public List getSavepoints()
0573:            {
0574:                return new ArrayList(mockFactory.getMockConnection().getSavepointMap().values());
0575:            }*/
0576:
0577:            /**
0578:             * Returns the <code>Savepoint</code> with the specified index.
0579:             * The index is the number of the created <code>Savepoint</code>
0580:             * starting with 0 for the first <code>Savepoint</code>.
0581:             * @param index the index
0582:             * @return the {@link com.mockrunner.mock.jdbc.MockSavepoint}
0583:             */
0584:            /*public MockSavepoint getSavepoint(int index)
0585:            {
0586:                List savepoints = getSavepoints();
0587:                for(int ii = 0; ii < savepoints.size(); ii++)
0588:                {
0589:                    MockSavepoint currentSavepoint = (MockSavepoint)savepoints.get(ii);
0590:                    if(currentSavepoint.getNumber() == index) return currentSavepoint;
0591:                }
0592:                return null;
0593:            }*/
0594:
0595:            /**
0596:             * Returns the first <code>Savepoint</code> with the specified name.
0597:             * Unnamed <code>Savepoint</code> objects get the name <i>""</i>.
0598:             * @param name the name
0599:             * @return the {@link com.mockrunner.mock.jdbc.MockSavepoint}
0600:             */
0601:            /*public MockSavepoint getSavepoint(String name)
0602:            {
0603:                List savepoints = getSavepoints();
0604:                for(int ii = 0; ii < savepoints.size(); ii++)
0605:                {
0606:                    MockSavepoint currentSavepoint = (MockSavepoint)savepoints.get(ii);
0607:                    try
0608:                    {
0609:                        if(currentSavepoint.getSavepointName().equals(name)) return currentSavepoint;
0610:                    }
0611:                    catch(SQLException exc)
0612:                    {
0613:                        throw new NestedApplicationException(exc);
0614:                    }
0615:                }
0616:                return null;
0617:            }*/
0618:
0619:            /**
0620:             * Verifies that an SQL statement was executed.
0621:             * @param sql the expected SQL string
0622:             * @throws VerifyFailedException if verification fails
0623:             */
0624:            public void verifySQLStatementExecuted(String sql) {
0625:                SQLStatementMatcher matcher = new SQLStatementMatcher(
0626:                        caseSensitive, exactMatch, useRegularExpressions);
0627:                if (!matcher.contains(getExecutedSQLStatements(), sql, false)) {
0628:                    throw new VerifyFailedException("Statement " + sql
0629:                            + " not executed.");
0630:                }
0631:            }
0632:
0633:            /**
0634:             * Verifies that an SQL statement was not executed.
0635:             * @param sql the SQL string
0636:             * @throws VerifyFailedException if verification fails
0637:             */
0638:            public void verifySQLStatementNotExecuted(String sql) {
0639:                SQLStatementMatcher matcher = new SQLStatementMatcher(
0640:                        caseSensitive, exactMatch, useRegularExpressions);
0641:                if (matcher.contains(getExecutedSQLStatements(), sql, false)) {
0642:                    throw new VerifyFailedException("Statement " + sql
0643:                            + " was executed.");
0644:                }
0645:            }
0646:
0647:            /**
0648:             * Verifies the number of parameters for the specified SQL statement.
0649:             * If more than one SQL statement is found, this method uses the
0650:             * first one. You can specify the index of the parameter set. If
0651:             * if a <code>PreparedStatement</code> or <code>CallableStatement</code> 
0652:             * is executed N times, it has N parameter sets. Each parameter set
0653:             * can contain any number of parameters (possibly 0 parameters).
0654:             * Ordinary statements do not have parameter sets, of course. If
0655:             * the specified SQL has been executed by an ordinary statements,
0656:             * a <code>VerifyFailedException</code> is thrown stating the reason.
0657:             * @param sql the SQL string
0658:             * @param indexOfParameterSet the number of the parameter set
0659:             * @param number the expected number of parameters
0660:             * @throws VerifyFailedException if verification fails
0661:             */
0662:            public void verifySQLStatementParameterNumber(String sql,
0663:                    int indexOfParameterSet, int number) {
0664:                Map actualParameterMap = verifyAndGetParametersForSQL(sql,
0665:                        indexOfParameterSet);
0666:                if (actualParameterMap.size() != number) {
0667:                    throw new VerifyFailedException("Expected " + number
0668:                            + " parameter, actual " + actualParameterMap.size()
0669:                            + " parameter");
0670:                }
0671:            }
0672:
0673:            /**
0674:             * Verifies the parameters for the specified SQL statement.
0675:             * If more than one SQL statement is found, this method uses the
0676:             * first one. The parameter map must match in size and the
0677:             * parameters must be equal (by comparing them with
0678:             * {de.lv1871.util.ParameterUtil#compareParameter}).
0679:             * You can specify the index of the parameter set. If
0680:             * if a <code>PreparedStatement</code> or <code>CallableStatement</code> 
0681:             * is executed N times, it has N parameter sets. Each parameter set
0682:             * can contain any number of parameters (possibly 0 parameters).
0683:             * Ordinary statements do not have parameter sets, of course. If
0684:             * the specified SQL has been executed by an ordinary statements,
0685:             * a <code>VerifyFailedException</code> is thrown stating the reason.
0686:             * @param sql the SQL string
0687:             * @param indexOfParameterSet the number of the parameter set
0688:             * @param parameterMap the map of expected parameters
0689:             * @throws VerifyFailedException if verification fails
0690:             */
0691:            public void verifySQLStatementParameter(String sql,
0692:                    int indexOfParameterSet, Map parameterMap) {
0693:                verifySQLStatementParameterNumber(sql, indexOfParameterSet,
0694:                        parameterMap.size());
0695:                Map actualParameterMap = verifyAndGetParametersForSQL(sql,
0696:                        indexOfParameterSet);
0697:                Iterator keys = parameterMap.keySet().iterator();
0698:                while (keys.hasNext()) {
0699:                    Object nextKey = keys.next();
0700:                    Object nextExpectedParameter = parameterMap.get(nextKey);
0701:                    Object nextActualParameter = actualParameterMap
0702:                            .get(nextKey);
0703:                    if (null == nextActualParameter) {
0704:                        throw new VerifyFailedException("No parameter "
0705:                                + nextKey + " found.");
0706:                    }
0707:                    if (!ParameterUtil.compareParameter(nextExpectedParameter,
0708:                            nextActualParameter)) {
0709:                        throw new VerifyFailedException("Expected "
0710:                                + nextExpectedParameter + " for parameter "
0711:                                + nextKey + ", but was " + nextActualParameter);
0712:                    }
0713:                }
0714:            }
0715:
0716:            /**
0717:             * Verifies the parameter for the specified SQL statement.
0718:             * If more than one SQL statement is found, this method uses the
0719:             * first one.
0720:             * You can specify the index of the parameter set. If
0721:             * if a <code>PreparedStatement</code> or <code>CallableStatement</code> 
0722:             * is executed N times, it has N parameter sets. Each parameter set
0723:             * can contain any number of parameters (possibly 0 parameters).
0724:             * Ordinary statements do not have parameter sets, of course. If
0725:             * the specified SQL has been executed by an ordinary statements,
0726:             * a <code>VerifyFailedException</code> is thrown stating the reason.
0727:             * @param sql the SQL string
0728:             * @param indexOfParameterSet the number of the parameter set
0729:             * @param indexOfParameter the index of the parameter
0730:             * @param expectedParameter the expected parameter
0731:             * @throws VerifyFailedException if verification fails
0732:             */
0733:            public void verifySQLStatementParameter(String sql,
0734:                    int indexOfParameterSet, int indexOfParameter,
0735:                    Object expectedParameter) {
0736:                Map actualParameterMap = verifyAndGetParametersForSQL(sql,
0737:                        indexOfParameterSet);
0738:                Object actualParameter = actualParameterMap.get(new Integer(
0739:                        indexOfParameter));
0740:                if (!ParameterUtil.compareParameter(expectedParameter,
0741:                        actualParameter)) {
0742:                    throw new VerifyFailedException("Expected "
0743:                            + expectedParameter + " for parameter "
0744:                            + indexOfParameter + ", but was " + actualParameter);
0745:                }
0746:            }
0747:
0748:            /**
0749:             * Verifies the parameter for the specified SQL statement.
0750:             * If more than one SQL statement is found, this method uses the
0751:             * first one.
0752:             * You can specify the index of the parameter set. If
0753:             * if a <code>PreparedStatement</code> or <code>CallableStatement</code> 
0754:             * is executed N times, it has N parameter sets. Each parameter set
0755:             * can contain any number of parameters (possibly 0 parameters).
0756:             * Ordinary statements do not have parameter sets, of course. If
0757:             * the specified SQL has been executed by an ordinary statements,
0758:             * a <code>VerifyFailedException</code> is thrown stating the reason.
0759:             * @param sql the SQL string
0760:             * @param indexOfParameterSet the number of the parameter set
0761:             * @param nameOfParameter the name of the parameter
0762:             * @param expectedParameter the expected parameter
0763:             * @throws VerifyFailedException if verification fails
0764:             */
0765:            public void verifySQLStatementParameter(String sql,
0766:                    int indexOfParameterSet, String nameOfParameter,
0767:                    Object expectedParameter) {
0768:                Map actualParameterMap = verifyAndGetParametersForSQL(sql,
0769:                        indexOfParameterSet);
0770:                Object actualParameter = actualParameterMap
0771:                        .get(nameOfParameter);
0772:                if (!ParameterUtil.compareParameter(expectedParameter,
0773:                        actualParameter)) {
0774:                    throw new VerifyFailedException("Expected "
0775:                            + expectedParameter + " for parameter "
0776:                            + nameOfParameter + ", but was " + actualParameter);
0777:                }
0778:            }
0779:
0780:            private Map verifyAndGetParametersForSQL(String sql,
0781:                    int indexOfParameterSet) {
0782:                verifySQLStatementExecuted(sql);
0783:                SQLStatementMatcher matcher = new SQLStatementMatcher(
0784:                        caseSensitive, exactMatch, useRegularExpressions);
0785:                List matchingParameterList = matcher
0786:                        .getMatchingObjects(
0787:                                getExecutedSQLStatementParameterMap(), sql,
0788:                                true, false);
0789:                if (null == matchingParameterList
0790:                        || matchingParameterList.size() == 0) {
0791:                    throw new VerifyFailedException(
0792:                            "No parameter sets for SQL "
0793:                                    + sql
0794:                                    + " found. Maybe the SQL has been executed by a regular "
0795:                                    + "statement instead of a prepared statement or callable statement.");
0796:                }
0797:                ParameterSets actualParameterSets = (ParameterSets) matchingParameterList
0798:                        .get(0);
0799:                if (null == actualParameterSets
0800:                        || indexOfParameterSet >= actualParameterSets
0801:                                .getNumberParameterSets()) {
0802:                    throw new VerifyFailedException("Statement " + sql
0803:                            + " has no parameter set with index "
0804:                            + indexOfParameterSet
0805:                            + ". Maybe it has been executed less than "
0806:                            + (indexOfParameterSet + 1) + " times.");
0807:                }
0808:                return actualParameterSets.getParameterSet(indexOfParameterSet);
0809:            }
0810:
0811:            /**
0812:             * Verifies that the connection is closed.
0813:             * @throws VerifyFailedException if verification fails
0814:             */
0815:            public void verifyConnectionClosed() {
0816:                try {
0817:                    if (!mockFactory.getMockConnection().isClosed()) {
0818:                        throw new VerifyFailedException(
0819:                                "Connection not closed.");
0820:                    }
0821:                } catch (SQLException exc) {
0822:                    throw new NestedApplicationException(exc);
0823:                }
0824:            }
0825:
0826:            /**
0827:             * Verifies that all statements, all prepared statements and
0828:             * all callable statements are closed.
0829:             * @throws VerifyFailedException if verification fails
0830:             */
0831:            public void verifyAllStatementsClosed() {
0832:                List statements = getStatements();
0833:                for (int ii = 0; ii < statements.size(); ii++) {
0834:                    MockStatement statement = (MockStatement) statements
0835:                            .get(ii);
0836:                    if (!statement.isClosed()) {
0837:                        throw new VerifyFailedException("Statement with index "
0838:                                + ii + " not closed.");
0839:                    }
0840:                }
0841:                statements = getPreparedStatements();
0842:                for (int ii = 0; ii < statements.size(); ii++) {
0843:                    MockPreparedStatement statement = (MockPreparedStatement) statements
0844:                            .get(ii);
0845:                    if (!statement.isClosed()) {
0846:                        throw new VerifyFailedException(
0847:                                "Prepared statement with index " + ii
0848:                                        + " (SQL " + statement.getSQL()
0849:                                        + ") not closed.");
0850:                    }
0851:                }
0852:                statements = getCallableStatements();
0853:                for (int ii = 0; ii < statements.size(); ii++) {
0854:                    MockPreparedStatement statement = (MockCallableStatement) statements
0855:                            .get(ii);
0856:                    if (!statement.isClosed()) {
0857:                        throw new VerifyFailedException(
0858:                                "Callable statement with index " + ii
0859:                                        + " (SQL " + statement.getSQL()
0860:                                        + ") not closed.");
0861:                    }
0862:                }
0863:            }
0864:
0865:            /**
0866:             * Verifies that the <code>ResultSet</code> with the
0867:             * specified id is closed. Only recognizes <code>ResultSet</code>
0868:             * objects that were actually returned when executing a statement
0869:             * and that were explicitly closed. Implicit closed <code>ResultSet</code>
0870:             * objects (when closing a statement) are not recognized.
0871:             * @throws VerifyFailedException if verification fails
0872:             */
0873:            public void verifyResultSetClosed(String id) {
0874:                MockResultSet resultSet = getReturnedResultSet(id);
0875:                if (null == resultSet) {
0876:                    throw new VerifyFailedException("ResultSet with id " + id
0877:                            + " not present.");
0878:                }
0879:                if (!resultSet.isClosed()) {
0880:                    throw new VerifyFailedException("ResultSet with id " + id
0881:                            + " not closed.");
0882:                }
0883:            }
0884:
0885:            /**
0886:             * Verifies that the specified row of a <code>ResultSet</code> was
0887:             * inserted.
0888:             * @param resultSet the <code>ResultSet</code>
0889:             * @param number the number of the row
0890:             * @throws VerifyFailedException if verification fails
0891:             */
0892:            public void verifyResultSetRowInserted(MockResultSet resultSet,
0893:                    int number) {
0894:                if (!resultSet.rowInserted(number)) {
0895:                    throw new VerifyFailedException("Row number " + number
0896:                            + " of ResultSet " + resultSet.getId()
0897:                            + " not inserted.");
0898:                }
0899:            }
0900:
0901:            /**
0902:             * Verifies that the specified row of a <code>ResultSet</code> was
0903:             * inserted.
0904:             * @param id the id of the <code>ResultSet</code>
0905:             * @param number the number of the row
0906:             * @throws VerifyFailedException if verification fails
0907:             */
0908:            public void verifyResultSetRowInserted(String id, int number) {
0909:                MockResultSet resultSet = getReturnedResultSet(id);
0910:                if (null == resultSet) {
0911:                    throw new VerifyFailedException("ResultSet with id " + id
0912:                            + " not present.");
0913:                }
0914:                verifyResultSetRowInserted(resultSet, number);
0915:            }
0916:
0917:            /**
0918:             * Verifies that the specified row of a <code>ResultSet</code> was
0919:             * not inserted.
0920:             * @param resultSet the <code>ResultSet</code>
0921:             * @param number the number of the row
0922:             * @throws VerifyFailedException if verification fails
0923:             */
0924:            public void verifyResultSetRowNotInserted(MockResultSet resultSet,
0925:                    int number) {
0926:                if (resultSet.rowInserted(number)) {
0927:                    throw new VerifyFailedException("Row number " + number
0928:                            + " of ResultSet " + resultSet.getId()
0929:                            + " was inserted.");
0930:                }
0931:            }
0932:
0933:            /**
0934:             * Verifies that the specified row of a <code>ResultSet</code> was
0935:             * not inserted.
0936:             * @param id the id of the <code>ResultSet</code>
0937:             * @param number the number of the row
0938:             * @throws VerifyFailedException if verification fails
0939:             */
0940:            public void verifyResultSetRowNotInserted(String id, int number) {
0941:                MockResultSet resultSet = getReturnedResultSet(id);
0942:                if (null == resultSet) {
0943:                    throw new VerifyFailedException("ResultSet with id " + id
0944:                            + " not present.");
0945:                }
0946:                verifyResultSetRowNotInserted(resultSet, number);
0947:            }
0948:
0949:            /**
0950:             * Verifies that the specified row of a <code>ResultSet</code> was
0951:             * updated.
0952:             * @param resultSet the <code>ResultSet</code>
0953:             * @param number the number of the row
0954:             * @throws VerifyFailedException if verification fails
0955:             */
0956:            public void verifyResultSetRowUpdated(MockResultSet resultSet,
0957:                    int number) {
0958:                if (!resultSet.rowUpdated(number)) {
0959:                    throw new VerifyFailedException("Row number " + number
0960:                            + " of ResultSet " + resultSet.getId()
0961:                            + " not updated.");
0962:                }
0963:            }
0964:
0965:            /**
0966:             * Verifies that the specified row of a <code>ResultSet</code> was
0967:             * updated.
0968:             * @param id the id of the <code>ResultSet</code>
0969:             * @param number the number of the row
0970:             * @throws VerifyFailedException if verification fails
0971:             */
0972:            public void verifyResultSetRowUpdated(String id, int number) {
0973:                MockResultSet resultSet = getReturnedResultSet(id);
0974:                if (null == resultSet) {
0975:                    throw new VerifyFailedException("ResultSet with id " + id
0976:                            + " not present.");
0977:                }
0978:                verifyResultSetRowUpdated(resultSet, number);
0979:            }
0980:
0981:            /**
0982:             * Verifies that the specified row of a <code>ResultSet</code> was
0983:             * not updated.
0984:             * @param resultSet the <code>ResultSet</code>
0985:             * @param number the number of the row
0986:             * @throws VerifyFailedException if verification fails
0987:             */
0988:            public void verifyResultSetRowNotUpdated(MockResultSet resultSet,
0989:                    int number) {
0990:                if (resultSet.rowUpdated(number)) {
0991:                    throw new VerifyFailedException("Row number " + number
0992:                            + " of ResultSet " + resultSet.getId()
0993:                            + " was updated.");
0994:                }
0995:            }
0996:
0997:            /**
0998:             * Verifies that the specified row of a <code>ResultSet</code> was
0999:             * not updated.
1000:             * @param id the id of the <code>ResultSet</code>
1001:             * @param number the number of the row
1002:             * @throws VerifyFailedException if verification fails
1003:             */
1004:            public void verifyResultSetRowNotUpdated(String id, int number) {
1005:                MockResultSet resultSet = getReturnedResultSet(id);
1006:                if (null == resultSet) {
1007:                    throw new VerifyFailedException("ResultSet with id " + id
1008:                            + " not present.");
1009:                }
1010:                verifyResultSetRowNotUpdated(resultSet, number);
1011:            }
1012:
1013:            /**
1014:             * Verifies that the specified row of a <code>ResultSet</code> was
1015:             * deleted.
1016:             * @param resultSet the <code>ResultSet</code>
1017:             * @param number the number of the row
1018:             * @throws VerifyFailedException if verification fails
1019:             */
1020:            public void verifyResultSetRowDeleted(MockResultSet resultSet,
1021:                    int number) {
1022:                if (!resultSet.rowDeleted(number)) {
1023:                    throw new VerifyFailedException("Row number " + number
1024:                            + " of ResultSet " + resultSet.getId()
1025:                            + " not deleted.");
1026:                }
1027:            }
1028:
1029:            /**
1030:             * Verifies that the specified row of a <code>ResultSet</code> was
1031:             * deleted.
1032:             * @param id the id of the <code>ResultSet</code>
1033:             * @param number the number of the row
1034:             * @throws VerifyFailedException if verification fails
1035:             */
1036:            public void verifyResultSetRowDeleted(String id, int number) {
1037:                MockResultSet resultSet = getReturnedResultSet(id);
1038:                if (null == resultSet) {
1039:                    throw new VerifyFailedException("ResultSet with id " + id
1040:                            + " not present.");
1041:                }
1042:                verifyResultSetRowDeleted(resultSet, number);
1043:            }
1044:
1045:            /**
1046:             * Verifies that the specified row of a <code>ResultSet</code> was
1047:             * not deleted.
1048:             * @param resultSet the <code>ResultSet</code>
1049:             * @param number the number of the row
1050:             * @throws VerifyFailedException if verification fails
1051:             */
1052:            public void verifyResultSetRowNotDeleted(MockResultSet resultSet,
1053:                    int number) {
1054:                if (resultSet.rowDeleted(number)) {
1055:                    throw new VerifyFailedException("Row number " + number
1056:                            + " of ResultSet " + resultSet.getId()
1057:                            + " was deleted.");
1058:                }
1059:            }
1060:
1061:            /**
1062:             * Verifies that the specified row of a <code>ResultSet</code> was
1063:             * not deleted.
1064:             * @param id the id of the <code>ResultSet</code>
1065:             * @param number the number of the row
1066:             * @throws VerifyFailedException if verification fails
1067:             */
1068:            public void verifyResultSetRowNotDeleted(String id, int number) {
1069:                MockResultSet resultSet = getReturnedResultSet(id);
1070:                if (null == resultSet) {
1071:                    throw new VerifyFailedException("ResultSet with id " + id
1072:                            + " not present.");
1073:                }
1074:                verifyResultSetRowNotDeleted(resultSet, number);
1075:            }
1076:
1077:            /**
1078:             * Verifies that all <code>ResultSet</code> objects are closed.
1079:             * Only recognizes <code>ResultSet</code> objects that were actually 
1080:             * returned when executing a statement and that were explicitly closed. 
1081:             * Implicit closed <code>ResultSet</code> objects (when closing a statement) 
1082:             * are not recognized.
1083:             * @throws VerifyFailedException if verification fails
1084:             */
1085:            public void verifyAllResultSetsClosed() {
1086:                List allResultSets = getReturnedResultSets();
1087:                for (int ii = 0; ii < allResultSets.size(); ii++) {
1088:                    Object object = allResultSets.get(ii);
1089:                    if (object instanceof  MockResultSet) {
1090:                        throwExceptionIfNotClosed((MockResultSet) object);
1091:                    } else if (object instanceof  MockResultSet[]) {
1092:                        MockResultSet[] resultSets = (MockResultSet[]) object;
1093:                        for (int yy = 0; yy < resultSets.length; yy++) {
1094:                            throwExceptionIfNotClosed(resultSets[yy]);
1095:                        }
1096:                    }
1097:                }
1098:            }
1099:
1100:            private void throwExceptionIfNotClosed(MockResultSet resultSet) {
1101:                if (!resultSet.isClosed()) {
1102:                    throw new VerifyFailedException("ResultSet with id "
1103:                            + resultSet.getId() + " not closed.");
1104:                }
1105:            }
1106:
1107:            /**
1108:             * Verifies that the changes were commited, i.e. the <code>commit</code>
1109:             * method of <code>Connection</code> was at least called once.
1110:             * Makes only sense, if the <code>Connection</code> is not in
1111:             * autocommit mode. Automatic commits are not recognized.
1112:             * @throws VerifyFailedException if verification fails
1113:             */
1114:            public void verifyCommitted() {
1115:                int number = mockFactory.getMockConnection().getNumberCommits();
1116:                if (number <= 0) {
1117:                    throw new VerifyFailedException(
1118:                            "Connection received no commits.");
1119:                }
1120:            }
1121:
1122:            /**
1123:             * Verifies that the changes were not commited.
1124:             * Makes only sense, if the <code>Connection</code> is not in
1125:             * autocommit mode. Automatic commits are not recognized.
1126:             * @throws VerifyFailedException if verification fails
1127:             */
1128:            public void verifyNotCommitted() {
1129:                int number = mockFactory.getMockConnection().getNumberCommits();
1130:                if (number > 0) {
1131:                    throw new VerifyFailedException("Connection was committed");
1132:                }
1133:            }
1134:
1135:            /**
1136:             * Verifies that the changes were rolled back, i.e. the <code>rollback</code>
1137:             * method of <code>Connection</code> was at least called once.
1138:             * Makes only sense, if the <code>Connection</code> is not in
1139:             * autocommit mode.
1140:             * @throws VerifyFailedException if verification fails
1141:             */
1142:            public void verifyRolledBack() {
1143:                int number = mockFactory.getMockConnection()
1144:                        .getNumberRollbacks();
1145:                if (number <= 0) {
1146:                    throw new VerifyFailedException(
1147:                            "Connection received no rollbacks.");
1148:                }
1149:            }
1150:
1151:            /**
1152:             * Verifies that the changes were not rolled back.
1153:             * Makes only sense, if the <code>Connection</code> is not in
1154:             * autocommit mode.
1155:             * @throws VerifyFailedException if verification fails
1156:             */
1157:            public void verifyNotRolledBack() {
1158:                int number = mockFactory.getMockConnection()
1159:                        .getNumberRollbacks();
1160:                if (number > 0) {
1161:                    throw new VerifyFailedException(
1162:                            "Connection was rolled back.");
1163:                }
1164:            }
1165:
1166:            /**
1167:             * Verifies the number of <code>commit</code> calls.
1168:             * Makes only sense, if the <code>Connection</code> is not in
1169:             * autocommit mode.
1170:             * @param number the expected number of commits
1171:             * @throws VerifyFailedException if verification fails
1172:             */
1173:            public void verifyNumberCommits(int number) {
1174:                int actualNumber = mockFactory.getMockConnection()
1175:                        .getNumberCommits();
1176:                if (actualNumber != number) {
1177:                    throw new VerifyFailedException("Connection received "
1178:                            + actualNumber + " commits, expected " + number);
1179:                }
1180:            }
1181:
1182:            /**
1183:             * Verifies the number of <code>rollback</code> calls.
1184:             * Makes only sense, if the <code>Connection</code> is not in
1185:             * autocommit mode.
1186:             * @param number the expected number of rollbacks
1187:             * @throws VerifyFailedException if verification fails
1188:             */
1189:            public void verifyNumberRollbacks(int number) {
1190:                int actualNumber = mockFactory.getMockConnection()
1191:                        .getNumberRollbacks();
1192:                if (actualNumber != number) {
1193:                    throw new VerifyFailedException("Connection received "
1194:                            + actualNumber + " rollbacks, expected " + number);
1195:                }
1196:            }
1197:
1198:            /**
1199:             * Verifies the number of statements.
1200:             * @param number the expected number
1201:             * @throws VerifyFailedException if verification fails
1202:             */
1203:            public void verifyNumberStatements(int number) {
1204:                verifyNumberStatements(number, getStatements());
1205:            }
1206:
1207:            /**
1208:             * Verifies the number of prepared statements.
1209:             * @param number the expected number
1210:             * @throws VerifyFailedException if verification fails
1211:             */
1212:            public void verifyNumberPreparedStatements(int number) {
1213:                verifyNumberStatements(number, getPreparedStatements());
1214:            }
1215:
1216:            /**
1217:             * Verifies the number of prepared statements with the specified
1218:             * SQL.
1219:             * @param number the expected number
1220:             * @param sql the SQL
1221:             * @throws VerifyFailedException if verification fails
1222:             */
1223:            public void verifyNumberPreparedStatements(int number, String sql) {
1224:                verifyNumberStatements(number, getPreparedStatements(sql));
1225:            }
1226:
1227:            /**
1228:             * Verifies the number of callable statements.
1229:             * @param number the expected number
1230:             * @throws VerifyFailedException if verification fails
1231:             */
1232:            public void verifyNumberCallableStatements(int number) {
1233:                verifyNumberStatements(number, getCallableStatements());
1234:            }
1235:
1236:            /**
1237:             * Verifies the number of callable statements with the specified
1238:             * SQL.
1239:             * @param number the expected number
1240:             * @param sql the SQL
1241:             * @throws VerifyFailedException if verification fails
1242:             */
1243:            public void verifyNumberCallableStatements(int number, String sql) {
1244:                verifyNumberStatements(number, getCallableStatements(sql));
1245:            }
1246:
1247:            private void verifyNumberStatements(int number, List statements) {
1248:                if (null == statements || statements.size() == 0) {
1249:                    if (number == 0)
1250:                        return;
1251:                    throw new VerifyFailedException("Expected " + number
1252:                            + " statements, received 0 statements");
1253:                }
1254:                if (statements.size() != number) {
1255:                    throw new VerifyFailedException("Expected " + number
1256:                            + " statements, received " + statements.size()
1257:                            + " statements");
1258:                }
1259:            }
1260:
1261:            /**
1262:             * Verifies that a statement is closed.
1263:             * @param index the index of the statement
1264:             * @throws VerifyFailedException if verification fails
1265:             */
1266:            public void verifyStatementClosed(int index) {
1267:                MockStatement statement = getStatement(index);
1268:                if (null == statement) {
1269:                    throw new VerifyFailedException("No statement with index "
1270:                            + index + " present.");
1271:                }
1272:                if (!statement.isClosed()) {
1273:                    throw new VerifyFailedException("Statement with index "
1274:                            + index + " not closed.");
1275:                }
1276:            }
1277:
1278:            /**
1279:             * Verifies that a prepared statement is closed.
1280:             * @param index the index of the prepared statement
1281:             * @throws VerifyFailedException if verification fails
1282:             */
1283:            public void verifyPreparedStatementClosed(int index) {
1284:                MockPreparedStatement statement = getPreparedStatement(index);
1285:                if (null == statement) {
1286:                    throw new VerifyFailedException(
1287:                            "No prepared statement with index " + index
1288:                                    + " present.");
1289:                }
1290:                if (!statement.isClosed()) {
1291:                    throw new VerifyFailedException(
1292:                            "Prepared statement with index " + index
1293:                                    + " not closed.");
1294:                }
1295:            }
1296:
1297:            /**
1298:             * Verifies that a prepared statement is closed.
1299:             * @param sql the SQL statement
1300:             * @throws VerifyFailedException if verification fails
1301:             */
1302:            public void verifyPreparedStatementClosed(String sql) {
1303:                MockPreparedStatement statement = getPreparedStatement(sql);
1304:                if (null == statement) {
1305:                    throw new VerifyFailedException(
1306:                            "No prepared statement with SQL " + sql
1307:                                    + " present.");
1308:                }
1309:                if (!statement.isClosed()) {
1310:                    throw new VerifyFailedException(
1311:                            "Prepared statement with SQL " + sql
1312:                                    + " not closed.");
1313:                }
1314:            }
1315:
1316:            /**
1317:             * Verifies that a callable statement is closed.
1318:             * @param index the index of the callable statement
1319:             * @throws VerifyFailedException if verification fails
1320:             */
1321:            public void verifyCallableStatementClosed(int index) {
1322:                MockCallableStatement statement = getCallableStatement(index);
1323:                if (null == statement) {
1324:                    throw new VerifyFailedException(
1325:                            "No callable statement with index " + index
1326:                                    + " present.");
1327:                }
1328:                if (!statement.isClosed()) {
1329:                    throw new VerifyFailedException(
1330:                            "Callable statement with index " + index
1331:                                    + " not closed.");
1332:                }
1333:            }
1334:
1335:            /**
1336:             * Verifies that a callable statement is closed.
1337:             * @param sql the SQL statement
1338:             * @throws VerifyFailedException if verification fails
1339:             */
1340:            public void verifyCallableStatementClosed(String sql) {
1341:                MockCallableStatement statement = getCallableStatement(sql);
1342:                if (null == statement) {
1343:                    throw new VerifyFailedException(
1344:                            "No callable statement with SQL " + sql
1345:                                    + " present.");
1346:                }
1347:                if (!statement.isClosed()) {
1348:                    throw new VerifyFailedException(
1349:                            "Callable statement with SQL " + sql
1350:                                    + " not closed.");
1351:                }
1352:            }
1353:
1354:            /**
1355:             * Verifies that a row of a <code>ResultSet</code> is equal to the
1356:             * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isRowEqual}.
1357:             * You can verify the data of returned <code>ResultSet</code> objects if
1358:             * the tested JDBC code makes updates.
1359:             * @param resultSet the <code>ResultSet</code>
1360:             * @param number the number of the row
1361:             * @param rowData the row data
1362:             * @throws VerifyFailedException if verification fails
1363:             */
1364:            public void verifyResultSetRow(MockResultSet resultSet, int number,
1365:                    List rowData) {
1366:                if (null == resultSet.getRow(number)) {
1367:                    throw new VerifyFailedException("ResultSet "
1368:                            + resultSet.getId() + " has no row " + number);
1369:                }
1370:                if (!resultSet.isRowEqual(number, rowData)) {
1371:                    StringBuffer buffer = new StringBuffer("Actual row data:\n");
1372:                    StringUtil.appendObjectsAsString(buffer, resultSet
1373:                            .getRow(number));
1374:                    buffer.append("\n");
1375:                    buffer.append("Expected row data:\n");
1376:                    StringUtil.appendObjectsAsString(buffer, rowData);
1377:                    throw new VerifyFailedException("Mismatch in row data.\n"
1378:                            + buffer.toString());
1379:                }
1380:            }
1381:
1382:            /**
1383:             * Verifies that a row of a <code>ResultSet</code> is equal to the
1384:             * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isRowEqual}.
1385:             * You can verify the data of returned <code>ResultSet</code> objects if
1386:             * the tested JDBC code makes updates.
1387:             * @param resultSet the <code>ResultSet</code>
1388:             * @param number the number of the row
1389:             * @param rowData the row data
1390:             * @throws VerifyFailedException if verification fails
1391:             */
1392:            public void verifyResultSetRow(MockResultSet resultSet, int number,
1393:                    Object[] rowData) {
1394:                List dataList = Arrays.asList(rowData);
1395:                verifyResultSetRow(resultSet, number, dataList);
1396:            }
1397:
1398:            /**
1399:             * Verifies that a row of a <code>ResultSet</code> is equal to the
1400:             * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isRowEqual}.
1401:             * You can verify the data of returned <code>ResultSet</code> objects if
1402:             * the tested JDBC code makes updates.
1403:             * @param id the id of the <code>ResultSet</code>
1404:             * @param number the number of the row
1405:             * @param rowData the row data
1406:             * @throws VerifyFailedException if verification fails
1407:             */
1408:            public void verifyResultSetRow(String id, int number, List rowData) {
1409:                MockResultSet resultSet = getReturnedResultSet(id);
1410:                if (null == resultSet) {
1411:                    throw new VerifyFailedException("ResultSet with id " + id
1412:                            + " not present.");
1413:                }
1414:                verifyResultSetRow(resultSet, number, rowData);
1415:            }
1416:
1417:            /**
1418:             * Verifies that a row of a <code>ResultSet</code> is equal to the
1419:             * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isRowEqual}.
1420:             * You can verify the data of returned <code>ResultSet</code> objects if
1421:             * the tested JDBC code makes updates.
1422:             * @param id the id of the <code>ResultSet</code>
1423:             * @param number the number of the row
1424:             * @param rowData the row data
1425:             * @throws VerifyFailedException if verification fails
1426:             */
1427:            public void verifyResultSetRow(String id, int number,
1428:                    Object[] rowData) {
1429:                List dataList = Arrays.asList(rowData);
1430:                verifyResultSetRow(id, number, dataList);
1431:            }
1432:
1433:            /**
1434:             * Verifies that a column of a <code>ResultSet</code> is equal to the
1435:             * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(int, List)}.
1436:             * You can verify the data of returned <code>ResultSet</code> objects if
1437:             * the tested JDBC code makes updates.
1438:             * @param resultSet the <code>ResultSet</code>
1439:             * @param number the number of the column
1440:             * @param columnData the column data
1441:             * @throws VerifyFailedException if verification fails
1442:             */
1443:            public void verifyResultSetColumn(MockResultSet resultSet,
1444:                    int number, List columnData) {
1445:                if (null == resultSet.getColumn(number)) {
1446:                    throw new VerifyFailedException("ResultSet "
1447:                            + resultSet.getId() + " has no column " + number);
1448:                }
1449:                if (!resultSet.isColumnEqual(number, columnData)) {
1450:                    StringBuffer buffer = new StringBuffer(
1451:                            "Actual column data:\n");
1452:                    StringUtil.appendObjectsAsString(buffer, resultSet
1453:                            .getColumn(number));
1454:                    buffer.append("\n");
1455:                    buffer.append("Expected column data:\n");
1456:                    StringUtil.appendObjectsAsString(buffer, columnData);
1457:                    throw new VerifyFailedException(
1458:                            "Mismatch in column data.\n" + buffer.toString());
1459:                }
1460:            }
1461:
1462:            /**
1463:             * Verifies that a column of a <code>ResultSet</code> is equal to the
1464:             * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(int, List)}.
1465:             * You can verify the data of returned <code>ResultSet</code> objects if
1466:             * the tested JDBC code makes updates.
1467:             * @param resultSet the <code>ResultSet</code>
1468:             * @param number the number of the column
1469:             * @param columnData the column data
1470:             * @throws VerifyFailedException if verification fails
1471:             */
1472:            public void verifyResultSetColumn(MockResultSet resultSet,
1473:                    int number, Object[] columnData) {
1474:                List dataList = Arrays.asList(columnData);
1475:                verifyResultSetColumn(resultSet, number, dataList);
1476:            }
1477:
1478:            /**
1479:             * Verifies that a column of a <code>ResultSet</code> is equal to the
1480:             * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(int, List)}.
1481:             * You can verify the data of returned <code>ResultSet</code> objects if
1482:             * the tested JDBC code makes updates.
1483:             * @param id the id of the <code>ResultSet</code>
1484:             * @param number the number of the column
1485:             * @param columnData the column data
1486:             * @throws VerifyFailedException if verification fails
1487:             */
1488:            public void verifyResultSetColumn(String id, int number,
1489:                    List columnData) {
1490:                MockResultSet resultSet = getReturnedResultSet(id);
1491:                if (null == resultSet) {
1492:                    throw new VerifyFailedException("ResultSet with id " + id
1493:                            + " not present.");
1494:                }
1495:                verifyResultSetColumn(resultSet, number, columnData);
1496:            }
1497:
1498:            /**
1499:             * Verifies that a column of a <code>ResultSet</code> is equal to the
1500:             * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(int, List)}.
1501:             * You can verify the data of returned <code>ResultSet</code> objects if
1502:             * the tested JDBC code makes updates.
1503:             * @param id the id of the <code>ResultSet</code>
1504:             * @param number the number of the column
1505:             * @param columnData the column data
1506:             * @throws VerifyFailedException if verification fails
1507:             */
1508:            public void verifyResultSetColumn(String id, int number,
1509:                    Object[] columnData) {
1510:                List dataList = Arrays.asList(columnData);
1511:                verifyResultSetColumn(id, number, dataList);
1512:            }
1513:
1514:            /**
1515:             * Verifies that a column of a <code>ResultSet</code> is equal to the
1516:             * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(String, List)}.
1517:             * You can verify the data of returned <code>ResultSet</code> objects if
1518:             * the tested JDBC code makes updates.
1519:             * @param resultSet the <code>ResultSet</code>
1520:             * @param name the name of the column
1521:             * @param columnData the column data
1522:             * @throws VerifyFailedException if verification fails
1523:             */
1524:            public void verifyResultSetColumn(MockResultSet resultSet,
1525:                    String name, List columnData) {
1526:                if (null == resultSet.getColumn(name)) {
1527:                    throw new VerifyFailedException("ResultSet "
1528:                            + resultSet.getId() + " has no column " + name);
1529:                }
1530:                if (!resultSet.isColumnEqual(name, columnData)) {
1531:                    StringBuffer buffer = new StringBuffer(
1532:                            "Actual column data:\n");
1533:                    StringUtil.appendObjectsAsString(buffer, resultSet
1534:                            .getColumn(name));
1535:                    buffer.append("\n");
1536:                    buffer.append("Expected column data:\n");
1537:                    StringUtil.appendObjectsAsString(buffer, columnData);
1538:                    throw new VerifyFailedException(
1539:                            "Mismatch in column data.\n" + buffer.toString());
1540:                }
1541:            }
1542:
1543:            /**
1544:             * Verifies that a column of a <code>ResultSet</code> is equal to the
1545:             * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(String, List)}.
1546:             * You can verify the data of returned <code>ResultSet</code> objects if
1547:             * the tested JDBC code makes updates.
1548:             * @param resultSet the <code>ResultSet</code>
1549:             * @param name the name of the column
1550:             * @param columnData the column data
1551:             * @throws VerifyFailedException if verification fails
1552:             */
1553:            public void verifyResultSetColumn(MockResultSet resultSet,
1554:                    String name, Object[] columnData) {
1555:                List dataList = Arrays.asList(columnData);
1556:                verifyResultSetColumn(resultSet, name, dataList);
1557:            }
1558:
1559:            /**
1560:             * Verifies that a column of a <code>ResultSet</code> is equal to the
1561:             * entries in the specified <code>List</code>. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(String, List)}.
1562:             * You can verify the data of returned <code>ResultSet</code> objects if
1563:             * the tested JDBC code makes updates.
1564:             * @param id the id of the <code>ResultSet</code>
1565:             * @param name the name of the column
1566:             * @param columnData the column data
1567:             * @throws VerifyFailedException if verification fails
1568:             */
1569:            public void verifyResultSetColumn(String id, String name,
1570:                    List columnData) {
1571:                MockResultSet resultSet = getReturnedResultSet(id);
1572:                if (null == resultSet) {
1573:                    throw new VerifyFailedException("ResultSet with id " + id
1574:                            + " not present.");
1575:                }
1576:                verifyResultSetColumn(resultSet, name, columnData);
1577:            }
1578:
1579:            /**
1580:             * Verifies that a column of a <code>ResultSet</code> is equal to the
1581:             * entries in the specified array. Uses {@link com.mockrunner.mock.jdbc.MockResultSet#isColumnEqual(String, List)}.
1582:             * You can verify the data of returned <code>ResultSet</code> objects if
1583:             * the tested JDBC code makes updates.
1584:             * @param id the id of the <code>ResultSet</code>
1585:             * @param name the name of the column
1586:             * @param columnData the column data
1587:             * @throws VerifyFailedException if verification fails
1588:             */
1589:            public void verifyResultSetColumn(String id, String name,
1590:                    Object[] columnData) {
1591:                List dataList = Arrays.asList(columnData);
1592:                verifyResultSetColumn(id, name, dataList);
1593:            }
1594:
1595:            /**
1596:             * Verifies that a <code>ResultSet</code> is equal to another one.
1597:             * Compares all the rows with {@link com.mockrunner.mock.jdbc.MockResultSet#isEqual}.
1598:             * @param source the source <code>ResultSet</code>
1599:             * @param target the target <code>ResultSet</code>
1600:             * @throws VerifyFailedException if verification fails
1601:             */
1602:            public void verifyResultSetEquals(MockResultSet source,
1603:                    MockResultSet target) {
1604:                if (!source.isEqual(target)) {
1605:                    StringBuffer buffer = new StringBuffer("Source data:\n");
1606:                    buffer.append(source.toString());
1607:                    buffer.append("\n");
1608:                    buffer.append("Target data:\n");
1609:                    buffer.append(target.toString());
1610:                    throw new VerifyFailedException(
1611:                            "Mismatch in ResultSet data.\n" + buffer.toString());
1612:                }
1613:            }
1614:
1615:            /**
1616:             * Verifies that a <code>ResultSet</code> is equal to another one.
1617:             * Compares all the rows with {@link com.mockrunner.jdbc.ParameterUtil#compareParameter}.
1618:             * @param id the id of the source <code>ResultSet</code>
1619:             * @param target the target <code>ResultSet</code>
1620:             * @throws VerifyFailedException if verification fails
1621:             */
1622:            public void verifyResultSetEquals(String id, MockResultSet target) {
1623:                MockResultSet resultSet = getReturnedResultSet(id);
1624:                if (null == resultSet) {
1625:                    throw new VerifyFailedException("ResultSet with id " + id
1626:                            + " not present.");
1627:                }
1628:                verifyResultSetEquals(resultSet, target);
1629:            }
1630:
1631:            /**
1632:             * Verifies that a <code>PreparedStatement</code> with the specified 
1633:             * SQL statement is present.
1634:             * @param sql the SQL statement
1635:             * @throws VerifyFailedException if verification fails
1636:             */
1637:            public void verifyPreparedStatementPresent(String sql) {
1638:                if (null == getPreparedStatement(sql)) {
1639:                    throw new VerifyFailedException(
1640:                            "Prepared statement with SQL " + sql + " present.");
1641:                }
1642:            }
1643:
1644:            /**
1645:             * Verifies that a <code>PreparedStatement</code> with the specified 
1646:             * SQL statement is not present.
1647:             * @param sql the SQL statement
1648:             * @throws VerifyFailedException if verification fails
1649:             */
1650:            public void verifyPreparedStatementNotPresent(String sql) {
1651:                if (null != getPreparedStatement(sql)) {
1652:                    throw new VerifyFailedException(
1653:                            "Prepared statement with SQL " + sql
1654:                                    + " not present.");
1655:                }
1656:            }
1657:
1658:            /**
1659:             * Verifies that a <code>CallableStatement</code> with the specified 
1660:             * SQL statement is present.
1661:             * @param sql the SQL statement
1662:             * @throws VerifyFailedException if verification fails
1663:             */
1664:            public void verifyCallableStatementPresent(String sql) {
1665:                if (null == getCallableStatement(sql)) {
1666:                    throw new VerifyFailedException(
1667:                            "Callable statement with SQL " + sql + " present.");
1668:                }
1669:            }
1670:
1671:            /**
1672:             * Verifies that a <code>CallableStatement</code> with the specified 
1673:             * SQL statement is not present.
1674:             * @param sql the SQL statement
1675:             * @throws VerifyFailedException if verification fails
1676:             */
1677:            public void verifyCallableStatementNotPresent(String sql) {
1678:                if (null != getCallableStatement(sql)) {
1679:                    throw new VerifyFailedException(
1680:                            "Callable statement with SQL " + sql
1681:                                    + " not present.");
1682:                }
1683:            }
1684:
1685:            /**
1686:             * Verifies that a parameter was added to a <code>PreparedStatement</code> with
1687:             * the specified index.
1688:             * @param statement the <code>PreparedStatement</code>
1689:             * @param indexOfParameter the index used to set the object
1690:             * @throws VerifyFailedException if verification fails
1691:             */
1692:            public void verifyPreparedStatementParameterPresent(
1693:                    PreparedStatement statement, int indexOfParameter) {
1694:                if (!containsPreparedStatementParameter(statement,
1695:                        indexOfParameter)) {
1696:                    throw new VerifyFailedException(
1697:                            "Prepared statement parameter with index "
1698:                                    + indexOfParameter + " not present.");
1699:                }
1700:            }
1701:
1702:            /**
1703:             * Verifies that a parameter was added to a <code>PreparedStatement</code> with
1704:             * the specified index. Uses the first <code>PreparedStatement</code> with
1705:             * the specified SQL.
1706:             * @param sql the SQL statement of the <code>PreparedStatement</code>
1707:             * @param indexOfParameter the index used to set the object
1708:             * @throws VerifyFailedException if verification fails
1709:             */
1710:            public void verifyPreparedStatementParameterPresent(String sql,
1711:                    int indexOfParameter) {
1712:                if (!containsPreparedStatementParameter(sql, indexOfParameter)) {
1713:                    throw new VerifyFailedException(
1714:                            "Prepared statement parameter with index "
1715:                                    + indexOfParameter + " not present.");
1716:                }
1717:            }
1718:
1719:            /**
1720:             * Verifies that a parameter was added to a <code>PreparedStatement</code> with
1721:             * the specified index.
1722:             * @param indexOfStatement the index of the statement
1723:             * @param indexOfParameter the index used to set the object
1724:             * @throws VerifyFailedException if verification fails
1725:             */
1726:            public void verifyPreparedStatementParameterPresent(
1727:                    int indexOfStatement, int indexOfParameter) {
1728:                if (!containsPreparedStatementParameter(indexOfStatement,
1729:                        indexOfParameter)) {
1730:                    throw new VerifyFailedException(
1731:                            "Prepared statement parameter with index "
1732:                                    + indexOfParameter + " not present.");
1733:                }
1734:            }
1735:
1736:            /**
1737:             * Verifies that a parameter with the specified index is not present.
1738:             * @param statement the <code>PreparedStatement</code>
1739:             * @param indexOfParameter the index used to set the object
1740:             * @throws VerifyFailedException if verification fails
1741:             */
1742:            public void verifyPreparedStatementParameterNotPresent(
1743:                    PreparedStatement statement, int indexOfParameter) {
1744:                if (containsPreparedStatementParameter(statement,
1745:                        indexOfParameter)) {
1746:                    throw new VerifyFailedException(
1747:                            "Prepared statement parameter with index "
1748:                                    + indexOfParameter + " present.");
1749:                }
1750:            }
1751:
1752:            /**
1753:             * Verifies that a parameter with the specified index is not present.
1754:             * Uses the first <code>PreparedStatement</code> with the specified SQL.
1755:             * @param sql the SQL statement of the <code>PreparedStatement</code>
1756:             * @param indexOfParameter the index used to set the object
1757:             * @throws VerifyFailedException if verification fails
1758:             */
1759:            public void verifyPreparedStatementParameterNotPresent(String sql,
1760:                    int indexOfParameter) {
1761:                if (containsPreparedStatementParameter(sql, indexOfParameter)) {
1762:                    throw new VerifyFailedException(
1763:                            "Prepared statement parameter with index "
1764:                                    + indexOfParameter + " present.");
1765:                }
1766:            }
1767:
1768:            /**
1769:             * Verifies that a parameter with the specified index is not present.
1770:             * @param indexOfStatement the index of the statement
1771:             * @param indexOfParameter the index used to set the object
1772:             * @throws VerifyFailedException if verification fails
1773:             */
1774:            public void verifyPreparedStatementParameterNotPresent(
1775:                    int indexOfStatement, int indexOfParameter) {
1776:                if (containsPreparedStatementParameter(indexOfStatement,
1777:                        indexOfParameter)) {
1778:                    throw new VerifyFailedException(
1779:                            "Prepared statement parameter with index "
1780:                                    + indexOfParameter + " present.");
1781:                }
1782:            }
1783:
1784:            private boolean containsPreparedStatementParameter(
1785:                    int indexOfStatement, int indexOfParameter) {
1786:                MockPreparedStatement statement = getPreparedStatement(indexOfStatement);
1787:                if (null == statement)
1788:                    return false;
1789:                return containsPreparedStatementParameter(statement,
1790:                        indexOfParameter);
1791:            }
1792:
1793:            private boolean containsPreparedStatementParameter(String sql,
1794:                    int indexOfParameter) {
1795:                MockPreparedStatement statement = getPreparedStatement(sql);
1796:                if (null == statement)
1797:                    return false;
1798:                return containsPreparedStatementParameter(statement,
1799:                        indexOfParameter);
1800:            }
1801:
1802:            private boolean containsPreparedStatementParameter(
1803:                    PreparedStatement statement, int indexOfParameter) {
1804:                return ((MockPreparedStatement) statement).getParameterMap()
1805:                        .containsKey(new Integer(indexOfParameter));
1806:            }
1807:
1808:            /**
1809:             * Verifies that a parameter was added to a <code>CallableStatement</code> with
1810:             * the specified index.
1811:             * @param statement the <code>CallableStatement</code>
1812:             * @param indexOfParameter the index used to set the object
1813:             * @throws VerifyFailedException if verification fails
1814:             */
1815:            public void verifyCallableStatementParameterPresent(
1816:                    CallableStatement statement, int indexOfParameter) {
1817:                if (!containsCallableStatementParameter(statement,
1818:                        indexOfParameter)) {
1819:                    throw new VerifyFailedException(
1820:                            "Callable statement parameter with index "
1821:                                    + indexOfParameter + " not present.");
1822:                }
1823:            }
1824:
1825:            /**
1826:             * Verifies that a parameter was added to a <code>CallableStatement</code> with
1827:             * the specified index. Uses the first <code>CallableStatement</code> with
1828:             * the specified SQL.
1829:             * @param sql the SQL statement of the <code>CallableStatement</code>
1830:             * @param indexOfParameter the index used to set the object
1831:             * @throws VerifyFailedException if verification fails
1832:             */
1833:            public void verifyCallableStatementParameterPresent(String sql,
1834:                    int indexOfParameter) {
1835:                if (!containsCallableStatementParameter(sql, indexOfParameter)) {
1836:                    throw new VerifyFailedException(
1837:                            "Callable statement parameter with index "
1838:                                    + indexOfParameter + " not present.");
1839:                }
1840:            }
1841:
1842:            /**
1843:             * Verifies that a parameter was added to a <code>CallableStatement</code> with
1844:             * the specified index.
1845:             * @param indexOfStatement the index of the statement
1846:             * @param indexOfParameter the index used to set the object
1847:             * @throws VerifyFailedException if verification fails
1848:             */
1849:            public void verifyCallableStatementParameterPresent(
1850:                    int indexOfStatement, int indexOfParameter) {
1851:                if (!containsCallableStatementParameter(indexOfStatement,
1852:                        indexOfParameter)) {
1853:                    throw new VerifyFailedException(
1854:                            "Callable statement parameter with index "
1855:                                    + indexOfParameter + " not present.");
1856:                }
1857:            }
1858:
1859:            /**
1860:             * Verifies that a parameter with the specified index is not present.
1861:             * @param statement the <code>CallableStatement</code>
1862:             * @param indexOfParameter the index used to set the object
1863:             * @throws VerifyFailedException if verification fails
1864:             */
1865:            public void verifyCallableStatementParameterNotPresent(
1866:                    CallableStatement statement, int indexOfParameter) {
1867:                if (containsCallableStatementParameter(statement,
1868:                        indexOfParameter)) {
1869:                    throw new VerifyFailedException(
1870:                            "Callable statement parameter with index "
1871:                                    + indexOfParameter + " present.");
1872:                }
1873:            }
1874:
1875:            /**
1876:             * Verifies that a parameter with the specified index is not present.
1877:             * Uses the first <code>CallableStatement</code> with the specified SQL.
1878:             * @param sql the SQL statement of the <code>CallableStatement</code>
1879:             * @param indexOfParameter the index used to set the object
1880:             * @throws VerifyFailedException if verification fails
1881:             */
1882:            public void verifyCallableStatementParameterNotPresent(String sql,
1883:                    int indexOfParameter) {
1884:                if (containsCallableStatementParameter(sql, indexOfParameter)) {
1885:                    throw new VerifyFailedException(
1886:                            "Callable statement parameter with index "
1887:                                    + indexOfParameter + " present.");
1888:                }
1889:            }
1890:
1891:            /**
1892:             * Verifies that a parameter with the specified index is not present.
1893:             * @param indexOfStatement the index of the statement
1894:             * @param indexOfParameter the index used to set the object
1895:             * @throws VerifyFailedException if verification fails
1896:             */
1897:            public void verifyCallableStatementParameterNotPresent(
1898:                    int indexOfStatement, int indexOfParameter) {
1899:                if (containsCallableStatementParameter(indexOfStatement,
1900:                        indexOfParameter)) {
1901:                    throw new VerifyFailedException(
1902:                            "Callable statement parameter with index "
1903:                                    + indexOfParameter + " present.");
1904:                }
1905:            }
1906:
1907:            /**
1908:             * Verifies that a parameter was added to a <code>CallableStatement</code> with
1909:             * the specified index.
1910:             * @param statement the <code>CallableStatement</code>
1911:             * @param nameOfParameter the name of the parameter
1912:             * @throws VerifyFailedException if verification fails
1913:             */
1914:            public void verifyCallableStatementParameterPresent(
1915:                    CallableStatement statement, String nameOfParameter) {
1916:                if (!containsCallableStatementParameter(statement,
1917:                        nameOfParameter)) {
1918:                    throw new VerifyFailedException(
1919:                            "Callable statement parameter with index "
1920:                                    + nameOfParameter + " not present.");
1921:                }
1922:            }
1923:
1924:            /**
1925:             * Verifies that a parameter was added to a <code>CallableStatement</code> with
1926:             * the specified index. Uses the first <code>CallableStatement</code> with
1927:             * the specified SQL.
1928:             * @param sql the SQL statement of the <code>CallableStatement</code>
1929:             * @param nameOfParameter the name of the parameter
1930:             * @throws VerifyFailedException if verification fails
1931:             */
1932:            public void verifyCallableStatementParameterPresent(String sql,
1933:                    String nameOfParameter) {
1934:                if (!containsCallableStatementParameter(sql, nameOfParameter)) {
1935:                    throw new VerifyFailedException(
1936:                            "Callable statement parameter with index "
1937:                                    + nameOfParameter + " not present.");
1938:                }
1939:            }
1940:
1941:            /**
1942:             * Verifies that a parameter was added to a <code>CallableStatement</code> with
1943:             * the specified index.
1944:             * @param indexOfStatement the index of the statement
1945:             * @param nameOfParameter the name of the parameter
1946:             * @throws VerifyFailedException if verification fails
1947:             */
1948:            public void verifyCallableStatementParameterPresent(
1949:                    int indexOfStatement, String nameOfParameter) {
1950:                if (!containsCallableStatementParameter(indexOfStatement,
1951:                        nameOfParameter)) {
1952:                    throw new VerifyFailedException(
1953:                            "Callable statement parameter with index "
1954:                                    + nameOfParameter + " not present.");
1955:                }
1956:            }
1957:
1958:            /**
1959:             * Verifies that a parameter with the specified index is not present.
1960:             * @param statement the <code>CallableStatement</code>
1961:             * @param nameOfParameter the name of the parameter
1962:             * @throws VerifyFailedException if verification fails
1963:             */
1964:            public void verifyCallableStatementParameterNotPresent(
1965:                    CallableStatement statement, String nameOfParameter) {
1966:                if (containsCallableStatementParameter(statement,
1967:                        nameOfParameter)) {
1968:                    throw new VerifyFailedException(
1969:                            "Callable statement parameter with index "
1970:                                    + nameOfParameter + " present.");
1971:                }
1972:            }
1973:
1974:            /**
1975:             * Verifies that a parameter with the specified index is not present.
1976:             * Uses the first <code>CallableStatement</code> with the specified SQL.
1977:             * @param sql the SQL statement of the <code>CallableStatement</code>
1978:             * @param nameOfParameter the name of the parameter
1979:             * @throws VerifyFailedException if verification fails
1980:             */
1981:            public void verifyCallableStatementParameterNotPresent(String sql,
1982:                    String nameOfParameter) {
1983:                if (containsCallableStatementParameter(sql, nameOfParameter)) {
1984:                    throw new VerifyFailedException(
1985:                            "Callable statement parameter with index "
1986:                                    + nameOfParameter + " present.");
1987:                }
1988:            }
1989:
1990:            /**
1991:             * Verifies that a parameter with the specified index is not present.
1992:             * @param indexOfStatement the index of the statement
1993:             * @param nameOfParameter the name of the parameter
1994:             * @throws VerifyFailedException if verification fails
1995:             */
1996:            public void verifyCallableStatementParameterNotPresent(
1997:                    int indexOfStatement, String nameOfParameter) {
1998:                if (containsCallableStatementParameter(indexOfStatement,
1999:                        nameOfParameter)) {
2000:                    throw new VerifyFailedException(
2001:                            "Callable statement parameter with index "
2002:                                    + nameOfParameter + " present.");
2003:                }
2004:            }
2005:
2006:            private boolean containsCallableStatementParameter(
2007:                    int indexOfStatement, int indexOfParameter) {
2008:                MockCallableStatement statement = getCallableStatement(indexOfStatement);
2009:                if (null == statement)
2010:                    return false;
2011:                return containsCallableStatementParameter(statement,
2012:                        indexOfParameter);
2013:            }
2014:
2015:            private boolean containsCallableStatementParameter(String sql,
2016:                    int indexOfParameter) {
2017:                MockCallableStatement statement = getCallableStatement(sql);
2018:                if (null == statement)
2019:                    return false;
2020:                return containsCallableStatementParameter(statement,
2021:                        indexOfParameter);
2022:            }
2023:
2024:            private boolean containsCallableStatementParameter(
2025:                    CallableStatement statement, int indexOfParameter) {
2026:                return ((MockCallableStatement) statement).getParameterMap()
2027:                        .containsKey(new Integer(indexOfParameter));
2028:            }
2029:
2030:            private boolean containsCallableStatementParameter(
2031:                    int indexOfStatement, String nameOfParameter) {
2032:                MockCallableStatement statement = getCallableStatement(indexOfStatement);
2033:                if (null == statement)
2034:                    return false;
2035:                return containsCallableStatementParameter(statement,
2036:                        nameOfParameter);
2037:            }
2038:
2039:            private boolean containsCallableStatementParameter(String sql,
2040:                    String nameOfParameter) {
2041:                MockCallableStatement statement = getCallableStatement(sql);
2042:                if (null == statement)
2043:                    return false;
2044:                return containsCallableStatementParameter(statement,
2045:                        nameOfParameter);
2046:            }
2047:
2048:            private boolean containsCallableStatementParameter(
2049:                    CallableStatement statement, String nameOfParameter) {
2050:                return ((MockCallableStatement) statement).getParameterMap()
2051:                        .containsKey(nameOfParameter);
2052:            }
2053:
2054:            /**
2055:             * Verifies that a parameter from the specified <code>PreparedStatement</code> is equal
2056:             * to the specified object. Please use the corresponding wrapper type for
2057:             * primitive data types.
2058:             * @param statement the <code>PreparedStatement</code>
2059:             * @param indexOfParameter the index used to set the object
2060:             * @param object the expected object
2061:             * @throws VerifyFailedException if verification fails
2062:             */
2063:            public void verifyPreparedStatementParameter(
2064:                    PreparedStatement statement, int indexOfParameter,
2065:                    Object object) {
2066:                verifyPreparedStatementParameterPresent(statement,
2067:                        indexOfParameter);
2068:                Object actualObject = getPreparedStatementParameter(statement,
2069:                        indexOfParameter);
2070:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2071:                    throw new VerifyFailedException(
2072:                            "Prepared statement parameter with index "
2073:                                    + indexOfParameter + " has the value "
2074:                                    + actualObject.toString() + ", expected "
2075:                                    + object.toString());
2076:                }
2077:            }
2078:
2079:            /**
2080:             * Verifies that a parameter from the <code>PreparedStatement</code> with the
2081:             * specified SQL statement is equal to the specified object.
2082:             * Uses the first <code>PreparedStatement</code> with the specified SQL.
2083:             * Please use the corresponding wrapper type for primitive data types.
2084:             * @param sql the SQL statement of the <code>PreparedStatement</code>
2085:             * @param indexOfParameter the index used to set the object
2086:             * @param object the expected object
2087:             * @throws VerifyFailedException if verification fails
2088:             */
2089:            public void verifyPreparedStatementParameter(String sql,
2090:                    int indexOfParameter, Object object) {
2091:                verifyPreparedStatementParameterPresent(sql, indexOfParameter);
2092:                Object actualObject = getPreparedStatementParameter(sql,
2093:                        indexOfParameter);
2094:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2095:                    throw new VerifyFailedException(
2096:                            "Prepared statement parameter with index "
2097:                                    + indexOfParameter + " has the value "
2098:                                    + actualObject.toString() + ", expected "
2099:                                    + object.toString());
2100:                }
2101:            }
2102:
2103:            /**
2104:             * Verifies that a parameter from the <code>PreparedStatement</code> with the
2105:             * specified SQL statement is equal to the specified object.
2106:             * Please use the corresponding wrapper type for primitive data types.
2107:             * @param indexOfStatement the index of the statement
2108:             * @param indexOfParameter the index used to set the object
2109:             * @param object the expected object
2110:             * @throws VerifyFailedException if verification fails
2111:             */
2112:            public void verifyPreparedStatementParameter(int indexOfStatement,
2113:                    int indexOfParameter, Object object) {
2114:                verifyPreparedStatementParameterPresent(indexOfStatement,
2115:                        indexOfParameter);
2116:                Object actualObject = getPreparedStatementParameter(
2117:                        indexOfStatement, indexOfParameter);
2118:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2119:                    throw new VerifyFailedException(
2120:                            "Prepared statement parameter with index "
2121:                                    + indexOfParameter + " has the value "
2122:                                    + actualObject.toString() + ", expected "
2123:                                    + object.toString());
2124:                }
2125:            }
2126:
2127:            /**
2128:             * Verifies that a parameter from the specified <code>CallableStatement</code> is equal
2129:             * to the specified object. Please use the corresponding wrapper type 
2130:             * for primitive data types.
2131:             * @param statement the <code>CallableStatement</code>
2132:             * @param indexOfParameter the index used to set the object
2133:             * @param object the expected object
2134:             * @throws VerifyFailedException if verification fails
2135:             */
2136:            public void verifyCallableStatementParameter(
2137:                    CallableStatement statement, int indexOfParameter,
2138:                    Object object) {
2139:                verifyCallableStatementParameterPresent(statement,
2140:                        indexOfParameter);
2141:                Object actualObject = getCallableStatementParameter(statement,
2142:                        indexOfParameter);
2143:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2144:                    throw new VerifyFailedException(
2145:                            "Callable statement parameter with index "
2146:                                    + indexOfParameter + " has the value "
2147:                                    + actualObject.toString() + ", expected "
2148:                                    + object.toString());
2149:                }
2150:            }
2151:
2152:            /**
2153:             * Verifies that a parameter from the <code>CallableStatement</code> with the
2154:             * specified SQL statement is equal to the specified object.
2155:             * Uses the first <code>CallableStatement</code> with the specified SQL.
2156:             * Please use the corresponding wrapper type for primitive data types.
2157:             * @param sql the SQL statement of the <code>CallableStatement</code>
2158:             * @param indexOfParameter the index used to set the object
2159:             * @param object the expected object
2160:             * @throws VerifyFailedException if verification fails
2161:             */
2162:            public void verifyCallableStatementParameter(String sql,
2163:                    int indexOfParameter, Object object) {
2164:                verifyCallableStatementParameterPresent(sql, indexOfParameter);
2165:                Object actualObject = getCallableStatementParameter(sql,
2166:                        indexOfParameter);
2167:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2168:                    throw new VerifyFailedException(
2169:                            "Callable statement parameter with index "
2170:                                    + indexOfParameter + " has the value "
2171:                                    + actualObject.toString() + ", expected "
2172:                                    + object.toString());
2173:                }
2174:            }
2175:
2176:            /**
2177:             * Verifies that a parameter from the <code>CallableStatement</code> with the
2178:             * specified SQL statement is equal to the specified object.
2179:             * Please use the corresponding wrapper type for primitive data types.
2180:             * @param indexOfStatement the index of the statement
2181:             * @param indexOfParameter the index used to set the object
2182:             * @param object the expected object
2183:             * @throws VerifyFailedException if verification fails
2184:             */
2185:            public void verifyCallableStatementParameter(int indexOfStatement,
2186:                    int indexOfParameter, Object object) {
2187:                verifyCallableStatementParameterPresent(indexOfStatement,
2188:                        indexOfParameter);
2189:                Object actualObject = getCallableStatementParameter(
2190:                        indexOfStatement, indexOfParameter);
2191:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2192:                    throw new VerifyFailedException(
2193:                            "Callable statement parameter with index "
2194:                                    + indexOfParameter + " has the value "
2195:                                    + actualObject.toString() + ", expected "
2196:                                    + object.toString());
2197:                }
2198:            }
2199:
2200:            /**
2201:             * Verifies that a parameter from the specified <code>CallableStatement</code> is equal
2202:             * to the specified object. Please use the corresponding wrapper type 
2203:             * for primitive data types.
2204:             * @param statement the <code>CallableStatement</code>
2205:             * @param nameOfParameter the name of the parameter
2206:             * @param object the expected object
2207:             * @throws VerifyFailedException if verification fails
2208:             */
2209:            public void verifyCallableStatementParameter(
2210:                    CallableStatement statement, String nameOfParameter,
2211:                    Object object) {
2212:                verifyCallableStatementParameterPresent(statement,
2213:                        nameOfParameter);
2214:                Object actualObject = getCallableStatementParameter(statement,
2215:                        nameOfParameter);
2216:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2217:                    throw new VerifyFailedException(
2218:                            "Callable statement parameter with name "
2219:                                    + nameOfParameter + " has the value "
2220:                                    + actualObject.toString() + ", expected "
2221:                                    + object.toString());
2222:                }
2223:            }
2224:
2225:            /**
2226:             * Verifies that a parameter from the <code>CallableStatement</code> with the
2227:             * specified SQL statement is equal to the specified object.
2228:             * Uses the first <code>CallableStatement</code> with the specified SQL.
2229:             * Please use the corresponding wrapper type for primitive data types.
2230:             * @param sql the SQL statement of the <code>CallableStatement</code>
2231:             * @param nameOfParameter the name of the parameter
2232:             * @param object the expected object
2233:             * @throws VerifyFailedException if verification fails
2234:             */
2235:            public void verifyCallableStatementParameter(String sql,
2236:                    String nameOfParameter, Object object) {
2237:                verifyCallableStatementParameterPresent(sql, nameOfParameter);
2238:                Object actualObject = getCallableStatementParameter(sql,
2239:                        nameOfParameter);
2240:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2241:                    throw new VerifyFailedException(
2242:                            "Callable statement parameter with name "
2243:                                    + nameOfParameter + " has the value "
2244:                                    + actualObject.toString() + ", expected "
2245:                                    + object.toString());
2246:                }
2247:            }
2248:
2249:            /**
2250:             * Verifies that a parameter from the <code>CallableStatement</code> with the
2251:             * specified SQL statement is equal to the specified object.
2252:             * Please use the corresponding wrapper type for primitive data types.
2253:             * @param indexOfStatement the index of the statement
2254:             * @param nameOfParameter the name of the parameter
2255:             * @param object the expected object
2256:             * @throws VerifyFailedException if verification fails
2257:             */
2258:            public void verifyCallableStatementParameter(int indexOfStatement,
2259:                    String nameOfParameter, Object object) {
2260:                verifyCallableStatementParameterPresent(indexOfStatement,
2261:                        nameOfParameter);
2262:                Object actualObject = getCallableStatementParameter(
2263:                        indexOfStatement, nameOfParameter);
2264:                if (!ParameterUtil.compareParameter(actualObject, object)) {
2265:                    throw new VerifyFailedException(
2266:                            "Callable statement parameter with name "
2267:                                    + nameOfParameter + " has the value "
2268:                                    + actualObject.toString() + ", expected "
2269:                                    + object.toString());
2270:                }
2271:            }
2272:
2273:            /**
2274:             * Verifies that an out parameter was registered on the specified
2275:             * <code>CallableStatement</code>.
2276:             * @param statement the <code>CallableStatement</code>
2277:             * @param indexOfParameter the index of the parameter
2278:             * @throws VerifyFailedException if verification fails
2279:             */
2280:            public void verifyCallableStatementOutParameterRegistered(
2281:                    CallableStatement statement, int indexOfParameter) {
2282:                if (!((MockCallableStatement) statement)
2283:                        .isOutParameterRegistered(indexOfParameter)) {
2284:                    throw new VerifyFailedException("Out parameter with index "
2285:                            + indexOfParameter
2286:                            + " not registered in callable statement ");
2287:                }
2288:            }
2289:
2290:            /**
2291:             * Verifies that an out parameter was registered on the
2292:             * <code>CallableStatement</code> with the specified SQL.
2293:             * @param sql the SQL statement
2294:             * @param indexOfParameter the index of the parameter
2295:             * @throws VerifyFailedException if verification fails
2296:             */
2297:            public void verifyCallableStatementOutParameterRegistered(
2298:                    String sql, int indexOfParameter) {
2299:                MockCallableStatement statement = getCallableStatement(sql);
2300:                if (null == statement) {
2301:                    throw new VerifyFailedException("No callable statement "
2302:                            + sql + " present");
2303:                }
2304:                if (!statement.isOutParameterRegistered(indexOfParameter)) {
2305:                    throw new VerifyFailedException("Out parameter with index "
2306:                            + indexOfParameter
2307:                            + " not registered in callable statement " + sql);
2308:                }
2309:            }
2310:
2311:            /**
2312:             * Verifies that an out parameter was registered on the
2313:             * <code>CallableStatement</code> with the specified index.
2314:             * @param indexOfStatement the index of the <code>CallableStatement</code>
2315:             * @param indexOfParameter the index of the parameter
2316:             * @throws VerifyFailedException if verification fails
2317:             */
2318:            public void verifyCallableStatementOutParameterRegistered(
2319:                    int indexOfStatement, int indexOfParameter) {
2320:                MockCallableStatement statement = getCallableStatement(indexOfStatement);
2321:                if (null == statement) {
2322:                    throw new VerifyFailedException(
2323:                            "No callable statement with index "
2324:                                    + indexOfStatement + " present");
2325:                }
2326:                if (!statement.isOutParameterRegistered(indexOfParameter)) {
2327:                    throw new VerifyFailedException(
2328:                            "Out parameter with index "
2329:                                    + indexOfParameter
2330:                                    + " not registered in callable statement with index "
2331:                                    + indexOfStatement);
2332:                }
2333:            }
2334:
2335:            /**
2336:             * Verifies that an out parameter was registered on the specified
2337:             * <code>CallableStatement</code>.
2338:             * @param statement the <code>CallableStatement</code>
2339:             * @param nameOfParameter the name of the parameter
2340:             * @throws VerifyFailedException if verification fails
2341:             */
2342:            public void verifyCallableStatementOutParameterRegistered(
2343:                    CallableStatement statement, String nameOfParameter) {
2344:                if (!((MockCallableStatement) statement)
2345:                        .isOutParameterRegistered(nameOfParameter)) {
2346:                    throw new VerifyFailedException("Out parameter with name "
2347:                            + nameOfParameter
2348:                            + " not registered in callable statement ");
2349:                }
2350:            }
2351:
2352:            /**
2353:             * Verifies that an out parameter was registered on the
2354:             * <code>CallableStatement</code> with the specified SQL.
2355:             * @param sql the SQL statement
2356:             * @param nameOfParameter the name of the parameter
2357:             * @throws VerifyFailedException if verification fails
2358:             */
2359:            public void verifyCallableStatementOutParameterRegistered(
2360:                    String sql, String nameOfParameter) {
2361:                MockCallableStatement statement = getCallableStatement(sql);
2362:                if (null == statement) {
2363:                    throw new VerifyFailedException("No callable statement "
2364:                            + sql + " present");
2365:                }
2366:                if (!statement.isOutParameterRegistered(nameOfParameter)) {
2367:                    throw new VerifyFailedException("Out parameter with name "
2368:                            + nameOfParameter
2369:                            + " not registered in callable statement " + sql);
2370:                }
2371:            }
2372:
2373:            /**
2374:             * Verifies that an out parameter was registered on the
2375:             * <code>CallableStatement</code> with the specified index.
2376:             * @param indexOfStatement the index of the <code>CallableStatement</code>
2377:             * @param nameOfParameter the name of the parameter
2378:             * @throws VerifyFailedException if verification fails
2379:             */
2380:            public void verifyCallableStatementOutParameterRegistered(
2381:                    int indexOfStatement, String nameOfParameter) {
2382:                MockCallableStatement statement = getCallableStatement(indexOfStatement);
2383:                if (null == statement) {
2384:                    throw new VerifyFailedException(
2385:                            "No callable statement with index "
2386:                                    + indexOfStatement + " present");
2387:                }
2388:                if (!statement.isOutParameterRegistered(nameOfParameter)) {
2389:                    throw new VerifyFailedException(
2390:                            "Out parameter with name "
2391:                                    + nameOfParameter
2392:                                    + " not registered in callable statement with index "
2393:                                    + indexOfStatement);
2394:                }
2395:            }
2396:
2397:            /**
2398:             * Verifies that a <code>Savepoint</code> with the specified index
2399:             * is present. The index is the number of the created <code>Savepoint</code>
2400:             * starting with 0 for the first <code>Savepoint</code>.
2401:             * @param index the index of the <code>Savepoint</code>
2402:             */
2403:            /*public void verifySavepointPresent(int index)
2404:            {
2405:                MockSavepoint savepoint = getSavepoint(index);
2406:                if(null == savepoint)
2407:                {
2408:                    throw new VerifyFailedException("No savepoint with index " + index + " present.");
2409:                }
2410:            }*/
2411:
2412:            /**
2413:             * Verifies that a <code>Savepoint</code> with the specified name
2414:             * is present.
2415:             * @param name the name of the <code>Savepoint</code>
2416:             */
2417:            /*public void verifySavepointPresent(String name)
2418:            {
2419:                MockSavepoint savepoint = getSavepoint(name);
2420:                if(null == savepoint)
2421:                {
2422:                    throw new VerifyFailedException("No savepoint with name " + name + " present.");
2423:                }
2424:            }*/
2425:
2426:            /**
2427:             * Verifies that the <code>Savepoint</code> with the specified index
2428:             * is released. The index is the number of the created <code>Savepoint</code>
2429:             * starting with 0 for the first <code>Savepoint</code>.
2430:             * @param index the index of the <code>Savepoint</code>
2431:             */
2432:            /*public void verifySavepointReleased(int index)
2433:            {
2434:                verifySavepointPresent(index);
2435:                if(!getSavepoint(index).isReleased())
2436:                {
2437:                    throw new VerifyFailedException("Savepoint with index " + index + " not released.");
2438:                }
2439:            }*/
2440:
2441:            /**
2442:             * Verifies that the <code>Savepoint</code> with the specified name
2443:             * is released.
2444:             * @param name the name of the <code>Savepoint</code>
2445:             */
2446:            /*public void verifySavepointReleased(String name)
2447:            {
2448:                verifySavepointPresent(name);
2449:                if(!getSavepoint(name).isReleased())
2450:                {
2451:                    throw new VerifyFailedException("Savepoint with name " + name + " not released.");
2452:                }
2453:            }*/
2454:
2455:            /**
2456:             * Verifies that the <code>Savepoint</code> with the specified index
2457:             * is not released. The index is the number of the created <code>Savepoint</code>
2458:             * starting with 0 for the first <code>Savepoint</code>.
2459:             * @param index the index of the <code>Savepoint</code>
2460:             */
2461:            /*public void verifySavepointNotReleased(int index)
2462:            {
2463:                verifySavepointPresent(index);
2464:                if(getSavepoint(index).isReleased())
2465:                {
2466:                    throw new VerifyFailedException("Savepoint with index " + index + " is released.");
2467:                }
2468:            }*/
2469:
2470:            /**
2471:             * Verifies that the <code>Savepoint</code> with the specified name
2472:             * is not released.
2473:             * @param name the name of the <code>Savepoint</code>
2474:             */
2475:            /*public void verifySavepointNotReleased(String name)
2476:            {
2477:                verifySavepointPresent(name);
2478:                if(getSavepoint(name).isReleased())
2479:                {
2480:                    throw new VerifyFailedException("Savepoint with name " + name + " is released.");
2481:                }
2482:            }*/
2483:
2484:            /**
2485:             * Verifies that the <code>Savepoint</code> with the specified index
2486:             * is rolled back. The index is the number of the created <code>Savepoint</code>
2487:             * starting with 0 for the first <code>Savepoint</code>.
2488:             * @param index the index of the <code>Savepoint</code>
2489:             */
2490:            /*public void verifySavepointRolledBack(int index)
2491:            {
2492:                verifySavepointPresent(index);
2493:                if(!getSavepoint(index).isRolledBack())
2494:                {
2495:                    throw new VerifyFailedException("Savepoint with index " + index + " not rolled back.");
2496:                }
2497:            }*/
2498:
2499:            /**
2500:             * Verifies that the <code>Savepoint</code> with the specified name
2501:             * is rolled back.
2502:             * @param name the name of the <code>Savepoint</code>
2503:             */
2504:            /*public void verifySavepointRolledBack(String name)
2505:            {
2506:                verifySavepointPresent(name);
2507:                if(!getSavepoint(name).isRolledBack())
2508:                {
2509:                    throw new VerifyFailedException("Savepoint with name " + name + " not rolled back.");
2510:                }
2511:            }*/
2512:
2513:            /**
2514:             * Verifies that the <code>Savepoint</code> with the specified index
2515:             * is not rolled back. The index is the number of the created <code>Savepoint</code>
2516:             * starting with 0 for the first <code>Savepoint</code>.
2517:             * @param index the index of the <code>Savepoint</code>
2518:             */
2519:            /*public void verifySavepointNotRolledBack(int index)
2520:            {
2521:                verifySavepointPresent(index);
2522:                if(getSavepoint(index).isRolledBack())
2523:                {
2524:                    throw new VerifyFailedException("Savepoint with index " + index + " is rolled back.");
2525:                }
2526:            }*/
2527:
2528:            /**
2529:             * Verifies that the <code>Savepoint</code> with the specified name
2530:             * is not rolled back.
2531:             * @param name the name of the <code>Savepoint</code>
2532:             */
2533:            /*public void verifySavepointNotRolledBack(String name)
2534:            {
2535:                verifySavepointPresent(name);
2536:                if(getSavepoint(name).isRolledBack())
2537:                {
2538:                    throw new VerifyFailedException("Savepoint with name " + name + " is rolled back.");
2539:                }
2540:            }*/
2541:
2542:            /**
2543:             * @deprecated use {@link #verifySavepointRolledBack(int)}
2544:             */
2545:            /*public void verifySavepointRollbacked(int index)
2546:            {
2547:                verifySavepointRolledBack(index);
2548:            }*/
2549:
2550:            /**
2551:             * @deprecated use {@link #verifySavepointRolledBack(String)}
2552:             */
2553:            /*public void verifySavepointRollbacked(String name)
2554:            {
2555:                verifySavepointRolledBack(name);
2556:            }*/
2557:
2558:            /**
2559:             * @deprecated use {@link #verifySavepointNotRolledBack(int)}
2560:             */
2561:            /*public void verifySavepointNotRollbacked(int index)
2562:            {
2563:                verifySavepointNotRolledBack(index);
2564:            }*/
2565:
2566:            /**
2567:             * @deprecated use {@link #verifySavepointNotRolledBack(String)}
2568:             */
2569:            /*public void verifySavepointNotRollbacked(String name)
2570:            {
2571:                verifySavepointNotRolledBack(name);
2572:            }*/
2573:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.