Save status in @before method, do the @test, then rollback the changes in @after

I was wondering if this is possible. This is my first question so bear with me if I do not exactly follow protocol. I am able to rollback my transactions with a transaction template. But now what I want to do is save a status in the method labeled @before and then roll it back in the @after method.

For example this is what I had before:

      _transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
     protected void doInTransactionWithoutResult(TransactionStatus transactionStatus)
     {

                Object transactionStatusSavepoint = transactionStatus.createSavepoint();
                //do some work
                transactionStatus.rollbackToSavepoint(transactionStatusSavepoint);
      }
     });

This all works well and good. Now I would like to do this:

@Before
    public void beforeTest() {
        _template.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {

                _transactionStatusSavepoint = _transactionStatus.createSavepoint();
            }
        });

@Test
public void foo(){//do some stuff}

@After
    public void afterTest() {
    _transactionStatus.rollbackToSavepoint(_transactionStatusSavepoint);
}

Please let me know if you do not understand or would like to elaborate more. Thanks in advance!

Answers


The transaction status will not be valid once doInTransactionWithoutResult is complete, so you cannot use it in your afterTest method.

It looks like you are using spring for your test. Spring comes with test runner that can rollback a transaction when your tests complete.

Spring testing


Need Your Help

First Jqgrid Load, sorting and filtering slow in IE6. Filtering slow in the rest of Browsers

sorting jqgrid load filtering

I'm facing this situation. I'm having a grid with approximately 3500 rows. And this grid should be cross-browsing, specially in IE6 (which is the Client's browser... unfortunately).

Encrypting and decrypting very long strings with AES 256 C# php

c# php encryption cryptography aes

I got an encrypting function written in PHP which encrypts my data, and a decrypt function in C# which decrypts it and prints on screen(I'm developing a game in Unity engine). So the problem is, if...