From 8f66d37bf9687f52532816e1842eda36a19078c4 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 7 Feb 2017 17:10:21 +0100 Subject: [PATCH] Remove some instantiations of ComponentDbTester --- .../server/ce/ws/ActivityActionTest.java | 12 ++- .../ce/ws/ActivityStatusActionTest.java | 8 +- .../server/ce/ws/ComponentActionTest.java | 20 +++-- .../server/component/ComponentFinderTest.java | 10 +-- .../sonar/db/component/ComponentDaoTest.java | 77 ++++++++++--------- .../sonar/db/component/SnapshotDaoTest.java | 15 ++-- .../ProjectQgateAssociationDaoTest.java | 5 +- .../qualityprofile/QualityProfileDaoTest.java | 45 +++++------ .../java/org/sonar/db/user/RoleDaoTest.java | 6 +- 9 files changed, 89 insertions(+), 109 deletions(-) diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java index dde5d621204..8110c87c780 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java @@ -36,7 +36,6 @@ import org.sonar.db.DbTester; import org.sonar.db.ce.CeActivityDto; import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskTypes; -import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; import org.sonar.server.exceptions.BadRequestException; @@ -77,7 +76,6 @@ public class ActivityActionTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - private ComponentDbTester componentDb = new ComponentDbTester(dbTester); private TaskFormatter formatter = new TaskFormatter(dbTester.getDbClient(), System2.INSTANCE); private ActivityAction underTest = new ActivityAction(userSession, dbTester.getDbClient(), formatter, new CeTaskProcessor[] {mock(CeTaskProcessor.class)}); private WsActionTester ws = new WsActionTester(underTest); @@ -237,9 +235,9 @@ public class ActivityActionTest { ComponentDto struts = newProjectDto(organizationDto).setName("old apache struts").setUuid("P1").setProjectUuid("P1"); ComponentDto zookeeper = newProjectDto(organizationDto).setName("new apache zookeeper").setUuid("P2").setProjectUuid("P2"); ComponentDto eclipse = newProjectDto(organizationDto).setName("eclipse").setUuid("P3").setProjectUuid("P3"); - componentDb.insertProjectAndSnapshot(struts); - componentDb.insertProjectAndSnapshot(zookeeper); - componentDb.insertProjectAndSnapshot(eclipse); + dbTester.components().insertProjectAndSnapshot(struts); + dbTester.components().insertProjectAndSnapshot(zookeeper); + dbTester.components().insertProjectAndSnapshot(eclipse); logInAsRoot(); insertActivity("T1", "P1", CeActivityDto.Status.SUCCESS); insertActivity("T2", "P2", CeActivityDto.Status.SUCCESS); @@ -255,8 +253,8 @@ public class ActivityActionTest { OrganizationDto organizationDto = dbTester.organizations().insert(); ComponentDto apacheView = newView(organizationDto).setName("Apache View").setUuid("V1").setProjectUuid("V1"); ComponentDto developer = newDeveloper(organizationDto, "Apache Developer").setUuid("D1").setProjectUuid("D1"); - componentDb.insertDeveloperAndSnapshot(developer); - componentDb.insertViewAndSnapshot(apacheView); + dbTester.components().insertDeveloperAndSnapshot(developer); + dbTester.components().insertViewAndSnapshot(apacheView); logInAsRoot(); insertActivity("T1", "D1", CeActivityDto.Status.SUCCESS); insertActivity("T2", "V1", CeActivityDto.Status.SUCCESS); diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java index 6292e3463f3..bd04b54efee 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java @@ -34,7 +34,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.ce.CeActivityDto; import org.sonar.db.ce.CeQueueDto; -import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; import org.sonar.server.component.ComponentFinder; @@ -62,7 +61,6 @@ public class ActivityStatusActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private WsActionTester ws = new WsActionTester(new ActivityStatusAction(userSession, dbClient, new ComponentFinder(dbClient))); @@ -88,8 +86,8 @@ public class ActivityStatusActionTest { String anotherProjectUuid = "another-project-uuid"; userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, projectUuid); OrganizationDto organizationDto = db.organizations().insert(); - componentDb.insertComponent(newProjectDto(organizationDto, projectUuid)); - componentDb.insertComponent(newProjectDto(organizationDto, anotherProjectUuid)); + db.components().insertComponent(newProjectDto(organizationDto, projectUuid)); + db.components().insertComponent(newProjectDto(organizationDto, anotherProjectUuid)); // pending tasks returned insertInQueue(CeQueueDto.Status.PENDING, projectUuid); insertInQueue(CeQueueDto.Status.PENDING, projectUuid); @@ -121,7 +119,7 @@ public class ActivityStatusActionTest { @Test public void fail_if_component_uuid_and_key_are_provided() { ComponentDto project = newProjectDto(db.organizations().insert()); - componentDb.insertComponent(project); + db.components().insertComponent(project); expectedException.expect(IllegalArgumentException.class); callByComponentUuidOrComponentKey(project.uuid(), project.key()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java index 0f7d102132a..9849401bad8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java @@ -29,7 +29,6 @@ import org.sonar.db.DbTester; import org.sonar.db.ce.CeActivityDto; import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskTypes; -import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; import org.sonar.server.component.ComponentFinder; @@ -57,14 +56,13 @@ public class ComponentActionTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); - TaskFormatter formatter = new TaskFormatter(dbTester.getDbClient(), System2.INSTANCE); - ComponentAction underTest = new ComponentAction(userSession, dbTester.getDbClient(), formatter, new ComponentFinder(dbTester.getDbClient())); - WsActionTester ws = new WsActionTester(underTest); + private TaskFormatter formatter = new TaskFormatter(dbTester.getDbClient(), System2.INSTANCE); + private ComponentAction underTest = new ComponentAction(userSession, dbTester.getDbClient(), formatter, new ComponentFinder(dbTester.getDbClient())); + private WsActionTester ws = new WsActionTester(underTest); @Test public void empty_queue_and_empty_activity() { - componentDbTester.insertComponent(newProjectDto(dbTester.organizations().insert(), "PROJECT_1")); + dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert(), "PROJECT_1")); userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1"); TestResponse wsResponse = ws.newRequest() @@ -80,7 +78,7 @@ public class ComponentActionTest { @Test public void project_tasks() { OrganizationDto organizationDto = dbTester.organizations().insert(); - componentDbTester.insertComponent(newProjectDto(organizationDto, "PROJECT_1")); + dbTester.components().insertComponent(newProjectDto(organizationDto, "PROJECT_1")); userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1"); insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS); insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED); @@ -108,7 +106,7 @@ public class ComponentActionTest { @Test public void search_tasks_by_component_key() { - ComponentDto project = componentDbTester.insertProject(); + ComponentDto project = dbTester.components().insertProject(); logInWithBrowsePermission(project); insertActivity("T1", project.uuid(), CeActivityDto.Status.SUCCESS); @@ -123,7 +121,7 @@ public class ComponentActionTest { @Test public void canceled_tasks_must_not_be_picked_as_current_analysis() { - componentDbTester.insertComponent(newProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1")); + dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1")); userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1"); insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS); insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED); @@ -156,7 +154,7 @@ public class ComponentActionTest { @Test public void throw_ForbiddenException_if_user_cant_access_project() { - ComponentDto project = componentDbTester.insertProject(); + ComponentDto project = dbTester.components().insertProject(); userSession.logIn(); expectedException.expect(ForbiddenException.class); @@ -170,7 +168,7 @@ public class ComponentActionTest { @Test public void fail_when_no_component_parameter() { expectedException.expect(IllegalArgumentException.class); - logInWithBrowsePermission(componentDbTester.insertProject()); + logInWithBrowsePermission(dbTester.components().insertProject()); ws.newRequest().execute(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java index 6492598a639..7e5814bc20b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java @@ -25,7 +25,6 @@ import org.junit.rules.ExpectedException; import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.server.exceptions.NotFoundException; @@ -41,10 +40,9 @@ public class ComponentFinderTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - ComponentDbTester componentDb = new ComponentDbTester(db); - final DbSession dbSession = db.getSession(); - ComponentFinder underTest = new ComponentFinder(db.getDbClient()); + private final DbSession dbSession = db.getSession(); + private ComponentFinder underTest = new ComponentFinder(db.getDbClient()); @Test public void fail_when_the_uuid_and_key_are_null() { @@ -97,7 +95,7 @@ public class ComponentFinderTest { @Test public void get_component_by_uuid() { - componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); + db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); ComponentDto component = underTest.getByUuidOrKey(dbSession, "project-uuid", null, ID_AND_KEY); @@ -106,7 +104,7 @@ public class ComponentFinderTest { @Test public void get_component_by_key() { - componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("project-key")); + db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("project-key")); ComponentDto component = underTest.getByUuidOrKey(dbSession, null, "project-key", ID_AND_KEY); diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 2ac7254b0ce..23f0afc361d 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -74,7 +74,6 @@ public class ComponentDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private ComponentDbTester componentDb = new ComponentDbTester(db); private DbSession dbSession = db.getSession(); private ComponentDao underTest = new ComponentDao(); @@ -527,21 +526,23 @@ public class ComponentDaoTest { public void select_projects() { OrganizationDto organization = db.organizations().insert(); ComponentDto provisionedProject = db.components().insertProject(); - ComponentDto provisionedView = db.components().insertView(organization, (dto) -> {}); + ComponentDto provisionedView = db.components().insertView(organization, (dto) -> { + }); String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid(); String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid(); String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid(); assertThat(underTest.selectProjects(dbSession)) - .extracting(ComponentDto::uuid) - .containsOnly(provisionedProject.uuid(), projectUuid); + .extracting(ComponentDto::uuid) + .containsOnly(provisionedProject.uuid(), projectUuid); } @Test public void select_provisioned() { OrganizationDto organization = db.organizations().insert(); ComponentDto provisionedProject = db.components().insertComponent(newProjectDto(organization).setKey("provisioned.project").setName("Provisioned Project")); - ComponentDto provisionedView = db.components().insertView(organization, (dto) -> {}); + ComponentDto provisionedView = db.components().insertView(organization, (dto) -> { + }); String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid(); String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid(); String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid(); @@ -824,8 +825,8 @@ public class ComponentDaoTest { @Test public void delete() throws Exception { - ComponentDto project1 = componentDb.insertProject(db.getDefaultOrganization(), (t) -> t.setKey("PROJECT_1")); - componentDb.insertProject(db.getDefaultOrganization(), (t) -> t.setKey("PROJECT_2")); + ComponentDto project1 = db.components().insertProject(db.getDefaultOrganization(), (t) -> t.setKey("PROJECT_1")); + db.components().insertProject(db.getDefaultOrganization(), (t) -> t.setKey("PROJECT_2")); underTest.delete(dbSession, project1.getId()); dbSession.commit(); @@ -853,11 +854,11 @@ public class ComponentDaoTest { @Test public void selectByQuery_with_paging_query_and_qualifiers() { OrganizationDto organizationDto = db.organizations().insert(); - componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto).setName("aaaa-name")); - componentDb.insertProjectAndSnapshot(newView(organizationDto)); - componentDb.insertProjectAndSnapshot(newDeveloper(organizationDto, "project-name")); + db.components().insertProjectAndSnapshot(newProjectDto(organizationDto).setName("aaaa-name")); + db.components().insertProjectAndSnapshot(newView(organizationDto)); + db.components().insertProjectAndSnapshot(newDeveloper(organizationDto, "project-name")); for (int i = 9; i >= 1; i--) { - componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto).setName("project-" + i)); + db.components().insertProjectAndSnapshot(newProjectDto(organizationDto).setName("project-" + i)); } ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("oJect").setQualifiers(Qualifiers.PROJECT).build(); @@ -874,8 +875,8 @@ public class ComponentDaoTest { public void selectByQuery_with_organization_filters_on_specified_organization() { OrganizationDto organization1 = db.organizations().insert(); OrganizationDto organization2 = db.organizations().insert(); - ComponentDto project1 = componentDb.insertProject(organization1); - ComponentDto project2 = componentDb.insertProject(organization2); + ComponentDto project1 = db.components().insertProject(organization1); + ComponentDto project2 = db.components().insertProject(organization2); assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2)) .extracting(ComponentDto::uuid) @@ -894,8 +895,8 @@ public class ComponentDaoTest { public void countByQuery_with_organization_filters_on_specified_organization() { OrganizationDto organization1 = db.organizations().insert(); OrganizationDto organization2 = db.organizations().insert(); - ComponentDto project1 = componentDb.insertProject(organization1); - ComponentDto project2 = componentDb.insertProject(organization2); + ComponentDto project1 = db.components().insertProject(organization1); + ComponentDto project2 = db.components().insertProject(organization2); assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY)) .isEqualTo(2); @@ -909,7 +910,7 @@ public class ComponentDaoTest { @Test public void selectByQuery_name_with_special_characters() { - componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization()).setName("project-\\_%/-name")); + db.components().insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization()).setName("project-\\_%/-name")); ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("-\\_%/-").setQualifiers(Qualifiers.PROJECT).build(); List result = underTest.selectByQuery(dbSession, query, 0, 10); @@ -920,7 +921,7 @@ public class ComponentDaoTest { @Test public void selectByQuery_key_with_special_characters() { - componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert()).setKey("project-_%-key")); + db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert()).setKey("project-_%-key")); ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-key").setQualifiers(Qualifiers.PROJECT).build(); List result = underTest.selectByQuery(dbSession, query, 0, 10); @@ -931,8 +932,8 @@ public class ComponentDaoTest { @Test public void selectByQuery_filter_on_language() { - componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("java-project-key").setLanguage("java")); - componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("cpp-project-key").setLanguage("cpp")); + db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("java-project-key").setLanguage("java")); + db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("cpp-project-key").setLanguage("cpp")); ComponentQuery query = ComponentQuery.builder().setLanguage("java").setQualifiers(Qualifiers.PROJECT).build(); List result = underTest.selectByQuery(dbSession, query, 0, 10); @@ -954,9 +955,9 @@ public class ComponentDaoTest { @Test public void selectByQuery_on_component_ids() { OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto sonarqube = componentDb.insertComponent(newProjectDto(organizationDto)); - ComponentDto jdk8 = componentDb.insertComponent(newProjectDto(organizationDto)); - ComponentDto cLang = componentDb.insertComponent(newProjectDto(organizationDto)); + ComponentDto sonarqube = db.components().insertComponent(newProjectDto(organizationDto)); + ComponentDto jdk8 = db.components().insertComponent(newProjectDto(organizationDto)); + ComponentDto cLang = db.components().insertComponent(newProjectDto(organizationDto)); ComponentQuery query = ComponentQuery.builder().setQualifiers(Qualifiers.PROJECT) .setComponentIds(newHashSet(sonarqube.getId(), jdk8.getId())).build(); @@ -973,11 +974,11 @@ public class ComponentDaoTest { OrganizationDto organization = db.organizations().insert(); // project -> module -> file ComponentDto project = newProjectDto(organization, PROJECT_UUID); - componentDb.insertProjectAndSnapshot(project); + db.components().insertProjectAndSnapshot(project); ComponentDto module = newModuleDto(MODULE_UUID, project); - componentDb.insertComponent(module); + db.components().insertComponent(module); ComponentDto file = newFileDto(module, null, FILE_1_UUID); - componentDb.insertComponent(file); + db.components().insertComponent(file); db.commit(); // ancestors of root @@ -997,15 +998,15 @@ public class ComponentDaoTest { public void select_descendants_with_children_stragegy() { // project has 2 children: module and file 1. Other files are part of module. ComponentDto project = newProjectDto(db.organizations().insert(), PROJECT_UUID); - componentDb.insertProjectAndSnapshot(project); + db.components().insertProjectAndSnapshot(project); ComponentDto module = newModuleDto(MODULE_UUID, project); - componentDb.insertComponent(module); + db.components().insertComponent(module); ComponentDto file1 = newFileDto(project, null, FILE_1_UUID).setKey("file-key-1").setName("File One"); - componentDb.insertComponent(file1); + db.components().insertComponent(file1); ComponentDto file2 = newFileDto(module, null, FILE_2_UUID).setKey("file-key-2").setName("File Two"); - componentDb.insertComponent(file2); + db.components().insertComponent(file2); ComponentDto file3 = newFileDto(module, null, FILE_3_UUID).setKey("file-key-3").setName("File Three"); - componentDb.insertComponent(file3); + db.components().insertComponent(file3); db.commit(); // test children of root @@ -1062,10 +1063,10 @@ public class ComponentDaoTest { @Test public void select_descendants_with_leaves_strategy() { ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID); - componentDb.insertProjectAndSnapshot(project); - componentDb.insertComponent(newModuleDto("module-1-uuid", project)); - componentDb.insertComponent(newFileDto(project, null, "file-1-uuid")); - componentDb.insertComponent(newFileDto(project, null, "file-2-uuid")); + db.components().insertProjectAndSnapshot(project); + db.components().insertComponent(newModuleDto("module-1-uuid", project)); + db.components().insertComponent(newFileDto(project, null, "file-1-uuid")); + db.components().insertComponent(newFileDto(project, null, "file-2-uuid")); db.commit(); ComponentTreeQuery query = newTreeQuery(PROJECT_UUID).setStrategy(LEAVES).build(); @@ -1086,14 +1087,14 @@ public class ComponentDaoTest { public void select_descendants_of_a_view_and_filter_by_name() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto view = newView(organizationDto, A_VIEW_UUID); - componentDb.insertViewAndSnapshot(view); + db.components().insertViewAndSnapshot(view); // one subview ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview name"); - componentDb.insertComponent(subView); + db.components().insertComponent(subView); // one project and its copy linked to the view ComponentDto project = newProjectDto(organizationDto, PROJECT_UUID).setName("project name"); - componentDb.insertProjectAndSnapshot(project); - componentDb.insertComponent(newProjectCopy("project-copy-uuid", project, view)); + db.components().insertProjectAndSnapshot(project); + db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view)); ComponentTreeQuery dbQuery = newTreeQuery(A_VIEW_UUID).setNameOrKeyQuery("name").setStrategy(CHILDREN).build(); List components = underTest.selectDescendants(dbSession, dbQuery); diff --git a/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java index faf2c5e4d2a..dce25875e67 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java @@ -47,14 +47,13 @@ public class SnapshotDaoTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); - ComponentDbTester componentDb = new ComponentDbTester(db); - DbClient dbClient = db.getDbClient(); - DbSession dbSession = db.getSession(); - SnapshotDao underTest = dbClient.snapshotDao(); + private DbClient dbClient = db.getDbClient(); + private DbSession dbSession = db.getSession(); + + private SnapshotDao underTest = dbClient.snapshotDao(); @Test public void test_selectByUuid() { @@ -136,12 +135,12 @@ public class SnapshotDaoTest { @Test public void selectLastSnapshotsByRootComponentUuids_returns_snapshots_flagged_as_last() { - ComponentDto firstProject = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_1")); + ComponentDto firstProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_1")); dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(false)); SnapshotDto lastSnapshotOfFirstProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(true)); - ComponentDto secondProject = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_2")); + ComponentDto secondProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_2")); SnapshotDto lastSnapshotOfSecondProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(secondProject).setLast(true)); - componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization())); + db.components().insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization())); List result = underTest.selectLastAnalysesByRootComponentUuids(dbSession, newArrayList(firstProject.uuid(), secondProject.uuid())); diff --git a/sonar-db/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java index d77350c7bb9..df5823737eb 100644 --- a/sonar-db/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java @@ -27,19 +27,16 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.property.PropertyDto; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.db.component.ComponentTesting.newProjectDto; public class ProjectQgateAssociationDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private ProjectQgateAssociationDao underTest = db.getDbClient().projectQgateAssociationDao(); @@ -91,7 +88,7 @@ public class ProjectQgateAssociationDaoTest { @Test public void select_qgate_id_is_absent() { - ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); + ComponentDto project = db.components().insertProject(); Optional result = underTest.selectQGateIdByComponentId(dbSession, project.getId()); diff --git a/sonar-db/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/sonar-db/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index 6ff569a7eb0..953965fe44d 100644 --- a/sonar-db/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -28,7 +28,6 @@ import org.sonar.api.utils.System2; import org.sonar.core.util.UtcDateUtils; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import static com.google.common.collect.ImmutableList.of; @@ -43,17 +42,14 @@ import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfil public class QualityProfileDaoTest { - System2 system = mock(System2.class); + private System2 system = mock(System2.class); @Rule public DbTester dbTester = DbTester.create(system); - DbSession dbSession = dbTester.getSession(); - - QualityProfileDbTester qualityProfileDb = new QualityProfileDbTester(dbTester); - ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); - - QualityProfileDao underTest = dbTester.getDbClient().qualityProfileDao(); + private DbSession dbSession = dbTester.getSession(); + private QualityProfileDbTester qualityProfileDb = new QualityProfileDbTester(dbTester); + private QualityProfileDao underTest = dbTester.getDbClient().qualityProfileDao(); @Before public void before() { @@ -70,7 +66,7 @@ public class QualityProfileDaoTest { underTest.insert(dto); - dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[]{"created_at", "updated_at", "rules_updated_at"}, "rules_profiles"); + dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"created_at", "updated_at", "rules_updated_at"}, "rules_profiles"); } @Test @@ -87,7 +83,7 @@ public class QualityProfileDaoTest { underTest.update(dbSession, dto); dbSession.commit(); - dbTester.assertDbUnit(getClass(), "update-result.xml", new String[]{"created_at", "updated_at", "rules_updated_at"}, "rules_profiles"); + dbTester.assertDbUnit(getClass(), "update-result.xml", new String[] {"created_at", "updated_at", "rules_updated_at"}, "rules_profiles"); } @Test @@ -300,9 +296,9 @@ public class QualityProfileDaoTest { @Test public void select_selected_projects() throws Exception { - ComponentDto project1 = componentDbTester.insertProject((t) -> t.setName("Project1 name")); - ComponentDto project2 = componentDbTester.insertProject((t) -> t.setName("Project2 name")); - ComponentDto project3 = componentDbTester.insertProject((t) -> t.setName("Project3 name")); + ComponentDto project1 = dbTester.components().insertProject((t) -> t.setName("Project1 name")); + ComponentDto project2 = dbTester.components().insertProject((t) -> t.setName("Project2 name")); + ComponentDto project3 = dbTester.components().insertProject((t) -> t.setName("Project3 name")); QualityProfileDto profile1 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile1); @@ -317,8 +313,7 @@ public class QualityProfileDaoTest { .extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey") .containsOnly( tuple(project1.getId(), project1.uuid(), project1.key(), project1.name(), profile1.getKey()), - tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), profile1.getKey()) - ); + tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), profile1.getKey())); assertThat(underTest.selectSelectedProjects(profile1.getKey(), "ect1", dbSession)).hasSize(1); assertThat(underTest.selectSelectedProjects("unknown", null, dbSession)).isEmpty(); @@ -326,9 +321,9 @@ public class QualityProfileDaoTest { @Test public void select_deselected_projects() throws Exception { - ComponentDto project1 = componentDbTester.insertProject((t) -> t.setName("Project1 name")); - ComponentDto project2 = componentDbTester.insertProject((t) -> t.setName("Project2 name")); - ComponentDto project3 = componentDbTester.insertProject((t) -> t.setName("Project3 name")); + ComponentDto project1 = dbTester.components().insertProject((t) -> t.setName("Project1 name")); + ComponentDto project2 = dbTester.components().insertProject((t) -> t.setName("Project2 name")); + ComponentDto project3 = dbTester.components().insertProject((t) -> t.setName("Project3 name")); QualityProfileDto profile1 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile1); @@ -342,8 +337,7 @@ public class QualityProfileDaoTest { .extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey") .containsOnly( tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), null), - tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null) - ); + tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null)); assertThat(underTest.selectDeselectedProjects(profile1.getKey(), "ect2", dbSession)).hasSize(1); assertThat(underTest.selectDeselectedProjects("unknown", null, dbSession)).hasSize(3); @@ -351,9 +345,9 @@ public class QualityProfileDaoTest { @Test public void select_project_associations() throws Exception { - ComponentDto project1 = componentDbTester.insertProject((t) -> t.setName("Project1 name")); - ComponentDto project2 = componentDbTester.insertProject((t) -> t.setName("Project2 name")); - ComponentDto project3 = componentDbTester.insertProject((t) -> t.setName("Project3 name")); + ComponentDto project1 = dbTester.components().insertProject((t) -> t.setName("Project1 name")); + ComponentDto project2 = dbTester.components().insertProject((t) -> t.setName("Project2 name")); + ComponentDto project3 = dbTester.components().insertProject((t) -> t.setName("Project3 name")); QualityProfileDto profile1 = newQualityProfileDto(); qualityProfileDb.insertQualityProfiles(profile1); @@ -368,8 +362,7 @@ public class QualityProfileDaoTest { .containsOnly( tuple(project1.getId(), project1.uuid(), project1.key(), project1.name(), profile1.getKey()), tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), null), - tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null) - ); + tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null)); assertThat(underTest.selectProjectAssociations(profile1.getKey(), "ect2", dbSession)).hasSize(1); assertThat(underTest.selectProjectAssociations("unknown", null, dbSession)).hasSize(3); @@ -377,7 +370,7 @@ public class QualityProfileDaoTest { @Test public void update_project_profile_association() { - ComponentDto project = componentDbTester.insertProject(); + ComponentDto project = dbTester.components().insertProject(); QualityProfileDto profile1Language1 = insertQualityProfileDto("profile1", "Profile 1", "xoo"); QualityProfileDto profile2Language2 = insertQualityProfileDto("profile2", "Profile 2", "xoo2"); QualityProfileDto profile3Language1 = insertQualityProfileDto("profile3", "Profile 3", "xoo"); diff --git a/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java index 7190db6203a..18efab675ff 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java @@ -28,7 +28,6 @@ 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.ComponentDbTester; import org.sonar.db.component.ComponentDto; import static org.assertj.core.api.Assertions.assertThat; @@ -50,9 +49,8 @@ public class RoleDaoTest { public void setUp() throws Exception { user1 = db.users().insertUser(); user2 = db.users().insertUser(); - ComponentDbTester componentDbTester = new ComponentDbTester(db); - project1 = componentDbTester.insertProject(); - project2 = componentDbTester.insertProject(); + project1 = db.components().insertProject(); + project2 = db.components().insertProject(); } @Test -- 2.39.5