Announcement Announcement Module
Collapse
No announcement yet.
Extending AbstractTransactionalSpringContextTests for ddsteps Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extending AbstractTransactionalSpringContextTests for ddsteps

    Hello folks,

    I’m trying to use springs’ AbstractTransactionalSpringContextTests related with the ddsteps junit extension (www.ddsteps.org). Finally I want to receive the test data for test cases from excel sheets and encase transaction around the test methods (for automatically rollbacks).

    I’ve following design problem:
    To do this I have to extend the class DDStepsSpringTestCase. This class inherits themselves from AbstractDependencyInjectionSpringContextTests. To use transaction functionally I have to extend the class AbstractTransactionalSpringContextTests too. This is not possible.

    My currently solution extends DDStepsSpringTestCase and delegates calls to setUpMethod and tearDownMethod to a member of the type AbstractTransactionalSpringContextTestsWrapper.

    This type wraps AbstractTransactionalSpringContextTests and enhanced the visibility of the protected final onSetUp and onTearDown methods of the AbstractTransactionalSpringContextTests class:

    public class AbstractTransactionalSpringContextTestsWrapper extends
    AbstractTransactionalSpringContextTests

    public void startTransaction() throws Exception
    {
    this.onSetUp();
    }

    public void finishTransaction() throws Exception
    {
    this.onTearDown();
    }


    The AbstractTransactionalSpringContextTestsWrapper is used as followed:

    public abstract class DDStepsTransactionalSpringContextTests extends DDStepsSpringTestCase implements TransactionalSpringContextTestsCallback
    {
    AbstractTransactionalSpringContextTestsWrapper transactionalContext = new AbstractTransactionalSpringContextTestsWrapper(thi s);


    public final void setUpMethod() throws Exception
    {
    // delegates the setUp to transactionalContext to start the transaction
    transactionalContext.startTransaction();
    }


    Is this the “best” solution or do you have a better idea? Or would you simple copy the functionality of the onSetUp and onTearDown of the AbstractTransactionalSpringContextTests class?
    Would this code duplication be ok?

    Cheers
    Martin
Working...
X