Announcement Announcement Module
No announcement yet.
Extending AbstractTransactionalSpringContextTests for ddsteps Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 ( 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

    public void startTransaction() throws Exception

    public void finishTransaction() throws Exception

    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

    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?