diff options
Diffstat (limited to 'server')
103 files changed, 551 insertions, 1007 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java index 63198953463..118367b2706 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java @@ -38,12 +38,10 @@ import org.sonar.api.server.ServerSide; import org.sonar.api.utils.System2; import org.sonar.api.utils.internal.Uuids; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; import org.sonar.core.component.ComponentKeys; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; -import org.sonar.db.component.ResourceIndexDao; -import org.sonar.db.component.ResourceKeyUpdaterDao; +import org.sonar.db.component.ComponentDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; @@ -56,18 +54,13 @@ public class ComponentService { private final DbClient dbClient; - private final ResourceKeyUpdaterDao resourceKeyUpdaterDao; private final I18n i18n; - private final ResourceIndexDao resourceIndexDao; private final UserSession userSession; private final System2 system2; - public ComponentService(DbClient dbClient, ResourceKeyUpdaterDao resourceKeyUpdaterDao, I18n i18n, ResourceIndexDao resourceIndexDao, - UserSession userSession, System2 system2) { + public ComponentService(DbClient dbClient, I18n i18n, UserSession userSession, System2 system2) { this.dbClient = dbClient; - this.resourceKeyUpdaterDao = resourceKeyUpdaterDao; this.i18n = i18n; - this.resourceIndexDao = resourceIndexDao; this.userSession = userSession; this.system2 = system2; } @@ -115,7 +108,7 @@ public class ComponentService { try { ComponentDto projectOrModule = getByKey(session, projectOrModuleKey); userSession.checkProjectUuidPermission(UserRole.ADMIN, projectOrModule.projectUuid()); - resourceKeyUpdaterDao.updateKey(projectOrModule.getId(), newKey); + dbClient.resourceKeyUpdaterDao().updateKey(projectOrModule.getId(), newKey); session.commit(); session.commit(); @@ -129,7 +122,7 @@ public class ComponentService { try { ComponentDto project = getByKey(projectKey); userSession.checkProjectUuidPermission(UserRole.ADMIN, project.projectUuid()); - return resourceKeyUpdaterDao.checkModuleKeysBeforeRenaming(project.getId(), stringToReplace, replacementString); + return dbClient.resourceKeyUpdaterDao().checkModuleKeysBeforeRenaming(project.getId(), stringToReplace, replacementString); } finally { session.close(); } @@ -141,7 +134,7 @@ public class ComponentService { try { ComponentDto project = getByKey(session, projectKey); userSession.checkProjectUuidPermission(UserRole.ADMIN, project.projectUuid()); - resourceKeyUpdaterDao.bulkUpdateKey(session, project.getId(), stringToReplace, replacementString); + dbClient.resourceKeyUpdaterDao().bulkUpdateKey(session, project.getId(), stringToReplace, replacementString); session.commit(); } finally { session.close(); @@ -164,20 +157,19 @@ public class ComponentService { String uuid = Uuids.create(); ComponentDto component = new ComponentDto() - .setUuid(uuid) - .setModuleUuid(null) - .setModuleUuidPath(ComponentDto.MODULE_UUID_PATH_SEP + uuid + ComponentDto.MODULE_UUID_PATH_SEP) - .setProjectUuid(uuid) - .setKey(keyWithBranch) - .setDeprecatedKey(keyWithBranch) - .setName(newComponent.name()) - .setLongName(newComponent.name()) - .setScope(Scopes.PROJECT) - .setQualifier(newComponent.qualifier()) - .setCreatedAt(new Date(system2.now())) - ; + .setUuid(uuid) + .setModuleUuid(null) + .setModuleUuidPath(ComponentDto.MODULE_UUID_PATH_SEP + uuid + ComponentDto.MODULE_UUID_PATH_SEP) + .setProjectUuid(uuid) + .setKey(keyWithBranch) + .setDeprecatedKey(keyWithBranch) + .setName(newComponent.name()) + .setLongName(newComponent.name()) + .setScope(Scopes.PROJECT) + .setQualifier(newComponent.qualifier()) + .setCreatedAt(new Date(system2.now())); dbClient.componentDao().insert(session, component); - resourceIndexDao.indexResource(session, component.getId()); + dbClient.componentIndexDao().indexResource(session, component.getId()); session.commit(); return component.key(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java index a9fa3ac1fc7..219ebfe9927 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java @@ -45,7 +45,7 @@ import static org.mockito.Mockito.when; public class ActivityServiceTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings())); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java index b8180f4cf25..1118bf96cc7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java @@ -20,6 +20,9 @@ package org.sonar.server.batch; +import java.io.ByteArrayInputStream; +import java.util.Arrays; +import javax.annotation.Nullable; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; @@ -32,10 +35,10 @@ import org.sonar.api.security.DefaultGroups; import org.sonar.api.utils.System2; import org.sonar.batch.protocol.Constants.Severity; import org.sonar.batch.protocol.input.BatchInput.ServerIssue; -import org.sonar.db.component.ComponentDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDao; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; @@ -53,11 +56,6 @@ import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; -import javax.annotation.Nullable; - -import java.io.ByteArrayInputStream; -import java.util.Arrays; - import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -70,7 +68,7 @@ public class IssuesActionTest { private final static String FILE_KEY = "Action.java"; @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings())); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceMediumTest.java deleted file mode 100644 index 42c77ff534a..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceMediumTest.java +++ /dev/null @@ -1,421 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.server.component; - -import java.util.Arrays; -import java.util.Map; -import org.assertj.core.api.Fail; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.security.DefaultGroups; -import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; -import org.sonar.core.permission.GlobalPermissions; -import org.sonar.db.DbSession; -import org.sonar.server.component.db.ComponentDao; -import org.sonar.server.db.DbClient; -import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.permission.InternalPermissionService; -import org.sonar.server.permission.PermissionChange; -import org.sonar.server.platform.Platform; -import org.sonar.server.tester.ServerTester; -import org.sonar.server.tester.UserSessionRule; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - -/** - * It's not possible to replace usage of ServerTester by DbTester because of the usage of {@link InternalPermissionService}. - * Maybe we should create a mock of the permission service ? - */ -public class ComponentServiceMediumTest { - - @ClassRule - public static ServerTester tester = new ServerTester(); - @Rule - public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester); - - DbClient db; - DbSession session; - ComponentService service; - - @Before - public void setUp() { - tester.clearDbAndIndexes(); - db = tester.get(DbClient.class); - session = db.openSession(false); - service = tester.get(ComponentService.class); - } - - @After - public void after() { - session.close(); - } - - @Test - public void get_by_key() { - ComponentDto project = createProject("sample:root"); - assertThat(service.getByKey(project.getKey())).isNotNull(); - } - - @Test - public void get_nullable_by_key() { - ComponentDto project = createProject("sample:root"); - assertThat(service.getNullableByKey(project.getKey())).isNotNull(); - assertThat(service.getNullableByKey("unknown")).isNull(); - } - - @Test - public void get_by_uuid() { - ComponentDto project = createProject("sample:root"); - assertThat(service.getByUuid(project.uuid())).isNotNull(); - } - - @Test - public void get_nullable_by_uuid() { - ComponentDto project = createProject("sample:root"); - assertThat(service.getNullableByUuid(project.uuid())).isNotNull(); - assertThat(service.getNullableByUuid("unknown")).isNull(); - } - - @Test - public void update_project_key() { - ComponentDto project = createProject("sample:root"); - ComponentDto file = ComponentTesting.newFileDto(project).setKey("sample:root:src/File.xoo"); - tester.get(ComponentDao.class).insert(session, file); - - session.commit(); - - userSessionRule.login("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid()); - service.updateKey(project.key(), "sample2:root"); - session.commit(); - - // Check project key has been updated - assertThat(service.getNullableByKey(project.key())).isNull(); - assertThat(service.getNullableByKey("sample2:root")).isNotNull(); - - // Check file key has been updated - assertThat(service.getNullableByKey(file.key())).isNull(); - assertThat(service.getNullableByKey("sample2:root:src/File.xoo")).isNotNull(); - } - - @Test - public void update_module_key() { - ComponentDto project = createProject("sample:root"); - ComponentDto module = ComponentTesting.newModuleDto(project).setKey("sample:root:module"); - tester.get(ComponentDao.class).insert(session, module); - - ComponentDto file = ComponentTesting.newFileDto(module).setKey("sample:root:module:src/File.xoo"); - tester.get(ComponentDao.class).insert(session, file); - - session.commit(); - - userSessionRule.login("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid()); - service.updateKey(module.key(), "sample:root2:module"); - session.commit(); - - // Project key has not changed - assertThat(service.getNullableByKey(project.key())).isNotNull(); - - // Check module key has been updated - assertThat(service.getNullableByKey(module.key())).isNull(); - assertThat(service.getNullableByKey("sample:root2:module")).isNotNull(); - - // Check file key has been updated - assertThat(service.getNullableByKey(file.key())).isNull(); - assertThat(service.getNullableByKey("sample:root2:module:src/File.xoo")).isNotNull(); - } - - @Test - public void update_provisioned_project_key() { - ComponentDto provisionedProject = ComponentTesting.newProjectDto().setKey("provisionedProject"); - tester.get(ComponentDao.class).insert(session, provisionedProject); - - session.commit(); - - userSessionRule.login("john").addProjectUuidPermissions(UserRole.ADMIN, provisionedProject.uuid()); - service.updateKey(provisionedProject.key(), "provisionedProject2"); - session.commit(); - - // Check project key has been updated - assertThat(service.getNullableByKey(provisionedProject.key())).isNull(); - assertThat(service.getNullableByKey("provisionedProject2")).isNotNull(); - } - - @Test(expected = ForbiddenException.class) - public void fail_to_update_project_key_without_admin_permission() { - ComponentDto project = createProject("sample:root"); - userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid()); - service.updateKey(project.key(), "sample2:root"); - } - - @Test - public void check_module_keys_before_renaming() { - ComponentDto project = createProject("sample:root"); - ComponentDto module = ComponentTesting.newModuleDto(project).setKey("sample:root:module"); - tester.get(ComponentDao.class).insert(session, module); - - ComponentDto file = ComponentTesting.newFileDto(module).setKey("sample:root:module:src/File.xoo"); - tester.get(ComponentDao.class).insert(session, file); - - session.commit(); - - userSessionRule.login("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid()); - Map<String, String> result = service.checkModuleKeysBeforeRenaming(project.key(), "sample", "sample2"); - - assertThat(result).hasSize(2); - assertThat(result.get("sample:root")).isEqualTo("sample2:root"); - assertThat(result.get("sample:root:module")).isEqualTo("sample2:root:module"); - } - - @Test - public void check_module_keys_before_renaming_return_duplicate_key() { - ComponentDto project = createProject("sample:root"); - ComponentDto module = ComponentTesting.newModuleDto(project).setKey("sample:root:module"); - tester.get(ComponentDao.class).insert(session, module); - - ComponentDto module2 = ComponentTesting.newModuleDto(project).setKey("foo:module"); - tester.get(ComponentDao.class).insert(session, module2); - - session.commit(); - - userSessionRule.login("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid()); - Map<String, String> result = service.checkModuleKeysBeforeRenaming(project.key(), "sample:root", "foo"); - - assertThat(result).hasSize(2); - assertThat(result.get("sample:root")).isEqualTo("foo"); - assertThat(result.get("sample:root:module")).isEqualTo("#duplicate_key#"); - } - - @Test(expected = ForbiddenException.class) - public void fail_to_check_module_keys_before_renaming_without_admin_permission() { - ComponentDto project = createProject("sample:root"); - userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid()); - service.checkModuleKeysBeforeRenaming(project.key(), "sample", "sample2"); - } - - @Test - public void bulk_update_project_key() { - ComponentDto project = createProject("sample:root"); - ComponentDto module = ComponentTesting.newModuleDto(project).setKey("sample:root:module"); - tester.get(ComponentDao.class).insert(session, module); - - ComponentDto file = ComponentTesting.newFileDto(module).setKey("sample:root:module:src/File.xoo"); - tester.get(ComponentDao.class).insert(session, file); - - session.commit(); - - userSessionRule.login("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid()); - service.bulkUpdateKey(project.key(), "sample", "sample2"); - session.commit(); - - // Check project key has been updated - assertThat(service.getNullableByKey(project.key())).isNull(); - assertThat(service.getNullableByKey("sample2:root")).isNotNull(); - - // Check module key has been updated - assertThat(service.getNullableByKey(module.key())).isNull(); - assertThat(service.getNullableByKey("sample2:root:module")).isNotNull(); - - // Check file key has been updated - assertThat(service.getNullableByKey(file.key())).isNull(); - assertThat(service.getNullableByKey("sample2:root:module:src/File.xoo")).isNotNull(); - } - - @Test - public void bulk_update_provisioned_project_key() { - ComponentDto provisionedProject = ComponentTesting.newProjectDto().setKey("provisionedProject"); - tester.get(ComponentDao.class).insert(session, provisionedProject); - - session.commit(); - - userSessionRule.login("john").addProjectUuidPermissions(UserRole.ADMIN, provisionedProject.uuid()); - service.bulkUpdateKey(provisionedProject.key(), "provisionedProject", "provisionedProject2"); - session.commit(); - - // Check project key has been updated - assertThat(service.getNullableByKey(provisionedProject.key())).isNull(); - assertThat(service.getNullableByKey("provisionedProject2")).isNotNull(); - } - - @Test(expected = ForbiddenException.class) - public void fail_to_bulk_update_project_key_without_admin_permission() { - ComponentDto project = createProject("sample:root"); - userSessionRule.login("john").addProjectPermissions(UserRole.USER, project.key()); - service.bulkUpdateKey("sample:root", "sample", "sample2"); - } - - @Test - public void create_project() { - executeStartupTasksToCreateDefaultPermissionTemplate(); - userSessionRule.login("john").setGlobalPermissions(GlobalPermissions.PROVISIONING); - - String key = service.create(NewComponent.create("struts", "Struts project")); - - ComponentDto project = service.getNullableByKey(key); - assertThat(project.key()).isEqualTo("struts"); - assertThat(project.deprecatedKey()).isEqualTo("struts"); - assertThat(project.uuid()).isNotNull(); - assertThat(project.projectUuid()).isEqualTo(project.uuid()); - assertThat(project.moduleUuid()).isNull(); - assertThat(project.moduleUuidPath()).isEqualTo("." + project.uuid() + "."); - assertThat(project.name()).isEqualTo("Struts project"); - assertThat(project.longName()).isEqualTo("Struts project"); - assertThat(project.scope()).isEqualTo("PRJ"); - assertThat(project.qualifier()).isEqualTo("TRK"); - assertThat(project.getCreatedAt()).isNotNull(); - } - - @Test - public void create_new_project_with_branch() { - executeStartupTasksToCreateDefaultPermissionTemplate(); - userSessionRule.login("john").setGlobalPermissions(GlobalPermissions.PROVISIONING); - - String key = service.create(NewComponent.create("struts", "Struts project").setBranch("origin/branch")); - - ComponentDto project = service.getNullableByKey(key); - assertThat(project.key()).isEqualTo("struts:origin/branch"); - assertThat(project.deprecatedKey()).isEqualTo("struts:origin/branch"); - } - - @Test - public void create_view() { - executeStartupTasksToCreateDefaultPermissionTemplate(); - userSessionRule.login("john").setGlobalPermissions(GlobalPermissions.PROVISIONING); - - String key = service.create(NewComponent.create("all-project", "All Projects").setQualifier(Qualifiers.VIEW)); - - ComponentDto project = service.getNullableByKey(key); - assertThat(project.key()).isEqualTo("all-project"); - assertThat(project.deprecatedKey()).isEqualTo("all-project"); - assertThat(project.uuid()).isNotNull(); - assertThat(project.projectUuid()).isEqualTo(project.uuid()); - assertThat(project.moduleUuid()).isNull(); - assertThat(project.moduleUuidPath()).isEqualTo("." + project.uuid() + "."); - assertThat(project.name()).isEqualTo("All Projects"); - assertThat(project.longName()).isEqualTo("All Projects"); - assertThat(project.scope()).isEqualTo("PRJ"); - assertThat(project.qualifier()).isEqualTo("VW"); - assertThat(project.getCreatedAt()).isNotNull(); - } - - @Test - public void fail_to_create_new_component_on_invalid_key() { - userSessionRule.login("john").setGlobalPermissions(GlobalPermissions.PROVISIONING); - - try { - service.create(NewComponent.create("struts?parent", "Struts project")); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage( - "Malformed key for Project: struts?parent. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit."); - } - } - - @Test - public void fail_to_create_new_component_on_invalid_branch() { - userSessionRule.login("john").setGlobalPermissions(GlobalPermissions.PROVISIONING); - - try { - service.create(NewComponent.create("struts", "Struts project").setBranch("origin?branch")); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage( - "Malformed branch for Project: origin?branch. Allowed characters are alphanumeric, '-', '_', '.' and '/', with at least one non-digit."); - } - } - - @Test - public void fail_to_create_new_component_if_key_already_exists() { - userSessionRule.login("john").setGlobalPermissions(GlobalPermissions.PROVISIONING); - - ComponentDto project = ComponentTesting.newProjectDto().setKey("struts"); - tester.get(ComponentDao.class).insert(session, project); - session.commit(); - - try { - service.create(NewComponent.create("struts", "Struts project")); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("Could not create Project, key already exists: struts"); - } - } - - @Test - public void should_return_project_uuids() { - ComponentDto project = createProject("sample:root"); - String moduleKey = "sample:root:module"; - ComponentDto module = ComponentTesting.newModuleDto(project).setKey(moduleKey); - tester.get(ComponentDao.class).insert(session, module); - String fileKey = "sample:root:module:Foo.xoo"; - ComponentDto file = ComponentTesting.newFileDto(module).setKey(fileKey); - tester.get(ComponentDao.class).insert(session, file); - session.commit(); - - assertThat(service.componentUuids(Arrays.asList(moduleKey, fileKey))).hasSize(2); - assertThat(service.componentUuids(null)).isEmpty(); - assertThat(service.componentUuids(Arrays.<String>asList())).isEmpty(); - } - - @Test - public void should_fail_on_components_not_found() { - String moduleKey = "sample:root:module"; - String fileKey = "sample:root:module:Foo.xoo"; - - try { - service.componentUuids(Arrays.asList(moduleKey, fileKey)); - Fail.fail("Should throw NotFoundException"); - } catch (NotFoundException notFound) { - assertThat(notFound.getMessage()).contains(moduleKey).contains(fileKey); - } - } - - @Test - public void should_fail_silently_on_components_not_found_if_told_so() { - String moduleKey = "sample:root:module"; - String fileKey = "sample:root:module:Foo.xoo"; - - assertThat(service.componentUuids(session, Arrays.asList(moduleKey, fileKey), true)).isEmpty(); - } - - private ComponentDto createProject(String key) { - ComponentDto project = ComponentTesting.newProjectDto().setKey("sample:root"); - tester.get(ComponentDao.class).insert(session, project); - session.commit(); - - // project can be seen by anyone - userSessionRule.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); - tester.get(InternalPermissionService.class).addPermission(new PermissionChange().setComponentKey(project.getKey()).setGroup(DefaultGroups.ANYONE).setPermission(UserRole.USER)); - - return project; - } - - private void executeStartupTasksToCreateDefaultPermissionTemplate() { - tester.get(Platform.class).executeStartupTasks(); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java index 4a70f92dd24..0a7eec4a332 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.Locale; import java.util.Map; import org.assertj.core.api.Fail; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -33,10 +32,10 @@ import org.sonar.api.i18n.I18n; import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ResourceIndexDao; import org.sonar.db.component.ResourceKeyUpdaterDao; import org.sonar.server.component.db.ComponentDao; @@ -55,32 +54,28 @@ import static org.mockito.Mockito.when; @Category(DbTests.class) public class ComponentServiceTest { + System2 system2 = System2.INSTANCE; + @Rule - public DbTester dbTester = new DbTester(); - + public DbTester dbTester = DbTester.create(system2); + @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); DbClient dbClient; - DbSession session; + DbSession session = dbTester.getSession(); I18n i18n = mock(I18n.class); ComponentService service; @Before public void setUp() { dbTester.truncateTables(); - dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new ComponentDao()); - session = dbClient.openSession(false); + dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new ComponentDao(), new ResourceKeyUpdaterDao(dbTester.myBatis()), + new ResourceIndexDao(dbTester.myBatis(), system2)); when(i18n.message(Locale.getDefault(), "qualifier.TRK", "Project")).thenReturn("Project"); - service = new ComponentService(dbClient, new ResourceKeyUpdaterDao(dbTester.myBatis()), i18n, new ResourceIndexDao(dbTester.myBatis(), mock(System2.class)), - userSessionRule, System2.INSTANCE); - } - - @After - public void after() { - session.close(); + service = new ComponentService(dbClient, i18n, userSessionRule, System2.INSTANCE); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java index 597e5a68a69..d257fc854a4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java @@ -22,14 +22,12 @@ package org.sonar.server.component.db; import java.util.Collections; import java.util.List; -import org.junit.After; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.sonar.api.utils.DateUtils; -import org.sonar.db.DbSession; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.FilePathWithHashDto; @@ -46,29 +44,16 @@ public class ComponentDaoTest { @Rule public ExpectedException thrown = ExpectedException.none(); - ComponentDao sut; - @Rule - public DbTester db = new DbTester(); - - DbSession session; + public DbTester db = DbTester.create(System2.INSTANCE); - @Before - public void createDao() { - session = db.myBatis().openSession(false); - sut = new ComponentDao(); - } - - @After - public void tearDown() { - session.close(); - } + ComponentDao sut = new ComponentDao(); @Test public void get_by_uuid() { loadBasicDataInDatabase(); - ComponentDto result = sut.selectNullableByUuid(session, "KLMN"); + ComponentDto result = sut.selectNullableByUuid(db.getSession(), "KLMN"); assertThat(result).isNotNull(); assertThat(result.uuid()).isEqualTo("KLMN"); assertThat(result.moduleUuid()).isEqualTo("EFGH"); @@ -93,7 +78,7 @@ public class ComponentDaoTest { public void get_by_uuid_on_technical_project_copy() { loadBasicDataInDatabase(); - ComponentDto result = sut.selectNullableByUuid(session, "STUV"); + ComponentDto result = sut.selectNullableByUuid(db.getSession(), "STUV"); assertThat(result).isNotNull(); assertThat(result.uuid()).isEqualTo("STUV"); assertThat(result.moduleUuid()).isEqualTo("OPQR"); @@ -114,7 +99,7 @@ public class ComponentDaoTest { public void get_by_uuid_on_disabled_component() { loadBasicDataInDatabase(); - ComponentDto result = sut.selectNullableByUuid(session, "DCBA"); + ComponentDto result = sut.selectNullableByUuid(db.getSession(), "DCBA"); assertThat(result).isNotNull(); assertThat(result.isEnabled()).isFalse(); } @@ -125,14 +110,14 @@ public class ComponentDaoTest { loadBasicDataInDatabase(); - sut.selectByUuid(session, "unknown"); + sut.selectByUuid(db.getSession(), "unknown"); } @Test public void get_by_key() { loadBasicDataInDatabase(); - ComponentDto result = sut.selectNullableByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java"); + ComponentDto result = sut.selectNullableByKey(db.getSession(), "org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(result).isNotNull(); assertThat(result.key()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(result.path()).isEqualTo("src/org/struts/RequestContext.java"); @@ -143,7 +128,7 @@ public class ComponentDaoTest { assertThat(result.language()).isEqualTo("java"); assertThat(result.parentProjectId()).isEqualTo(2); - assertThat(sut.selectNullableByKey(session, "unknown")).isNull(); + assertThat(sut.selectNullableByKey(db.getSession(), "unknown")).isNull(); } @Test @@ -152,14 +137,14 @@ public class ComponentDaoTest { loadBasicDataInDatabase(); - sut.selectByUuid(session, "unknown"); + sut.selectByUuid(db.getSession(), "unknown"); } @Test public void get_by_key_on_disabled_component() { loadBasicDataInDatabase(); - ComponentDto result = sut.selectByKey(session, "org.disabled.project"); + ComponentDto result = sut.selectByKey(db.getSession(), "org.disabled.project"); assertThat(result).isNotNull(); assertThat(result.isEnabled()).isFalse(); } @@ -168,7 +153,7 @@ public class ComponentDaoTest { public void get_by_key_on_a_root_project() { loadBasicDataInDatabase(); - ComponentDto result = sut.selectByKey(session, "org.struts:struts"); + ComponentDto result = sut.selectByKey(db.getSession(), "org.struts:struts"); assertThat(result).isNotNull(); assertThat(result.key()).isEqualTo("org.struts:struts"); assertThat(result.deprecatedKey()).isEqualTo("org.struts:struts"); @@ -187,7 +172,7 @@ public class ComponentDaoTest { public void get_by_keys() { loadBasicDataInDatabase(); - List<ComponentDto> results = sut.selectByKeys(session, Collections.singletonList("org.struts:struts-core:src/org/struts/RequestContext.java")); + List<ComponentDto> results = sut.selectByKeys(db.getSession(), Collections.singletonList("org.struts:struts-core:src/org/struts/RequestContext.java")); assertThat(results).hasSize(1); ComponentDto result = results.get(0); @@ -201,14 +186,14 @@ public class ComponentDaoTest { assertThat(result.language()).isEqualTo("java"); assertThat(result.parentProjectId()).isEqualTo(2); - assertThat(sut.selectByKeys(session, Collections.singletonList("unknown"))).isEmpty(); + assertThat(sut.selectByKeys(db.getSession(), Collections.singletonList("unknown"))).isEmpty(); } @Test public void get_by_ids() { loadBasicDataInDatabase(); - List<ComponentDto> results = sut.selectByIds(session, newArrayList(4L)); + List<ComponentDto> results = sut.selectByIds(db.getSession(), newArrayList(4L)); assertThat(results).hasSize(1); ComponentDto result = results.get(0); @@ -222,14 +207,14 @@ public class ComponentDaoTest { assertThat(result.language()).isEqualTo("java"); assertThat(result.parentProjectId()).isEqualTo(2); - assertThat(sut.selectByIds(session, newArrayList(555L))).isEmpty(); + assertThat(sut.selectByIds(db.getSession(), newArrayList(555L))).isEmpty(); } @Test public void get_by_uuids() { loadBasicDataInDatabase(); - List<ComponentDto> results = sut.selectByUuids(session, newArrayList("KLMN")); + List<ComponentDto> results = sut.selectByUuids(db.getSession(), newArrayList("KLMN")); assertThat(results).hasSize(1); ComponentDto result = results.get(0); @@ -247,14 +232,14 @@ public class ComponentDaoTest { assertThat(result.scope()).isEqualTo("FIL"); assertThat(result.language()).isEqualTo("java"); - assertThat(sut.selectByUuids(session, newArrayList("unknown"))).isEmpty(); + assertThat(sut.selectByUuids(db.getSession(), newArrayList("unknown"))).isEmpty(); } @Test public void get_by_uuids_on_removed_components() { loadBasicDataInDatabase(); - List<ComponentDto> results = sut.selectByUuids(session, newArrayList("DCBA")); + List<ComponentDto> results = sut.selectByUuids(db.getSession(), newArrayList("DCBA")); assertThat(results).hasSize(1); ComponentDto result = results.get(0); @@ -266,25 +251,25 @@ public class ComponentDaoTest { public void select_existing_uuids() { loadBasicDataInDatabase(); - List<String> results = sut.selectExistingUuids(session, newArrayList("KLMN")); + List<String> results = sut.selectExistingUuids(db.getSession(), newArrayList("KLMN")); assertThat(results).containsOnly("KLMN"); - assertThat(sut.selectExistingUuids(session, newArrayList("KLMN", "unknown"))).hasSize(1); - assertThat(sut.selectExistingUuids(session, newArrayList("unknown"))).isEmpty(); + assertThat(sut.selectExistingUuids(db.getSession(), newArrayList("KLMN", "unknown"))).hasSize(1); + assertThat(sut.selectExistingUuids(db.getSession(), newArrayList("unknown"))).isEmpty(); } @Test public void get_by_id() { loadBasicDataInDatabase(); - assertThat(sut.selectById(4L, session)).isNotNull(); + assertThat(sut.selectById(4L, db.getSession())).isNotNull(); } @Test public void get_by_id_on_disabled_component() { loadBasicDataInDatabase(); - ComponentDto result = sut.selectNullableById(10L, session); + ComponentDto result = sut.selectNullableById(10L, db.getSession()); assertThat(result).isNotNull(); assertThat(result.isEnabled()).isFalse(); } @@ -293,23 +278,23 @@ public class ComponentDaoTest { public void fail_to_get_by_id_when_project_not_found() { loadBasicDataInDatabase(); - sut.selectById(111L, session); + sut.selectById(111L, db.getSession()); } @Test public void get_nullable_by_id() { loadBasicDataInDatabase(); - assertThat(sut.selectNullableById(4L, session)).isNotNull(); - assertThat(sut.selectNullableById(111L, session)).isNull(); + assertThat(sut.selectNullableById(4L, db.getSession())).isNotNull(); + assertThat(sut.selectNullableById(111L, db.getSession())).isNull(); } @Test public void count_by_id() { loadBasicDataInDatabase(); - assertThat(sut.existsById(4L, session)).isTrue(); - assertThat(sut.existsById(111L, session)).isFalse(); + assertThat(sut.existsById(4L, db.getSession())).isTrue(); + assertThat(sut.existsById(111L, db.getSession())).isFalse(); } @Test @@ -317,34 +302,34 @@ public class ComponentDaoTest { db.prepareDbUnit(getClass(), "multi-modules.xml"); // Sub project of a file - List<ComponentDto> results = sut.selectSubProjectsByComponentUuids(session, newArrayList("HIJK")); + List<ComponentDto> results = sut.selectSubProjectsByComponentUuids(db.getSession(), newArrayList("HIJK")); assertThat(results).hasSize(1); assertThat(results.get(0).getKey()).isEqualTo("org.struts:struts-data"); // Sub project of a directory - results = sut.selectSubProjectsByComponentUuids(session, newArrayList("GHIJ")); + results = sut.selectSubProjectsByComponentUuids(db.getSession(), newArrayList("GHIJ")); assertThat(results).hasSize(1); assertThat(results.get(0).getKey()).isEqualTo("org.struts:struts-data"); // Sub project of a sub module - results = sut.selectSubProjectsByComponentUuids(session, newArrayList("FGHI")); + results = sut.selectSubProjectsByComponentUuids(db.getSession(), newArrayList("FGHI")); assertThat(results).hasSize(1); assertThat(results.get(0).getKey()).isEqualTo("org.struts:struts"); // Sub project of a module - results = sut.selectSubProjectsByComponentUuids(session, newArrayList("EFGH")); + results = sut.selectSubProjectsByComponentUuids(db.getSession(), newArrayList("EFGH")); assertThat(results).hasSize(1); assertThat(results.get(0).getKey()).isEqualTo("org.struts:struts"); // Sub project of a project - assertThat(sut.selectSubProjectsByComponentUuids(session, newArrayList("ABCD"))).isEmpty(); + assertThat(sut.selectSubProjectsByComponentUuids(db.getSession(), newArrayList("ABCD"))).isEmpty(); // SUb projects of a component and a sub module - assertThat(sut.selectSubProjectsByComponentUuids(session, newArrayList("HIJK", "FGHI"))).hasSize(2); + assertThat(sut.selectSubProjectsByComponentUuids(db.getSession(), newArrayList("HIJK", "FGHI"))).hasSize(2); - assertThat(sut.selectSubProjectsByComponentUuids(session, newArrayList("unknown"))).isEmpty(); + assertThat(sut.selectSubProjectsByComponentUuids(db.getSession(), newArrayList("unknown"))).isEmpty(); - assertThat(sut.selectSubProjectsByComponentUuids(session, Collections.<String>emptyList())).isEmpty(); + assertThat(sut.selectSubProjectsByComponentUuids(db.getSession(), Collections.<String>emptyList())).isEmpty(); } @Test @@ -352,20 +337,20 @@ public class ComponentDaoTest { db.prepareDbUnit(getClass(), "multi-modules.xml"); // From root project - List<ComponentDto> modules = sut.selectEnabledDescendantModules(session, "ABCD"); + List<ComponentDto> modules = sut.selectEnabledDescendantModules(db.getSession(), "ABCD"); assertThat(modules).extracting("uuid").containsOnly("ABCD", "EFGH", "FGHI"); // From module - modules = sut.selectEnabledDescendantModules(session, "EFGH"); + modules = sut.selectEnabledDescendantModules(db.getSession(), "EFGH"); assertThat(modules).extracting("uuid").containsOnly("EFGH", "FGHI"); // From sub module - modules = sut.selectEnabledDescendantModules(session, "FGHI"); + modules = sut.selectEnabledDescendantModules(db.getSession(), "FGHI"); assertThat(modules).extracting("uuid").containsOnly("FGHI"); // Folder - assertThat(sut.selectEnabledDescendantModules(session, "GHIJ")).isEmpty(); - assertThat(sut.selectEnabledDescendantModules(session, "unknown")).isEmpty(); + assertThat(sut.selectEnabledDescendantModules(db.getSession(), "GHIJ")).isEmpty(); + assertThat(sut.selectEnabledDescendantModules(db.getSession(), "unknown")).isEmpty(); } @Test @@ -373,15 +358,15 @@ public class ComponentDaoTest { db.prepareDbUnit(getClass(), "multi-modules.xml"); // From root project, disabled sub module is returned - List<ComponentDto> modules = sut.selectDescendantModules(session, "ABCD"); + List<ComponentDto> modules = sut.selectDescendantModules(db.getSession(), "ABCD"); assertThat(modules).extracting("uuid").containsOnly("ABCD", "EFGH", "FGHI", "IHGF"); // From module, disabled sub module is returned - modules = sut.selectDescendantModules(session, "EFGH"); + modules = sut.selectDescendantModules(db.getSession(), "EFGH"); assertThat(modules).extracting("uuid").containsOnly("EFGH", "FGHI", "IHGF"); // From removed sub module -> should not be returned - assertThat(sut.selectDescendantModules(session, "IHGF")).isEmpty(); + assertThat(sut.selectDescendantModules(db.getSession(), "IHGF")).isEmpty(); } @Test @@ -389,30 +374,30 @@ public class ComponentDaoTest { db.prepareDbUnit(getClass(), "select_module_files_tree.xml"); // From root project - List<FilePathWithHashDto> files = sut.selectEnabledDescendantFiles(session, "ABCD"); + List<FilePathWithHashDto> files = sut.selectEnabledDescendantFiles(db.getSession(), "ABCD"); assertThat(files).extracting("uuid").containsOnly("EFGHI", "HIJK"); assertThat(files).extracting("moduleUuid").containsOnly("EFGH", "FGHI"); assertThat(files).extracting("srcHash").containsOnly("srcEFGHI", "srcHIJK"); assertThat(files).extracting("path").containsOnly("src/org/struts/pom.xml", "src/org/struts/RequestContext.java"); // From module - files = sut.selectEnabledDescendantFiles(session, "EFGH"); + files = sut.selectEnabledDescendantFiles(db.getSession(), "EFGH"); assertThat(files).extracting("uuid").containsOnly("EFGHI", "HIJK"); assertThat(files).extracting("moduleUuid").containsOnly("EFGH", "FGHI"); assertThat(files).extracting("srcHash").containsOnly("srcEFGHI", "srcHIJK"); assertThat(files).extracting("path").containsOnly("src/org/struts/pom.xml", "src/org/struts/RequestContext.java"); // From sub module - files = sut.selectEnabledDescendantFiles(session, "FGHI"); + files = sut.selectEnabledDescendantFiles(db.getSession(), "FGHI"); assertThat(files).extracting("uuid").containsOnly("HIJK"); assertThat(files).extracting("moduleUuid").containsOnly("FGHI"); assertThat(files).extracting("srcHash").containsOnly("srcHIJK"); assertThat(files).extracting("path").containsOnly("src/org/struts/RequestContext.java"); // From directory - assertThat(sut.selectEnabledDescendantFiles(session, "GHIJ")).isEmpty(); + assertThat(sut.selectEnabledDescendantFiles(db.getSession(), "GHIJ")).isEmpty(); - assertThat(sut.selectEnabledDescendantFiles(session, "unknown")).isEmpty(); + assertThat(sut.selectEnabledDescendantFiles(db.getSession(), "unknown")).isEmpty(); } @Test @@ -420,68 +405,68 @@ public class ComponentDaoTest { db.prepareDbUnit(getClass(), "select_module_files_tree.xml"); // From root project - List<FilePathWithHashDto> files = sut.selectEnabledFilesFromProject(session, "ABCD"); + List<FilePathWithHashDto> files = sut.selectEnabledFilesFromProject(db.getSession(), "ABCD"); assertThat(files).extracting("uuid").containsOnly("EFGHI", "HIJK"); assertThat(files).extracting("moduleUuid").containsOnly("EFGH", "FGHI"); assertThat(files).extracting("srcHash").containsOnly("srcEFGHI", "srcHIJK"); assertThat(files).extracting("path").containsOnly("src/org/struts/pom.xml", "src/org/struts/RequestContext.java"); // From module - assertThat(sut.selectEnabledFilesFromProject(session, "EFGH")).isEmpty(); + assertThat(sut.selectEnabledFilesFromProject(db.getSession(), "EFGH")).isEmpty(); // From sub module - assertThat(sut.selectEnabledFilesFromProject(session, "FGHI")).isEmpty(); + assertThat(sut.selectEnabledFilesFromProject(db.getSession(), "FGHI")).isEmpty(); // From directory - assertThat(sut.selectEnabledFilesFromProject(session, "GHIJ")).isEmpty(); + assertThat(sut.selectEnabledFilesFromProject(db.getSession(), "GHIJ")).isEmpty(); - assertThat(sut.selectEnabledFilesFromProject(session, "unknown")).isEmpty(); + assertThat(sut.selectEnabledFilesFromProject(db.getSession(), "unknown")).isEmpty(); } @Test public void select_components_from_project() { db.prepareDbUnit(getClass(), "multi-modules.xml"); - List<ComponentDto> components = sut.selectComponentsFromProjectKey(session, "org.struts:struts"); + List<ComponentDto> components = sut.selectComponentsFromProjectKey(db.getSession(), "org.struts:struts"); assertThat(components).hasSize(5); - assertThat(sut.selectComponentsFromProjectKey(session, "UNKNOWN")).isEmpty(); + assertThat(sut.selectComponentsFromProjectKey(db.getSession(), "UNKNOWN")).isEmpty(); } @Test public void select_modules_from_project() { db.prepareDbUnit(getClass(), "multi-modules.xml"); - List<ComponentDto> components = sut.selectModulesFromProjectKey(session, "org.struts:struts"); + List<ComponentDto> components = sut.selectModulesFromProjectKey(db.getSession(), "org.struts:struts"); assertThat(components).hasSize(3); - assertThat(sut.selectModulesFromProjectKey(session, "UNKNOWN")).isEmpty(); + assertThat(sut.selectModulesFromProjectKey(db.getSession(), "UNKNOWN")).isEmpty(); } @Test public void select_views_and_sub_views() { db.prepareDbUnit(getClass(), "shared_views.xml"); - assertThat(sut.selectAllViewsAndSubViews(session)).extracting("uuid").containsOnly("ABCD", "EFGH", "FGHI", "IJKL"); - assertThat(sut.selectAllViewsAndSubViews(session)).extracting("projectUuid").containsOnly("ABCD", "EFGH", "IJKL"); + assertThat(sut.selectAllViewsAndSubViews(db.getSession())).extracting("uuid").containsOnly("ABCD", "EFGH", "FGHI", "IJKL"); + assertThat(sut.selectAllViewsAndSubViews(db.getSession())).extracting("projectUuid").containsOnly("ABCD", "EFGH", "IJKL"); } @Test public void select_projects_from_view() { db.prepareDbUnit(getClass(), "shared_views.xml"); - assertThat(sut.selectProjectsFromView(session, "ABCD", "ABCD")).containsOnly("JKLM"); - assertThat(sut.selectProjectsFromView(session, "EFGH", "EFGH")).containsOnly("KLMN", "JKLM"); - assertThat(sut.selectProjectsFromView(session, "FGHI", "EFGH")).containsOnly("JKLM"); - assertThat(sut.selectProjectsFromView(session, "IJKL", "IJKL")).isEmpty(); - assertThat(sut.selectProjectsFromView(session, "Unknown", "Unknown")).isEmpty(); + assertThat(sut.selectProjectsFromView(db.getSession(), "ABCD", "ABCD")).containsOnly("JKLM"); + assertThat(sut.selectProjectsFromView(db.getSession(), "EFGH", "EFGH")).containsOnly("KLMN", "JKLM"); + assertThat(sut.selectProjectsFromView(db.getSession(), "FGHI", "EFGH")).containsOnly("JKLM"); + assertThat(sut.selectProjectsFromView(db.getSession(), "IJKL", "IJKL")).isEmpty(); + assertThat(sut.selectProjectsFromView(db.getSession(), "Unknown", "Unknown")).isEmpty(); } @Test public void select_provisioned_projects() { db.prepareDbUnit(getClass(), "select_provisioned_projects.xml"); - List<ComponentDto> result = sut.selectProvisionedProjects(session, new SearchOptions(), null); + List<ComponentDto> result = sut.selectProvisionedProjects(db.getSession(), new SearchOptions(), null); ComponentDto project = result.get(0); assertThat(result).hasSize(1); @@ -492,7 +477,7 @@ public class ComponentDaoTest { public void count_provisioned_projects() { db.prepareDbUnit(getClass(), "select_provisioned_projects.xml"); - int numberOfProjects = sut.countProvisionedProjects(session, null); + int numberOfProjects = sut.countProvisionedProjects(db.getSession(), null); assertThat(numberOfProjects).isEqualTo(1); } @@ -501,11 +486,11 @@ public class ComponentDaoTest { public void select_ghost_projects() { db.prepareDbUnit(getClass(), "select_ghost_projects.xml"); - List<ComponentDto> result = sut.selectGhostProjects(session, null, new SearchOptions()); + List<ComponentDto> result = sut.selectGhostProjects(db.getSession(), null, new SearchOptions()); assertThat(result).hasSize(1); assertThat(result.get(0).key()).isEqualTo("org.ghost.project"); - assertThat(sut.countGhostProjects(session, null)).isEqualTo(1); + assertThat(sut.countGhostProjects(db.getSession(), null)).isEqualTo(1); } @Test @@ -533,8 +518,8 @@ public class ComponentDaoTest { .setCreatedAt(DateUtils.parseDate("2014-06-18")) .setAuthorizationUpdatedAt(123456789L); - sut.insert(session, componentDto); - session.commit(); + sut.insert(db.getSession(), componentDto); + db.getSession().commit(); assertThat(componentDto.getId()).isNotNull(); db.assertDbUnit(getClass(), "insert-result.xml", "projects"); @@ -562,8 +547,8 @@ public class ComponentDaoTest { .setCreatedAt(DateUtils.parseDate("2014-06-18")) .setAuthorizationUpdatedAt(123456789L); - sut.insert(session, componentDto); - session.commit(); + sut.insert(db.getSession(), componentDto); + db.getSession().commit(); assertThat(componentDto.getId()).isNotNull(); db.assertDbUnit(getClass(), "insert_disabled_component-result.xml", "projects"); @@ -592,8 +577,8 @@ public class ComponentDaoTest { .setEnabled(false) .setAuthorizationUpdatedAt(12345678910L); - sut.update(session, componentDto); - session.commit(); + sut.update(db.getSession(), componentDto); + db.getSession().commit(); db.assertDbUnit(getClass(), "update-result.xml", "projects"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java index 5eb1f0ecdc5..8de78371afa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java @@ -44,7 +44,7 @@ import static org.mockito.Mockito.mock; public class SearchActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java index ffd733514de..06138e1122d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java @@ -20,6 +20,9 @@ package org.sonar.server.computation; +import java.io.File; +import java.io.InputStream; +import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.After; @@ -30,19 +33,15 @@ import org.junit.experimental.categories.Category; import org.junit.rules.TemporaryFolder; import org.sonar.api.config.Settings; import org.sonar.api.utils.System2; -import org.sonar.db.compute.AnalysisReportDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.compute.AnalysisReportDao; +import org.sonar.db.compute.AnalysisReportDto; import org.sonar.process.ProcessProperties; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.compute.AnalysisReportDao; import org.sonar.server.db.DbClient; import org.sonar.test.DbTests; -import java.io.File; -import java.io.InputStream; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -55,7 +54,7 @@ public class ReportQueueTest { static final long NOW = 1_500_000_000_000L; @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient; DbSession session; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/activity/ActivityManagerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/activity/ActivityManagerTest.java index f580fd25d79..69457635125 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/activity/ActivityManagerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/activity/ActivityManagerTest.java @@ -24,8 +24,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.mockito.ArgumentCaptor; -import org.sonar.db.compute.AnalysisReportDto; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; +import org.sonar.db.compute.AnalysisReportDto; import org.sonar.server.activity.Activity; import org.sonar.server.activity.ActivityService; import org.sonar.server.component.db.ComponentDao; @@ -39,7 +40,7 @@ import static org.mockito.Mockito.verify; @Category(DbTests.class) public class ActivityManagerTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); ArgumentCaptor<Activity> activityArgumentCaptor = ArgumentCaptor.forClass(Activity.class); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ProjectSettingsRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ProjectSettingsRepositoryTest.java index c31e0bac01f..2e988605afd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ProjectSettingsRepositoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ProjectSettingsRepositoryTest.java @@ -26,9 +26,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.config.Settings; -import org.sonar.db.component.ComponentDto; +import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; import org.sonar.db.property.PropertiesDao; import org.sonar.db.property.PropertyDto; import org.sonar.server.component.ComponentTesting; @@ -45,7 +46,7 @@ public class ProjectSettingsRepositoryTest { private static final String PROJECT_KEY = "PROJECT_KEY"; @Rule - public final DbTester dbTester = new DbTester(); + public final DbTester dbTester = DbTester.create(System2.INSTANCE); DbClient dbClient; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleCacheLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleCacheLoaderTest.java index f5953547541..4f59b661d83 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleCacheLoaderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/RuleCacheLoaderTest.java @@ -41,7 +41,7 @@ import static org.mockito.Mockito.mock; public class RuleCacheLoaderTest { @org.junit.Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @org.junit.Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java index 77257c56e08..8086cb67cd5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java @@ -36,13 +36,15 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.sonar.api.rule.RuleKey; +import org.sonar.api.utils.System2; import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.db.measure.MeasureDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.SnapshotDao; +import org.sonar.db.measure.MeasureDao; +import org.sonar.db.measure.MeasureDto; import org.sonar.db.rule.RuleDto; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.computation.batch.BatchReportReader; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.component.Component; @@ -52,7 +54,6 @@ import org.sonar.server.computation.metric.Metric; import org.sonar.server.computation.metric.MetricImpl; import org.sonar.server.computation.metric.MetricRepository; import org.sonar.server.db.DbClient; -import org.sonar.db.measure.MeasureDao; import org.sonar.server.metric.persistence.MetricDao; import static com.google.common.collect.FluentIterable.from; @@ -68,7 +69,7 @@ import static org.mockito.Mockito.when; @RunWith(DataProviderRunner.class) public class MeasureRepositoryImplTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricRepositoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricRepositoryImplTest.java index 424a7b90bb8..df55b7bc335 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricRepositoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricRepositoryImplTest.java @@ -24,6 +24,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.server.db.DbClient; import org.sonar.server.metric.persistence.MetricDao; @@ -37,7 +38,7 @@ public class MetricRepositoryImplTest { private static final long SOME_ID = 156; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public final ExpectedException expectedException = ExpectedException.none(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ApplyPermissionsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ApplyPermissionsStepTest.java index b7d36e46434..d652d346ff3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ApplyPermissionsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ApplyPermissionsStepTest.java @@ -32,13 +32,13 @@ import org.sonar.api.config.Settings; import org.sonar.api.security.DefaultGroups; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; +import org.sonar.db.DbSession; +import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ResourceDao; import org.sonar.db.permission.PermissionFacade; import org.sonar.db.permission.PermissionTemplateDao; import org.sonar.db.permission.PermissionTemplateDto; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; -import org.sonar.db.component.ResourceDao; import org.sonar.db.user.GroupRoleDto; import org.sonar.db.user.RoleDao; import org.sonar.server.component.ComponentTesting; @@ -65,7 +65,7 @@ public class ApplyPermissionsStepTest extends BaseStepTest { public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings())); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); @@ -88,7 +88,7 @@ public class ApplyPermissionsStepTest extends BaseStepTest { RoleDao roleDao = new RoleDao(); PermissionTemplateDao permissionTemplateDao = new PermissionTemplateDao(dbTester.myBatis(), System2.INSTANCE); - dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new ComponentDao(), roleDao, permissionTemplateDao); + dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new ComponentDao(), roleDao, permissionTemplateDao, new ResourceDao(dbTester.myBatis(), System2.INSTANCE)); dbSession = dbClient.openSession(false); settings = new Settings(); @@ -98,8 +98,7 @@ public class ApplyPermissionsStepTest extends BaseStepTest { dbIdsRepository = new DbIdsRepository(); - step = new ApplyPermissionsStep(dbClient, dbIdsRepository, issueAuthorizationIndexer, new PermissionFacade(roleDao, null, - new ResourceDao(dbTester.myBatis(), System2.INSTANCE), permissionTemplateDao, settings), treeRootHolder); + step = new ApplyPermissionsStep(dbClient, dbIdsRepository, issueAuthorizationIndexer, new PermissionFacade(dbClient, settings), treeRootHolder); } @After diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/CustomMeasuresCopyStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/CustomMeasuresCopyStepTest.java index 8429381fb21..96a21b187ca 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/CustomMeasuresCopyStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/CustomMeasuresCopyStepTest.java @@ -24,8 +24,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.mockito.ArgumentCaptor; -import org.sonar.db.measure.CustomMeasureDto; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; +import org.sonar.db.measure.CustomMeasureDto; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.DumbComponent; @@ -51,7 +52,7 @@ import static org.sonar.server.computation.step.CustomMeasuresCopyStep.dtoToMeas public class CustomMeasuresCopyStepTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedDebtModelStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedDebtModelStepTest.java index 8c13d093fd8..b1a4bfc6c59 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedDebtModelStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedDebtModelStepTest.java @@ -25,6 +25,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.debt.CharacteristicDao; @@ -40,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class FeedDebtModelStepTest extends BaseStepTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); DbClient dbClient; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java index d6794ac2eab..1c9eade5a44 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java @@ -31,12 +31,13 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; +import org.sonar.api.utils.System2; import org.sonar.api.utils.log.LogTester; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.server.component.db.ComponentDao; import org.sonar.db.component.SnapshotDao; +import org.sonar.server.component.db.ComponentDao; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; @@ -56,7 +57,7 @@ public class FeedPeriodsStepTest extends BaseStepTest { private static final String PROJECT_KEY = "PROJECT_KEY"; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillComponentsStepTest.java index b8741e5b7de..016aaaddf35 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillComponentsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillComponentsStepTest.java @@ -27,12 +27,13 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.sonar.api.utils.System2; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.db.component.ComponentDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.MyBatis; +import org.sonar.db.component.ComponentDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.computation.batch.BatchReportReaderRule; @@ -50,7 +51,7 @@ public class FillComponentsStepTest extends BaseStepTest { private static final String PROJECT_KEY = "PROJECT_KEY"; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.java index ee2d54389c9..85e72246065 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest.java @@ -28,16 +28,17 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.utils.System2; import org.sonar.batch.protocol.output.BatchReport; +import org.sonar.db.DbSession; +import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; +import org.sonar.db.debt.CharacteristicDao; +import org.sonar.db.measure.MeasureDao; import org.sonar.db.measure.MeasureDto; import org.sonar.db.metric.MetricDto; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; -import org.sonar.db.debt.CharacteristicDao; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; @@ -52,7 +53,6 @@ import org.sonar.server.computation.metric.MetricRepositoryImpl; import org.sonar.server.computation.period.Period; import org.sonar.server.computation.period.PeriodsHolderRule; import org.sonar.server.db.DbClient; -import org.sonar.db.measure.MeasureDao; import org.sonar.server.metric.persistence.MetricDao; import org.sonar.server.rule.db.RuleDao; import org.sonar.test.DbTests; @@ -78,7 +78,7 @@ public class FillMeasuresWithVariationsStepTest { static final Component PROJECT = DumbComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_DTO.uuid()).build(); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java index d47a51f771f..c29071332be 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java @@ -27,6 +27,7 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.sonar.api.config.Settings; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.source.FileSourceDao; import org.sonar.server.computation.batch.TreeRootHolderRule; @@ -44,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class IndexSourceLinesStepTest extends BaseStepTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new SourceLineIndexDefinition(new Settings())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java index cf11bca2120..e32d9cfb906 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java @@ -31,12 +31,12 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.db.component.ComponentDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDao; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; @@ -58,7 +58,7 @@ public class PersistComponentsStepTest extends BaseStepTest { private static final String PROJECT_KEY = "PROJECT_KEY"; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java index 4356f08f9ec..9ec1acdce4e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java @@ -27,18 +27,19 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.utils.System2; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Range; -import org.sonar.db.metric.MetricDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.measure.MeasureDao; +import org.sonar.db.metric.MetricDto; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.DbIdsRepository; import org.sonar.server.computation.component.DumbComponent; import org.sonar.server.db.DbClient; -import org.sonar.db.measure.MeasureDao; import org.sonar.server.metric.persistence.MetricDao; import org.sonar.test.DbTests; @@ -51,7 +52,7 @@ public class PersistDuplicationsStepTest extends BaseStepTest { private static final String PROJECT_KEY = "PROJECT_KEY"; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java index b13e7b22ba6..35d0bdc9d4f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java @@ -31,6 +31,7 @@ import org.sonar.api.utils.System2; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.event.EventDao; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; @@ -39,7 +40,6 @@ import org.sonar.server.computation.component.DumbComponent; import org.sonar.server.computation.event.Event; import org.sonar.server.computation.event.EventRepository; import org.sonar.server.db.DbClient; -import org.sonar.db.event.EventDao; import org.sonar.test.DbTests; import static org.mockito.Matchers.any; @@ -50,7 +50,7 @@ import static org.mockito.Mockito.when; public class PersistEventsStepTest extends BaseStepTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java index e17ae729069..39976354aa6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java @@ -21,7 +21,6 @@ package org.sonar.server.computation.step; import com.google.common.base.Optional; -import java.io.IOException; import java.util.List; import org.junit.After; import org.junit.Before; @@ -35,6 +34,7 @@ import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.source.FileSourceDao; import org.sonar.db.source.FileSourceDto; import org.sonar.db.source.FileSourceDto.Type; import org.sonar.server.computation.batch.BatchReportReaderRule; @@ -43,7 +43,6 @@ import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.DumbComponent; import org.sonar.server.computation.language.LanguageRepository; import org.sonar.server.db.DbClient; -import org.sonar.db.source.FileSourceDao; import org.sonar.server.source.db.FileSourceDb; import org.sonar.test.DbTests; @@ -63,7 +62,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { private static final String FILE_UUID = "FILE"; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java index b8f4254d933..29ce9923955 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java @@ -55,7 +55,7 @@ public class PersistIssuesStepTest extends BaseStepTest { public TemporaryFolder temp = new TemporaryFolder(); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); 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 ca3c89c5859..5c92a15fae8 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 @@ -32,9 +32,10 @@ import org.sonar.api.utils.System2; import org.sonar.api.utils.internal.Uuids; import org.sonar.batch.protocol.Constants.MeasureValueType; import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.db.component.ComponentDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.measure.MeasureDao; import org.sonar.db.rule.RuleDto; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.computation.batch.BatchReportReaderRule; @@ -46,7 +47,6 @@ import org.sonar.server.computation.measure.MeasureRepository; import org.sonar.server.computation.measure.MeasureRepositoryImpl; import org.sonar.server.computation.metric.MetricRepositoryRule; import org.sonar.server.db.DbClient; -import org.sonar.db.measure.MeasureDao; import org.sonar.server.metric.persistence.MetricDao; import org.sonar.server.rule.db.RuleDao; import org.sonar.test.DbTests; @@ -74,7 +74,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { private static final int FILE_REF = 2; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java index 692c3052577..5e8675bd68b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java @@ -29,6 +29,7 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.db.DbTester; +import org.sonar.db.measure.MeasureDao; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; @@ -39,7 +40,6 @@ import org.sonar.server.computation.metric.Metric; import org.sonar.server.computation.metric.MetricImpl; import org.sonar.server.computation.metric.MetricRepository; import org.sonar.server.db.DbClient; -import org.sonar.db.measure.MeasureDao; import org.sonar.server.source.index.SourceLineIndex; import static org.mockito.Matchers.anyString; @@ -49,7 +49,7 @@ import static org.mockito.Mockito.when; public class PersistNumberOfDaysSinceLastCommitStepTest extends BaseStepTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java index 950a4ac7b21..bada58ba226 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java @@ -27,6 +27,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.i18n.I18n; +import org.sonar.api.utils.System2; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.db.DbSession; @@ -48,7 +49,7 @@ import static org.mockito.Mockito.when; public class PersistProjectLinksStepTest extends BaseStepTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java index fdc3bc3a28b..7a9dd63955c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSnapshotsStepTest.java @@ -30,15 +30,15 @@ import org.sonar.api.CoreProperties; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.batch.protocol.output.BatchReport; +import org.sonar.db.DbSession; +import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotQuery; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.SnapshotTesting; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; @@ -60,7 +60,7 @@ public class PersistSnapshotsStepTest extends BaseStepTest { private static final String PROJECT_KEY = "PROJECT_KEY"; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); 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 8a682e435ba..b00a5045f44 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 @@ -35,6 +35,7 @@ import org.sonar.batch.protocol.output.BatchReport.CoverageDetail; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.MyBatis; +import org.sonar.db.source.FileSourceDao; import org.sonar.db.source.FileSourceDto; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; @@ -42,7 +43,6 @@ import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.DumbComponent; import org.sonar.server.computation.component.FileAttributes; import org.sonar.server.db.DbClient; -import org.sonar.db.source.FileSourceDao; import org.sonar.server.source.db.FileSourceDb; import static org.assertj.core.api.Assertions.assertThat; @@ -66,7 +66,7 @@ public class PersistTestsStepTest extends BaseStepTest { private static final String TEST_FILE_PATH_2 = "TEST-PATH-2"; @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); 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 c1d1c48b1d6..9c29f36b893 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 @@ -42,7 +42,7 @@ import static org.mockito.Mockito.when; public class SwitchSnapshotStepTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); 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 ad759579da7..c9b3e711a0e 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 @@ -29,15 +29,16 @@ import org.junit.rules.ExpectedException; import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.api.utils.MessageException; +import org.sonar.api.utils.System2; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.db.component.ComponentDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDao; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.SnapshotTesting; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; @@ -53,7 +54,7 @@ public class ValidateProjectStepTest { private static final String MODULE_KEY = "MODULE_KEY"; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public ExpectedException thrown = ExpectedException.none(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectIssuesDashboardTest.java b/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectIssuesDashboardTest.java index 74a92634f8a..3d4e9f03381 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectIssuesDashboardTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectIssuesDashboardTest.java @@ -24,10 +24,11 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.sonar.api.utils.System2; import org.sonar.api.web.Dashboard; import org.sonar.api.web.DashboardLayout; -import org.sonar.db.issue.IssueFilterDao; import org.sonar.db.DbTester; +import org.sonar.db.issue.IssueFilterDao; import org.sonar.test.DbTests; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ProjectIssuesDashboardTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); ProjectIssuesDashboard template; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java index c1726c38da5..476ad8831c0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class DbClientTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Test public void get_daos() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/BaseDataChangeTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/BaseDataChangeTest.java index 70a1291c02c..a9bc1222f9c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/BaseDataChangeTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/BaseDataChangeTest.java @@ -19,29 +19,27 @@ */ package org.sonar.server.db.migrations; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.sonar.api.utils.System2; -import org.sonar.db.AbstractDaoTestCase; import org.sonar.db.BatchSession; import org.sonar.db.DbTester; import org.sonar.server.db.migrations.Select.Row; import org.sonar.server.db.migrations.Select.RowReader; import org.sonar.test.DbTests; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @Category(DbTests.class) -public class BaseDataChangeTest extends AbstractDaoTestCase { +public class BaseDataChangeTest { @Rule public DbTester db = DbTester.createForSchema(System2.INSTANCE, BaseDataChangeTest.class, "schema.sql"); @@ -444,7 +442,7 @@ public class BaseDataChangeTest extends AbstractDaoTestCase { .list(new Select.RowReader<Object[]>() { @Override public Object[] read(Select.Row row) throws SQLException { - return new Object[] { + return new Object[]{ // id, login, age, enabled row.getLong(1), row.getString(2), @@ -469,7 +467,7 @@ public class BaseDataChangeTest extends AbstractDaoTestCase { static class UserReader implements Select.RowReader<Object[]> { @Override public Object[] read(Select.Row row) throws SQLException { - return new Object[] { + return new Object[]{ // id, login, age, enabled row.getNullableLong(1), row.getNullableString(2), diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/DatabaseMigratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/DatabaseMigratorTest.java index 9575d534eee..975ee2b96b7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/DatabaseMigratorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/DatabaseMigratorTest.java @@ -19,21 +19,19 @@ */ package org.sonar.server.db.migrations; +import java.sql.Connection; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; import org.sonar.api.platform.ServerUpgradeStatus; -import org.sonar.db.AbstractDaoTestCase; import org.sonar.db.DbSession; import org.sonar.db.dialect.Dialect; import org.sonar.db.dialect.H2; import org.sonar.db.dialect.MySql; import org.sonar.server.db.DbClient; -import java.sql.Connection; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.mock; @@ -41,7 +39,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class DatabaseMigratorTest extends AbstractDaoTestCase { +public class DatabaseMigratorTest { @Rule public ExpectedException thrown = ExpectedException.none(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java index c6c9cbdfd91..6045a3fcf5e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueStorageTest.java @@ -21,44 +21,38 @@ package org.sonar.server.issue; import java.util.Collection; import java.util.Date; -import org.junit.After; -import org.junit.Before; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.Duration; +import org.sonar.api.utils.System2; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.IssueChangeContext; -import org.sonar.db.AbstractDaoTestCase; import org.sonar.db.DbSession; +import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueMapper; import org.sonar.server.db.DbClient; +import org.sonar.test.DbTests; -public class IssueStorageTest extends AbstractDaoTestCase { +@Category(DbTests.class) +public class IssueStorageTest { IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik"); - DbSession session; + @org.junit.Rule + public DbTester dbTester = DbTester.create(System2.INSTANCE); - @Before - public void before() { - session = getMyBatis().openSession(false); - } - - @After - public void after() { - session.close(); - } + DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis()); @Test public void batch_insert_new_issues() { - DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis()); FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder()); DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment"); @@ -89,12 +83,12 @@ public class IssueStorageTest extends AbstractDaoTestCase { saver.save(issue); - checkTables("should_insert_new_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml", + new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); } @Test public void batch_insert_new_issues_with_session() { - DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis()); FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder()); DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment"); @@ -123,17 +117,17 @@ public class IssueStorageTest extends AbstractDaoTestCase { .setProjectUuid("uuid-10") .setComponentKey("struts:Action"); - saver.save(session, issue); - session.commit(); + saver.save(dbTester.getSession(), issue); + dbTester.getSession().commit(); - checkTables("should_insert_new_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml", + new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); } @Test public void server_insert_new_issues_with_session() { ComponentDto project = new ComponentDto().setId(10L).setUuid("uuid-10"); ComponentDto component = new ComponentDto().setId(100L).setUuid("uuid-100"); - DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis()); FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project); DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment"); @@ -162,17 +156,17 @@ public class IssueStorageTest extends AbstractDaoTestCase { .setComponentUuid("component-uuid") .setProjectUuid("project-uuid"); - saver.save(session, issue); - session.commit(); + saver.save(dbTester.getSession(), issue); + dbTester.getSession().commit(); - checkTables("should_insert_new_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml", + new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); } @Test public void batch_update_issues() { - setupData("should_update_issues"); + dbTester.prepareDbUnit(getClass(), "should_update_issues.xml"); - DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis()); FakeBatchSaver saver = new FakeBatchSaver(dbClient, new FakeRuleFinder()); DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment"); @@ -185,7 +179,7 @@ public class IssueStorageTest extends AbstractDaoTestCase { .setNew(false) .setChanged(true) - // updated fields + // updated fields .setLine(5000) .setDebt(Duration.create(10L)) .setChecksum("FFFFF") @@ -204,22 +198,21 @@ public class IssueStorageTest extends AbstractDaoTestCase { .setComponentUuid("uuid-100") .setProjectUuid("uuid-10") - // unmodifiable fields + // unmodifiable fields .setRuleKey(RuleKey.of("xxx", "unknown")) .setComponentKey("not:a:component"); saver.save(issue); - checkTables("should_update_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); } @Test public void server_update_issues() { - setupData("should_update_issues"); + dbTester.prepareDbUnit(getClass(), "should_update_issues.xml"); ComponentDto project = new ComponentDto().setId(10L).setUuid("whatever-uuid"); ComponentDto component = new ComponentDto().setId(100L).setUuid("whatever-uuid-2"); - DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis()); FakeServerSaver saver = new FakeServerSaver(dbClient, new FakeRuleFinder(), component, project); DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment"); @@ -232,7 +225,7 @@ public class IssueStorageTest extends AbstractDaoTestCase { .setNew(false) .setChanged(true) - // updated fields + // updated fields .setLine(5000) .setDebt(Duration.create(10L)) .setChecksum("FFFFF") @@ -250,13 +243,13 @@ public class IssueStorageTest extends AbstractDaoTestCase { .setCloseDate(date) .setProjectUuid("uuid-10") - // unmodifiable fields + // unmodifiable fields .setRuleKey(RuleKey.of("xxx", "unknown")) .setComponentKey("not:a:component"); saver.save(issue); - checkTables("should_update_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_update_issues-result.xml", new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); } static class FakeBatchSaver extends IssueStorage { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java index 613dfd0a164..f4aaf495ed3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java @@ -20,11 +20,11 @@ package org.sonar.server.issue; +import java.util.Collection; +import java.util.Date; import org.junit.Before; import org.junit.Test; -import org.sonar.core.issue.DefaultIssue; -import org.sonar.core.issue.DefaultIssueComment; -import org.sonar.core.issue.IssueChangeContext; +import org.junit.experimental.categories.Category; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; @@ -32,41 +32,44 @@ import org.sonar.api.rules.RuleQuery; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.Duration; import org.sonar.api.utils.System2; -import org.sonar.db.AbstractDaoTestCase; +import org.sonar.core.issue.DefaultIssue; +import org.sonar.core.issue.DefaultIssueComment; +import org.sonar.core.issue.IssueChangeContext; +import org.sonar.db.DbTester; import org.sonar.db.component.ResourceDao; +import org.sonar.db.issue.IssueDao; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; -import org.sonar.db.issue.IssueDao; import org.sonar.server.issue.index.IssueIndexer; - -import java.util.Collection; -import java.util.Date; +import org.sonar.test.DbTests; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class ServerIssueStorageTest extends AbstractDaoTestCase { +@Category(DbTests.class) +public class ServerIssueStorageTest { + + System2 system = mock(System2.class); - DbClient dbClient; + @org.junit.Rule + public DbTester dbTester = DbTester.create(system); - ServerIssueStorage storage; + DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), + new ComponentDao(), + new IssueDao(dbTester.myBatis()), + new ResourceDao(dbTester.myBatis(), system)); + + ServerIssueStorage storage = new ServerIssueStorage(new FakeRuleFinder(), dbClient, mock(IssueIndexer.class)); @Before public void setupDbClient() { - System2 system = mock(System2.class); when(system.now()).thenReturn(2000000000L); - dbClient = new DbClient(dbTester.database(), getMyBatis(), - new ComponentDao(), - new IssueDao(getMyBatis()), - new ResourceDao(getMyBatis(), system)); - - storage = new ServerIssueStorage(new FakeRuleFinder(), dbClient, mock(IssueIndexer.class)); } @Test public void load_component_id_from_db() { - setupData("load_component_id_from_db"); + dbTester.prepareDbUnit(getClass(), "load_component_id_from_db.xml"); long componentId = storage.component(dbTester.getSession(), new DefaultIssue().setComponentKey("struts:Action")).getId(); @@ -75,7 +78,7 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase { @Test public void load_project_id_from_db() { - setupData("load_project_id_from_db"); + dbTester.prepareDbUnit(getClass(), "load_project_id_from_db.xml"); long projectId = storage.project(dbTester.getSession(), new DefaultIssue().setProjectKey("struts")).getId(); @@ -84,7 +87,7 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase { @Test public void should_insert_new_issues() { - setupData("should_insert_new_issues"); + dbTester.prepareDbUnit(getClass(), "should_insert_new_issues.xml"); DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment"); // override generated key @@ -113,12 +116,13 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase { storage.save(issue); - checkTables("should_insert_new_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_insert_new_issues-result.xml", + new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); } @Test public void should_update_issues() { - setupData("should_update_issues"); + dbTester.prepareDbUnit(getClass(), "should_update_issues.xml"); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik"); @@ -132,7 +136,7 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase { .setNew(false) .setChanged(true) - // updated fields + // updated fields .setLine(5000) .setProjectUuid("CDEF") .setDebt(Duration.create(10L)) @@ -150,14 +154,15 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase { .setUpdateDate(date) .setCloseDate(date) - // unmodifiable fields + // unmodifiable fields .setRuleKey(RuleKey.of("xxx", "unknown")) .setComponentKey("struts:Action") .setProjectKey("struts"); storage.save(issue); - checkTables("should_update_issues", new String[] {"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_update_issues-result.xml", + new String[]{"id", "created_at", "updated_at", "issue_change_creation_date"}, "issues", "issue_changes"); } static class FakeRuleFinder implements RuleFinder { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/RegisterIssueFiltersTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/RegisterIssueFiltersTest.java index c032c854f3c..e5a3b6270a7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/RegisterIssueFiltersTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/RegisterIssueFiltersTest.java @@ -19,19 +19,18 @@ */ package org.sonar.server.issue.filter; +import java.util.Date; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; -import org.sonar.db.issue.IssueFilterDao; import org.sonar.db.DbTester; +import org.sonar.db.issue.IssueFilterDao; import org.sonar.db.loadedtemplate.LoadedTemplateDao; import org.sonar.test.DbTests; -import java.util.Date; - import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -39,7 +38,7 @@ import static org.mockito.Mockito.when; public class RegisterIssueFiltersTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); RegisterIssueFilters taskUnderTest; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexerTest.java index 625961026f1..2124ba45f6a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexerTest.java @@ -19,6 +19,9 @@ */ package org.sonar.server.issue.index; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; import org.elasticsearch.search.SearchHit; import org.junit.Before; import org.junit.ClassRule; @@ -26,22 +29,19 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.config.Settings; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.test.DbTests; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; @Category(DbTests.class) public class IssueAuthorizationIndexerTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java index b799660bab0..36f5853acbf 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java @@ -20,6 +20,7 @@ package org.sonar.server.issue.index; import com.google.common.collect.Iterators; +import java.util.List; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; @@ -27,20 +28,19 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.config.Settings; import org.sonar.api.rule.RuleKey; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.test.DbTests; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; @Category(DbTests.class) public class IssueIndexerTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java index 0a98a8bf59c..9ec49c01169 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java @@ -19,6 +19,10 @@ */ package org.sonar.server.measure; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Date; +import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -27,16 +31,11 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; -import org.sonar.db.component.SnapshotDto; import org.sonar.db.DbTester; import org.sonar.db.component.ResourceDao; +import org.sonar.db.component.SnapshotDto; import org.sonar.test.DbTests; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; @@ -57,7 +56,7 @@ public class MeasureFilterExecutorTest { private static final Metric METRIC_COVERAGE = new Metric.Builder("coverage", "Coverage", Metric.ValueType.FLOAT).create().setId(3); private static final Metric METRIC_UNKNOWN = new Metric.Builder("unknown", "Unknown", Metric.ValueType.FLOAT).create().setId(4); @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); private MeasureFilterExecutor executor; @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java index 09800e7abf8..8107c1d0c10 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java @@ -27,9 +27,10 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.sonar.db.measure.CustomMeasureDto; +import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.measure.CustomMeasureDto; import org.sonar.server.db.DbClient; import org.sonar.test.DbTests; @@ -40,7 +41,7 @@ import static org.sonar.server.measure.custom.persistence.CustomMeasureTesting.n @Category(DbTests.class) public class CustomMeasureDaoTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); CustomMeasureDao sut; DbSession session; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java index a273fe111f5..5fcf179b069 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java @@ -35,12 +35,12 @@ import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metric.ValueType; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.measure.CustomMeasureDto; -import org.sonar.db.metric.MetricDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.measure.CustomMeasureDto; +import org.sonar.db.metric.MetricDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; @@ -73,7 +73,7 @@ public class CreateActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings())); DbClient dbClient; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java index 4191c77a1c4..c03f6da62e6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java @@ -26,12 +26,13 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.measure.CustomMeasureDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.measure.CustomMeasureDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; @@ -52,7 +53,7 @@ public class DeleteActionTest { public static final String ACTION = "delete"; @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java index 1c7f8e63e14..523d761ced4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java @@ -30,13 +30,14 @@ import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.sonar.api.config.Settings; import org.sonar.api.measures.Metric; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.measure.CustomMeasureDto; -import org.sonar.db.metric.MetricDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.measure.CustomMeasureDto; +import org.sonar.db.metric.MetricDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; @@ -68,7 +69,7 @@ public class MetricsActionTest { @ClassRule public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings())); @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient; DbSession dbSession; WsTester ws; 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 7a046289909..b2ef0731792 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 @@ -33,17 +33,18 @@ import org.sonar.api.config.Settings; import org.sonar.api.measures.Metric.ValueType; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.measure.CustomMeasureDto; -import org.sonar.db.metric.MetricDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDao; +import org.sonar.db.measure.CustomMeasureDto; +import org.sonar.db.metric.MetricDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.SnapshotTesting; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -71,7 +72,7 @@ public class SearchActionTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings())); WsTester ws; diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java index 15a6671b13a..2c239990f59 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java @@ -31,12 +31,12 @@ import org.junit.rules.ExpectedException; import org.sonar.api.config.Settings; import org.sonar.api.measures.Metric.ValueType; import org.sonar.api.utils.System2; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.measure.CustomMeasureDto; -import org.sonar.db.metric.MetricDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.measure.CustomMeasureDto; +import org.sonar.db.metric.MetricDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; @@ -73,7 +73,7 @@ public class UpdateActionTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings())); DbClient dbClient; diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java index 4b5d887ebf9..b377ee0eb46 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java @@ -24,6 +24,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.server.db.DbClient; import org.sonar.server.metric.persistence.MetricDao; @@ -37,7 +38,7 @@ import static org.junit.Assert.assertThat; public class DefaultMetricFinderTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); DefaultMetricFinder finder; diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java index 1febd8d443f..f8cf592bfb2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java @@ -25,9 +25,10 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.sonar.db.metric.MetricDto; +import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.metric.MetricDto; import org.sonar.server.exceptions.NotFoundException; import org.sonar.test.DbTests; @@ -37,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class MetricDaoTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); DbSession session; diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java index 39d4ced7ed4..f3829d68a70 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java @@ -27,10 +27,11 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.sonar.api.measures.Metric.ValueType; -import org.sonar.db.metric.MetricDto; +import org.sonar.api.utils.System2; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.metric.MetricDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.ServerException; @@ -61,7 +62,7 @@ public class CreateActionTest { private static final String DEFAULT_TYPE = ValueType.INT.name(); @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java index 45871fa616d..06db2278d42 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java @@ -28,11 +28,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; -import org.sonar.db.measure.CustomMeasureDto; -import org.sonar.db.metric.MetricDto; +import org.sonar.api.utils.System2; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.measure.CustomMeasureDto; +import org.sonar.db.metric.MetricDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.measure.custom.persistence.CustomMeasureDao; @@ -52,7 +53,7 @@ import static org.sonar.server.metric.ws.MetricTesting.newMetricDto; public class DeleteActionTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DomainsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DomainsActionTest.java index 22a0469b6b4..dd8d0b9e5bb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DomainsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DomainsActionTest.java @@ -25,9 +25,10 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.sonar.db.metric.MetricDto; +import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.metric.MetricDto; import org.sonar.server.db.DbClient; import org.sonar.server.metric.persistence.MetricDao; import org.sonar.server.ws.WsTester; @@ -40,7 +41,7 @@ import static org.sonar.server.metric.ws.MetricTesting.newMetricDto; public class DomainsActionTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); WsTester ws; DbClient dbClient; DbSession dbSession; diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java index 6af35058db0..dc1a55dd207 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/SearchActionTest.java @@ -27,9 +27,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.server.ws.WebService.Param; -import org.sonar.db.metric.MetricDto; +import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.metric.MetricDto; import org.sonar.server.db.DbClient; import org.sonar.server.metric.persistence.MetricDao; import org.sonar.server.ws.WsTester; @@ -43,7 +44,7 @@ import static org.sonar.server.metric.ws.SearchAction.PARAM_IS_CUSTOM; public class SearchActionTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); DbClient dbClient; DbSession dbSession; WsTester ws; diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java index 866ffbd78db..ef048c87d4a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java @@ -27,10 +27,11 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.sonar.api.measures.Metric.ValueType; -import org.sonar.db.metric.MetricDto; +import org.sonar.api.utils.System2; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.metric.MetricDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.ServerException; @@ -62,7 +63,7 @@ public class UpdateActionTest { private static final String DEFAULT_TYPE = ValueType.INT.name(); @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java index 84e9be9afb6..03aea74bfad 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java @@ -26,11 +26,12 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; +import org.sonar.db.rule.RuleTesting; import org.sonar.server.es.EsTester; import org.sonar.server.issue.IssueTesting; import org.sonar.server.issue.index.IssueIndexDefinition; -import org.sonar.db.rule.RuleTesting; import org.sonar.server.rule.index.RuleDoc; import org.sonar.server.rule.index.RuleNormalizer; import org.sonar.server.search.IndexDefinition; @@ -50,7 +51,7 @@ public class BackendCleanupMediumTest { public static EsTester esTester = new EsTester(); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); BackendCleanup backendCleanup; diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java index d8394a8a15b..c143791f55c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java @@ -19,21 +19,21 @@ */ package org.sonar.server.platform.monitoring; +import java.util.LinkedHashMap; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.sonar.db.version.DatabaseVersion; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; +import org.sonar.db.version.DatabaseVersion; import org.sonar.server.db.DbClient; -import java.util.LinkedHashMap; - import static org.assertj.core.api.Assertions.assertThat; public class DatabaseMonitorTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); DatabaseMonitor sut; diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java index 90b55c60b09..a6d1d2a0117 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java @@ -82,7 +82,7 @@ public class BulkDeleteActionTest { private static final String ACTION = "bulk_delete"; @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new SourceLineIndexDefinition(new Settings()), new TestIndexDefinition(new Settings())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java index 5ac38ed985a..d2355612885 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java @@ -80,7 +80,7 @@ public class DeleteActionTest { private static final String ACTION = "delete"; @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new SourceLineIndexDefinition(new Settings()), new TestIndexDefinition(new Settings())); 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 7e6db7a8687..da069fc0c7f 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 @@ -29,15 +29,16 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.SnapshotDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDao; +import org.sonar.db.component.SnapshotDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.SnapshotTesting; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.tester.UserSessionRule; @@ -51,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class GhostsActionTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); WsTester ws; 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 20e56c06c7f..562c598c951 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 @@ -30,15 +30,16 @@ import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.DateUtils; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.SnapshotDto; +import org.sonar.api.utils.System2; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDao; +import org.sonar.db.component.SnapshotDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.SnapshotTesting; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.tester.UserSessionRule; @@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ProvisionedActionTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java index 041eac72829..7dd91786d01 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java @@ -21,6 +21,11 @@ package org.sonar.server.qualityprofile; import com.google.common.collect.Lists; import com.google.common.io.Resources; +import java.io.StringReader; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.List; +import javax.xml.stream.XMLStreamException; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import org.junit.After; @@ -35,18 +40,11 @@ import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.QualityProfileDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; -import org.sonar.server.db.DbClient; import org.sonar.db.rule.RuleTesting; +import org.sonar.server.db.DbClient; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; -import javax.xml.stream.XMLStreamException; - -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.charset.StandardCharsets; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -130,7 +128,7 @@ public class QProfileBackuperMediumTest { Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), null); - QualityProfileDto profile = db.qualityProfileDao().getByNameAndLanguage("P1", "xoo"); + QualityProfileDto profile = db.qualityProfileDao().getByNameAndLanguage("P1", "xoo", dbSession); assertThat(profile).isNotNull(); List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(profile.getKey())); @@ -305,7 +303,7 @@ public class QProfileBackuperMediumTest { List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY)); assertThat(activeRules).hasSize(0); - QualityProfileDto target = db.qualityProfileDao().getByNameAndLanguage("P3", "xoo"); + QualityProfileDto target = db.qualityProfileDao().getByNameAndLanguage("P3", "xoo", dbSession); assertThat(target).isNotNull(); activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(target.getKey())); assertThat(activeRules).hasSize(1); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java index 0ca036e8e3d..f44231a963d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java @@ -21,6 +21,9 @@ package org.sonar.server.qualityprofile; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; @@ -33,15 +36,10 @@ import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QualityProfileDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; +import org.sonar.db.rule.RuleTesting; import org.sonar.server.db.DbClient; import org.sonar.server.qualityprofile.index.ActiveRuleIndex; -import org.sonar.db.rule.RuleTesting; import org.sonar.server.tester.ServerTester; - -import javax.annotation.Nullable; - -import java.util.List; -import java.util.Map; import org.sonar.server.tester.UserSessionRule; import static org.assertj.core.api.Assertions.assertThat; @@ -171,7 +169,7 @@ public class QProfileCopierMediumTest { private void verifyOneActiveRule(QProfileName profileName, String expectedSeverity, @Nullable String expectedInheritance, Map<String, String> expectedParams) { - QualityProfileDto dto = db.qualityProfileDao().getByNameAndLanguage(profileName.getName(), profileName.getLanguage()); + QualityProfileDto dto = db.qualityProfileDao().getByNameAndLanguage(profileName.getName(), profileName.getLanguage(), dbSession); verifyOneActiveRule(dto.getKey(), expectedSeverity, expectedInheritance, expectedParams); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java index e7cbd054a13..f63ef333620 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java @@ -29,6 +29,7 @@ import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.server.db.DbClient; import org.sonar.server.language.LanguageTesting; @@ -47,7 +48,7 @@ import static org.mockito.Mockito.mock; public class BackupActionTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); // TODO Replace with proper DbTester + EsTester medium test once DaoV2 is removed @Mock diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java index 58376beaa72..1907f05f029 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java @@ -39,6 +39,7 @@ import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.rule.RuleDto; +import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; import org.sonar.server.activity.Activity; import org.sonar.server.activity.index.ActivityDoc; @@ -52,7 +53,6 @@ import org.sonar.server.qualityprofile.ActiveRuleChange; import org.sonar.server.qualityprofile.ActiveRuleChange.Type; import org.sonar.server.qualityprofile.QProfileFactory; import org.sonar.server.qualityprofile.QProfileTesting; -import org.sonar.db.rule.RuleTesting; import org.sonar.server.rule.db.RuleDao; import org.sonar.server.user.db.UserDao; import org.sonar.server.ws.WsTester; @@ -63,7 +63,7 @@ import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P1_KEY; public class ChangelogActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java index 0862d4c1c5f..84636b8ef24 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java @@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock; public class CreateActionTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); 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 7a346e8255c..77d1040f796 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 @@ -26,10 +26,10 @@ import org.junit.Test; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.utils.System2; -import org.sonar.db.component.ComponentDto; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.qualityprofile.QualityProfileDto; import org.sonar.server.component.ComponentTesting; @@ -50,7 +50,7 @@ import static org.mockito.Mockito.mock; public class DeleteActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); 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 69177b62e0c..700c0da164e 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 @@ -61,7 +61,7 @@ import static org.mockito.Mockito.when; public class ExportActionTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); 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 df3dedb5fc0..e912bb7682a 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 @@ -26,9 +26,9 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.qualityprofile.QualityProfileDto; import org.sonar.db.user.AuthorizationDao; @@ -53,7 +53,7 @@ import static org.mockito.Mockito.mock; public class ProjectsActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); 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 112c1f24a16..fe7caf986d8 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 @@ -42,7 +42,7 @@ import static org.mockito.Mockito.mock; public class RenameActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index 8f389b8f43f..cab70ae8230 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -46,7 +46,7 @@ import static org.mockito.Mockito.when; public class SearchActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); private DbClient dbClient; 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 9e53e57dd44..c7f1ffd5317 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 @@ -45,7 +45,7 @@ import static org.mockito.Mockito.mock; public class SetDefaultActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index a9c6752d12e..f3c6c7ae328 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -20,9 +20,11 @@ package org.sonar.server.rule; import com.google.common.collect.Sets; -import org.junit.After; +import java.util.Date; +import java.util.List; import org.junit.Before; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.rule.RuleKey; @@ -31,49 +33,45 @@ import org.sonar.api.rule.Severity; import org.sonar.api.server.rule.RulesDefinition; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; -import org.sonar.db.AbstractDaoTestCase; -import org.sonar.db.DbSession; +import org.sonar.db.DbTester; +import org.sonar.db.debt.CharacteristicDao; import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; -import org.sonar.db.debt.CharacteristicDao; import org.sonar.server.db.DbClient; import org.sonar.server.qualityprofile.RuleActivator; import org.sonar.server.qualityprofile.db.ActiveRuleDao; import org.sonar.server.rule.db.RuleDao; - -import java.util.Date; -import java.util.List; +import org.sonar.test.DbTests; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class RegisterRulesTest extends AbstractDaoTestCase { +@Category(DbTests.class) +public class RegisterRulesTest { static final Date DATE1 = DateUtils.parseDateTime("2014-01-01T19:10:03+0100"); static final Date DATE2 = DateUtils.parseDateTime("2014-02-01T12:10:03+0100"); static final Date DATE3 = DateUtils.parseDateTime("2014-03-01T12:10:03+0100"); - RuleActivator ruleActivator = mock(RuleActivator.class); System2 system; + + @org.junit.Rule + public DbTester dbTester = DbTester.create(system); + + RuleActivator ruleActivator = mock(RuleActivator.class); + DbClient dbClient; - DbSession dbSession; @Before public void before() { system = mock(System2.class); when(system.now()).thenReturn(DATE1.getTime()); RuleDao ruleDao = new RuleDao(system); - ActiveRuleDao activeRuleDao = new ActiveRuleDao(new QualityProfileDao(getMyBatis(), system), ruleDao, system); - dbClient = new DbClient(dbTester.database(), getMyBatis(), ruleDao, activeRuleDao, - new QualityProfileDao(getMyBatis(), system), new CharacteristicDao(getMyBatis())); - dbSession = dbClient.openSession(false); - } - - @After - public void after() { - dbSession.close(); + ActiveRuleDao activeRuleDao = new ActiveRuleDao(new QualityProfileDao(dbTester.myBatis(), system), ruleDao, system); + dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), ruleDao, activeRuleDao, + new QualityProfileDao(dbTester.myBatis(), system), new CharacteristicDao(dbTester.myBatis())); } @Test @@ -81,9 +79,9 @@ public class RegisterRulesTest extends AbstractDaoTestCase { execute(new FakeRepositoryV1()); // verify db - assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2); + assertThat(dbClient.ruleDao().findAll(dbTester.getSession())).hasSize(2); RuleKey ruleKey1 = RuleKey.of("fake", "rule1"); - RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbSession, ruleKey1); + RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbTester.getSession(), ruleKey1); assertThat(rule1.getName()).isEqualTo("One"); assertThat(rule1.getDescription()).isEqualTo("Description of One"); assertThat(rule1.getSeverityString()).isEqualTo(Severity.BLOCKER); @@ -95,7 +93,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase { assertThat(rule1.getUpdatedAt()).isEqualTo(DATE1); // TODO check characteristic and remediation function - List<RuleParamDto> params = dbClient.ruleDao().findRuleParamsByRuleKey(dbSession, ruleKey1); + List<RuleParamDto> params = dbClient.ruleDao().findRuleParamsByRuleKey(dbTester.getSession(), ruleKey1); assertThat(params).hasSize(2); RuleParamDto param = getParam(params, "param1"); assertThat(param.getDescription()).isEqualTo("parameter one"); @@ -105,13 +103,13 @@ public class RegisterRulesTest extends AbstractDaoTestCase { @Test public void do_not_update_rules_when_no_changes() { execute(new FakeRepositoryV1()); - assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2); + assertThat(dbClient.ruleDao().findAll(dbTester.getSession())).hasSize(2); when(system.now()).thenReturn(DATE2.getTime()); execute(new FakeRepositoryV1()); RuleKey ruleKey1 = RuleKey.of("fake", "rule1"); - RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbSession, ruleKey1); + RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbTester.getSession(), ruleKey1); assertThat(rule1.getCreatedAt()).isEqualTo(DATE1); assertThat(rule1.getUpdatedAt()).isEqualTo(DATE1); } @@ -119,22 +117,22 @@ public class RegisterRulesTest extends AbstractDaoTestCase { @Test public void update_and_remove_rules_on_changes() { execute(new FakeRepositoryV1()); - assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2); + assertThat(dbClient.ruleDao().findAll(dbTester.getSession())).hasSize(2); // user adds tags and sets markdown note RuleKey ruleKey1 = RuleKey.of("fake", "rule1"); - RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbSession, ruleKey1); + RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbTester.getSession(), ruleKey1); rule1.setTags(Sets.newHashSet("usertag1", "usertag2")); rule1.setNoteData("user *note*"); rule1.setNoteUserLogin("marius"); - dbClient.ruleDao().update(dbSession, rule1); - dbSession.commit(); + dbClient.ruleDao().update(dbTester.getSession(), rule1); + dbTester.getSession().commit(); when(system.now()).thenReturn(DATE2.getTime()); execute(new FakeRepositoryV2()); // rule1 has been updated - rule1 = dbClient.ruleDao().getNullableByKey(dbSession, ruleKey1); + rule1 = dbClient.ruleDao().getNullableByKey(dbTester.getSession(), ruleKey1); assertThat(rule1.getName()).isEqualTo("One v2"); assertThat(rule1.getDescription()).isEqualTo("Description of One v2"); assertThat(rule1.getSeverityString()).isEqualTo(Severity.INFO); @@ -148,19 +146,19 @@ public class RegisterRulesTest extends AbstractDaoTestCase { assertThat(rule1.getUpdatedAt()).isEqualTo(DATE2); // TODO check characteristic and remediation function - List<RuleParamDto> params = dbClient.ruleDao().findRuleParamsByRuleKey(dbSession, ruleKey1); + List<RuleParamDto> params = dbClient.ruleDao().findRuleParamsByRuleKey(dbTester.getSession(), ruleKey1); assertThat(params).hasSize(2); RuleParamDto param = getParam(params, "param1"); assertThat(param.getDescription()).isEqualTo("parameter one v2"); assertThat(param.getDefaultValue()).isEqualTo("default1 v2"); // rule2 has been removed -> status set to REMOVED but db row is not deleted - RuleDto rule2 = dbClient.ruleDao().getNullableByKey(dbSession, RuleKey.of("fake", "rule2")); + RuleDto rule2 = dbClient.ruleDao().getNullableByKey(dbTester.getSession(), RuleKey.of("fake", "rule2")); assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED); assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2); // rule3 has been created - RuleDto rule3 = dbClient.ruleDao().getNullableByKey(dbSession, RuleKey.of("fake", "rule3")); + RuleDto rule3 = dbClient.ruleDao().getNullableByKey(dbTester.getSession(), RuleKey.of("fake", "rule3")); assertThat(rule3).isNotNull(); assertThat(rule3.getStatus()).isEqualTo(RuleStatus.READY); } @@ -168,28 +166,28 @@ public class RegisterRulesTest extends AbstractDaoTestCase { @Test public void do_not_update_already_removed_rules() { execute(new FakeRepositoryV1()); - assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2); + assertThat(dbClient.ruleDao().findAll(dbTester.getSession())).hasSize(2); - RuleDto rule2 = dbClient.ruleDao().getByKey(dbSession, RuleKey.of("fake", "rule2")); + RuleDto rule2 = dbClient.ruleDao().getByKey(dbTester.getSession(), RuleKey.of("fake", "rule2")); assertThat(rule2.getStatus()).isEqualTo(RuleStatus.READY); when(system.now()).thenReturn(DATE2.getTime()); execute(new FakeRepositoryV2()); // On MySQL, need to update a rule otherwise rule2 will be seen as READY, but why ??? - dbClient.ruleDao().update(dbSession, dbClient.ruleDao().getByKey(dbSession, RuleKey.of("fake", "rule1"))); - dbSession.commit(); + dbClient.ruleDao().update(dbTester.getSession(), dbClient.ruleDao().getByKey(dbTester.getSession(), RuleKey.of("fake", "rule1"))); + dbTester.getSession().commit(); // rule2 is removed - rule2 = dbClient.ruleDao().getNullableByKey(dbSession, RuleKey.of("fake", "rule2")); + rule2 = dbClient.ruleDao().getNullableByKey(dbTester.getSession(), RuleKey.of("fake", "rule2")); assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED); when(system.now()).thenReturn(DATE3.getTime()); execute(new FakeRepositoryV2()); - dbSession.commit(); + dbTester.getSession().commit(); // -> rule2 is still removed, but not update at DATE3 - rule2 = dbClient.ruleDao().getNullableByKey(dbSession, RuleKey.of("fake", "rule2")); + rule2 = dbClient.ruleDao().getNullableByKey(dbTester.getSession(), RuleKey.of("fake", "rule2")); assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED); assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2); } @@ -197,14 +195,14 @@ public class RegisterRulesTest extends AbstractDaoTestCase { @Test public void mass_insert() { execute(new BigRepository()); - assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(BigRepository.SIZE); - assertThat(dbClient.ruleDao().findAllRuleParams(dbSession)).hasSize(BigRepository.SIZE * 20); + assertThat(dbClient.ruleDao().findAll(dbTester.getSession())).hasSize(BigRepository.SIZE); + assertThat(dbClient.ruleDao().findAllRuleParams(dbTester.getSession())).hasSize(BigRepository.SIZE * 20); } @Test public void manage_repository_extensions() { execute(new FindbugsRepository(), new FbContribRepository()); - List<RuleDto> rules = dbClient.ruleDao().findAll(dbSession); + List<RuleDto> rules = dbClient.ruleDao().findAll(dbTester.getSession()); assertThat(rules).hasSize(2); for (RuleDto rule : rules) { assertThat(rule.getRepositoryKey()).isEqualTo("findbugs"); @@ -212,14 +210,14 @@ public class RegisterRulesTest extends AbstractDaoTestCase { } private void execute(RulesDefinition... defs) { - RuleDefinitionsLoader loader = new RuleDefinitionsLoader(mock(DeprecatedRulesDefinitionLoader.class), new RuleRepositories(),defs); + RuleDefinitionsLoader loader = new RuleDefinitionsLoader(mock(DeprecatedRulesDefinitionLoader.class), new RuleRepositories(), defs); Languages languages = mock(Languages.class); when(languages.get("java")).thenReturn(mock(Language.class)); RegisterRules task = new RegisterRules(loader, ruleActivator, dbClient, languages); task.start(); // Execute a commit to refresh session state as the task is using its own session - dbSession.commit(); + dbTester.getSession().commit(); } private RuleParamDto getParam(List<RuleParamDto> params, String key) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/db/RuleDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/db/RuleDaoTest.java index fae1c548c41..be6d3e8d80c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/db/RuleDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/db/RuleDaoTest.java @@ -20,49 +20,39 @@ package org.sonar.server.rule.db; import com.google.common.collect.Iterables; -import org.junit.After; -import org.junit.Before; +import java.util.List; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; -import org.sonar.db.AbstractDaoTestCase; -import org.sonar.db.DbSession; +import org.sonar.db.DbTester; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Format; import org.sonar.db.rule.RuleParamDto; - -import java.util.List; +import org.sonar.test.DbTests; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class RuleDaoTest extends AbstractDaoTestCase { +@Category(DbTests.class) +public class RuleDaoTest { - private RuleDao dao; - private DbSession session; - private System2 system2; + private System2 system2 = mock(System2.class); - @Before - public void before() { - this.session = getMyBatis().openSession(false); - this.system2 = mock(System2.class); - this.dao = new RuleDao(system2); - } + @org.junit.Rule + public DbTester dbTester = DbTester.create(system2); - @After - public void after() { - this.session.close(); - } + private RuleDao dao = new RuleDao(system2); @Test public void select_all() { - setupData("selectAll"); - List<RuleDto> ruleDtos = dao.findAll(session); + dbTester.prepareDbUnit(getClass(), "selectAll.xml"); + List<RuleDto> ruleDtos = dao.findAll(dbTester.getSession()); assertThat(ruleDtos).hasSize(1); @@ -87,8 +77,8 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Test public void select_enables_and_non_manual() { - setupData("select_enables_and_non_manual"); - List<RuleDto> ruleDtos = dao.findByEnabledAndNotManual(session); + dbTester.prepareDbUnit(getClass(), "select_enables_and_non_manual.xml"); + List<RuleDto> ruleDtos = dao.findByEnabledAndNotManual(dbTester.getSession()); assertThat(ruleDtos.size()).isEqualTo(1); RuleDto ruleDto = ruleDtos.get(0); @@ -112,8 +102,8 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Test public void select_by_id() { - setupData("selectById"); - RuleDto ruleDto = dao.getById(session, 2); + dbTester.prepareDbUnit(getClass(), "selectById.xml"); + RuleDto ruleDto = dao.getById(dbTester.getSession(), 2); assertThat(ruleDto.getId()).isEqualTo(2); assertThat(ruleDto.getName()).isEqualTo("Avoid Null"); @@ -125,16 +115,16 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Test public void select_by_rule_key() { - setupData("select_by_rule_key"); - assertThat(dao.getNullableByKey(session, RuleKey.of("checkstyle", "AvoidComparison"))).isNotNull(); - assertThat(dao.getNullableByKey(session, RuleKey.of("checkstyle", "Unknown"))).isNull(); - assertThat(dao.getNullableByKey(session, RuleKey.of("Unknown", "AvoidComparison"))).isNull(); + dbTester.prepareDbUnit(getClass(), "select_by_rule_key.xml"); + assertThat(dao.getNullableByKey(dbTester.getSession(), RuleKey.of("checkstyle", "AvoidComparison"))).isNotNull(); + assertThat(dao.getNullableByKey(dbTester.getSession(), RuleKey.of("checkstyle", "Unknown"))).isNull(); + assertThat(dao.getNullableByKey(dbTester.getSession(), RuleKey.of("Unknown", "AvoidComparison"))).isNull(); } @Test public void select_by_name() { - setupData("select_by_name"); - RuleDto ruleDto = dao.getByName("Avoid Null", session); + dbTester.prepareDbUnit(getClass(), "select_by_name.xml"); + RuleDto ruleDto = dao.getByName("Avoid Null", dbTester.getSession()); assertThat(ruleDto).isNotNull(); @@ -147,10 +137,10 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Test public void select_non_manual() { - setupData("selectNonManual"); - List<RuleDto> ruleDtos = dao.findByNonManual(session); - session.commit(); - session.close(); + dbTester.prepareDbUnit(getClass(), "selectNonManual.xml"); + List<RuleDto> ruleDtos = dao.findByNonManual(dbTester.getSession()); + dbTester.getSession().commit(); + dbTester.getSession().close(); assertThat(ruleDtos.size()).isEqualTo(1); RuleDto ruleDto = ruleDtos.get(0); @@ -163,10 +153,9 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Test public void update() { - when(system2.now()).thenReturn(DateUtils.parseDate("2014-01-01").getTime()); - setupData("update"); + dbTester.prepareDbUnit(getClass(), "update.xml"); RuleDto ruleToUpdate = new RuleDto() .setId(1) @@ -196,18 +185,17 @@ public class RuleDaoTest extends AbstractDaoTestCase { .setEffortToFixDescription("squid.S115.effortToFix"); - dao.update(session, ruleToUpdate); - session.commit(); + dao.update(dbTester.getSession(), ruleToUpdate); + dbTester.getSession().commit(); - checkTables("update", "rules"); + dbTester.assertDbUnit(getClass(), "update-result.xml", "rules"); } @Test public void insert() { - when(system2.now()).thenReturn(DateUtils.parseDate("2013-12-16").getTime()); - setupData("empty"); + dbTester.prepareDbUnit(getClass(), "empty.xml"); RuleDto ruleToInsert = new RuleDto() .setId(1) @@ -232,17 +220,17 @@ public class RuleDaoTest extends AbstractDaoTestCase { .setDefaultRemediationOffset("10h") .setEffortToFixDescription("squid.S115.effortToFix"); - dao.insert(session, ruleToInsert); - session.commit(); + dao.insert(dbTester.getSession(), ruleToInsert); + dbTester.getSession().commit(); - checkTables("insert", "rules"); + dbTester.assertDbUnit(getClass(), "insert-result.xml", "rules"); } @Test public void insert_all() { when(system2.now()).thenReturn(DateUtils.parseDate("2013-12-16").getTime()); - setupData("empty"); + dbTester.prepareDbUnit(getClass(), "empty.xml"); RuleDto ruleToInsert1 = new RuleDto() .setId(1) @@ -290,16 +278,16 @@ public class RuleDaoTest extends AbstractDaoTestCase { .setDefaultRemediationOffset("5min") .setEffortToFixDescription("squid.S115.effortToFix2"); - dao.insert(session, ruleToInsert1, ruleToInsert2); - session.commit(); + dao.insert(dbTester.getSession(), ruleToInsert1, ruleToInsert2); + dbTester.getSession().commit(); - checkTables("insert_all", "rules"); + dbTester.assertDbUnit(getClass(), "insert_all-result.xml", "rules"); } @Test public void select_parameters() { - setupData("selectParameters"); - List<RuleParamDto> ruleDtos = dao.findAllRuleParams(session); + dbTester.prepareDbUnit(getClass(), "selectParameters.xml"); + List<RuleParamDto> ruleDtos = dao.findAllRuleParams(dbTester.getSession()); assertThat(ruleDtos.size()).isEqualTo(1); RuleParamDto ruleDto = ruleDtos.get(0); @@ -312,9 +300,9 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Test public void select_parameters_by_rule_id() { - setupData("select_parameters_by_rule_id"); - RuleDto rule = dao.getById(session, 1); - List<RuleParamDto> ruleDtos = dao.findRuleParamsByRuleKey(session, rule.getKey()); + dbTester.prepareDbUnit(getClass(), "select_parameters_by_rule_id.xml"); + RuleDto rule = dao.getById(dbTester.getSession(), 1); + List<RuleParamDto> ruleDtos = dao.findRuleParamsByRuleKey(dbTester.getSession(), rule.getKey()); assertThat(ruleDtos.size()).isEqualTo(1); RuleParamDto ruleDto = ruleDtos.get(0); @@ -327,9 +315,9 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Test public void insert_parameter() { - setupData("insert_parameter"); + dbTester.prepareDbUnit(getClass(), "insert_parameter.xml"); - RuleDto rule1 = dao.getById(session, 1); + RuleDto rule1 = dao.getById(dbTester.getSession(), 1); RuleParamDto param = RuleParamDto.createFor(rule1) .setName("max") @@ -337,19 +325,19 @@ public class RuleDaoTest extends AbstractDaoTestCase { .setDefaultValue("30") .setDescription("My Parameter"); - dao.addRuleParam(session, rule1, param); - session.commit(); + dao.addRuleParam(dbTester.getSession(), rule1, param); + dbTester.getSession().commit(); - checkTables("insert_parameter", "rules_parameters"); + dbTester.assertDbUnit(getClass(), "insert_parameter-result.xml", "rules_parameters"); } @Test public void update_parameter() { - setupData("update_parameter"); + dbTester.prepareDbUnit(getClass(), "update_parameter.xml"); - RuleDto rule1 = dao.getById(session, 1); + RuleDto rule1 = dao.getById(dbTester.getSession(), 1); - List<RuleParamDto> params = dao.findRuleParamsByRuleKey(session, rule1.getKey()); + List<RuleParamDto> params = dao.findRuleParamsByRuleKey(dbTester.getSession(), rule1.getKey()); assertThat(params).hasSize(1); RuleParamDto param = Iterables.getFirst(params, null); @@ -361,9 +349,9 @@ public class RuleDaoTest extends AbstractDaoTestCase { .setDefaultValue("^[a-z]+(\\.[a-z][a-z0-9]*)*$") .setDescription("Regular expression used to check the package names against."); - dao.updateRuleParam(session, rule1, param); - session.commit(); + dao.updateRuleParam(dbTester.getSession(), rule1, param); + dbTester.getSession().commit(); - checkTables("update_parameter", "rules_parameters"); + dbTester.assertDbUnit(getClass(), "update_parameter-result.xml", "rules_parameters"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java index 40afadac13d..d654de558fe 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java @@ -38,6 +38,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.config.Settings; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; @@ -73,7 +74,7 @@ public class SourceLineIndexerTest { public static EsTester es = new EsTester().addDefinitions(new SourceLineIndexDefinition(new Settings())); @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); private SourceLineIndexer indexer; 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 73998375d8b..bb7c352c516 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 @@ -26,14 +26,15 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.source.FileSourceDao; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; -import org.sonar.db.source.FileSourceDao; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -49,7 +50,7 @@ public class HashActionTest { final static String PROJECT_UUID = "ABCD"; @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); 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 a107c6495ea..48798c302aa 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 @@ -21,16 +21,18 @@ package org.sonar.server.source.ws; import com.google.common.collect.ImmutableList; +import java.util.Date; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.sonar.api.config.Settings; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; @@ -44,8 +46,6 @@ import org.sonar.server.source.index.SourceLineIndexDefinition; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; -import java.util.Date; - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; import static org.junit.Assert.fail; @@ -59,7 +59,7 @@ public class LinesActionTest { @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new SourceLineIndexDefinition(new Settings())); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); 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 362d42f575f..5d50c9799a3 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 @@ -20,6 +20,7 @@ package org.sonar.server.source.ws; +import java.util.Date; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; @@ -27,10 +28,11 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.config.Settings; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; @@ -42,8 +44,6 @@ import org.sonar.server.source.index.SourceLineIndexDefinition; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; -import java.util.Date; - public class ScmActionTest { private static final String FILE_KEY = "FILE_KEY"; @@ -51,7 +51,7 @@ public class ScmActionTest { private static final String PROJECT_UUID = "PROJECT_A"; @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new SourceLineIndexDefinition(new Settings())); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java index 09692942b50..c1b557dccea 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java @@ -29,8 +29,8 @@ import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDto; import org.sonar.db.loadedtemplate.LoadedTemplateDao; +import org.sonar.db.rule.RuleDto; import org.sonar.server.db.DbClient; import org.sonar.server.rule.db.RuleDao; import org.sonar.test.DbTests; @@ -43,7 +43,7 @@ import static org.mockito.Mockito.when; public class CopyRequirementsFromCharacteristicsToRulesTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @Mock System2 system2; 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 803b960b9b3..7a797c27bf4 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 @@ -21,13 +21,13 @@ package org.sonar.server.startup; import java.util.Collections; import java.util.List; - import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metrics; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.qualitygate.QualityGateConditionDao; import org.sonar.server.db.DbClient; @@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class RegisterMetricsTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); /** * Insert new metrics, including custom metrics diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java index dc5e60c7c0b..0aa669b6486 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java @@ -44,7 +44,7 @@ import static org.mockito.Mockito.when; public class RenameIssueWidgetsTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Test public void should_rename_widgets() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java index 1246e079d2c..3403bd654b1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java @@ -20,6 +20,8 @@ package org.sonar.server.test.ws; +import java.util.Arrays; +import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; @@ -27,10 +29,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.config.Settings; +import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; import org.sonar.server.component.db.ComponentDao; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; @@ -43,9 +46,6 @@ import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; -import java.util.Arrays; -import java.util.List; - @Category(DbTests.class) public class ListActionTest { DbClient dbClient; @@ -55,7 +55,7 @@ public class ListActionTest { WsTester ws; @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings())); @Rule 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 5556c6a1d3f..0af0a2bc1a9 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 @@ -40,25 +40,25 @@ import org.sonar.api.web.ResourceLanguage; import org.sonar.api.web.ResourceQualifier; import org.sonar.api.web.ResourceScope; import org.sonar.api.web.UserRole; +import org.sonar.core.permission.GlobalPermissions; +import org.sonar.db.DbSession; +import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; import org.sonar.db.dashboard.ActiveDashboardDao; import org.sonar.db.dashboard.ActiveDashboardDto; import org.sonar.db.dashboard.DashboardDao; import org.sonar.db.dashboard.DashboardDto; -import org.sonar.core.permission.GlobalPermissions; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; +import org.sonar.db.measure.MeasureDao; import org.sonar.db.property.PropertiesDao; import org.sonar.db.property.PropertyDto; import org.sonar.server.component.ComponentTesting; import org.sonar.server.component.SnapshotTesting; import org.sonar.server.component.db.ComponentDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; -import org.sonar.db.measure.MeasureDao; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ui.Views; import org.sonar.server.user.db.UserDao; @@ -71,7 +71,7 @@ import static org.mockito.Mockito.when; public class ComponentNavigationActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); 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 dc4b40983bc..342b924e6f9 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 @@ -32,13 +32,13 @@ import org.sonar.api.web.NavigationSection; import org.sonar.api.web.Page; import org.sonar.api.web.UserRole; import org.sonar.api.web.View; +import org.sonar.core.permission.GlobalPermissions; +import org.sonar.db.DbSession; +import org.sonar.db.DbTester; import org.sonar.db.dashboard.ActiveDashboardDao; import org.sonar.db.dashboard.ActiveDashboardDto; import org.sonar.db.dashboard.DashboardDao; import org.sonar.db.dashboard.DashboardDto; -import org.sonar.core.permission.GlobalPermissions; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; import org.sonar.db.user.UserDto; import org.sonar.server.db.DbClient; import org.sonar.server.tester.UserSessionRule; @@ -51,7 +51,7 @@ import static org.mockito.Mockito.mock; public class GlobalNavigationActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/GroupMembershipServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/GroupMembershipServiceTest.java index c7c0000e4cb..386060f0f91 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/GroupMembershipServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/GroupMembershipServiceTest.java @@ -21,16 +21,15 @@ package org.sonar.server.user; import com.google.common.collect.ImmutableMap; -import org.junit.Before; +import java.util.List; +import org.junit.Rule; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.sonar.api.utils.System2; -import org.sonar.db.AbstractDaoTestCase; import org.sonar.core.user.GroupMembership; -import org.sonar.db.user.GroupMembershipDao; -import org.sonar.db.user.UserDao; +import org.sonar.db.DbTester; import org.sonar.server.exceptions.NotFoundException; - -import java.util.List; +import org.sonar.test.DbTests; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -38,21 +37,17 @@ import static org.junit.Assert.fail; /** * Use BbUnit tests because there's no IT on this feature for the moment */ -public class GroupMembershipServiceTest extends AbstractDaoTestCase { +@Category(DbTests.class) +public class GroupMembershipServiceTest { - GroupMembershipService service; + @Rule + public DbTester dbTester = DbTester.create(System2.INSTANCE); - @Before - public void before() { - GroupMembershipDao membershipDao = new GroupMembershipDao(getMyBatis()); - UserDao userDao = new UserDao(getMyBatis(), System2.INSTANCE); - GroupMembershipFinder finder = new GroupMembershipFinder(userDao, membershipDao); - service = new GroupMembershipService(finder); - } + GroupMembershipService service = new GroupMembershipService(new GroupMembershipFinder(dbTester.getDbClient().userDao(), dbTester.getDbClient().groupMembershipDao())); @Test public void find_all_member_groups() { - setupData("shared"); + dbTester.prepareDbUnit(getClass(), "shared.xml"); GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of( "user", "user1", @@ -66,7 +61,7 @@ public class GroupMembershipServiceTest extends AbstractDaoTestCase { @Test public void find_all_member_groups_when_no_selected_parameter() { - setupData("shared"); + dbTester.prepareDbUnit(getClass(), "shared.xml"); GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of( "user", "user1")); @@ -79,7 +74,7 @@ public class GroupMembershipServiceTest extends AbstractDaoTestCase { @Test public void find_member_groups() { - setupData("shared"); + dbTester.prepareDbUnit(getClass(), "shared.xml"); GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of( "user", "user1", @@ -91,7 +86,7 @@ public class GroupMembershipServiceTest extends AbstractDaoTestCase { @Test public void find_not_member_groups() { - setupData("shared"); + dbTester.prepareDbUnit(getClass(), "shared.xml"); GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of( "user", "user1", @@ -104,14 +99,14 @@ public class GroupMembershipServiceTest extends AbstractDaoTestCase { @Test public void find_with_paging_with_more_results() { - setupData("shared"); + dbTester.prepareDbUnit(getClass(), "shared.xml"); GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of( "user", "user1", "selected", "all", "page", 1, "pageSize", 2 - )); + )); List<GroupMembership> result = queryResult.groups(); assertThat(result).hasSize(2); assertThat(queryResult.hasMoreResults()).isTrue(); @@ -119,14 +114,14 @@ public class GroupMembershipServiceTest extends AbstractDaoTestCase { @Test public void find_with_paging_with_no_more_results() { - setupData("shared"); + dbTester.prepareDbUnit(getClass(), "shared.xml"); GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of( "user", "user1", "selected", "all", "page", 3, "pageSize", 1 - )); + )); List<GroupMembership> result = queryResult.groups(); assertThat(result).hasSize(1); assertThat(queryResult.hasMoreResults()).isFalse(); @@ -134,7 +129,7 @@ public class GroupMembershipServiceTest extends AbstractDaoTestCase { @Test public void fail_if_user_not_found() { - setupData("shared"); + dbTester.prepareDbUnit(getClass(), "shared.xml"); try { service.find(ImmutableMap.<String, Object>of( @@ -148,7 +143,7 @@ public class GroupMembershipServiceTest extends AbstractDaoTestCase { @Test public void find_matched_groups_name() { - setupData("shared"); + dbTester.prepareDbUnit(getClass(), "shared.xml"); GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of( "user", "user1", diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java index 97c54d602b9..e6fb69e2062 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java @@ -40,6 +40,7 @@ import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.GroupMembershipQuery; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.BadRequestException; @@ -47,7 +48,6 @@ import org.sonar.server.exceptions.Message; import org.sonar.server.exceptions.ServerException; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.user.index.UserIndexDefinition; import org.sonar.server.user.index.UserIndexer; import org.sonar.server.util.Validation; @@ -65,7 +65,7 @@ import static org.mockito.Mockito.when; public class UserUpdaterTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/db/GroupDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/db/GroupDaoTest.java index c2c7ff2811a..41657bbf5af 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/db/GroupDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/db/GroupDaoTest.java @@ -40,7 +40,7 @@ import static org.mockito.Mockito.when; public class GroupDaoTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); GroupDao dao; DbSession session; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/db/UserDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/db/UserDaoTest.java index fe6b79cbe27..6b6b638e2a7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/db/UserDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/db/UserDaoTest.java @@ -20,6 +20,7 @@ package org.sonar.server.user.db; +import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -32,8 +33,6 @@ import org.sonar.db.user.UserDto; import org.sonar.server.exceptions.NotFoundException; import org.sonar.test.DbTests; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -42,7 +41,7 @@ import static org.mockito.Mockito.mock; public class UserDaoTest { @Rule - public DbTester db = new DbTester(); + public DbTester db = DbTester.create(System2.INSTANCE); private UserDao dao; private DbSession session; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java index b78e38c17d3..b893ee5ede4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java @@ -19,26 +19,26 @@ */ package org.sonar.server.user.index; +import java.util.List; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.config.Settings; +import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.test.DbTests; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; @Category(DbTests.class) public class UserIndexerTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java index a77e55b949d..261568bbbdf 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java @@ -32,6 +32,7 @@ import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.BadRequestException; @@ -44,7 +45,6 @@ import org.sonar.server.user.SecurityRealmFactory; import org.sonar.server.user.UserUpdater; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.user.index.UserIndex; import org.sonar.server.user.index.UserIndexDefinition; import org.sonar.server.user.index.UserIndexer; @@ -60,7 +60,7 @@ public class ChangePasswordActionTest { static final Settings settings = new Settings().setProperty("sonar.defaultGroup", "sonar-users"); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index 90ec43259ed..ebcd12af6a2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -36,6 +36,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -45,7 +46,6 @@ import org.sonar.server.user.SecurityRealmFactory; import org.sonar.server.user.UserUpdater; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.user.index.UserDoc; import org.sonar.server.user.index.UserIndex; import org.sonar.server.user.index.UserIndexDefinition; @@ -63,7 +63,7 @@ public class CreateActionTest { static final Settings settings = new Settings().setProperty("sonar.defaultGroup", "sonar-users"); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index 3b993ea4c4c..2939ce81f9d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -61,7 +61,7 @@ public class DeactivateActionTest { static final Settings settings = new Settings(); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings)); @Rule 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 dc68bbe7c62..0d9248068cc 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 @@ -33,6 +33,7 @@ import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; @@ -40,13 +41,12 @@ import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.ws.WsTester; public class GroupsActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSession = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java index 3c5a8e6c21b..c0c49ca2f30 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java @@ -39,13 +39,13 @@ import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.user.index.UserDoc; import org.sonar.server.user.index.UserIndex; import org.sonar.server.user.index.UserIndexDefinition; @@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class SearchActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java index 62641c70060..db6f3932faf 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java @@ -34,6 +34,7 @@ import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; @@ -43,7 +44,6 @@ import org.sonar.server.user.SecurityRealmFactory; import org.sonar.server.user.UserUpdater; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.user.index.UserIndex; import org.sonar.server.user.index.UserIndexDefinition; import org.sonar.server.user.index.UserIndexer; @@ -57,7 +57,7 @@ public class UpdateActionTest { static final Settings settings = new Settings().setProperty("sonar.defaultGroup", "sonar-users"); @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings)); @Rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java index 394a5a851e2..adb1f863a96 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java @@ -36,13 +36,13 @@ import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -52,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class AddUserActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public final UserSessionRule userSession = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java index 0d49f2bbc3a..5c422838003 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java @@ -45,7 +45,7 @@ import org.sonar.test.DbTests; public class CreateActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSession = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java index 7e2d9d26c9b..786e2d50e89 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java @@ -30,18 +30,18 @@ import org.sonar.api.config.Settings; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; import org.sonar.core.permission.GlobalPermissions; -import org.sonar.db.permission.PermissionTemplateDao; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.permission.PermissionTemplateDao; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupRoleDto; import org.sonar.db.user.RoleDao; +import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.db.GroupDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class DeleteActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSession = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java index 6e410e339d7..94e3b208c77 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java @@ -35,13 +35,13 @@ import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class RemoveUserActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public final UserSessionRule userSession = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java index 641539ffbb1..1c100744bc5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java @@ -32,10 +32,10 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; +import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.db.DbClient; import org.sonar.server.user.db.GroupDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class SearchActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); private WsTester tester; diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java index 50c0bb158ef..f54ea91549e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java @@ -34,6 +34,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; +import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; @@ -41,7 +42,6 @@ import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.ServerException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.db.GroupDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -49,7 +49,7 @@ import org.sonar.test.DbTests; public class UpdateActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSession = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java index 60feb1a1e73..f8f12b85e55 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java @@ -34,6 +34,7 @@ import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; @@ -41,7 +42,6 @@ import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.db.GroupDao; import org.sonar.server.user.db.UserDao; -import org.sonar.db.user.UserGroupDao; import org.sonar.server.ws.WsTester; import org.sonar.server.ws.WsTester.TestRequest; import org.sonar.test.DbTests; @@ -50,7 +50,7 @@ import org.sonar.test.DbTests; public class UsersActionTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSession = UserSessionRule.standalone(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java index 07547ed9fb5..b9c7033e44a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java @@ -33,11 +33,13 @@ import org.junit.experimental.categories.Category; import org.sonar.api.config.Settings; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.issue.IssueDto; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.issue.IssueDao; +import org.sonar.db.issue.IssueDto; import org.sonar.db.rule.RuleDto; +import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.GroupRoleDto; import org.sonar.db.user.RoleDao; import org.sonar.server.component.ComponentTesting; @@ -48,13 +50,11 @@ import org.sonar.server.es.SearchOptions; import org.sonar.server.es.SearchResult; import org.sonar.server.issue.IssueQuery; import org.sonar.server.issue.IssueTesting; -import org.sonar.db.issue.IssueDao; import org.sonar.server.issue.index.IssueAuthorizationIndexer; import org.sonar.server.issue.index.IssueDoc; import org.sonar.server.issue.index.IssueIndex; import org.sonar.server.issue.index.IssueIndexDefinition; import org.sonar.server.issue.index.IssueIndexer; -import org.sonar.db.rule.RuleTesting; import org.sonar.server.rule.db.RuleDao; import org.sonar.server.tester.UserSessionRule; import org.sonar.test.DbTests; @@ -66,7 +66,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ViewIndexerTest { @Rule - public DbTester dbTester = new DbTester(); + public DbTester dbTester = DbTester.create(System2.INSTANCE); @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings())); |