Source Code Cross Referenced for BookstoreTest.java in  » Testing » mockrunner-0.4 » com » mockrunner » example » 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.example.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.example.jdbc;
002:
003:        import java.util.ArrayList;
004:        import java.util.List;
005:
006:        import com.mockrunner.jdbc.BasicJDBCTestCaseAdapter;
007:        import com.mockrunner.jdbc.FileResultSetFactory;
008:        import com.mockrunner.mock.jdbc.MockResultSet;
009:
010:        /**
011:         * Example test for {@link Bookstore}. Demonstrates the usage of 
012:         * {@link com.mockrunner.jdbc.JDBCTestModule} 
013:         * and {@link com.mockrunner.jdbc.BasicJDBCTestCaseAdapter}.
014:         * This is an example for the handling of {@link com.mockrunner.mock.jdbc.MockResultSet}.
015:         * The data that the JDBC code should receive when executing the <i>select</i>
016:         * statement is specified in the file <i>bookstore.txt</i>. Please note that we
017:         * do not pass a filled <code>List</code> to the order method in the
018:         * succesful order test, because the choice if a table row should
019:         * be in the result is done by SQL. The framework does not execute any
020:         * SQL. In the second test, we check the correct SQL string.
021:         * In the third test, we specify that the statement should raise an
022:         * SQL exception (to simulate a database error) and verify, that
023:         * the transaction is rolled back.
024:         * 
025:         * This example uses regular expressions. Per default, regular expressions
026:         * are disabled, i.e. the preparation of result sets and verification of
027:         * executed SQL statements is based on simple string comparison.
028:         * With<br><br>
029:         * <code>setUseRegularExpressions(true);</code>
030:         * <br><br>and<br><br>
031:         * <code>getStatementResultSetHandler().setUseRegularExpressions(true);</code>
032:         * <br>
033:         * you enable regular expressions for the preparation of result sets and 
034:         * verification of executed SQL statements (note that for prepared and
035:         * callable statements you would have to enable it seperately).
036:         * E.g. <code>prepareResultSet("select.*isbn,.*quantity.*", result)</code>
037:         * means that only the words <i>select</i>, <i>isbn,</i>, and <i>quantity</i>
038:         * must appear in the specified order, all other characters are irrelevant.
039:         * Besides that simple example, you can use any Perl5 compatible expression.
040:         */
041:        public class BookstoreTest extends BasicJDBCTestCaseAdapter {
042:            protected void setUp() throws Exception {
043:                super .setUp();
044:                setUseRegularExpressions(true);
045:                getStatementResultSetHandler().setUseRegularExpressions(true);
046:            }
047:
048:            public void testSuccessfulOrder() throws Exception {
049:                FileResultSetFactory factory = new FileResultSetFactory(
050:                        "src/com/mockrunner/example/jdbc/bookstore.txt");
051:                factory.setFirstLineContainsColumnNames(true);
052:                MockResultSet result = getStatementResultSetHandler()
053:                        .createResultSet("bookresult", factory);
054:                //System.out.println(result.toString());
055:                getStatementResultSetHandler().prepareResultSet(
056:                        "select.*isbn,.*quantity.*", result);
057:                List resultList = Bookstore.order(getJDBCMockObjectFactory()
058:                        .getMockConnection(), new ArrayList());
059:                assertEquals(4, resultList.size());
060:                assertTrue(resultList.contains("1234567890"));
061:                assertTrue(resultList.contains("1111111111"));
062:                assertTrue(resultList.contains("1212121212"));
063:                assertTrue(resultList.contains("3333333333"));
064:                verifyResultSetRow("bookresult", 1, new String[] {
065:                        "1234567890", "0" });
066:                verifyResultSetRow("bookresult", 2, new String[] {
067:                        "1111111111", "4" });
068:                verifyResultSetRow("bookresult", 3, new String[] {
069:                        "0987654321", "0" });
070:                verifyResultSetRow("bookresult", 4, new String[] {
071:                        "1212121212", "2" });
072:                verifyResultSetRow("bookresult", 5, new String[] {
073:                        "3333333333", "0" });
074:                verifyCommitted();
075:                verifyAllResultSetsClosed();
076:                verifyAllStatementsClosed();
077:            }
078:
079:            public void testCorrectSQL() throws Exception {
080:                MockResultSet result = getStatementResultSetHandler()
081:                        .createResultSet();
082:                getStatementResultSetHandler().prepareResultSet(
083:                        "select.*isbn,.*quantity.*", result);
084:                List orderList = new ArrayList();
085:                orderList.add("1234567890");
086:                orderList.add("1111111111");
087:                Bookstore.order(getJDBCMockObjectFactory().getMockConnection(),
088:                        orderList);
089:                verifySQLStatementExecuted("select.*isbn,.*quantity.*\\(isbn='1234567890'.*or.*isbn='1111111111'\\)");
090:            }
091:
092:            public void testException() throws Exception {
093:                getStatementResultSetHandler().prepareThrowsSQLException(
094:                        "select.*isbn,.*quantity.*");
095:                Bookstore.order(getJDBCMockObjectFactory().getMockConnection(),
096:                        new ArrayList());
097:                verifyRolledBack();
098:                verifyAllResultSetsClosed();
099:                verifyAllStatementsClosed();
100:            }
101:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.