From 18e32057f362e892993c39ed8bea9aa2f41d8eab Mon Sep 17 00:00:00 2001
From: kaloyane <kaloyane>
Date: Wed, 12 Jan 2011 13:38:38 +0000
Subject: [PATCH] SystemTest-s are now Transactional i.e. everything they
 commit in the database is rolled-back after the end of the test, so that
 different tests can run independently from each other.

SVN: 19391
---
 .../cisd/openbis/systemtest/SystemTestCase.java        |  8 ++++++--
 .../generic/DynamicPropertiesEvaluationTest.java       |  2 ++
 .../plugin/generic/FileFormatTypeHeadlessTest.java     | 10 ++++++----
 .../systemtest/plugin/generic/SampleBrowsingTest.java  |  4 ++--
 .../systemtest/plugin/generic/SampleDetailsTest.java   |  4 ++--
 .../systemtest/plugin/query/QueryEditingTest.java      |  3 +++
 6 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/SystemTestCase.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/SystemTestCase.java
index f1a8c7c38aa..69df074d138 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/SystemTestCase.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/SystemTestCase.java
@@ -22,7 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
+import org.springframework.test.context.transaction.TransactionConfiguration;
 import org.testng.AssertJUnit;
 import org.testng.annotations.BeforeSuite;
 
@@ -40,7 +41,10 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer;
  * @author Franz-Josef Elmer
  */
 @ContextConfiguration(locations = "classpath:applicationContext.xml")
-public abstract class SystemTestCase extends AbstractTestNGSpringContextTests
+// In 'commonContext.xml', our transaction manager is called 'transaction-manager' (by default
+// Spring looks for 'transactionManager').
+@TransactionConfiguration(transactionManager = "transaction-manager")
+public abstract class SystemTestCase extends AbstractTransactionalTestNGSpringContextTests
 {
     protected static final String SESSION_KEY = "session-key";
 
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/DynamicPropertiesEvaluationTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/DynamicPropertiesEvaluationTest.java
index f26ae8521bc..dcfa4b9c402 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/DynamicPropertiesEvaluationTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/DynamicPropertiesEvaluationTest.java
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
+import org.springframework.test.context.transaction.TransactionConfiguration;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
@@ -47,6 +48,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
  * @author Piotr Buczek
  */
 @Test(groups = "system test")
+@TransactionConfiguration(defaultRollback = false)
 public class DynamicPropertiesEvaluationTest extends GenericSystemTestCase
 {
     private static final String CELL_PLATE = "CELL_PLATE";
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/FileFormatTypeHeadlessTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/FileFormatTypeHeadlessTest.java
index 92c3c3f8afa..e69972d4c97 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/FileFormatTypeHeadlessTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/FileFormatTypeHeadlessTest.java
@@ -28,6 +28,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TypedTableResultSe
 import ch.systemsx.cisd.openbis.generic.shared.basic.Row;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FileFormatType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelRowWithObject;
+import ch.systemsx.cisd.openbis.systemtest.SystemTestCase;
 
 /**
  * A headless system test having the same functionality as {@link FileFormatTypeGridTest}.
@@ -35,8 +36,9 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelRowWithObject
  * @author Kaloyan Enimanev
  */
 @Test(groups = "system test")
-public class FileFormatTypeHeadlessTest extends GenericSystemTestCase
+public class FileFormatTypeHeadlessTest extends SystemTestCase
 {
+    private static final int FILE_TYPES_IN_DB = 8;
 
     @BeforeMethod
     public final void setUp()
@@ -44,7 +46,7 @@ public class FileFormatTypeHeadlessTest extends GenericSystemTestCase
         logIntoCommonClientService();
     }
 
-    @Test
+    @Test()
     public void testListFileFormats()
     {
         DefaultResultSetConfig<String, TableModelRowWithObject<FileFormatType>> criteria =
@@ -52,7 +54,7 @@ public class FileFormatTypeHeadlessTest extends GenericSystemTestCase
         TypedTableResultSet<FileFormatType> tableResultSet =
                 commonClientService.listFileTypes(criteria);
 
-        assertTable(tableResultSet).hasNumberOfRows(8);
+        assertTable(tableResultSet).hasNumberOfRows(FILE_TYPES_IN_DB);
         assertColumn(tableResultSet, "CODE").containsValues("TIFF", "XML", "HDF5");
     }
 
@@ -76,7 +78,7 @@ public class FileFormatTypeHeadlessTest extends GenericSystemTestCase
                 new Row().withCell("CODE", fft.getCode()).withCell("DESCRIPTION",
                         fft.getDescription());
 
-        assertTable(tableResultSet).hasNumberOfRows(9);
+        assertTable(tableResultSet).hasNumberOfRows(FILE_TYPES_IN_DB + 1);
         assertTable(tableResultSet).containsRow(expectedRow);
 
     }
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleBrowsingTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleBrowsingTest.java
index eb9b4c8d09f..2e5807139a6 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleBrowsingTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleBrowsingTest.java
@@ -69,7 +69,7 @@ public class SampleBrowsingTest extends GenericSystemTestCase
 
         ResultSetWithEntityTypes<Sample> samples =
                 commonClientService.listSamples(new ListSampleDisplayCriteria(listCriteria));
-        assertEquals(42, samples.getResultSet().getTotalLength());
+        assertEquals(40, samples.getResultSet().getTotalLength());
         assertEquals("[DILUTION_PLATE, REINFECT_PLATE, MASTER_PLATE, CONTROL_LAYOUT, CELL_PLATE]",
                 samples.getAvailableEntityTypes().toString());
 
@@ -162,7 +162,7 @@ public class SampleBrowsingTest extends GenericSystemTestCase
 
         ResultSetWithEntityTypes<Sample> samples =
                 commonClientService.listSamples(new ListSampleDisplayCriteria(listCriteria));
-        assertEquals(17, samples.getResultSet().getTotalLength());
+        assertEquals(15, samples.getResultSet().getTotalLength());
         assertEquals("[CELL_PLATE]", samples.getAvailableEntityTypes().toString());
 
         GridRowModels<Sample> list = samples.getResultSet().getList();
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleDetailsTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleDetailsTest.java
index 83c013d1f32..de7482494dc 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleDetailsTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleDetailsTest.java
@@ -133,7 +133,7 @@ public class SampleDetailsTest extends GenericSystemTestCase
 
         ResultSetWithEntityTypes<Sample> samples =
                 commonClientService.listSamples(new ListSampleDisplayCriteria(listCriteria));
-        assertEquals(17, samples.getResultSet().getTotalLength());
+        assertEquals(15, samples.getResultSet().getTotalLength());
         assertEquals("[CELL_PLATE]", samples.getAvailableEntityTypes().toString());
 
         GridRowModels<Sample> list = samples.getResultSet().getList();
@@ -179,7 +179,7 @@ public class SampleDetailsTest extends GenericSystemTestCase
 
         ResultSetWithEntityTypes<Sample> samples =
                 commonClientService.listSamples(new ListSampleDisplayCriteria(listCriteria));
-        assertEquals(17, samples.getResultSet().getTotalLength());
+        assertEquals(15, samples.getResultSet().getTotalLength());
         assertEquals("[CELL_PLATE]", samples.getAvailableEntityTypes().toString());
 
         GridRowModels<Sample> list = samples.getResultSet().getList();
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/query/QueryEditingTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/query/QueryEditingTest.java
index e5f15c705d7..57fbcd2f7be 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/query/QueryEditingTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/query/QueryEditingTest.java
@@ -25,6 +25,8 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
@@ -51,6 +53,7 @@ import ch.systemsx.cisd.openbis.plugin.query.shared.basic.dto.QueryParameterBind
  * @author Franz-Josef Elmer
  */
 @Test(groups = "system test")
+@Transactional(propagation = Propagation.NOT_SUPPORTED)
 public class QueryEditingTest extends QuerySystemTestCase
 {
 
-- 
GitLab