![JAR search and dependency download from the Maven repository](/logo.png)
com.mockrunner.example.ejb.DBStatefulTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.example.ejb;
import com.mockrunner.ejb.EJBTestCaseAdapter;
import com.mockrunner.example.ejb.interfaces.DBStateful;
import com.mockrunner.jdbc.JDBCTestModule;
/**
* Example test for {@link DBStatefulBean}. This example demonstrates
* how to test stateful beans and how to deal with BMT.
*/
public class DBStatefulTest extends EJBTestCaseAdapter
{
private JDBCTestModule jdbcModule;
private DBStateful bean;
protected void setUp() throws Exception
{
super.setUp();
jdbcModule = createJDBCTestModule();
setInterfacePackage("com.mockrunner.example.ejb.interfaces");
//true = stateful, null = no TransactionPolicy = BMT
deploySessionBean("com/mockrunner/example/DBStateful", DBStatefulBean.class, true, null);
bindToContext("java:/MySQLDB", getJDBCMockObjectFactory().getMockDataSource());
bean = (DBStateful)createBean("com/mockrunner/example/DBStateful");
}
public void testCommit() throws Exception
{
bean.beginTransaction();
bean.executeSQL("drop database");
bean.endTransaction(true);
jdbcModule.verifyAllStatementsClosed();
jdbcModule.verifyConnectionClosed();
jdbcModule.verifySQLStatementExecuted("drop database");
verifyCommitted();
verifyNotRolledBack();
}
public void testRollback() throws Exception
{
bean.beginTransaction();
bean.executeSQL("drop database");
bean.endTransaction(false);
jdbcModule.verifyAllStatementsClosed();
jdbcModule.verifyConnectionClosed();
jdbcModule.verifySQLStatementExecuted("drop database");
verifyRolledBack();
verifyNotCommitted();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy