]> source.dussan.org Git - sonarqube.git/commitdiff
Refactor scope of DbTester
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 24 May 2016 21:11:15 +0000 (23:11 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 24 May 2016 21:12:58 +0000 (23:12 +0200)
so that it is always @Rule but not @ClassRule.
That allows to drop calls to truncateTables() from
tests. Each db test is ensured to be isolated.

50 files changed:
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistComponentsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java
server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
sonar-db/src/test/java/org/sonar/db/DbTester.java
sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java
sonar-db/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
sonar-db/src/test/java/org/sonar/db/issue/IssueChangeMapperTest.java
sonar-db/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java
sonar-db/src/test/java/org/sonar/db/metric/MetricDaoTest.java
sonar-db/src/test/java/org/sonar/db/notification/NotificationQueueDaoTest.java
sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java
sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/UserGroupDaoTest.java
sonar-db/src/test/java/org/sonar/db/version/v51/FeedIssueComponentUuidsTest.java
sonar-db/src/test/java/org/sonar/db/version/v52/RemoveDuplicatedComponentKeysTest.java
sonar-db/src/test/java/org/sonar/db/version/v52/RemoveRuleMeasuresOnIssuesTest.java
sonar-db/src/test/java/org/sonar/db/version/v54/InsertGateAdminPermissionForEachProfileAdminTest.java
sonar-db/src/test/java/org/sonar/db/version/v54/MigrateQualityGatesConditionsTest.java
sonar-db/src/test/java/org/sonar/db/version/v54/RemoveComponentPagePropertiesTest.java
sonar-db/src/test/java/org/sonar/db/version/v54/RemovePreviewPermissionTest.java

index 64a26f9fb4700c94bc65386c4813f41d6006a550..7d429e9c122652629d917db6073312023f31b269 100644 (file)
@@ -104,8 +104,6 @@ public class PersistMeasuresStepTest extends BaseStepTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
-
     underTest = new PersistMeasuresStep(dbClient, metricRepository, new MeasureToMeasureDto(dbIdsRepository), treeRootHolder, measureRepository);
   }
 
index 52e49fa5e6e48194c77c41b2849ad7415b9dca6a..e34d410038166bc208dce670fd1d4c1366c2112d 100644 (file)
@@ -79,7 +79,6 @@ public class PersistTestsStepTest extends BaseStepTest {
 
   @Before
   public void setup() {
-    db.truncateTables();
     System2 system2 = mock(System2.class);
     when(system2.now()).thenReturn(now);
 
index 972a45df642676212fe9607e9b2fadee31ab1fd4..fd583d31ead14e9935abf1d18a2b6c97b910c861 100644 (file)
@@ -88,7 +88,6 @@ public class ReportComputeMeasureVariationsStepTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
     dbClient.componentDao().insert(session, PROJECT_DTO);
     session.commit();
 
index 9353f579eda21fcf43f134e79b1a2543b8630fd0..3977c052c7c8a324cb3f0898fc0c719ee0afef96 100644 (file)
@@ -69,8 +69,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
 
   @Before
   public void setup() throws Exception {
-    dbTester.truncateTables();
-
     now = DATE_FORMAT.parse("2015-06-02");
     when(system2.now()).thenReturn(now.getTime());
 
index 6c1d3a465fe4e89d89cdcd4419c92f2d6086cc8c..930595e9cf3d7353713ea7ebcba6f11a14ba95a8 100644 (file)
@@ -78,7 +78,6 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest {
 
   @Before
   public void setup() {
-    dbTester.truncateTables();
     analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime();
     analysisMetadataHolder.setAnalysisDate(analysisDate);
     dbIdsRepository = new DbIdsRepositoryImpl();
index 8417d049bae43bd4d299dd90a7a362133c051341..817853579cc08533d385f41eb18e85a1435d1ec5 100644 (file)
@@ -50,7 +50,6 @@ public class SwitchSnapshotStepTest {
 
   @Before
   public void before() {
-    db.truncateTables();
     System2 system2 = mock(System2.class);
     when(system2.now()).thenReturn(DateUtils.parseDate("2011-09-29").getTime());
     underTest = new SwitchSnapshotStep(new DbClient(db.database(), db.myBatis(), new SnapshotDao()), treeRootHolder, dbIdsRepository);
index e34dcdb7de1e0ffe35b0836598345706307c265d..e95898e84a79fa1fc567abb03182359a4a686bb1 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.computation.step;
 
 import java.util.Date;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -68,11 +67,6 @@ public class ValidateProjectStepTest {
 
   ValidateProjectStep underTest = new ValidateProjectStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   @Test
   public void fail_if_root_component_is_not_a_project_in_db() {
     reportReader.putComponent(ScannerReport.Component.newBuilder()
@@ -88,7 +82,7 @@ public class ValidateProjectStepTest {
 
     thrown.expect(MessageException.class);
     thrown.expectMessage("Validation of project failed:\n" +
-        "  o Component (uuid=ABCD, key=PROJECT_KEY) is not a project");
+      "  o Component (uuid=ABCD, key=PROJECT_KEY) is not a project");
 
     underTest.execute();
   }
index b66676144e4d26e0d505f1e3793fafa40b487d3e..493c6dfbd24e45a58fafa60ccf2243b613105696 100644 (file)
@@ -47,7 +47,6 @@ import static org.sonar.db.component.SnapshotTesting.createForComponent;
 import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject;
 import static org.sonar.db.component.SnapshotTesting.newSnapshotForView;
 
-
 public class ViewsComputeMeasureVariationsStepTest {
 
   static final Metric ISSUES_METRIC = new MetricImpl(1, "violations", "violations", Metric.MetricType.INT);
@@ -89,7 +88,6 @@ public class ViewsComputeMeasureVariationsStepTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
     dbClient.componentDao().insert(session, VIEW_DTO);
     session.commit();
 
@@ -202,7 +200,7 @@ public class ViewsComputeMeasureVariationsStepTest {
       newMeasureDto(DEBT_METRIC.getId(), VIEW_DTO.getId(), period1ViewSnapshot.getId(), 10d),
       newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), VIEW_DTO.getId(), period1ViewSnapshot.getId(), 2d),
       newMeasureDto(BUILD_BREAKER_METRIC.getId(), VIEW_DTO.getId(), period1ViewSnapshot.getId(), 1d)
-    );
+      );
     session.commit();
 
     periodsHolder.setPeriods(newPeriod(1, period1ViewSnapshot));
index ef126bbe1b88e33deb8e161468135c7b7cb4728c..ea4c4e5dfaa67e9a74f900dd6976b0f6848f02d3 100644 (file)
@@ -81,8 +81,6 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
 
   @Before
   public void setup() throws Exception {
-    dbTester.truncateTables();
-
     now = DATE_FORMAT.parse("2015-06-02");
     when(system2.now()).thenReturn(now.getTime());
 
index 0b812822820c0036780efebf6eaed812573c42f4..b0b2bc73aae356f75821b812936a3f5a616a81b2 100644 (file)
@@ -53,7 +53,6 @@ import static org.sonar.server.computation.component.Component.Type.SUBVIEW;
 import static org.sonar.server.computation.component.Component.Type.VIEW;
 import static org.sonar.server.computation.component.ComponentFunctions.toKey;
 
-
 public class ViewsPersistSnapshotsStepTest extends BaseStepTest {
 
   private static final int PROJECT_KEY = 1;
@@ -84,7 +83,6 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest {
 
   @Before
   public void setup() {
-    dbTester.truncateTables();
     analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime();
     analysisMetadataHolder.setAnalysisDate(analysisDate);
 
index 8ba8dbcfc2a920532aa9c1432c4e6dedaa5d533f..67877ec449ad3a5e913847c8ae5ba9dffd854fc9 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.issue.index;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import java.util.Collection;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
@@ -30,7 +29,6 @@ import org.sonar.db.DbTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-
 public class IssueAuthorizationDaoTest {
 
   @Rule
@@ -38,11 +36,6 @@ public class IssueAuthorizationDaoTest {
 
   IssueAuthorizationDao dao = new IssueAuthorizationDao();
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   @Test
   public void select_all() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
index 25fb7a093b1469da350b144890440d9a1fcf177a..95735624d31210016b9d60e9018a8e780baf15b9 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.base.Function;
 import com.google.common.collect.Maps;
 import java.util.Map;
 import javax.annotation.Nonnull;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
@@ -32,26 +31,11 @@ import org.sonar.db.DbTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-
 public class IssueResultSetIteratorTest {
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  private static Map<String, IssueDoc> issuesByKey(IssueResultSetIterator it) {
-    return Maps.uniqueIndex(it, new Function<IssueDoc, String>() {
-      @Override
-      public String apply(@Nonnull IssueDoc issue) {
-        return issue.key();
-      }
-    });
-  }
-
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   @Test
   public void iterator_over_one_issue() {
     dbTester.prepareDbUnit(getClass(), "one_issue.xml");
@@ -223,4 +207,13 @@ public class IssueResultSetIteratorTest {
     assertThat(it.hasNext()).isFalse();
     it.close();
   }
+
+  private static Map<String, IssueDoc> issuesByKey(IssueResultSetIterator it) {
+    return Maps.uniqueIndex(it, new Function<IssueDoc, String>() {
+      @Override
+      public String apply(@Nonnull IssueDoc issue) {
+        return issue.key();
+      }
+    });
+  }
 }
index 3fee4cdd97fff0a388901fe23e421a15e86a2c4c..8ba7b01c84146d96f5366be622b36236e07dafaf 100644 (file)
@@ -79,7 +79,6 @@ public class SearchActionTest {
 
   @Before
   public void setUp() {
-    db.truncateTables();
     CustomMeasureJsonWriter customMeasureJsonWriter = new CustomMeasureJsonWriter(new UserJsonWriter(userSessionRule));
     ws = new WsTester(new CustomMeasuresWs(new SearchAction(dbClient, customMeasureJsonWriter, userSessionRule, new ComponentFinder(dbClient))));
     defaultProject = insertDefaultProject();
index 8a3435cfea3bc4369219656ebaf8852fcfc7bbf2..532946d022765c014f456a161c6e5e52a611a4c2 100644 (file)
@@ -55,20 +55,20 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_P
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
 
-
 public class UsersActionTest {
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
+
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
+
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
   ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
   DbClient dbClient = db.getDbClient();
   DbSession dbSession = db.getSession();
   WsActionTester ws;
-
   UsersAction underTest;
 
   @Before
@@ -79,24 +79,15 @@ public class UsersActionTest {
     ws = new WsActionTester(underTest);
 
     userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
-
-    UserDto user1 = insertUser(new UserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
-    UserDto user2 = insertUser(new UserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
-    UserDto user3 = insertUser(new UserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
-    insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
-    insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
-    insertUserRole(new UserRoleDto().setRole(SYSTEM_ADMIN).setUserId(user3.getId()));
-    commit();
   }
 
   @Test
   public void search_for_users_with_response_example() {
-    db.truncateTables();
     UserDto user1 = insertUser(new UserDto().setLogin("admin").setName("Administrator").setEmail("admin@admin.com"));
     UserDto user2 = insertUser(new UserDto().setLogin("george.orwell").setName("George Orwell").setEmail("george.orwell@1984.net"));
     insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
     insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
-    commit();
+    dbSession.commit();
 
     String result = ws.newRequest().setParam("permission", "scan").execute().getInput();
 
@@ -105,6 +96,7 @@ public class UsersActionTest {
 
   @Test
   public void search_for_users_with_one_permission() {
+    insertUsers();
     String result = ws.newRequest().setParam("permission", "scan").execute().getInput();
 
     assertJson(result).isSimilarTo(getClass().getResource("UsersActionTest/users.json"));
@@ -116,7 +108,7 @@ public class UsersActionTest {
     ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, "project-uuid");
     UserDto user = insertUser(newUserDto().setLogin("project-user-login").setName("project-user-name"));
     insertUserRole(new UserRoleDto().setRole(ISSUE_ADMIN).setUserId(user.getId()).setResourceId(project.getId()));
-    commit();
+    dbSession.commit();
     userSession.login().addProjectUuidPermissions(SYSTEM_ADMIN, "project-uuid");
 
     String result = ws.newRequest()
@@ -130,6 +122,7 @@ public class UsersActionTest {
 
   @Test
   public void search_for_users_with_query_as_a_parameter() {
+    insertUsers();
     String result = ws.newRequest()
       .setParam("permission", "scan")
       .setParam(Param.TEXT_QUERY, "ame-1")
@@ -142,6 +135,7 @@ public class UsersActionTest {
 
   @Test
   public void search_for_users_with_select_as_a_parameter() {
+    insertUsers();
     String result = ws.newRequest()
       .setParam("permission", "scan")
       .setParam(Param.SELECTED, SelectionMode.ALL.value())
@@ -192,7 +186,7 @@ public class UsersActionTest {
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Project id or project key can be provided, not both.");
     dbClient.componentDao().insert(dbSession, newProjectDto("project-uuid").setKey("project-key"));
-    commit();
+    dbSession.commit();
 
     ws.newRequest()
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
@@ -203,16 +197,22 @@ public class UsersActionTest {
 
   private UserDto insertUser(UserDto userDto) {
     UserDto user = dbClient.userDao().insert(dbSession, userDto.setActive(true));
-    commit();
+    dbSession.commit();
     return user;
   }
 
   private void insertUserRole(UserRoleDto userRoleDto) {
     dbClient.roleDao().insertUserRole(dbSession, userRoleDto);
-    commit();
+    dbSession.commit();
   }
 
-  private void commit() {
+  private void insertUsers() {
+    UserDto user1 = insertUser(new UserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
+    UserDto user2 = insertUser(new UserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
+    UserDto user3 = insertUser(new UserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
+    insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user1.getId()));
+    insertUserRole(new UserRoleDto().setRole(SCAN_EXECUTION).setUserId(user2.getId()));
+    insertUserRole(new UserRoleDto().setRole(SYSTEM_ADMIN).setUserId(user3.getId()));
     dbSession.commit();
   }
 }
index ca3c2f0e53945d6062854026e419e1b8251c500b..bbf2f1222b0eb038dad79f4f4a4a81fb595733bd 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Date;
 import java.util.List;
 import javax.annotation.Nullable;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -34,7 +33,6 @@ import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.permission.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
@@ -58,27 +56,25 @@ import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
 import static org.sonar.test.JsonAssert.assertJson;
 
-
 public class SearchTemplatesActionTest {
-  @ClassRule
-  public static DbTester db = DbTester.create(System2.INSTANCE);
+  @Rule
+  public DbTester db = DbTester.create(System2.INSTANCE);
+
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
+
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
   WsActionTester ws;
   I18nRule i18n = new I18nRule();
   DbClient dbClient = db.getDbClient();
-  final DbSession dbSession = db.getSession();
   ResourceTypes resourceTypes = mock(ResourceTypes.class);
   SearchTemplatesDataLoader dataLoader;
-
   SearchTemplatesAction underTest;
 
   @Before
   public void setUp() {
-    db.truncateTables();
     i18n.setProjectPermissions();
     when(resourceTypes.getRoots()).thenReturn(rootResourceTypes());
 
@@ -125,7 +121,7 @@ public class SearchTemplatesActionTest {
 
     addGroupToTemplate(developerTemplate.getId(), group1.getId(), UserRole.USER);
 
-    commit();
+    db.commit();
 
     String result = newRequest();
 
@@ -150,7 +146,7 @@ public class SearchTemplatesActionTest {
     insertProjectTemplate();
     insertViewsTemplate();
     insertDeveloperTemplate();
-    commit();
+    db.commit();
 
     String result = ws.newRequest()
       .setParam(TEXT_QUERY, "views")
@@ -214,27 +210,23 @@ public class SearchTemplatesActionTest {
   }
 
   private PermissionTemplateDto insertTemplate(PermissionTemplateDto template) {
-    return dbClient.permissionTemplateDao().insert(dbSession, template);
+    return dbClient.permissionTemplateDao().insert(db.getSession(), template);
   }
 
   private GroupDto insertGroup(GroupDto groupDto) {
-    return dbClient.groupDao().insert(dbSession, groupDto);
+    return dbClient.groupDao().insert(db.getSession(), groupDto);
   }
 
   private UserDto insertUser(UserDto userDto) {
-    return dbClient.userDao().insert(dbSession, userDto.setActive(true));
+    return dbClient.userDao().insert(db.getSession(), userDto.setActive(true));
   }
 
   private void addGroupToTemplate(long templateId, @Nullable Long groupId, String permission) {
-    dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateId, groupId, permission);
+    dbClient.permissionTemplateDao().insertGroupPermission(db.getSession(), templateId, groupId, permission);
   }
 
   private void addUserToTemplate(long templateId, long userId, String permission) {
-    dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateId, userId, permission);
-  }
-
-  private void commit() {
-    dbSession.commit();
+    dbClient.permissionTemplateDao().insertUserPermission(db.getSession(), templateId, userId, permission);
   }
 
   private static List<ResourceType> rootResourceTypes() {
index 71982fbb07ed56f3756c7030dd5dd9049752ee9c..85e680a0708466f6f4c3c3b0bb3f454af6a24307 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.project.ws;
 
 import com.google.common.io.Resources;
 import org.apache.commons.lang.StringUtils;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.server.ws.WebService.Param;
@@ -41,7 +40,6 @@ import org.sonar.test.JsonAssert;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-
 public class GhostsActionTest {
 
   @Rule
@@ -49,15 +47,9 @@ public class GhostsActionTest {
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
-  WsTester ws;
 
   DbClient dbClient = db.getDbClient();
-
-  @Before
-  public void setUp() {
-    ws = new WsTester(new ProjectsWs(new GhostsAction(dbClient, userSessionRule)));
-    db.truncateTables();
-  }
+  WsTester ws = new WsTester(new ProjectsWs(new GhostsAction(dbClient, userSessionRule)));
 
   @Test
   public void ghost_projects_without_analyzed_projects() throws Exception {
index c85c9c77684a2860c99bc47dc71a75866f667b69..0b352d5c898fb1d9c4a893438a44df75d5036237 100644 (file)
@@ -62,7 +62,6 @@ public class ProvisionedActionTest {
   @Before
   public void setUp() {
     componentDao = dbClient.componentDao();
-    db.truncateTables();
     ws = new WsTester(new ProjectsWs(new ProvisionedAction(dbClient, userSessionRule)));
   }
 
index cdce8f33cce587be5f4fbdfedb122a4d3b0b63bf..2a74628a12660a86324a30dda44684a9a34e411c 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.base.Function;
 import com.google.common.collect.Maps;
 import java.util.Map;
 import javax.annotation.Nonnull;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
@@ -38,17 +37,11 @@ import static org.sonar.api.rule.Severity.CRITICAL;
 import static org.sonar.api.rule.Severity.INFO;
 import static org.sonar.server.qualityprofile.ActiveRule.Inheritance.INHERITED;
 
-
 public class ActiveRuleResultSetIteratorTest {
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   @Test
   public void iterator_over_one_active_rule() {
     dbTester.prepareDbUnit(getClass(), "one_active_rule.xml");
index 8996e3bcd1e1c7439728274c3c5d0ad74b8bc455..34b42f4800bb7a8d3e7ad0440094aa186f19c78a 100644 (file)
@@ -68,8 +68,6 @@ public class DeleteActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
-
     xoo1 = LanguageTesting.newLanguage("xoo1");
     xoo2 = LanguageTesting.newLanguage("xoo2");
 
index 7d02c4524b18585ca1b6bfaf151982a15ef0cb87..6320e88f4fb8ff04c1722f408316c8d3360dd4a6 100644 (file)
@@ -73,8 +73,6 @@ public class ExportActionTest {
   public void before() {
     backuper = mock(QProfileBackuper.class);
 
-    db.truncateTables();
-
     ProfileExporter exporter1 = newExporter("polop");
     ProfileExporter exporter2 = newExporter("palap");
 
index ad9bc747a7e8052d4c3bc826ac18fb7da03055b6..f974161f493d1b7f5d2cb5881c7990a818ed2e80 100644 (file)
@@ -77,7 +77,6 @@ public class ProjectsActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
     dbClient = new DbClient(dbTester.database(), dbTester.myBatis(),
       new QualityProfileDao(dbTester.myBatis(), system2),
       new ComponentDao(),
index 63a763166f6f26a2bfc3069eba903380a1c8ec99..950a0afb610f03e672a48be6f25d8febb04ea340 100644 (file)
@@ -61,7 +61,6 @@ public class RenameActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
     qualityProfileDao = new QualityProfileDao(dbTester.myBatis(), mock(System2.class));
     dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), qualityProfileDao);
     session = dbClient.openSession(false);
index 66dfaeb90d36197a92e12db95015645ac1c91eac..1e45f1875e3686987ecbec1cd4e78d1a2c2f17c2 100644 (file)
@@ -62,7 +62,6 @@ public class SetDefaultActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
     qualityProfileDao = new QualityProfileDao(dbTester.myBatis(), mock(System2.class));
     dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), qualityProfileDao);
     session = dbClient.openSession(false);
index 7f8825a01f6185997b82d5c653d61eebb313759a..d09dad29b98273b21afbde44d963d109e1e9ba91 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.base.Function;
 import com.google.common.collect.Maps;
 import java.util.Map;
 import javax.annotation.Nonnull;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
@@ -80,11 +79,6 @@ public class RuleResultSetIteratorTest {
     .setCreatedAt(2000000000000L)
     .setUpdatedAt(2100000000000L);
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   @Test
   public void iterator_over_one_rule() {
     dbClient.ruleDao().insert(dbSession, templateRule);
index 2384065251799939e529b235d171c2f2b202f42e..f0184df9dd9754bf6f10614df7e49dc6d418ba81 100644 (file)
@@ -54,7 +54,6 @@ public class HashActionTest {
 
   @Before
   public void before() {
-    db.truncateTables();
     DbClient dbClient = db.getDbClient();
 
     tester = new WsTester(new SourcesWs(new HashAction(dbClient, userSessionRule, new ComponentFinder(dbClient))));
index ac9332dfe739c5f41726329f061a65f1e4211818..cd5b0f96d051be1a17acd31ff1f27a62d4505f80 100644 (file)
@@ -72,8 +72,6 @@ public class LinesActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
-
     htmlSourceDecorator = mock(HtmlSourceDecorator.class);
     when(htmlSourceDecorator.getDecoratedSourceAsHtml(anyString(), anyString(), anyString())).then(new Answer<String>() {
       @Override
index 1f6e170a78115e036c9edacc3a84972a36fe567e..a1fbb0f3b0b037cc0c30453d6fe295a431f83eb5 100644 (file)
@@ -57,7 +57,6 @@ public class ScmActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
     tester = new WsTester(
       new SourcesWs(new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()), userSessionRule, new ComponentFinder(dbClient))));
   }
index 005bfc29318657f469ab4709f294a2d5ca8f76f0..03d2dfbf80d90e18a9deac749770f5f7e27e9625 100644 (file)
@@ -121,8 +121,6 @@ public class RegisterMetricsTest {
 
   @Test
   public void insert_core_metrics() {
-    dbTester.truncateTables();
-
     RegisterMetrics register = new RegisterMetrics(dbClient);
     register.start();
 
index cd92e6eb7406a44f8f556b55ad66433c7cb3517e..bd457413dca7d2c213a5fe5f0ef0386e14fa55f4 100644 (file)
@@ -44,13 +44,13 @@ import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.component.SnapshotDto;
+import org.sonar.db.component.SnapshotTesting;
 import org.sonar.db.dashboard.ActiveDashboardDto;
 import org.sonar.db.dashboard.DashboardDto;
 import org.sonar.db.property.PropertyDto;
 import org.sonar.server.component.ComponentFinder;
-import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.component.SnapshotTesting;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
@@ -79,8 +79,6 @@ public class ComponentNavigationActionTest {
 
   @Before
   public void before() {
-    dbTester.truncateTables();
-
     i18n = mock(I18n.class);
     when(i18n.message(any(Locale.class), any(String.class), any(String.class)))
       .thenAnswer(new Answer<String>() {
index c9ba63f652d3e245bf9234c3af149474742bacad..ade8fbbdde181d252889a202fb544f8e49de4ff0 100644 (file)
@@ -67,8 +67,6 @@ public class GlobalNavigationActionTest {
 
   @Before
   public void before() {
-    dbTester.truncateTables();
-
     userDao = new UserDao(dbTester.myBatis(), mock(System2.class));
     dashboardDao = new DashboardDao(dbTester.myBatis());
     activeDashboardDao = new ActiveDashboardDao(dbTester.myBatis());
index 958f6ae0d51646015eb7a12d462711c94190c1f8..37e953f12656eccd7f6b9a5172e9e8caa5b9f2ae 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.user.index;
 import com.google.common.base.Function;
 import com.google.common.collect.Maps;
 import java.util.Map;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
@@ -30,17 +29,11 @@ import org.sonar.db.DbTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-
 public class UserResultSetIteratorTest {
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   @Test
   public void iterator_over_users() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
index e6624f5a1cbd9fd6efeb255d13b70ead57145a66..ec198c0f995ebbbc787d6784c03c7571c6d5712e 100644 (file)
@@ -55,8 +55,6 @@ public class GroupsActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
-
     System2 system2 = new System2();
     UserDao userDao = new UserDao(dbTester.myBatis(), system2);
     GroupDao groupDao = new GroupDao(system2);
index cf3f4f4c22b52e4e2b51100d655fdd625ba73669..99a17517e07b0fd6cd5cb4bd5a9b75e9323fa25e 100644 (file)
@@ -91,7 +91,7 @@ public class DbTester extends ExternalResource {
   @Override
   protected void before() throws Throwable {
     db.start();
-    truncateTables();
+    db.truncateTables();
   }
 
   @Override
@@ -113,10 +113,6 @@ public class DbTester extends ExternalResource {
     getSession().commit();
   }
 
-  public void truncateTables() {
-    db.truncateTables();
-  }
-
   public DbClient getDbClient() {
     if (client == null) {
       TransientPicoContainer ioc = new TransientPicoContainer();
index c1735a9da54f16646c2857e7154f5e670981fe5e..4bd171d65da0684177923e2e691ccb55653d7ba0 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.db.component;
 
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.resources.Qualifiers;
@@ -38,11 +37,6 @@ public class ResourceIndexDaoTest {
 
   ResourceIndexDao underTest = dbTester.getDbClient().componentIndexDao();
 
-  @Before
-  public void setUp() throws Exception {
-    dbTester.truncateTables();
-  }
-
   @Test
   public void shouldIndexResource() {
     dbTester.prepareDbUnit(getClass(), "shouldIndexResource.xml");
index c6cd44923445da6418a33daccad475657d9ea16a..725017d55e01869978f77bcdff01ce6f0591226d 100644 (file)
@@ -109,8 +109,6 @@ public class IssueChangeDaoTest {
 
   @Test
   public void select_comments_by_issues_empty_input() {
-    dbTester.truncateTables();
-
     // no need to connect to db
     DbSession session = mock(DbSession.class);
     List<DefaultIssueComment> comments = dao.selectCommentsByIssues(session, Collections.<String>emptyList());
@@ -136,8 +134,6 @@ public class IssueChangeDaoTest {
 
   @Test
   public void insert() {
-    dbTester.truncateTables();
-
     IssueChangeDto changeDto = new IssueChangeDto()
       .setKey("EFGH")
       .setUserLogin("emmerik")
index 0d929d96185d8571e715cc0910ae4d4b7558d58b..11e9610ecd6bab039ff539273240b3c16dc8a610 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.db.issue;
 
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
@@ -31,11 +30,6 @@ public class IssueChangeMapperTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   @Test
   public void insert_diff() {
     IssueChangeDto dto = new IssueChangeDto();
index 29de726f6c78d62a883c9d2032bec3737b11cbd1..a3b4655ae795390254802dc11ad89c89c26de234 100644 (file)
@@ -48,7 +48,6 @@ public class CustomMeasureDaoTest {
   public void setUp() {
     session = db.getSession();
     underTest = new CustomMeasureDao();
-    db.truncateTables();
   }
 
   @Test
index 17922a57483ea03be85931e8826c54377f984002..01db968faf54acd6976803912afd848045c046ab 100644 (file)
@@ -49,7 +49,6 @@ public class MetricDaoTest {
 
   @Before
   public void createDao() {
-    dbTester.truncateTables();
     session = dbTester.myBatis().openSession(false);
     underTest = new MetricDao();
   }
index c22cbc7a96a90cdd6806a3f4b4ec1bb0c5211b63..093ae8b800769dd72a7227cf99e62f3efd2a2df2 100644 (file)
@@ -38,8 +38,6 @@ public class NotificationQueueDaoTest {
 
   @Test
   public void should_insert_new_notification_queue() throws Exception {
-    db.truncateTables();
-
     NotificationQueueDto notificationQueueDto = NotificationQueueDto.toNotificationQueueDto(new Notification("email"));
 
     dao.insert(Arrays.asList(notificationQueueDto));
@@ -50,8 +48,6 @@ public class NotificationQueueDaoTest {
 
   @Test
   public void should_count_notification_queue() {
-    db.truncateTables();
-
     NotificationQueueDto notificationQueueDto = NotificationQueueDto.toNotificationQueueDto(new Notification("email"));
 
     assertThat(dao.count()).isEqualTo(0);
index 6998f5c7ccee2947beb5bdaedf09ceec8fe3db16..ca3dbee1f0a62c521ca5160008b97102e74a2713 100644 (file)
@@ -227,8 +227,6 @@ public class PermissionTemplateDaoTest {
 
   @Test
   public void should_retrieve_permission_template() {
-    db.truncateTables();
-
     PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto().setName("Test template").setUuid("test_template");
     PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto().setUuid("test_template");
     underTest = mock(PermissionTemplateDao.class);
@@ -243,8 +241,6 @@ public class PermissionTemplateDaoTest {
 
   @Test
   public void should_fail_on_unmatched_template() {
-    db.truncateTables();
-
     expectedException.expect(IllegalArgumentException.class);
 
     underTest.selectPermissionTemplateWithPermissions(db.getSession(), "unmatched");
index c2955d9d029ea5b2b71f816c39a4d007f3d4c3f9..5568b0c00cde7ba73ab74eec90fbbce3a39d8724 100644 (file)
@@ -53,8 +53,6 @@ public class PurgeCommandsTest {
    */
   @Test
   public void should_not_fail_when_deleting_huge_number_of_snapshots() {
-    dbTester.truncateTables();
-
     new PurgeCommands(dbTester.getSession(), profiler).deleteSnapshots(getHugeNumberOfIds());
     // The goal of this test is only to check that the query do no fail, not to check result
   }
@@ -85,8 +83,6 @@ public class PurgeCommandsTest {
    */
   @Test
   public void should_not_fail_when_purging_huge_number_of_snapshots() {
-    dbTester.truncateTables();
-
     new PurgeCommands(dbTester.getSession(), profiler).purgeSnapshots(getHugeNumberOfIds());
     // The goal of this test is only to check that the query do no fail, not to check result
   }
@@ -110,7 +106,6 @@ public class PurgeCommandsTest {
    */
   @Test
   public void should_not_fail_when_deleting_huge_number_of_resources() {
-    dbTester.truncateTables();
     new PurgeCommands(dbTester.getSession(), profiler).deleteComponents(getHugeNumberOfIdUuids());
     // The goal of this test is only to check that the query do no fail, not to check result
   }
index fda1aa3a8f7497bfc95b67ee96d1386c6e6e9621..fc470b2bd464e01196c59e47ae96b0daea5fa158 100644 (file)
@@ -116,8 +116,6 @@ public class UserDaoTest {
 
   @Test
   public void selectUsersByLogins_empty_logins() {
-    db.truncateTables();
-
     // no need to access db
     Collection<UserDto> users = underTest.selectByLogins(Collections.<String>emptyList());
     assertThat(users).isEmpty();
index af1ae76cb6227053d43d2409e85a40f14f2e4e36..d27a9c9f2e9959100292981c9168ca00916c5419 100644 (file)
@@ -34,8 +34,6 @@ public class UserGroupDaoTest {
 
   @Test
   public void insert() {
-    dbTester.truncateTables();
-
     UserGroupDto userGroupDto = new UserGroupDto().setUserId(1L).setGroupId(2L);
     dao.insert(dbTester.getSession(), userGroupDto);
     dbTester.getSession().commit();
index abf8cf5059ddc7102f0de8585771d67e2b3b5c9a..a243fe4100896a0b164068e70adf5a8adf0d9203 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.db.version.v51;
 
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
@@ -29,14 +28,7 @@ public class FeedIssueComponentUuidsTest {
   @Rule
   public DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedIssueComponentUuidsTest.class, "schema.sql");
 
-  FeedIssueComponentUuids underTest;
-
-  @Before
-  public void setUp() {
-    db.truncateTables();
-
-    underTest = new FeedIssueComponentUuids(db.database());
-  }
+  FeedIssueComponentUuids underTest = new FeedIssueComponentUuids(db.database());
 
   @Test
   public void migrate_empty_db() throws Exception {
index cacf4a0262d7a8e0f0fe4fed2a690a8b7aaf6789..3865d5869ee13fcb633de0881dacd55cff94b951 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.db.version.v52;
 
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
@@ -28,8 +28,8 @@ import org.sonar.db.version.MigrationStep;
 
 public class RemoveDuplicatedComponentKeysTest {
 
-  @ClassRule
-  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveDuplicatedComponentKeysTest.class, "schema.sql");
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveDuplicatedComponentKeysTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 9b3d173190e781ba51fbf6ce30fa2eaffe7df7fe..bc1b5fd432138c2a421a89f35ca99148201f4d83 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.db.version.v52;
 
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
@@ -28,8 +28,8 @@ import org.sonar.db.version.MigrationStep;
 
 public class RemoveRuleMeasuresOnIssuesTest {
 
-  @ClassRule
-  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveRuleMeasuresOnIssuesTest.class, "schema.sql");
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveRuleMeasuresOnIssuesTest.class, "schema.sql");
 
   MigrationStep migration;
 
index 8afdbdf09ab2d09c8b5cef86efc5bd063cb77f72..1b758f56297e028f75178200b45a9b6ab57674b5 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.db.version.v54;
 
 import javax.annotation.Nullable;
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
@@ -42,8 +42,8 @@ public class InsertGateAdminPermissionForEachProfileAdminTest {
   private static final String NOT_PROFILE_ADMIN_ROLE = "ProfileAdmin";
   private static final String GATE_ADMIN_ROLE = "gateadmin";
 
-  @ClassRule
-  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, InsertGateAdminPermissionForEachProfileAdminTest.class, "schema.sql");
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, InsertGateAdminPermissionForEachProfileAdminTest.class, "schema.sql");
 
   MigrationStep migration;
 
index a0b2e2311528dd921e3ab9904c72a73762d08db2..8b17de410e1a9bec8aea0ff4f323ee7a89e8091d 100644 (file)
@@ -48,7 +48,6 @@ public class MigrateQualityGatesConditionsTest {
 
   @Before
   public void setUp() {
-    db.truncateTables();
     when(system2.now()).thenReturn(DateUtils.parseDate(NOW).getTime());
     migration = new MigrateQualityGatesConditions(db.database(), system2);
   }
index 8533751c82f0f8bca30e25a6cad56f47671f6cd6..7e3b7621883f0797a4e3d70822f212c248d17f9f 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.db.version.v54;
 
 import javax.annotation.Nullable;
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
@@ -34,8 +34,8 @@ public class RemoveComponentPagePropertiesTest {
   private static final String TABLE_PROPERTIES = "properties";
   private static final String EXPECTED_PREFIX = "sonar.core.projectsdashboard.";
 
-  @ClassRule
-  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveComponentPagePropertiesTest.class, "schema.sql");
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, RemoveComponentPagePropertiesTest.class, "schema.sql");
 
   RemoveComponentPageProperties underTest;
 
index 2297f26df992f933bff7da6c76bd8ee27009f46d..a6f73334cf70f27504cd6334dd88740571203e26 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.db.version.v54;
 
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
@@ -31,8 +31,8 @@ public class RemovePreviewPermissionTest {
   static final String GROUP_ROLES_TABLE = "group_roles";
   static final String USER_ROLES_TABLE = "user_roles";
 
-  @ClassRule
-  public static DbTester db = DbTester.createForSchema(System2.INSTANCE, RemovePreviewPermissionTest.class, "schema.sql");
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, RemovePreviewPermissionTest.class, "schema.sql");
 
   MigrationStep migration;