01: package com.mockrunner.example.ejb;
02:
03: import com.mockrunner.ejb.EJBTestCaseAdapter;
04: import com.mockrunner.example.ejb.interfaces.DBStateful;
05: import com.mockrunner.jdbc.JDBCTestModule;
06:
07: /**
08: * Example test for {@link DBStatefulBean}. This example demonstrates
09: * how to test stateful beans and how to deal with BMT.
10: */
11: public class DBStatefulTest extends EJBTestCaseAdapter {
12: private JDBCTestModule jdbcModule;
13: private DBStateful bean;
14:
15: protected void setUp() throws Exception {
16: super .setUp();
17: jdbcModule = createJDBCTestModule();
18: setInterfacePackage("com.mockrunner.example.ejb.interfaces");
19: //true = stateful, null = no TransactionPolicy = BMT
20: deploySessionBean("com/mockrunner/example/DBStateful",
21: DBStatefulBean.class, true, null);
22: bindToContext("java:/MySQLDB", getJDBCMockObjectFactory()
23: .getMockDataSource());
24: bean = (DBStateful) createBean("com/mockrunner/example/DBStateful");
25: }
26:
27: public void testCommit() throws Exception {
28: bean.beginTransaction();
29: bean.executeSQL("drop database");
30: bean.endTransaction(true);
31: jdbcModule.verifyAllStatementsClosed();
32: jdbcModule.verifyConnectionClosed();
33: jdbcModule.verifySQLStatementExecuted("drop database");
34: verifyCommitted();
35: verifyNotRolledBack();
36: }
37:
38: public void testRollback() throws Exception {
39: bean.beginTransaction();
40: bean.executeSQL("drop database");
41: bean.endTransaction(false);
42: jdbcModule.verifyAllStatementsClosed();
43: jdbcModule.verifyConnectionClosed();
44: jdbcModule.verifySQLStatementExecuted("drop database");
45: verifyRolledBack();
46: verifyNotCommitted();
47: }
48: }
|