All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mockrunner.example.ejb.DBStatefulTest Maven / Gradle / Ivy

Go to download

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