01: package com.mockrunner.example.ejb;
02:
03: import org.mockejb.TransactionPolicy;
04:
05: import com.mockrunner.ejb.EJBTestModule;
06: import com.mockrunner.jdbc.JDBCTestModule;
07: import com.mockrunner.struts.ActionTestCaseAdapter;
08:
09: /**
10: * Example test for {@link LogAction}. This example demonstrates
11: * how to use {@link com.mockrunner.struts.ActionTestModule},
12: * {@link com.mockrunner.jdbc.JDBCTestModule} and
13: * {@link com.mockrunner.ejb.EJBTestModule} in conjunction.
14: * This example works with the simulated JDBC environment of Mockrunner.
15: */
16: public class LogActionTest extends ActionTestCaseAdapter {
17: private JDBCTestModule jdbcModule;
18: private EJBTestModule ejbModule;
19:
20: protected void setUp() throws Exception {
21: super .setUp();
22: jdbcModule = createJDBCTestModule();
23: ejbModule = createEJBTestModule();
24: ejbModule
25: .setInterfacePackage("com.mockrunner.example.ejb.interfaces");
26: ejbModule.deploySessionBean(
27: "com/mockrunner/example/LogSession",
28: LogSessionBean.class, TransactionPolicy.REQUIRED);
29: ejbModule.bindToContext("java:comp/env/jdbc/MySQLDB",
30: getJDBCMockObjectFactory().getMockDataSource());
31: }
32:
33: public void testLogActionSuccess() {
34: addRequestParameter("message", "testmessage");
35: actionPerform(LogAction.class);
36: jdbcModule.verifySQLStatementExecuted("insert into logtable");
37: jdbcModule.verifyPreparedStatementParameter(
38: "insert into logtable", 2, "testmessage");
39: ejbModule.verifyNotMarkedForRollback();
40: ejbModule.verifyCommitted();
41: jdbcModule.verifyAllStatementsClosed();
42: jdbcModule.verifyConnectionClosed();
43: verifyNoActionErrors();
44: verifyForward("success");
45: }
46: }
|