aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-05-24 23:11:15 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-05-24 23:12:58 +0200
commit82d87617e686f8f99abe2323f98214aa2d8f4182 (patch)
tree659d180764bb100ff062ef9e5ef491bf64ab6106 /server
parent98df2f003158fb39819d91777234990ae110bb26 (diff)
downloadsonarqube-82d87617e686f8f99abe2323f98214aa2d8f4182.tar.gz
sonarqube-82d87617e686f8f99abe2323f98214aa2d8f4182.zip
Refactor scope of DbTester
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.
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistComponentsStepTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java25
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java34
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java30
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleResultSetIteratorTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/index/UserResultSetIteratorTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java2
32 files changed, 42 insertions, 133 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
index 64a26f9fb47..7d429e9c122 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
@@ -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);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
index 52e49fa5e6e..e34d4100381 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java
index 972a45df642..fd583d31ead 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComputeMeasureVariationsStepTest.java
@@ -88,7 +88,6 @@ public class ReportComputeMeasureVariationsStepTest {
@Before
public void setUp() {
- dbTester.truncateTables();
dbClient.componentDao().insert(session, PROJECT_DTO);
session.commit();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistComponentsStepTest.java
index 9353f579eda..3977c052c7c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistComponentsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistComponentsStepTest.java
@@ -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());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java
index 6c1d3a465fe..930595e9cf3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java
@@ -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();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java
index 8417d049bae..817853579cc 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java
index e34dcdb7de1..e95898e84a7 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java
@@ -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();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java
index b66676144e4..493c6dfbd24 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java
@@ -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));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java
index ef126bbe1b8..ea4c4e5dfaa 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java
@@ -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());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java
index 0b812822820..b0b2bc73aae 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java
index 8ba8dbcfc2a..67877ec449a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationDaoTest.java
@@ -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");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java
index 25fb7a093b1..95735624d31 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java
@@ -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();
+ }
+ });
+ }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
index 3fee4cdd97f..8ba7b01c841 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
@@ -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();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
index 8a3435cfea3..532946d0227 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
@@ -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();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java
index ca3c2f0e539..bbf2f1222b0 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java
@@ -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() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java
index 71982fbb07e..85e680a0708 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/GhostsActionTest.java
@@ -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 {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
index c85c9c77684..0b352d5c898 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/ProvisionedActionTest.java
@@ -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)));
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
index cdce8f33cce..2a74628a126 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest.java
@@ -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");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
index 8996e3bcd1e..34b42f4800b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
@@ -68,8 +68,6 @@ public class DeleteActionTest {
@Before
public void setUp() {
- dbTester.truncateTables();
-
xoo1 = LanguageTesting.newLanguage("xoo1");
xoo2 = LanguageTesting.newLanguage("xoo2");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
index 7d02c4524b1..6320e88f4fb 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
@@ -73,8 +73,6 @@ public class ExportActionTest {
public void before() {
backuper = mock(QProfileBackuper.class);
- db.truncateTables();
-
ProfileExporter exporter1 = newExporter("polop");
ProfileExporter exporter2 = newExporter("palap");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
index ad9bc747a7e..f974161f493 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
@@ -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(),
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java
index 63a763166f6..950a0afb610 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java
index 66dfaeb90d3..1e45f1875e3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleResultSetIteratorTest.java
index 7f8825a01f6..d09dad29b98 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleResultSetIteratorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleResultSetIteratorTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
index 23840652517..f0184df9dd9 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
@@ -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))));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
index ac9332dfe73..cd5b0f96d05 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java
index 1f6e170a781..a1fbb0f3b0b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java
@@ -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))));
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
index 005bfc29318..03d2dfbf80d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
@@ -121,8 +121,6 @@ public class RegisterMetricsTest {
@Test
public void insert_core_metrics() {
- dbTester.truncateTables();
-
RegisterMetrics register = new RegisterMetrics(dbClient);
register.start();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java
index cd92e6eb740..bd457413dca 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java
@@ -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>() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java
index c9ba63f652d..ade8fbbdde1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java
@@ -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());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserResultSetIteratorTest.java
index 958f6ae0d51..37e953f1265 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserResultSetIteratorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserResultSetIteratorTest.java
@@ -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");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
index e6624f5a1cb..ec198c0f995 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
@@ -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);