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

com.mockrunner.mock.connector.cci.MockLocalTransaction 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.mock.connector.cci;

import javax.resource.ResourceException;
import javax.resource.cci.LocalTransaction;

/**
 * Mock implementation of LocalTransaction.
 */
public class MockLocalTransaction implements LocalTransaction
{
    private boolean beginCalled;
    private boolean commitCalled;
    private boolean rollbackCalled;
    private int beginCalls;
    private int commitCalls;
    private int rollbackCalls;
    
    public MockLocalTransaction()
    {
        reset();
    }
    
    /**
     * Resets the transaction state. Sets the number of overall 
     * begin, commit and rollback calls to 0.
     */
    public void reset()
    {
        beginCalled = false;
        commitCalled = false;
        rollbackCalled = false;
        beginCalls = 0;
        commitCalls = 0;
        rollbackCalls = 0;
    }
    
    /**
     * Starts the transaction. The flags wasCommitCalled 
     * and wasRollbackCalled are reset to false. 
     * This method does not reset the number of overall calls.
     */
    public void begin() throws ResourceException
    {
        beginCalled = true;
        commitCalled = false;
        rollbackCalled = false;
        beginCalls++;
    }

    /**
     * Commits the transaction.
     */
    public void commit() throws ResourceException
    {
        commitCalled = true;
        commitCalls++;
    }

    /**
     * Rolls back the transaction.
     */
    public void rollback() throws ResourceException
    {
        rollbackCalled = true;
        rollbackCalls++;
    }

    /**
     * Returns if {@link #begin} was called.
     * @return was {@link #begin} called
     */
    public boolean wasBeginCalled()
    {
        return beginCalled;
    }
    
    /**
     * Returns if {@link #commit} was called.
     * @return was {@link #commit} called
     */
    public boolean wasCommitCalled()
    {
        return commitCalled;
    }
    
    /**
     * Returns if {@link #rollback} was called.
     * @return was {@link #rollback} called
     */
    public boolean wasRollbackCalled()
    {
        return rollbackCalled;
    }
    
    /**
     * Returns the number of overall {@link #begin} calls.
     * @return the number of overall {@link #begin} calls
     */
    public int getNumberBeginCalls()
    {
        return beginCalls;
    }
    
    /**
     * Returns the number of overall {@link #commit} calls.
     * @return the number of overall {@link #commit} calls
     */
    public int getNumberCommitCalls()
    {
        return commitCalls;
    }
    
    /**
     * Returns the number of overall {@link #rollback} calls.
     * @return the number of overall {@link #rollback} calls
     */
    public int getNumberRollbackCalls()
    {
        return rollbackCalls;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy