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.
@Before
public void setUp() {
- dbTester.truncateTables();
-
underTest = new PersistMeasuresStep(dbClient, metricRepository, new MeasureToMeasureDto(dbIdsRepository), treeRootHolder, measureRepository);
}
@Before
public void setup() {
- db.truncateTables();
System2 system2 = mock(System2.class);
when(system2.now()).thenReturn(now);
@Before
public void setUp() {
- dbTester.truncateTables();
dbClient.componentDao().insert(session, PROJECT_DTO);
session.commit();
@Before
public void setup() throws Exception {
- dbTester.truncateTables();
-
now = DATE_FORMAT.parse("2015-06-02");
when(system2.now()).thenReturn(now.getTime());
@Before
public void setup() {
- dbTester.truncateTables();
analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime();
analysisMetadataHolder.setAnalysisDate(analysisDate);
dbIdsRepository = new DbIdsRepositoryImpl();
@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);
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;
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()
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();
}
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);
@Before
public void setUp() {
- dbTester.truncateTables();
dbClient.componentDao().insert(session, VIEW_DTO);
session.commit();
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));
@Before
public void setup() throws Exception {
- dbTester.truncateTables();
-
now = DATE_FORMAT.parse("2015-06-02");
when(system2.now()).thenReturn(now.getTime());
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;
@Before
public void setup() {
- dbTester.truncateTables();
analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime();
analysisMetadataHolder.setAnalysisDate(analysisDate);
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;
import static org.assertj.core.api.Assertions.assertThat;
-
public class IssueAuthorizationDaoTest {
@Rule
IssueAuthorizationDao dao = new IssueAuthorizationDao();
- @Before
- public void setUp() {
- dbTester.truncateTables();
- }
-
@Test
public void select_all() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
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;
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");
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();
+ }
+ });
+ }
}
@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();
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
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();
@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"));
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()
@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")
@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())
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)
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();
}
}
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;
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;
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());
addGroupToTemplate(developerTemplate.getId(), group1.getId(), UserRole.USER);
- commit();
+ db.commit();
String result = newRequest();
insertProjectTemplate();
insertViewsTemplate();
insertDeveloperTemplate();
- commit();
+ db.commit();
String result = ws.newRequest()
.setParam(TEXT_QUERY, "views")
}
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() {
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;
import static org.assertj.core.api.Assertions.assertThat;
-
public class GhostsActionTest {
@Rule
@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 {
@Before
public void setUp() {
componentDao = dbClient.componentDao();
- db.truncateTables();
ws = new WsTester(new ProjectsWs(new ProvisionedAction(dbClient, userSessionRule)));
}
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;
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");
@Before
public void setUp() {
- dbTester.truncateTables();
-
xoo1 = LanguageTesting.newLanguage("xoo1");
xoo2 = LanguageTesting.newLanguage("xoo2");
public void before() {
backuper = mock(QProfileBackuper.class);
- db.truncateTables();
-
ProfileExporter exporter1 = newExporter("polop");
ProfileExporter exporter2 = newExporter("palap");
@Before
public void setUp() {
- dbTester.truncateTables();
dbClient = new DbClient(dbTester.database(), dbTester.myBatis(),
new QualityProfileDao(dbTester.myBatis(), system2),
new ComponentDao(),
@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);
@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);
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;
.setCreatedAt(2000000000000L)
.setUpdatedAt(2100000000000L);
- @Before
- public void setUp() {
- dbTester.truncateTables();
- }
-
@Test
public void iterator_over_one_rule() {
dbClient.ruleDao().insert(dbSession, templateRule);
@Before
public void before() {
- db.truncateTables();
DbClient dbClient = db.getDbClient();
tester = new WsTester(new SourcesWs(new HashAction(dbClient, userSessionRule, new ComponentFinder(dbClient))));
@Before
public void setUp() {
- dbTester.truncateTables();
-
htmlSourceDecorator = mock(HtmlSourceDecorator.class);
when(htmlSourceDecorator.getDecoratedSourceAsHtml(anyString(), anyString(), anyString())).then(new Answer<String>() {
@Override
@Before
public void setUp() {
- dbTester.truncateTables();
tester = new WsTester(
new SourcesWs(new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()), userSessionRule, new ComponentFinder(dbClient))));
}
@Test
public void insert_core_metrics() {
- dbTester.truncateTables();
-
RegisterMetrics register = new RegisterMetrics(dbClient);
register.start();
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;
@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>() {
@Before
public void before() {
- dbTester.truncateTables();
-
userDao = new UserDao(dbTester.myBatis(), mock(System2.class));
dashboardDao = new DashboardDao(dbTester.myBatis());
activeDashboardDao = new ActiveDashboardDao(dbTester.myBatis());
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;
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");
@Before
public void setUp() {
- dbTester.truncateTables();
-
System2 system2 = new System2();
UserDao userDao = new UserDao(dbTester.myBatis(), system2);
GroupDao groupDao = new GroupDao(system2);
@Override
protected void before() throws Throwable {
db.start();
- truncateTables();
+ db.truncateTables();
}
@Override
getSession().commit();
}
- public void truncateTables() {
- db.truncateTables();
- }
-
public DbClient getDbClient() {
if (client == null) {
TransientPicoContainer ioc = new TransientPicoContainer();
*/
package org.sonar.db.component;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.resources.Qualifiers;
ResourceIndexDao underTest = dbTester.getDbClient().componentIndexDao();
- @Before
- public void setUp() throws Exception {
- dbTester.truncateTables();
- }
-
@Test
public void shouldIndexResource() {
dbTester.prepareDbUnit(getClass(), "shouldIndexResource.xml");
@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());
@Test
public void insert() {
- dbTester.truncateTables();
-
IssueChangeDto changeDto = new IssueChangeDto()
.setKey("EFGH")
.setUserLogin("emmerik")
*/
package org.sonar.db.issue;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @Before
- public void setUp() {
- dbTester.truncateTables();
- }
-
@Test
public void insert_diff() {
IssueChangeDto dto = new IssueChangeDto();
public void setUp() {
session = db.getSession();
underTest = new CustomMeasureDao();
- db.truncateTables();
}
@Test
@Before
public void createDao() {
- dbTester.truncateTables();
session = dbTester.myBatis().openSession(false);
underTest = new MetricDao();
}
@Test
public void should_insert_new_notification_queue() throws Exception {
- db.truncateTables();
-
NotificationQueueDto notificationQueueDto = NotificationQueueDto.toNotificationQueueDto(new Notification("email"));
dao.insert(Arrays.asList(notificationQueueDto));
@Test
public void should_count_notification_queue() {
- db.truncateTables();
-
NotificationQueueDto notificationQueueDto = NotificationQueueDto.toNotificationQueueDto(new Notification("email"));
assertThat(dao.count()).isEqualTo(0);
@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);
@Test
public void should_fail_on_unmatched_template() {
- db.truncateTables();
-
expectedException.expect(IllegalArgumentException.class);
underTest.selectPermissionTemplateWithPermissions(db.getSession(), "unmatched");
*/
@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
}
*/
@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
}
*/
@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
}
@Test
public void selectUsersByLogins_empty_logins() {
- db.truncateTables();
-
// no need to access db
Collection<UserDto> users = underTest.selectByLogins(Collections.<String>emptyList());
assertThat(users).isEmpty();
@Test
public void insert() {
- dbTester.truncateTables();
-
UserGroupDto userGroupDto = new UserGroupDto().setUserId(1L).setGroupId(2L);
dao.insert(dbTester.getSession(), userGroupDto);
dbTester.getSession().commit();
*/
package org.sonar.db.version.v51;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
@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 {
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;
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;
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;
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;
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;
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;
@Before
public void setUp() {
- db.truncateTables();
when(system2.now()).thenReturn(DateUtils.parseDate(NOW).getTime());
migration = new MigrateQualityGatesConditions(db.database(), system2);
}
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;
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;
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;
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;