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


001:        package com.mockrunner.example.ejb;
002:
003:        import org.mockejb.TransactionPolicy;
004:
005:        import com.mockrunner.ejb.EJBTestCaseAdapter;
006:        import com.mockrunner.example.ejb.interfaces.PaySession;
007:        import com.mockrunner.jdbc.JDBCTestModule;
008:        import com.mockrunner.jdbc.StatementResultSetHandler;
009:        import com.mockrunner.mock.jdbc.MockResultSet;
010:
011:        /**
012:         * Example test for {@link PaySessionBean}. This example demonstrates
013:         * how to use {@link com.mockrunner.jdbc.JDBCTestModule} and 
014:         * {@link com.mockrunner.ejb.EJBTestModule} in conjunction. 
015:         * The tests are similar to {@link com.mockrunner.example.jdbc.PayActionTest} 
016:         * but instead of an action we test an EJB. This example works with the simulated 
017:         * JDBC environment of Mockrunner.
018:         */
019:        public class PaySessionTest extends EJBTestCaseAdapter {
020:            private JDBCTestModule jdbcModule;
021:            private PaySession bean;
022:            private StatementResultSetHandler statementHandler;
023:
024:            protected void setUp() throws Exception {
025:                super .setUp();
026:                jdbcModule = createJDBCTestModule();
027:                setInterfacePackage("com.mockrunner.example.ejb.interfaces");
028:                deploySessionBean("com/mockrunner/example/PaySession",
029:                        PaySessionBean.class, TransactionPolicy.REQUIRED);
030:                bindToContext("java:comp/env/jdbc/MySQLDB",
031:                        getJDBCMockObjectFactory().getMockDataSource());
032:                bean = (PaySession) createBean("com/mockrunner/example/PaySession");
033:                statementHandler = getJDBCMockObjectFactory()
034:                        .getMockConnection().getStatementResultSetHandler();
035:            }
036:
037:            private void createValidCustomerResult() {
038:                MockResultSet result = statementHandler.createResultSet();
039:                result.addColumn("name", new String[] { "MyName" });
040:                statementHandler.prepareResultSet("select name", result);
041:            }
042:
043:            private void createValidBillResult() {
044:                MockResultSet result = statementHandler.createResultSet();
045:                result.addColumn("id", new String[] { "1" });
046:                result.addColumn("customerid", new String[] { "1" });
047:                result.addColumn("amount", new Double[] { new Double(100) });
048:                statementHandler.prepareResultSet("select * from openbills",
049:                        result);
050:            }
051:
052:            public void testUnknownCustomer() throws Exception {
053:                MockResultSet result = statementHandler.createResultSet();
054:                result.addColumn("name");
055:                statementHandler.prepareResultSet("select name", result);
056:                try {
057:                    bean.payBill("1", "1", 100);
058:                    fail();
059:                } catch (PaySessionException exc) {
060:                    assertEquals(PaySessionException.UNKNOWN_CUSTOMER, exc
061:                            .getCode());
062:                }
063:                verifyMarkedForRollback();
064:                verifyRolledBack();
065:                jdbcModule.verifySQLStatementExecuted("select name");
066:                jdbcModule
067:                        .verifySQLStatementNotExecuted("delete from openbills");
068:                jdbcModule
069:                        .verifySQLStatementNotExecuted("insert into paidbills");
070:                jdbcModule.verifyAllResultSetsClosed();
071:                jdbcModule.verifyAllStatementsClosed();
072:                jdbcModule.verifyConnectionClosed();
073:            }
074:
075:            public void testUnknownBill() throws Exception {
076:                createValidCustomerResult();
077:                MockResultSet result = statementHandler.createResultSet();
078:                result.addColumn("id");
079:                result.addColumn("customerid");
080:                result.addColumn("amount");
081:                statementHandler.prepareResultSet("select * from openbills",
082:                        result);
083:                try {
084:                    bean.payBill("1", "1", 100);
085:                    fail();
086:                } catch (PaySessionException exc) {
087:                    assertEquals(PaySessionException.UNKNOWN_BILL, exc
088:                            .getCode());
089:                }
090:                verifyMarkedForRollback();
091:                verifyRolledBack();
092:                jdbcModule
093:                        .verifySQLStatementExecuted("select * from openbills");
094:                jdbcModule
095:                        .verifySQLStatementNotExecuted("delete from openbills");
096:                jdbcModule
097:                        .verifySQLStatementNotExecuted("insert into paidbills");
098:                jdbcModule.verifyAllResultSetsClosed();
099:                jdbcModule.verifyAllStatementsClosed();
100:                jdbcModule.verifyConnectionClosed();
101:            }
102:
103:            public void testCustomerIdMismatch() throws Exception {
104:                createValidCustomerResult();
105:                createValidBillResult();
106:                try {
107:                    bean.payBill("2", "1", 100);
108:                    fail();
109:                } catch (PaySessionException exc) {
110:                    assertEquals(PaySessionException.WRONG_BILL_FOR_CUSTOMER,
111:                            exc.getCode());
112:                }
113:                verifyMarkedForRollback();
114:                verifyRolledBack();
115:                jdbcModule
116:                        .verifySQLStatementExecuted("select * from openbills");
117:                jdbcModule
118:                        .verifySQLStatementNotExecuted("delete from openbills");
119:                jdbcModule
120:                        .verifySQLStatementNotExecuted("insert into paidbills");
121:                jdbcModule.verifyAllResultSetsClosed();
122:                jdbcModule.verifyAllStatementsClosed();
123:                jdbcModule.verifyConnectionClosed();
124:            }
125:
126:            public void testAmountMismatch() throws Exception {
127:                createValidCustomerResult();
128:                createValidBillResult();
129:                try {
130:                    bean.payBill("1", "1", 200);
131:                    fail();
132:                } catch (PaySessionException exc) {
133:                    assertEquals(PaySessionException.WRONG_AMOUNT_FOR_BILL, exc
134:                            .getCode());
135:                }
136:                verifyMarkedForRollback();
137:                verifyRolledBack();
138:                jdbcModule
139:                        .verifySQLStatementExecuted("select * from openbills");
140:                jdbcModule
141:                        .verifySQLStatementNotExecuted("delete from openbills");
142:                jdbcModule
143:                        .verifySQLStatementNotExecuted("insert into paidbills");
144:                jdbcModule.verifyAllResultSetsClosed();
145:                jdbcModule.verifyAllStatementsClosed();
146:                jdbcModule.verifyConnectionClosed();
147:            }
148:
149:            public void testValidTransaction() throws Exception {
150:                createValidCustomerResult();
151:                createValidBillResult();
152:                bean.payBill("1", "1", 100);
153:                verifyNotMarkedForRollback();
154:                verifyCommitted();
155:                jdbcModule
156:                        .verifySQLStatementExecuted("delete from openbills where id='1'");
157:                jdbcModule
158:                        .verifySQLStatementExecuted("insert into paidbills values('1','1',100.0)");
159:                jdbcModule.verifyAllResultSetsClosed();
160:                jdbcModule.verifyAllStatementsClosed();
161:                jdbcModule.verifyConnectionClosed();
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.