net.sourceforge.sqlunit.test.mock

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 » sqlunit » net.sourceforge.sqlunit.test.mock 
net.sourceforge.sqlunit.test.mock
Mock Testing framework for SQLUnit. Provides a framework to test SQLUnit code without a database. The database independence is achieved by using the MockRunner JDBC framework.

Instead of a real database, the testing framework relies on introspecting a specified class. The class implements the IMockDatabase interface and contains methods with the signature: public MockResultSet methodName(Integer resultSetId); The IMockDatabase interface mandates a getResultSet(String,int) method which returns a MockResultSet. The implementation of this method is provided in the AbstractMockDatabase class. Clients wishing to develop their own mock database classes should extend this class.

Examples of methods that mimic the behavior of stored procedures can be found in the SQLUnitMockDatabase class which extends AbstractMockDatabase. Things to note are:

  1. The count of the number of results (used for the Statement.execute() and CallableStatement.getMoreResults()) is returned in wrapped in result set 0.
  2. Outparam values are generated internally using the negative of the supplied index. Thus, the value of OUTPARAM at position 1 will be wrapped in the resultset that is returned by invoking the appropriate method with -1. Scalar OUTPARAM values are specified as Strings, but are converted to the appropriate Object on retrieval. REF CURSOR OUTPARAM objects are returned as themselves since they are essentially ResultSet objects.
  3. Exceptions are not thrown directly, but they are wrapped in the resultset that is being made to throw the exception.
  4. ResultSets are returned from the method using the supplied index. Thus the first ResultSet will be returned by invoking the method with Integer(1).
The functionality of wrapping and unwrapping scalar and SQLException objects back and forth from MockResultSet objects can be found in the MockResultSetUtils class.

To make this work with the MockRunner framework, the following classes were extended from the MockRunner distribution:

  1. SQLUnitMockConnection extends com.mockrunner.mock.jdbc.MockConnection. The extensions were mainly to call the Introspecting versions of the ResultSetHandler classes instead of MockRunner's ResultSetHandlers.
  2. SQLUnitMockDriver extends com.mockrunner.mock.jdbc.MockDriver. This version provides a URL signature which the mock framework will respond to.
  3. SQLUnitMockStatement extends com.mockrunner.mock.jdbc.MockStatement. Calls the Introspecting version of the ResultSetHandler.
  4. SQLUnitMockPreparedStatement extends com.mockrunner.mock.jdbc.MockPreparedStatement. Calls the Introspecting version of the ResultSetHandler.
  5. SQLUnitMockCallableStatement extends com.mockrunner.mock.jdbc.MockStatement. Calls the Introspecting version of the ResultSetHandler.
  6. IntrospectingStatementResultSetHandler extends com.mockrunner.jdbc.StatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute Statement objects.
  7. IntrospectingPreparedStatementResultSetHandler extends com.mockrunner.jdbc.PreparedStatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute PreparedStatement objects.
  8. IntrospectingCallableStatementResultSetHandler extends com.mockrunner.jdbc.CallableStatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute CallableStatement objects.
  9. IntrospectingResultSetHandler implements the com.mockrunner.jdbc.ResultSetHandler. Implements multi-resultset handling and getting the result sets using Introspection.
A sample test file which uses the SQLUnit mock testing framework can be found at test/mock/test.xml in the distribution.
Java Source File NameTypeComment
AbstractMockDatabase.javaClass Abstract base class from which all IMockDatabase objects must extend.
ColumnMetaData.javaClass Container for Column Metadata information.
IMockDatabase.javaInterface Provides a convenient abstraction of what a mock database should look like for SQLUnit mock testing.
IntrospectingCallableStatementResultSetHandler.javaClass Extends the CallableStatementResultSetHandler to use introspection.
IntrospectingPreparedStatementResultSetHandler.javaClass Extends the PreparedStatementResultSetHandler to use introspection.
IntrospectingResultSetFactory.javaClass Introspects a given IMockDataStore object and invokes the named method to return ResultSet objects.
IntrospectingStatementResultSetHandler.javaClass Extends the StatementResultSetHandler to use introspection.
MockInitialContext.javaClass Overrides the InitialContext to provide an in-memory lookup mechanism instead of network lookup.
MockInitialContextFactory.javaClass Builds a MockInitialContext using an environment Hashtable.
MockResultSetUtils.javaClass Collection of utility methods to manipulate MockResultSets.
SQLUnitMockCallableStatement.javaClass Overrides certain methods in the MockCallableStatement class for mock testing of SQLUnit.
SQLUnitMockConnection.javaClass Represents a Connection object that depends on an underlying IDatabase.
SQLUnitMockDatabase.javaClass Mock database to supply results.
SQLUnitMockDriver.javaClass Implements a Mock JDBC driver for SQLUnit.
SQLUnitMockPreparedStatement.javaClass Overrides certain methods in the MockPreparedStatement class for mock testing of SQLUnit.
SQLUnitMockStatement.javaClass Overrides certain methods in the MockStatement class for mock testing of SQLUnit.
VarSetter.javaClass Simple class whose method is called from the set tag.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.