title: SqlException during SliM testing a transactional method on spring application
body: <p>When running Fitnesse SliM test a transactional method on spring application, a SQLException thrown - Data Source is Closed.</p>
  
  <p>Here is what happends:
  In my application, method importFile(String filename) reads a csv file and update data to a few tables in database. This is a transactional method of spring application. So that if updating one row of the file throws an exception, all updates of this row rollbacks and all other rows (including previous rows and next rows) keep on updating. </p>
  
  <p>See related link: <a href="https://stackoverflow.com/questions/8295366/how-to-define-rollback-transactions-which-are-called-inside-of-a-loop-with-sprin">How to define rollback transactions which are called inside of a loop with spring aop?</a></p>
  
  <p>The testing step on Query table SliM FitNesse page </p>
  
  <p>1 SetUp page sets up the testing data with a setup file</p>
  
  <pre><code>|Query: Test Case   |   test_file_setup.csv   |
  |     name     |     phone     |     email     |
  |     tom      |     123       |  tom@test.com |
  |     dick     |     456       | dick@test.com |
  |     harry    |     789       |harry@test.com |
  </code></pre>
  
  <p>result: testing passed</p>
  
  <p>2 Test page tests a testing file with a invalid row, so that when it executes this row it only rollbacks this row, but all other rows proceeds, however... the test failed and rollback all rows and closed the data source. </p>
  
  <p>3 So when the tearDown which tries to test with a valid file and clean up the database failed too... thus the data source was closed</p>
  
  <p>This is one SliM test but there is a query table on each SetUp, Test and tearDown page. My guessing is one Fitness test only init one Spring context instance. Tell me if I am wrong. However, this method is declared as a transaction on spring config. It rollbacks as expected, but the test doesn't.</p>
  
  <p>Here is my testing class</p>
  
  <pre><code>public class TestCase{
  
    private ImportFile importFile; 
    private String filename;
  
    public TestCase(String filename){
       this.filename = filename;
       init();
    }
  
    public void init(){
       //initialize the spring context
       //and get beans...
       importFile = (ImportFile) context.getBeans("importFile");
       start();
    }
  
    public void start(){
       //read rows from file...
       for( ... loop per row...){
          //this is a transactional method...
          //it reads the file and update every row to the database
          //it is supposed to row back one row (per loop) 
          //and continue if an exception thrown
          //but it rollback the all rows and close the datasource
          importFile.importFile(filename);
       }
    }
  
    public List&lt;Object&gt; query(){
       //read from database and return the test result to the Slim query table
       ...
       cleanup();
    }
  
    public void cleanup(){
       //close the spring context
       ...
    }
  }
  </code></pre>
  
  <p>It seems that on the test page, Fitnesse starts a new testing process (creates a new TestClass instance) on SetUp, Test, TearDown. However, the result proves my wrong?!</p>