From 5bfa95f6d5928460f1d8102417d5b6604f96feba Mon Sep 17 00:00:00 2001 From: Michal Duda Date: Mon, 21 Dec 2020 17:55:10 +0100 Subject: [PATCH] SONAR-13999 Remove OrganizationDbTester --- .../step/ViewsPersistComponentsStepTest.java | 6 +- .../org/sonar/db/ce/CeActivityDaoTest.java | 15 +- .../sonar/db/component/ComponentDaoTest.java | 125 ++++----- .../sonar/db/component/ComponentDtoTest.java | 8 +- .../component/ComponentKeyUpdaterDaoTest.java | 31 +-- .../db/component/ComponentTreeQueryTest.java | 5 +- .../sonar/db/component/SnapshotDaoTest.java | 20 +- .../db/duplication/DuplicationDaoTest.java | 33 +-- .../java/org/sonar/db/event/EventDaoTest.java | 24 +- .../java/org/sonar/db/issue/IssueDaoTest.java | 9 +- .../org/sonar/db/issue/IssueMapperTest.java | 46 ++-- .../sonar/db/measure/LiveMeasureDaoTest.java | 17 +- .../db/measure/MeasureTreeQueryTest.java | 5 +- .../ProjectMeasuresIndexerIteratorTest.java | 58 ++-- .../db/permission/PermissionQueryTest.java | 5 +- .../sonar/db/property/PropertiesDaoTest.java | 13 +- .../java/org/sonar/db/purge/PurgeDaoTest.java | 28 +- .../org/sonar/db/purge/PurgeMapperTest.java | 12 +- .../qualityprofile/QualityProfileDaoTest.java | 5 +- .../sonar/db/source/FileSourceDaoTest.java | 26 +- .../org/sonar/db/webhook/WebhookDaoTest.java | 10 +- .../java/org/sonar/db/DbTester.java | 33 +-- .../sonar/db/component/ComponentDbTester.java | 251 +++--------------- .../sonar/db/component/ComponentTesting.java | 49 ---- .../org/sonar/db/issue/IssueDbTester.java | 27 +- .../db/organization/OrganizationDbTester.java | 81 ------ .../db/organization/OrganizationTesting.java | 46 ---- .../component/index/ComponentIndexerTest.java | 4 +- .../server/es/ProjectIndexersImplTest.java | 8 +- .../issue/index/IssueIteratorFactoryTest.java | 18 +- .../index/ProjectMeasuresIndexerTest.java | 30 +-- .../DefaultOrganizationProviderImplTest.java | 13 +- .../server/rule/index/RuleIndexerTest.java | 3 - .../server/view/index/ViewIndexerTest.java | 27 +- .../ProjectLifeCycleListenersImplTest.java | 23 +- .../server/project/RekeyedProjectTest.java | 3 +- .../DefaultGroupCreatorImplTest.java | 8 +- .../TelemetryDataLoaderImplTest.java | 7 +- .../WebhookQGChangeEventListenerTest.java | 18 +- .../measure/index/ProjectMeasuresQuery.java | 4 + .../index/ComponentIndexSearchTest.java | 21 +- .../component/index/ComponentIndexTest.java | 15 +- .../issue/index/IssueIndexDebtTest.java | 41 ++- .../issue/index/IssueIndexFacetsTest.java | 67 ++--- .../IssueIndexProjectStatisticsTest.java | 42 ++- .../index/IssueIndexSecurityHotspotsTest.java | 7 +- .../index/IssueIndexSecurityReportsTest.java | 31 +-- .../issue/index/IssueIndexSortTest.java | 30 +-- .../IssueIndexSyncProgressCheckerTest.java | 4 +- .../issue/index/IssueQueryFactoryTest.java | 18 +- .../index/ProjectMeasuresIndexTest.java | 107 +++----- .../ProjectMeasuresIndexTextSearchTest.java | 74 +++--- .../index/PermissionIndexerDaoTest.java | 32 +-- .../index/PermissionIndexerTest.java | 16 +- .../server/badge/ws/MeasureActionTest.java | 4 +- .../badge/ws/QualityGateActionTest.java | 6 +- .../server/batch/ProjectDataLoaderTest.java | 16 +- .../server/branch/pr/ws/ListActionTest.java | 9 +- .../server/branch/ws/ListActionTest.java | 20 +- .../server/ce/ws/ActivityActionTest.java | 12 +- .../server/component/ws/ShowActionTest.java | 4 +- .../component/ws/SuggestionsActionTest.java | 2 +- .../server/duplication/ws/ShowActionTest.java | 7 +- .../measure/ws/ComponentActionTest.java | 2 +- .../PermissionTemplateServiceTest.java | 2 +- .../permission/ws/RemoveGroupActionTest.java | 2 +- .../permission/ws/RemoveUserActionTest.java | 2 +- .../project/ws/BulkDeleteActionTest.java | 2 +- .../ws/UpdateVisibilityActionTest.java | 2 +- .../projectanalysis/ws/SearchActionTest.java | 9 +- .../projectlink/ws/CreateActionTest.java | 2 +- .../projectlink/ws/SearchActionTest.java | 2 +- .../server/projecttag/ws/SetActionTest.java | 6 +- .../setting/ws/ListDefinitionsActionTest.java | 2 +- .../server/setting/ws/ResetActionTest.java | 16 +- .../server/setting/ws/SetActionTest.java | 12 +- .../setting/ws/SettingsUpdaterTest.java | 8 +- .../server/setting/ws/ValuesActionTest.java | 6 +- .../server/source/ws/HashActionTest.java | 12 +- .../source/ws/IssueSnippetsActionTest.java | 2 +- .../server/source/ws/LinesActionTest.java | 42 +-- .../sonar/server/source/ws/ScmActionTest.java | 20 +- .../server/source/ws/ShowActionTest.java | 3 +- .../server/usergroups/ws/UsersActionTest.java | 3 - .../sonarqube/ws/client/DefaultWsClient.java | 8 - .../org/sonarqube/ws/client/WsClient.java | 3 - .../organizations/OrganizationsService.java | 89 ------- .../organizations/SearchMembersRequest.java | 103 ------- .../client/organizations/SearchRequest.java | 92 ------- .../ws/client/organizations/package-info.java | 26 -- .../src/main/protobuf/ws-organizations.proto | 81 ------ 91 files changed, 640 insertions(+), 1658 deletions(-) delete mode 100644 server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java delete mode 100644 server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationTesting.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/OrganizationsService.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/SearchMembersRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/SearchRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/package-info.java delete mode 100644 sonar-ws/src/main/protobuf/ws-organizations.proto diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java index ed4377c5109..696c7a8961f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java @@ -378,7 +378,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persists_new_components_as_public_if_root_does_not_exist_yet_out_of_functional_transaction() { - ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); + ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto()); treeRootHolder.setRoot( createViewBuilder(PORTFOLIO) .addChildren( @@ -397,7 +397,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persists_new_components_with_visibility_of_root_in_db_out_of_functional_transaction() { boolean isRootPrivate = new Random().nextBoolean(); - ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); + ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto()); ComponentDto view = newViewDto().setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); dbTester.components().insertComponent(view); treeRootHolder.setRoot( @@ -420,7 +420,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { @Test public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() { boolean isRootPrivate = new Random().nextBoolean(); - ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); + ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto()); ComponentDto view = newViewDto().setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); dbTester.components().insertComponent(view); ComponentDto subView = newSubView(view).setUuid("BCDE").setDbKey("MODULE").setPrivate(!isRootPrivate); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java index faf9cee5e27..b2d0f5e16d2 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java @@ -768,17 +768,22 @@ public class CeActivityDaoTest { insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS); insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED); - ProjectDto projectDto1 = db.components() - .insertPrivateProjectDto(db.getDefaultOrganization(), branchDto -> branchDto.setNeedIssueSync(false)); + ProjectDto projectDto1 = db.components().insertPrivateProjectDto( + branchDto -> branchDto.setNeedIssueSync(false), c -> { + }, p -> { + }); insert("TASK_3", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto1.getUuid(), projectDto1.getUuid(), SUCCESS); - ProjectDto projectDto2 = db.components() - .insertPrivateProjectDto(db.getDefaultOrganization(), branchDto -> branchDto.setNeedIssueSync(false)); + ProjectDto projectDto2 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> { + }, p -> { + }); insert("TASK_4", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto2.getUuid(), projectDto2.getUuid(), SUCCESS); assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse(); - ProjectDto projectDto3 = db.components().insertPrivateProjectDto(db.getDefaultOrganization(), branchDto -> branchDto.setNeedIssueSync(false)); + ProjectDto projectDto3 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> { + }, p -> { + }); insert("TASK_5", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto3.getUuid(), projectDto3.getUuid(), SUCCESS); BranchDto projectBranch = db.components() diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 9e07a000cf4..5f39008bf3d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -50,7 +50,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.RowNotFoundException; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.source.FileSourceDto; import static com.google.common.collect.ImmutableSet.of; @@ -96,14 +95,14 @@ public class ComponentDaoTest { private static final String A_VIEW_UUID = "view-uuid"; private static final ComponentQuery ALL_PROJECTS_COMPONENT_QUERY = ComponentQuery.builder().setQualifiers("TRK").build(); - private System2 system2 = new AlwaysIncreasingSystem2(1000L); + private final System2 system2 = new AlwaysIncreasingSystem2(1000L); @Rule public DbTester db = DbTester.create(system2); - private Random random = new Random(); - private DbSession dbSession = db.getSession(); - private ComponentDao underTest = new ComponentDao(); + private final Random random = new Random(); + private final DbSession dbSession = db.getSession(); + private final ComponentDao underTest = new ComponentDao(); private static ComponentTreeQuery.Builder newTreeQuery(String baseUuid) { return ComponentTreeQuery.builder() @@ -113,16 +112,15 @@ public class ComponentDaoTest { @Test public void get_by_uuid() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization, p -> p + ComponentDto project = db.components().insertPrivateProject(p -> p .setDbKey("org.struts:struts") .setName("Struts") .setLongName("Apache Struts")); - ComponentDto anotherProject = db.components().insertPrivateProject(organization); + ComponentDto anotherProject = db.components().insertPrivateProject(); ComponentDto result = underTest.selectByUuid(dbSession, project.uuid()).get(); assertThat(result).isNotNull(); - assertThat(result.getOrganizationUuid()).isEqualTo(organization.getUuid()); + assertThat(result.getOrganizationUuid()).isEqualTo(db.getDefaultOrganization().getUuid()); assertThat(result.uuid()).isEqualTo(project.uuid()); assertThat(result.getUuidPath()).isEqualTo("."); assertThat(result.moduleUuid()).isNull(); @@ -143,7 +141,7 @@ public class ComponentDaoTest { @Test public void get_by_uuid_on_technical_project_copy() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPublicPortfolio(); ComponentDto project = db.components().insertPublicProject(p -> p .setDbKey("org.struts:struts") .setName("Struts") @@ -188,8 +186,7 @@ public class ComponentDaoTest { @Test public void selectByKey() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "src")); ComponentDto file = db.components().insertComponent(newFileDto(project, directory) .setDbKey("org.struts:struts-core:src/org/struts/RequestContext.java") @@ -201,7 +198,7 @@ public class ComponentDaoTest { Optional optional = underTest.selectByKey(dbSession, file.getDbKey()); ComponentDto result = optional.get(); - assertThat(result.getOrganizationUuid()).isEqualTo(organization.getUuid()); + assertThat(result.getOrganizationUuid()).isEqualTo(db.getDefaultOrganization().getUuid()); assertThat(result.uuid()).isEqualTo(file.uuid()); assertThat(result.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(result.path()).isEqualTo("src/RequestContext.java"); @@ -683,12 +680,14 @@ public class ComponentDaoTest { @Test public void select_views_and_sub_views_and_applications() { - OrganizationDto organization = db.organizations().insert(); - db.components().insertView(organization, "ABCD"); - db.components().insertView(organization, "IJKL"); - ComponentDto view = db.components().insertView(organization, "EFGH"); + db.components().insertPublicPortfolio("ABCD", p -> { + }); + db.components().insertPublicPortfolio("IJKL", p -> { + }); + ComponentDto view = db.components().insertPublicPortfolio("EFGH", p -> { + }); db.components().insertSubView(view, dto -> dto.setUuid("FGHI")); - ComponentDto application = db.components().insertPublicApplication(organization); + ComponentDto application = db.components().insertPublicApplication(); assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getUuid) .containsExactlyInAnyOrder("ABCD", "EFGH", "FGHI", "IJKL", application.uuid()); @@ -981,7 +980,7 @@ public class ComponentDaoTest { db.components().insertComponent(newProjectCopy(project2, viewWithSubView)); ComponentDto subView = db.components().insertSubView(viewWithSubView); db.components().insertComponent(newProjectCopy(project1, subView)); - ComponentDto viewWithoutProject = db.components().insertView(); + ComponentDto viewWithoutProject = db.components().insertPrivatePortfolio(); assertThat(underTest.selectProjectsFromView(dbSession, view.uuid(), view.uuid())).containsExactlyInAnyOrder(project1.uuid()); assertThat(underTest.selectProjectsFromView(dbSession, viewWithSubView.uuid(), viewWithSubView.uuid())).containsExactlyInAnyOrder(project1.uuid(), project2.uuid()); @@ -993,7 +992,7 @@ public class ComponentDaoTest { @Test public void select_projects() { ComponentDto provisionedProject = db.components().insertPrivateProject(); - ComponentDto provisionedView = db.components().insertView(); + ComponentDto provisionedView = db.components().insertPrivatePortfolio(); String projectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto()).getComponentUuid(); String disabledProjectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto().setEnabled(false)).getComponentUuid(); String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView()).getComponentUuid(); @@ -1186,9 +1185,8 @@ public class ComponentDaoTest { } private ListAssert assertSelectForIndexing(@Nullable String projectUuid) { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization, "U1"); - ComponentDto removedProject = db.components().insertPrivateProject(organization, p -> p.setEnabled(false)); + ComponentDto project = db.components().insertPrivateProject("U1"); + ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false)); ComponentDto module = db.components().insertComponent(newModuleDto("U2", project)); ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false)); ComponentDto directory = db.components().insertComponent(newDirectory(module, "U3", "src")); @@ -1196,10 +1194,11 @@ public class ComponentDaoTest { ComponentDto file = db.components().insertComponent(newFileDto(module, directory, "U4")); ComponentDto removedFile = db.components().insertComponent(newFileDto(module, directory).setEnabled(false)); - ComponentDto view = db.components().insertView(organization, "VW1"); + ComponentDto view = db.components().insertPublicPortfolio("VW1", p -> { + }); db.components().insertComponent(newProjectCopy("COPY8", project, view)); - ComponentDto project2 = db.components().insertPrivateProject(organization, "U5"); + ComponentDto project2 = db.components().insertPrivateProject("U5"); ComponentDto moduleOnProject2 = db.components().insertComponent(newModuleDto("U6", project2)); List components = new ArrayList<>(); @@ -1210,7 +1209,7 @@ public class ComponentDaoTest { @Test public void update() { - db.components().insertPrivateProject(db.getDefaultOrganization(), "U1"); + db.components().insertPrivateProject("U1"); underTest.update(dbSession, new ComponentUpdateDto() .setUuid("U1") @@ -1300,8 +1299,8 @@ public class ComponentDaoTest { @Test public void delete() { - ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setDbKey("PROJECT_1")); - db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setDbKey("PROJECT_2")); + ComponentDto project1 = db.components().insertPrivateProject(t -> t.setDbKey("PROJECT_1")); + db.components().insertPrivateProject(t -> t.setDbKey("PROJECT_2")); underTest.delete(dbSession, project1.uuid()); dbSession.commit(); @@ -1373,7 +1372,7 @@ public class ComponentDaoTest { @Test public void selectByQuery_name_with_special_characters() { - db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization()).setName("project-\\_%/-name")); + db.components().insertProjectAndSnapshot(newPrivateProjectDto().setName("project-\\_%/-name")); ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("-\\_%/-").setQualifiers(PROJECT).build(); List result = underTest.selectByQuery(dbSession, query, 0, 10); @@ -1384,8 +1383,8 @@ public class ComponentDaoTest { @Test public void selectByQuery_key_with_special_characters() { - db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert()).setDbKey("project-_%-key")); - db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert()).setDbKey("project-key-that-does-not-match")); + db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-_%-key")); + db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-key-that-does-not-match")); ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-key").setQualifiers(PROJECT).build(); List result = underTest.selectByQuery(dbSession, query, 0, 10); @@ -1396,7 +1395,7 @@ public class ComponentDaoTest { @Test public void selectByQuery_on_key_partial_match_case_insensitive() { - db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert()).setDbKey("project-key")); + db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-key")); ComponentQuery query = ComponentQuery.builder() .setNameOrKeyQuery("JECT-K") @@ -1505,8 +1504,8 @@ public class ComponentDaoTest { @Test public void selectByQuery_filter_on_visibility() { - db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("private-key")); - db.components().insertComponent(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("public-key")); + db.components().insertComponent(newPrivateProjectDto().setDbKey("private-key")); + db.components().insertComponent(ComponentTesting.newPublicProjectDto().setDbKey("public-key")); ComponentQuery privateProjectsQuery = ComponentQuery.builder().setPrivate(true).setQualifiers(PROJECT).build(); ComponentQuery publicProjectsQuery = ComponentQuery.builder().setPrivate(false).setQualifiers(PROJECT).build(); @@ -1531,10 +1530,9 @@ public class ComponentDaoTest { @Test public void selectByQuery_on_component_keys() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto(organizationDto)); - ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto(organizationDto)); - ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto(organizationDto)); + ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto()); + ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto()); + ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto()); ComponentQuery query = ComponentQuery.builder().setQualifiers(PROJECT) .setComponentKeys(newHashSet(sonarqube.getDbKey(), jdk8.getDbKey())).build(); @@ -1559,10 +1557,9 @@ public class ComponentDaoTest { @Test public void selectByQuery_on_component_uuids() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto(organizationDto)); - ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto(organizationDto)); - ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto(organizationDto)); + ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto()); + ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto()); + ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto()); ComponentQuery query = ComponentQuery.builder().setQualifiers(PROJECT) .setComponentUuids(newHashSet(sonarqube.uuid(), jdk8.uuid())).build(); @@ -1575,10 +1572,8 @@ public class ComponentDaoTest { @Test public void selectAncestors() { - // organization - OrganizationDto organization = db.organizations().insert(); // project -> module -> file - ComponentDto project = newPrivateProjectDto(organization, PROJECT_UUID); + ComponentDto project = newPrivateProjectDto(PROJECT_UUID); db.components().insertProjectAndSnapshot(project); ComponentDto module = newModuleDto(MODULE_UUID, project); db.components().insertComponent(module); @@ -1602,7 +1597,7 @@ public class ComponentDaoTest { @Test public void select_descendants_with_children_strategy() { // project has 2 children: module and file 1. Other files are part of module. - ComponentDto project = newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID); + ComponentDto project = newPrivateProjectDto(PROJECT_UUID); db.components().insertProjectAndSnapshot(project); ComponentDto module = newModuleDto(MODULE_UUID, project); db.components().insertComponent(module); @@ -1677,7 +1672,7 @@ public class ComponentDaoTest { @Test public void select_descendants_with_leaves_strategy() { - ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID); + ComponentDto project = newPrivateProjectDto(PROJECT_UUID); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newModuleDto("module-1-uuid", project)); db.components().insertComponent(newFileDto(project, null, "file-1-uuid")); @@ -1700,21 +1695,20 @@ public class ComponentDaoTest { @Test public void select_descendants_of_a_view_and_filter_by_name() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto view = newView(organizationDto, A_VIEW_UUID); + ComponentDto view = newView(A_VIEW_UUID); db.components().insertViewAndSnapshot(view); // one subview ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview name"); db.components().insertComponent(subView); // one project and its copy linked to the view - ComponentDto project = newPrivateProjectDto(organizationDto, PROJECT_UUID).setName("project name"); + ComponentDto project = newPrivateProjectDto(PROJECT_UUID).setName("project name"); 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); assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid"); - assertThat(components).extracting("organizationUuid").containsOnly(organizationDto.getUuid()); + assertThat(components).extracting("organizationUuid").containsOnly(db.getDefaultOrganization().getUuid()); } @Test @@ -1722,13 +1716,12 @@ public class ComponentDaoTest { String uuid1 = "uuid1"; String uuid2 = "uuid2"; - OrganizationDto organizationDto = db.organizations().insert(); String[] uuids = { - db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(true)).uuid(), - db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(false)).uuid(), - db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(true)).uuid(), - db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(false)).uuid(), - db.components().insertComponent(newPrivateProjectDto(organizationDto).setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid1).setPrivate(true)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid1).setPrivate(false)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid2).setPrivate(true)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid2).setPrivate(false)).uuid(), + db.components().insertComponent(newPrivateProjectDto().setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(), }; underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true); @@ -1767,25 +1760,21 @@ public class ComponentDaoTest { @Test public void selectPrivateProjectsWithNcloc() { MetricDto metric = db.measures().insertMetric(m -> m.setKey("ncloc")); - OrganizationDto organizationDto = db.organizations().insert(); // project1, not the biggest branch - not returned - final ComponentDto project1 = db.components().insertPrivateProject(organizationDto, b -> b.setName("foo")); + final ComponentDto project1 = db.components().insertPrivateProject(b -> b.setName("foo")); insertMeasure(20d, project1, metric); // branch of project1 - returned insertMeasure(30d, db.components().insertProjectBranch(project1, b -> b.setBranchType(BRANCH)), metric); // project2 - returned - insertMeasure(10d, db.components().insertPrivateProject(organizationDto, b -> b.setName("bar")), metric); + insertMeasure(10d, db.components().insertPrivateProject(b -> b.setName("bar")), metric); // public project - not returned - insertMeasure(11d, db.components().insertPublicProject(organizationDto, b -> b.setPrivate(false)), metric); - - // different org - not returned - insertMeasure(12d, db.components().insertPrivateProject(db.organizations().insert()), metric); + insertMeasure(11d, db.components().insertPublicProject(b -> b.setName("other")), metric); - List result = underTest.selectPrivateProjectsWithNcloc(db.getSession(), organizationDto.getUuid()); + List result = underTest.selectPrivateProjectsWithNcloc(db.getSession(), db.getDefaultOrganization().getUuid()); assertThat(result).extracting(ProjectNclocDistributionDto::getName).containsExactly("foo", "bar"); assertThat(result).extracting(ProjectNclocDistributionDto::getNcloc).containsExactly(30L, 10L); @@ -1793,12 +1782,12 @@ public class ComponentDaoTest { @Test public void existAnyOfComponentsWithQualifiers() { - ComponentDto projectDto = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization())); + ComponentDto projectDto = db.components().insertComponent(newPrivateProjectDto()); - ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization())); + ComponentDto view = db.components().insertComponent(newView()); ComponentDto subview = db.components().insertComponent(newSubView(view)); - ComponentDto app = db.components().insertComponent(newApplication(db.getDefaultOrganization())); + ComponentDto app = db.components().insertComponent(newApplication()); assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), emptyList(), newHashSet(APP, VIEW, SUBVIEW))).isFalse(); assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), singletonList("not-existing-component"), newHashSet(APP, VIEW, SUBVIEW))).isFalse(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java index 0271571a08f..b9654462500 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java @@ -22,10 +22,8 @@ package org.sonar.db.component; import org.junit.Test; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Scopes; -import org.sonar.db.organization.OrganizationDto; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class ComponentDtoTest { @@ -87,15 +85,13 @@ public class ComponentDtoTest { @Test public void formatUuidPathFromParent() { - ComponentDto parent = ComponentTesting.newPrivateProjectDto(newOrganizationDto(), "123").setUuidPath(ComponentDto.UUID_PATH_OF_ROOT); + ComponentDto parent = ComponentTesting.newPrivateProjectDto("123").setUuidPath(ComponentDto.UUID_PATH_OF_ROOT); assertThat(ComponentDto.formatUuidPathFromParent(parent)).isEqualTo(".123."); } @Test public void getUuidPathLikeIncludingSelf() { - OrganizationDto organizationDto = newOrganizationDto(); - - ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto).setUuidPath(ComponentDto.UUID_PATH_OF_ROOT); + ComponentDto project = ComponentTesting.newPrivateProjectDto().setUuidPath(ComponentDto.UUID_PATH_OF_ROOT); assertThat(project.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + ".%"); ComponentDto module = ComponentTesting.newModuleDto(project); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java index c9491da15c3..bc768f8a133 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java @@ -34,7 +34,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentKeyUpdaterDao.RekeyedResource; -import org.sonar.db.organization.OrganizationDto; import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; @@ -81,9 +80,8 @@ public class ComponentKeyUpdaterDaoTest { @Test public void updateKey_updates_disabled_components() { - OrganizationDto organizationDto = db.organizations().insert(); ComponentDto project = db.components().insertComponent( - newPrivateProjectDto(organizationDto, "A") + newPrivateProjectDto("A") .setDbKey("my_project")); ComponentDto directory = db.components().insertComponent( newDirectory(project, "B") @@ -133,7 +131,7 @@ public class ComponentKeyUpdaterDaoTest { } @Test - public void update_application_branch_key_will_fail_if_newKey_exist(){ + public void update_application_branch_key_will_fail_if_newKey_exist() { ComponentDto app = db.components().insertPublicProject(); ComponentDto appBranch = db.components().insertProjectBranch(app); db.components().insertProjectBranch(app, b -> b.setKey("newName")); @@ -368,15 +366,14 @@ public class ComponentKeyUpdaterDaoTest { @Test public void shouldNotUpdateAllSubmodules() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project1 = db.components().insertPrivateProject(organization, t1 -> t1.setDbKey("org.struts:struts").setUuid("A")); + ComponentDto project1 = db.components().insertPrivateProject(t1 -> t1.setDbKey("org.struts:struts").setUuid("A")); ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setDbKey("org.struts:struts-core").setUuid("B")); ComponentDto directory1 = db.components().insertComponent(newDirectory(module1, "/src/org/struts").setUuid("C")); db.components().insertComponent(ComponentTesting.newFileDto(module1, directory1).setDbKey("org.struts:struts-core:/src/org/struts/RequestContext.java").setUuid("D")); ComponentDto module2 = db.components().insertComponent(newModuleDto(project1).setDbKey("foo:struts-ui").setUuid("E")); ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "/src/org/struts").setUuid("F")); db.components().insertComponent(ComponentTesting.newFileDto(module2, directory2).setDbKey("foo:struts-ui:/src/org/struts/RequestContext.java").setUuid("G")); - ComponentDto project2 = db.components().insertPublicProject(organization, t1 -> t1.setDbKey("foo:struts-core").setUuid("H")); + ComponentDto project2 = db.components().insertPublicProject(t1 -> t1.setDbKey("foo:struts-core").setUuid("H")); underTest.bulkUpdateKey(dbSession, "A", "org.struts", "org.apache.struts", doNotReturnAnyRekeyedResource()); dbSession.commit(); @@ -396,8 +393,7 @@ public class ComponentKeyUpdaterDaoTest { @Test public void updateKey_throws_IAE_when_sub_component_key_is_too_long() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid").setDbKey("old-project-key"); + ComponentDto project = newPrivateProjectDto("project-uuid").setDbKey("old-project-key"); db.components().insertComponent(project); db.components().insertComponent(newFileDto(project, null).setDbKey("old-project-key:file")); String newLongProjectKey = Strings.repeat("a", 400); @@ -430,9 +426,8 @@ public class ComponentKeyUpdaterDaoTest { @Test public void check_component_keys_checks_inactive_components() { - OrganizationDto organizationDto = db.organizations().insert(); - db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("my-project")); - db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("your-project").setEnabled(false)); + db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey("my-project")); + db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey("your-project").setEnabled(false)); Map result = underTest.checkComponentKeys(dbSession, newArrayList("my-project", "your-project", "new-project")); @@ -454,10 +449,10 @@ public class ComponentKeyUpdaterDaoTest { @Test public void simulate_bulk_update_key_does_not_return_disable_components() { - ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setDbKey("project")); + ComponentDto project = db.components().insertComponent(newPrivateProjectDto("A").setDbKey("project")); db.components().insertComponent(newModuleDto(project).setDbKey("project:enabled-module")); db.components().insertComponent(newModuleDto(project).setDbKey("project:disabled-module").setEnabled(false)); - db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "D").setDbKey("other-project")); + db.components().insertComponent(newPrivateProjectDto("D").setDbKey("other-project")); Map result = underTest.simulateBulkUpdateKey(dbSession, "A", "project", "new-project"); @@ -468,8 +463,7 @@ public class ComponentKeyUpdaterDaoTest { @Test public void simulate_bulk_update_key_fails_if_invalid_componentKey() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "A").setDbKey("project")); + ComponentDto project = db.components().insertComponent(newPrivateProjectDto("A").setDbKey("project")); db.components().insertComponent(newModuleDto(project).setDbKey("project:enabled-module")); db.components().insertComponent(newModuleDto(project).setDbKey("project:disabled-module").setEnabled(false)); @@ -489,14 +483,13 @@ public class ComponentKeyUpdaterDaoTest { } private void populateSomeData() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project1 = db.components().insertPrivateProject(organization, t -> t.setDbKey("org.struts:struts").setUuid("A")); + ComponentDto project1 = db.components().insertPrivateProject(t -> t.setDbKey("org.struts:struts").setUuid("A")); ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setDbKey("org.struts:struts-core").setUuid("B")); ComponentDto directory1 = db.components().insertComponent(newDirectory(module1, "/src/org/struts").setUuid("C")); db.components().insertComponent(ComponentTesting.newFileDto(module1, directory1).setDbKey("org.struts:struts-core:/src/org/struts/RequestContext.java").setUuid("D")); ComponentDto module2 = db.components().insertComponent(newModuleDto(project1).setDbKey("org.struts:struts-ui").setUuid("E")); ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "/src/org/struts").setUuid("F")); db.components().insertComponent(ComponentTesting.newFileDto(module2, directory2).setDbKey("org.struts:struts-ui:/src/org/struts/RequestContext.java").setUuid("G")); - ComponentDto project2 = db.components().insertPublicProject(organization, t -> t.setDbKey("foo:struts-core").setUuid("H")); + ComponentDto project2 = db.components().insertPublicProject(t -> t.setDbKey("foo:struts-core").setUuid("H")); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java index 255225f2b45..8d2d7051072 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java @@ -28,7 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN; import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class ComponentTreeQueryTest { @@ -70,10 +69,10 @@ public class ComponentTreeQueryTest { @Test public void test_getUuidPath() { assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(CHILDREN) - .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID."); + .build().getUuidPath(newPrivateProjectDto("PROJECT_UUID"))).isEqualTo(".PROJECT_UUID."); assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(LEAVES) - .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%"); + .build().getUuidPath(newPrivateProjectDto("PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%"); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java index da73a802f49..4bfd2efb7c6 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java @@ -43,7 +43,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.organization.OrganizationTesting; import static com.google.common.collect.Lists.newArrayList; import static java.util.Collections.emptyList; @@ -70,10 +69,9 @@ public class SnapshotDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private DbClient dbClient = db.getDbClient(); - private DbSession dbSession = db.getSession(); - - private SnapshotDao underTest = dbClient.snapshotDao(); + private final DbClient dbClient = db.getDbClient(); + private final DbSession dbSession = db.getSession(); + private final SnapshotDao underTest = dbClient.snapshotDao(); @Test public void test_selectByUuid() { @@ -155,12 +153,12 @@ public class SnapshotDaoTest { @Test public void selectLastSnapshotsByRootComponentUuids_returns_snapshots_flagged_as_last() { - ComponentDto firstProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_1")); + ComponentDto firstProject = db.components().insertComponent(newPrivateProjectDto("PROJECT_UUID_1")); dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(false)); SnapshotDto lastSnapshotOfFirstProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(true)); - ComponentDto secondProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_2")); + ComponentDto secondProject = db.components().insertComponent(newPrivateProjectDto("PROJECT_UUID_2")); SnapshotDto lastSnapshotOfSecondProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(secondProject).setLast(true)); - db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization())); + db.components().insertProjectAndSnapshot(newPrivateProjectDto()); List result = underTest.selectLastAnalysesByRootComponentUuids(dbSession, newArrayList(firstProject.uuid(), secondProject.uuid())); @@ -259,9 +257,7 @@ public class SnapshotDaoTest { @Test public void select_first_snapshots() { - ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization()); - db.getDbClient().componentDao().insert(dbSession, project); - + ComponentDto project = db.components().insertPrivateProject(); db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(5L), newAnalysis(project).setCreatedAt(2L), @@ -493,7 +489,7 @@ public class SnapshotDaoTest { } private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) { - SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid)) + SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(projectUuid)) .setLast(isLastFlag) .setStatus(status) .setUuid(uuid); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java index e92978a03a2..0c0214f9abc 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java @@ -34,7 +34,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.organization.OrganizationDto; import static com.google.common.collect.ImmutableList.of; import static java.util.Collections.singletonList; @@ -46,14 +45,12 @@ public class DuplicationDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private DbSession dbSession = db.getSession(); - - private DuplicationDao dao = db.getDbClient().duplicationDao(); + private final DbSession dbSession = db.getSession(); + private final DuplicationDao dao = db.getDbClient().duplicationDao(); @Test public void selectCandidates_returns_block_from_last_snapshot_only_of_component_with_language_and_if_not_specified_analysis() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project1 = db.components().insertPrivateProject(organization); + ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto fooFile = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(true)); ComponentDto fooFile1 = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(true)); ComponentDto disabledFooFile = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(false)); @@ -74,12 +71,10 @@ public class DuplicationDaoTest { assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "foo", singletonList(hash))) .containsOnly( tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), hash), - tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), hash) - ); + tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), hash)); assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "bar", singletonList(hash))) .containsOnly( - tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), hash) - ); + tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), hash)); assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "donut", singletonList(hash))) .isEmpty(); } @@ -89,13 +84,11 @@ public class DuplicationDaoTest { tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), "aa"), tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), "bb"), tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), "aa"), - tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), "bb") - ); + tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), "bb")); assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "bar", hashes)) .containsOnly( tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), "aa"), - tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), "bb") - ); + tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), "bb")); assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "donut", hashes)) .isEmpty(); } @@ -116,14 +109,13 @@ public class DuplicationDaoTest { @Test public void select_component() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project1 = db.components().insertPrivateProject(organization); + ComponentDto project1 = db.components().insertPrivateProject(); SnapshotDto analysis1 = db.components().insertSnapshot(project1); - ComponentDto project2 = db.components().insertPrivateProject(organization); + ComponentDto project2 = db.components().insertPrivateProject(); SnapshotDto analysis2 = db.components().insertSnapshot(project2); - ComponentDto project3 = db.components().insertPrivateProject(organization); + ComponentDto project3 = db.components().insertPrivateProject(); SnapshotDto analysis3 = db.components().insertSnapshot(project3); - ComponentDto project4 = db.components().insertPrivateProject(organization); + ComponentDto project4 = db.components().insertPrivateProject(); insert(project1, analysis1, "bb", 0, 0, 0); insert(project2, analysis2, "aa", 0, 1, 2); insert(project3, analysis3, "bb", 0, 0, 0); @@ -146,8 +138,7 @@ public class DuplicationDaoTest { @Test public void insert() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = newPrivateProjectDto(organization); + ComponentDto project = newPrivateProjectDto(); SnapshotDto analysis = db.components().insertProjectAndSnapshot(project); insert(project, analysis, "bb", 0, 1, 2); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java index 75856b03d47..b2d8a234682 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java @@ -33,7 +33,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.organization.OrganizationDto; import static com.google.common.collect.Lists.newArrayList; import static java.util.stream.Collectors.toList; @@ -48,14 +47,13 @@ public class EventDaoTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - private DbClient dbClient = dbTester.getDbClient(); - private DbSession dbSession = dbTester.getSession(); - - private EventDao underTest = dbTester.getDbClient().eventDao(); + private final DbClient dbClient = dbTester.getDbClient(); + private final DbSession dbSession = dbTester.getSession(); + private final EventDao underTest = dbTester.getDbClient().eventDao(); @Test public void select_by_uuid() { - SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); + SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto()); dbTester.events().insertEvent(newEvent(analysis).setUuid("A1")); dbTester.events().insertEvent(newEvent(analysis).setUuid("A2")); dbTester.events().insertEvent(newEvent(analysis).setUuid("A3")); @@ -68,9 +66,8 @@ public class EventDaoTest { @Test public void select_by_component_uuid() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project1 = ComponentTesting.newPrivateProjectDto(organization); - ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organization); + ComponentDto project1 = ComponentTesting.newPrivateProjectDto(); + ComponentDto project2 = ComponentTesting.newPrivateProjectDto(); SnapshotDto analysis1 = dbTester.components().insertProjectAndSnapshot(project1); SnapshotDto analysis2 = dbTester.components().insertProjectAndSnapshot(project2); String[] eventUuids1 = IntStream.range(0, 1 + new Random().nextInt(10)) @@ -112,7 +109,7 @@ public class EventDaoTest { @Test public void select_by_analysis_uuid() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project); SnapshotDto otherAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); dbTester.commit(); @@ -154,8 +151,7 @@ public class EventDaoTest { @Test public void return_different_categories() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = ComponentTesting.newPrivateProjectDto(organization); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project); List events = IntStream.range(0, 1 + new Random().nextInt(10)) .mapToObj(i -> dbTester.events().insertEvent(newEvent(analysis).setCategory("cat_" + i))) @@ -197,7 +193,7 @@ public class EventDaoTest { @Test public void update_name_and_description() { - SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); + SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto()); dbTester.events().insertEvent(newEvent(analysis).setUuid("E1")); underTest.update(dbSession, "E1", "New Name", "New Description"); @@ -209,7 +205,7 @@ public class EventDaoTest { @Test public void delete_by_uuid() { - dbTester.events().insertEvent(newEvent(newAnalysis(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()))).setUuid("E1")); + dbTester.events().insertEvent(newEvent(newAnalysis(ComponentTesting.newPrivateProjectDto())).setUuid("E1")); underTest.delete(dbTester.getSession(), "E1"); dbTester.commit(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java index 554078dce24..075998d0b06 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -37,7 +37,6 @@ import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.ComponentUpdateDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; @@ -302,7 +301,6 @@ public class IssueDaoTest { assertThat(underTest.selectModuleAndDirComponentUuidsOfOpenIssuesForProjectUuid(db.getSession(), randomAlphabetic(12))) .isEmpty(); - OrganizationDto organization = db.organizations().insert(); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto module11 = db.components().insertComponent(newModuleDto(project1)); ComponentDto dir11 = db.components().insertComponent(newDirectory(module11, randomAlphabetic(10))); @@ -311,8 +309,8 @@ public class IssueDaoTest { ComponentDto dir13 = db.components().insertComponent(newDirectory(module12, randomAlphabetic(12))); ComponentDto dir14 = db.components().insertComponent(newDirectory(project1, randomAlphabetic(13))); ComponentDto file11 = db.components().insertComponent(newFileDto(project1)); - ComponentDto application = db.components().insertPrivateApplication(organization); - ComponentDto view = db.components().insertView(organization); + ComponentDto application = db.components().insertPrivateApplication(); + ComponentDto view = db.components().insertPublicPortfolio(); ComponentDto subview = db.components().insertSubView(view); ComponentDto project2 = db.components().insertPublicProject(); ComponentDto module21 = db.components().insertComponent(newModuleDto(project2)); @@ -418,8 +416,7 @@ public class IssueDaoTest { private void prepareTables() { db.rules().insertRule(RULE.setIsExternal(true)); - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto projectDto = db.components().insertPrivateProject(organizationDto, (t) -> t.setUuid(PROJECT_UUID).setDbKey(PROJECT_KEY)); + ComponentDto projectDto = db.components().insertPrivateProject(t -> t.setUuid(PROJECT_UUID).setDbKey(PROJECT_KEY)); db.components().insertComponent(newFileDto(projectDto).setUuid(FILE_UUID).setDbKey(FILE_KEY)); underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY1) .setMessage("the message") diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java index 3660905b3b2..c52fd2367fe 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java @@ -47,7 +47,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; @@ -64,20 +63,16 @@ public class IssueMapperTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - private DbSession dbSession = dbTester.getSession(); - - private IssueMapper underTest = dbSession.getMapper(IssueMapper.class); - + private final DbSession dbSession = dbTester.getSession(); + private final IssueMapper underTest = dbSession.getMapper(IssueMapper.class); + private final Random random = new Random(); + private final System2 system2 = new AlwaysIncreasingSystem2(); private ComponentDto project, file, file2; private RuleDto rule; - private Random random = new Random(); - private System2 system2 = new AlwaysIncreasingSystem2(); @Before public void setUp() { - OrganizationDto organizationDto = dbTester.organizations().insert(); - project = ComponentTesting.newPrivateProjectDto(organizationDto); - dbTester.getDbClient().componentDao().insert(dbSession, project); + project = dbTester.components().insertPrivateProject(); file = ComponentTesting.newFileDto(project, null); dbTester.getDbClient().componentDao().insert(dbSession, file); file2 = ComponentTesting.newFileDto(project, null).setUuid("file2 uuid"); @@ -252,8 +247,7 @@ public class IssueMapperTest { @Test @UseDataProvider("closedIssuesSupportedRuleTypes") public void scrollClosedByComponentUuid_returns_closed_issues_with_at_least_one_diff_to_CLOSED(RuleType ruleType) { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); IssueDto expected = insertNewClosedIssue(component, ruleType); IssueChangeDto changeDto = insertToClosedDiff(expected); @@ -269,8 +263,7 @@ public class IssueMapperTest { @Test @UseDataProvider("closedIssuesSupportedRuleTypes") public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_non_existing_rule(RuleType ruleType) { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); IssueDto issueWithRule = insertNewClosedIssue(component, ruleType); IssueChangeDto issueChange = insertToClosedDiff(issueWithRule); IssueDto issueWithoutRule = insertNewClosedIssue(component, new RuleDefinitionDto().setType(ruleType).setUuid("uuid-50")); @@ -287,8 +280,7 @@ public class IssueMapperTest { @Test @UseDataProvider("closedIssuesSupportedRuleTypes") public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_orphan_component(RuleType ruleType) { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); IssueDto issue = insertNewClosedIssue(component, ruleType); IssueChangeDto issueChange = insertToClosedDiff(issue); IssueDto issueMissingComponent = insertNewClosedIssue(component, ruleType, t -> t.setComponentUuid("does_not_exist")); @@ -307,8 +299,7 @@ public class IssueMapperTest { @Test @UseDataProvider("closedIssuesSupportedRuleTypes") public void scrollClosedByComponentUuid_does_not_return_closed_issues_without_any_status_diff_to_CLOSED(RuleType ruleType) { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); IssueDto issueWithLineDiff = insertNewClosedIssue(component, ruleType); IssueChangeDto issueChange = insertToClosedDiff(issueWithLineDiff); insertNewClosedIssue(component, ruleType); @@ -324,8 +315,7 @@ public class IssueMapperTest { @Test public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_type_SECURITY_HOTSPOT() { RuleType ruleType = randomSupportedRuleType(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); IssueDto securityHotspotIssue = insertNewClosedIssue(component, RuleType.SECURITY_HOTSPOT); insertToClosedDiff(securityHotspotIssue); IssueDto issue = insertNewClosedIssue(component, ruleType); @@ -342,8 +332,7 @@ public class IssueMapperTest { @Test public void scrollClosedByComponentUuid_does_not_return_closed_issues_without_close_date() { RuleType ruleType = randomSupportedRuleType(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); IssueDto issueWithoutCloseDate = insertNewClosedIssue(component, ruleType, t -> t.setIssueCloseDate(null)); insertToClosedDiff(issueWithoutCloseDate); IssueDto issueCloseDate = insertNewClosedIssue(component, ruleType); @@ -361,8 +350,7 @@ public class IssueMapperTest { @Test public void scrollClosedByComponentUuid_returns_closed_issues_which_close_date_is_greater_or_equal_to_requested() { RuleType ruleType = randomSupportedRuleType(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); RuleDefinitionDto rule1 = dbTester.rules().insert(t -> t.setType(ruleType)); IssueDto[] issues = new IssueDto[] { insertNewClosedIssue(component, rule1, 1_999_999L), @@ -409,8 +397,7 @@ public class IssueMapperTest { @Test @UseDataProvider("closedIssuesSupportedRuleTypes") public void scrollClosedByComponentUuid_return_one_row_per_status_diff_to_CLOSED_sorted_by_most_recent_creation_date_first(RuleType ruleType) { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); IssueDto issue = insertNewClosedIssue(component, ruleType); Date date = new Date(); IssueChangeDto[] changes = new IssueChangeDto[] { @@ -436,8 +423,7 @@ public class IssueMapperTest { @Test @UseDataProvider("closedIssuesSupportedRuleTypes") public void scrollClosedByComponentUuid_does_not_return_row_for_status_change_from_close(RuleType ruleType) { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto component = randomComponent(organization); + ComponentDto component = randomComponent(); IssueDto issue = insertNewClosedIssue(component, ruleType); Date date = new Date(); IssueChangeDto[] changes = new IssueChangeDto[] { @@ -526,8 +512,8 @@ public class IssueMapperTest { return SUPPORTED_RULE_TYPES[new Random().nextInt(SUPPORTED_RULE_TYPES.length)]; } - private ComponentDto randomComponent(OrganizationDto organization) { - ComponentDto project = dbTester.components().insertPublicProject(organization); + private ComponentDto randomComponent() { + ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project)); ComponentDto dir = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "foo")); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java index 489b83e4313..1c8a2b45b04 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java @@ -36,7 +36,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; @@ -54,7 +53,7 @@ public class LiveMeasureDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private LiveMeasureDao underTest = db.getDbClient().liveMeasureDao(); + private final LiveMeasureDao underTest = db.getDbClient().liveMeasureDao(); private MetricDto metric; @Before @@ -303,19 +302,18 @@ public class LiveMeasureDaoTest { @Test public void countNcloc() { - OrganizationDto organization = db.organizations().insert(); MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); MetricDto lines = db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString())); - ComponentDto simpleProject = db.components().insertPublicProject(organization); + ComponentDto simpleProject = db.components().insertPublicProject(); db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d)); - ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(organization); + ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(); ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH)); db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d)); db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d)); - ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject(organization); + ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject(); db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d)); db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d)); @@ -341,18 +339,17 @@ public class LiveMeasureDaoTest { @Test public void countNcloc_and_exclude_project() { - OrganizationDto organization = db.organizations().insert(); MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); - ComponentDto simpleProject = db.components().insertPublicProject(organization); + ComponentDto simpleProject = db.components().insertPublicProject(); db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d)); - ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(organization); + ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(); ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH)); db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d)); db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d)); - ComponentDto projectToExclude = db.components().insertPublicProject(organization); + ComponentDto projectToExclude = db.components().insertPublicProject(); ComponentDto projectToExcludeBranch = db.components().insertProjectBranch(projectToExclude, b -> b.setBranchType(BranchType.BRANCH)); db.measures().insertLiveMeasure(projectToExclude, ncloc, m -> m.setValue(300d)); db.measures().insertLiveMeasure(projectToExcludeBranch, ncloc, m -> m.setValue(400d)); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java index 66349c17b66..32575d5eecb 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java @@ -24,7 +24,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationTesting; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; @@ -78,10 +77,10 @@ public class MeasureTreeQueryTest { @Test public void test_getUuidPath() { assertThat(MeasureTreeQuery.builder().setStrategy(CHILDREN) - .build().getUuidPath(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID."); + .build().getUuidPath(ComponentTesting.newPrivateProjectDto("PROJECT_UUID"))).isEqualTo(".PROJECT_UUID."); assertThat(MeasureTreeQuery.builder().setStrategy(LEAVES) - .build().getUuidPath(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%"); + .build().getUuidPath(ComponentTesting.newPrivateProjectDto("PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%"); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java index 28117efbf7d..dc5d99c707f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java @@ -33,7 +33,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; @@ -54,13 +53,12 @@ public class ProjectMeasuresIndexerIteratorTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - private DbClient dbClient = dbTester.getDbClient(); - private DbSession dbSession = dbTester.getSession(); + private final DbClient dbClient = dbTester.getDbClient(); + private final DbSession dbSession = dbTester.getSession(); @Test public void return_project_measure() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization, + ComponentDto project = dbTester.components().insertPrivateProject( c -> c.setDbKey("Project-Key").setName("Project Name"), p -> p.setTags(newArrayList("platform", "java"))); @@ -108,8 +106,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_project_measure_having_leak() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization, + ComponentDto project = dbTester.components().insertPrivateProject( c -> c.setDbKey("Project-Key").setName("Project Name"), p -> p.setTagsString("platform,java")); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines")); @@ -122,10 +119,9 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_quality_gate_status_measure() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project1 = dbTester.components().insertPrivateProject(organization); - ComponentDto project2 = dbTester.components().insertPrivateProject(organization); - ComponentDto project3 = dbTester.components().insertPrivateProject(organization); + ComponentDto project1 = dbTester.components().insertPrivateProject(); + ComponentDto project2 = dbTester.components().insertPrivateProject(); + ComponentDto project3 = dbTester.components().insertPrivateProject(); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status")); dbTester.measures().insertLiveMeasure(project2, metric, m -> m.setValue(null).setData(OK.name())); dbTester.measures().insertLiveMeasure(project3, metric, m -> m.setValue(null).setData(ERROR.name())); @@ -138,8 +134,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void does_not_fail_when_quality_gate_has_no_value() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setVariation(null).setData((String) null)); @@ -150,8 +145,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_language_distribution_measure() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(DATA.name()).setKey("ncloc_language_distribution")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData("=2;java=6;xoo=18")); @@ -163,8 +157,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void does_not_return_none_numeric_metrics() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); MetricDto dataMetric = dbTester.measures().insertMetric(m -> m.setValueType(DATA.name()).setKey("data")); MetricDto distribMetric = dbTester.measures().insertMetric(m -> m.setValueType(DISTRIB.name()).setKey("distrib")); MetricDto stringMetric = dbTester.measures().insertMetric(m -> m.setValueType(STRING.name()).setKey("string")); @@ -179,8 +172,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void does_not_return_disabled_metrics() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); MetricDto disabledMetric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setEnabled(false).setHidden(false).setKey("disabled")); dbTester.measures().insertLiveMeasure(project, disabledMetric, m -> m.setValue(10d)); @@ -191,11 +183,10 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void ignore_measure_that_does_not_have_value() { - OrganizationDto organization = dbTester.organizations().insert(); MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("coverage")); MetricDto metric2 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc")); MetricDto leakMetric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines")); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d)); dbTester.measures().insertLiveMeasure(project, leakMetric, m -> m.setValue(null).setVariation(20d)); @@ -207,10 +198,9 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void ignore_numeric_measure_that_has_text_value_but_not_numeric_value() { - OrganizationDto organization = dbTester.organizations().insert(); MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("coverage")); MetricDto metric2 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc")); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d).setData((String) null)); dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(null).setData("foo")); @@ -220,10 +210,9 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_many_project_measures() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project1 = dbTester.components().insertPrivateProject(organization); - ComponentDto project2 = dbTester.components().insertPrivateProject(organization); - ComponentDto project3 = dbTester.components().insertPrivateProject(organization); + ComponentDto project1 = dbTester.components().insertPrivateProject(); + ComponentDto project2 = dbTester.components().insertPrivateProject(); + ComponentDto project3 = dbTester.components().insertPrivateProject(); dbTester.components().insertSnapshot(project1); dbTester.components().insertSnapshot(project2); dbTester.components().insertSnapshot(project3); @@ -233,7 +222,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_project_without_analysis() { - ComponentDto project = dbTester.components().insertPrivateProject(dbTester.organizations().insert()); + ComponentDto project = dbTester.components().insertPrivateProject(); dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false)); dbSession.commit(); @@ -246,10 +235,9 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_only_docs_from_given_project() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project1 = dbTester.components().insertPrivateProject(organization); - ComponentDto project2 = dbTester.components().insertPrivateProject(organization); - ComponentDto project3 = dbTester.components().insertPrivateProject(organization); + ComponentDto project1 = dbTester.components().insertPrivateProject(); + ComponentDto project2 = dbTester.components().insertPrivateProject(); + ComponentDto project3 = dbTester.components().insertPrivateProject(); SnapshotDto analysis1 = dbTester.components().insertSnapshot(project1); SnapshotDto analysis2 = dbTester.components().insertSnapshot(project2); SnapshotDto analysis3 = dbTester.components().insertSnapshot(project3); @@ -267,8 +255,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void return_nothing_on_unknown_project() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); dbTester.components().insertSnapshot(project); Map docsById = createResultSetAndReturnDocsById("UNKNOWN"); @@ -278,8 +265,7 @@ public class ProjectMeasuresIndexerIteratorTest { @Test public void non_main_branches_are_not_indexed() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(10d)); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java index 1fbce9a9e9a..90af6e67868 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java @@ -23,11 +23,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.component.ComponentTesting.newPublicProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class PermissionQueryTest { @@ -36,8 +34,7 @@ public class PermissionQueryTest { @Test public void create_query() { - OrganizationDto organization = newOrganizationDto(); - ComponentDto project = newPublicProjectDto(organization); + ComponentDto project = newPublicProjectDto(); PermissionQuery query = PermissionQuery.builder() .setComponent(project) .setPermission("user") diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index 644d17895c1..880069adcbd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -63,17 +63,16 @@ public class PropertiesDaoTest { private static final String VALUE_SIZE_4001 = VALUE_SIZE_4000 + "P"; private static final long INITIAL_DATE = 1_444_000L; - private AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(INITIAL_DATE, 1); + private final AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(INITIAL_DATE, 1); @Rule public ExpectedException thrown = ExpectedException.none(); @Rule public DbTester db = DbTester.create(system2); - private DbClient dbClient = db.getDbClient(); - private DbSession session = db.getSession(); - - private PropertiesDao underTest = db.getDbClient().propertiesDao(); + private final DbClient dbClient = db.getDbClient(); + private final DbSession session = db.getSession(); + private final PropertiesDao underTest = db.getDbClient().propertiesDao(); @Test public void shouldFindUsersForNotification() { @@ -121,7 +120,7 @@ public class PropertiesDaoTest { String userUuid1 = db.users().insertUser(u -> u.setLogin("user1")).getUuid(); String userUuid2 = db.users().insertUser(u -> u.setLogin("user2")).getUuid(); String projectUuid = randomAlphabetic(8); - db.components().insertPrivateProject(db.getDefaultOrganization(), projectUuid); + db.components().insertPrivateProject(projectUuid); // global subscription insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userUuid2); @@ -1240,7 +1239,7 @@ public class PropertiesDaoTest { } private ComponentDto insertPrivateProject(String projectKey) { - return db.components().insertPrivateProject(db.getDefaultOrganization(), t -> t.setDbKey(projectKey)); + return db.components().insertPrivateProject(t -> t.setDbKey(projectKey)); } private static Consumer withEmail(String login) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 80810c1917b..a39d7d7ad59 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -73,7 +73,6 @@ import org.sonar.db.measure.custom.CustomMeasureDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.newcodeperiod.NewCodePeriodDto; import org.sonar.db.newcodeperiod.NewCodePeriodType; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.property.PropertyDto; import org.sonar.db.rule.RuleDefinitionDto; @@ -446,7 +445,7 @@ public class PurgeDaoTest { @Test public void selectPurgeableAnalyses_does_not_return_the_baseline() { - ComponentDto project1 = db.components().insertPublicProject(db.getDefaultOrganization(), "master"); + ComponentDto project1 = db.components().insertPublicProject("master"); SnapshotDto analysis1 = db.components().insertSnapshot(newSnapshot() .setComponentUuid(project1.uuid()) .setStatus(STATUS_PROCESSED) @@ -472,7 +471,7 @@ public class PurgeDaoTest { @Test public void selectPurgeableAnalyses_does_not_return_the_baseline_of_specific_branch() { - ComponentDto project = db.components().insertPublicProject(db.getDefaultOrganization(), "master"); + ComponentDto project = db.components().insertPublicProject("master"); SnapshotDto analysisProject = db.components().insertSnapshot(newSnapshot() .setComponentUuid(project.uuid()) .setStatus(STATUS_PROCESSED) @@ -624,11 +623,10 @@ public class PurgeDaoTest { @Test public void delete_webhooks_from_project() { - OrganizationDto organization = db.organizations().insert(); - ProjectDto project1 = db.components().insertPrivateProjectDto(organization); + ProjectDto project1 = db.components().insertPrivateProjectDto(); WebhookDto webhook = db.webhooks().insertWebhook(project1); db.webhookDelivery().insert(webhook); - ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto(organization); + ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto(); WebhookDto webhookNotDeleted = db.webhooks().insertWebhook(projectNotToBeDeleted); WebhookDeliveryLiteDto webhookDeliveryNotDeleted = db.webhookDelivery().insert(webhookNotDeleted); @@ -1058,10 +1056,10 @@ public class PurgeDaoTest { @Test public void delete_view_and_child() { ComponentDto project = db.components().insertPrivateProject(); - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subView = db.components().insertComponent(newSubView(view)); ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(project, subView)); - ComponentDto otherView = db.components().insertView(); + ComponentDto otherView = db.components().insertPrivatePortfolio(); ComponentDto otherSubView = db.components().insertComponent(newSubView(otherView)); ComponentDto otherProjectCopy = db.components().insertComponent(newProjectCopy(project, otherSubView)); @@ -1363,8 +1361,8 @@ public class PurgeDaoTest { verifyNoEffect(componentDbTester.insertPrivateProject()); verifyNoEffect(componentDbTester.insertPublicProject()); - verifyNoEffect(componentDbTester.insertView()); - verifyNoEffect(componentDbTester.insertView(), componentDbTester.insertPrivateProject(), componentDbTester.insertPublicProject()); + verifyNoEffect(componentDbTester.insertPrivatePortfolio()); + verifyNoEffect(componentDbTester.insertPrivatePortfolio(), componentDbTester.insertPrivateProject(), componentDbTester.insertPublicProject()); } @Test @@ -1429,7 +1427,7 @@ public class PurgeDaoTest { db.components().insertPrivateProject() }; - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subview1 = db.components().insertComponent(newSubView(view)); ComponentDto subview2 = db.components().insertComponent(newSubView(subview1)); List components = asList( @@ -1475,7 +1473,7 @@ public class PurgeDaoTest { db.components().insertPrivateProject() }; - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subview1 = db.components().insertComponent(newSubView(view)); ComponentDto subview2 = db.components().insertComponent(newSubView(subview1)); ComponentDto pc1 = db.components().insertComponent(newProjectCopy("a", projects[0], view)); @@ -1495,7 +1493,7 @@ public class PurgeDaoTest { @Test public void deleteNonRootComponents_deletes_measures_of_any_non_root_component_of_a_view() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subview = db.components().insertComponent(newSubView(view)); ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view)); insertMeasureFor(view, subview, pc); @@ -1512,7 +1510,7 @@ public class PurgeDaoTest { @Test public void deleteNonRootComponents_deletes_properties_of_subviews_of_a_view() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subview1 = db.components().insertComponent(newSubView(view)); ComponentDto subview2 = db.components().insertComponent(newSubView(subview1)); ComponentDto subview3 = db.components().insertComponent(newSubView(view)); @@ -1531,7 +1529,7 @@ public class PurgeDaoTest { @Test public void deleteNonRootComponentsInView_deletes_manual_measures_of_subviews_of_a_view() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subview1 = db.components().insertComponent(newSubView(view)); ComponentDto subview2 = db.components().insertComponent(newSubView(subview1)); ComponentDto subview3 = db.components().insertComponent(newSubView(view)); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java index 1b400e5e02f..ec1864a0f79 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java @@ -83,7 +83,7 @@ public class PurgeMapperTest { @Test public void selectRootAndModulesOrSubviewsByProjectUuid_returns_view_with_specified_uuid() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid())) .containsOnly(view.uuid()); @@ -91,7 +91,7 @@ public class PurgeMapperTest { @Test public void selectRootAndModulesOrSubviewsByProjectUuid_returns_application_with_specified_uuid() { - ComponentDto view = db.components().insertPublicApplication(db.getDefaultOrganization()); + ComponentDto view = db.components().insertPublicApplication(); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid())) .containsOnly(view.uuid()); @@ -99,7 +99,7 @@ public class PurgeMapperTest { @Test public void selectRootAndModulesOrSubviewsByProjectUuid_returns_subviews_with_specified_project_uuid_and_view() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPublicPortfolio(); ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view)); ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(view)); ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view)); @@ -111,7 +111,7 @@ public class PurgeMapperTest { @Test public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_project_copy_with_specified_project_uuid() { ComponentDto privateProject = db.components().insertPrivateProject(); - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject)); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid())) @@ -147,7 +147,7 @@ public class PurgeMapperTest { @Test public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_subview_with_specified_uuid() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view)); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(subview.uuid())) @@ -157,7 +157,7 @@ public class PurgeMapperTest { @Test public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_technicalCopy_with_specified_uuid() { ComponentDto privateProject = db.components().insertPrivateProject(); - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto technicalCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject)); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(technicalCopy.uuid())) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index 02b718c992a..564929adf25 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -37,7 +37,6 @@ import org.sonar.core.util.Uuids; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.rule.RuleDefinitionDto; @@ -703,8 +702,7 @@ public class QualityProfileDaoTest { ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")); ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")); ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")); - OrganizationDto organization2 = db.organizations().insert(); - ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name").setOrganizationUuid(organization2.getUuid())); + ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name")); ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch")); QProfileDto profile1 = newQualityProfileDto(); @@ -796,7 +794,6 @@ public class QualityProfileDaoTest { @Test public void renameAndCommit_updates_name_of_specified_profiles() { - OrganizationDto org1 = db.organizations().insert(); QProfileDto fooInOrg1 = db.qualityProfiles().insert(p -> p.setName("foo")); QProfileDto bar = db.qualityProfiles().insert(p -> p.setName("bar")); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java index 25052001869..77157c0b132 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java @@ -41,7 +41,6 @@ import org.sonar.core.util.Uuids; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import static com.google.common.collect.ImmutableList.of; import static java.util.Collections.emptyList; @@ -56,14 +55,13 @@ public class FileSourceDaoTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - private DbSession dbSession = dbTester.getSession(); + private final DbSession dbSession = dbTester.getSession(); - private FileSourceDao underTest = dbTester.getDbClient().fileSourceDao(); + private final FileSourceDao underTest = dbTester.getDbClient().fileSourceDao(); @Test public void select() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); FileSourceDto expected = dbTester.fileSources().insertFileSource(file); @@ -82,8 +80,7 @@ public class FileSourceDaoTest { @Test public void select_line_hashes() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); FileSourceDto expected = dbTester.fileSources().insertFileSource(file); @@ -95,8 +92,7 @@ public class FileSourceDaoTest { @Test public void no_line_hashes_on_unknown_file() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); dbTester.fileSources().insertFileSource(file); @@ -253,8 +249,7 @@ public class FileSourceDaoTest { @Test public void scrollLineHashes_scrolls_hashes_of_specific_keys() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject(organization) : dbTester.components().insertPublicProject(organization); + ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject() : dbTester.components().insertPublicProject(); ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project)); FileSourceDto fileSource1 = dbTester.fileSources().insertFileSource(file1); ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project)); @@ -279,8 +274,7 @@ public class FileSourceDaoTest { @Test public void scrollLineHashes_does_not_scroll_hashes_of_component_without_path() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject(organization) : dbTester.components().insertPublicProject(organization); + ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject() : dbTester.components().insertPublicProject(); ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project)); FileSourceDto fileSource1 = dbTester.fileSources().insertFileSource(file1); ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project).setPath(null)); @@ -293,8 +287,7 @@ public class FileSourceDaoTest { @Test public void scrollLineHashes_handles_scrolling_more_than_1000_files() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject(organization) : dbTester.components().insertPublicProject(organization); + ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject() : dbTester.components().insertPublicProject(); List files = IntStream.range(0, 1001 + new Random().nextInt(5)) .mapToObj(i -> { ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); @@ -340,8 +333,7 @@ public class FileSourceDaoTest { @Test public void update() { - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); FileSourceDto expected = dbTester.fileSources().insertFileSource(file); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java index c27ba15ecec..719b512918a 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java @@ -29,8 +29,6 @@ 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.organization.OrganizationDbTester; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import static org.assertj.core.api.Assertions.assertThat; @@ -47,7 +45,6 @@ public class WebhookDaoTest { private final WebhookDao underTest = dbClient.webhookDao(); private final WebhookDbTester webhookDbTester = dbTester.webhooks(); private final ComponentDbTester componentDbTester = dbTester.components(); - private final OrganizationDbTester organizationDbTester = dbTester.organizations(); @Test public void selectByUuid_returns_empty_if_uuid_does_not_exist() { @@ -113,7 +110,7 @@ public class WebhookDaoTest { assertThat(stored.getUuid()).isEqualTo(dto.getUuid()); assertThat(stored.getName()).isEqualTo(dto.getName()); assertThat(stored.getUrl()).isEqualTo(dto.getUrl()); - assertThat(stored.getOrganizationUuid()).isEqualTo(organizationDbTester.getDefaultOrganization().getUuid()); + assertThat(stored.getOrganizationUuid()).isEqualTo(dbTester.getDefaultOrganization().getUuid()); assertThat(stored.getProjectUuid()).isNull(); assertThat(stored.getSecret()).isEqualTo(dto.getSecret()); assertThat(new Date(stored.getCreatedAt())).isInSameMinuteWindowAs(new Date(system2.now())); @@ -189,8 +186,7 @@ public class WebhookDaoTest { @Test public void cleanWebhooksOfAProject() { - OrganizationDto organization = organizationDbTester.insert(); - ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(organization); + ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(); webhookDbTester.insertWebhook(projectDto); webhookDbTester.insertWebhook(projectDto); webhookDbTester.insertWebhook(projectDto); @@ -223,7 +219,7 @@ public class WebhookDaoTest { Optional reloaded = underTest.selectByUuid(dbSession, dto.getUuid()); assertThat(reloaded).isPresent(); - assertThat(reloaded.get().getOrganizationUuid()).isEqualTo(organizationDbTester.getDefaultOrganization().getUuid()); + assertThat(reloaded.get().getOrganizationUuid()).isEqualTo(dbTester.getDefaultOrganization().getUuid()); } @Test diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java index 01b9afd9bab..36a067b4423 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java @@ -42,9 +42,7 @@ import org.sonar.db.issue.IssueDbTester; import org.sonar.db.measure.MeasureDbTester; import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; import org.sonar.db.notification.NotificationDbTester; -import org.sonar.db.organization.OrganizationDbTester; import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.db.permission.template.PermissionTemplateDbTester; import org.sonar.db.plugin.PluginDbTester; import org.sonar.db.property.InternalComponentPropertyDbTester; @@ -60,6 +58,7 @@ import org.sonar.db.webhook.WebhookDeliveryDbTester; import static com.google.common.base.Preconditions.checkState; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; +import static org.sonar.db.organization.OrganizationDto.Subscription.FREE; /** * This class should be called using @Rule. @@ -82,7 +81,6 @@ public class DbTester extends AbstractDbTester { private final ProjectLinkDbTester componentLinkTester; private final FavoriteDbTester favoriteTester; private final EventDbTester eventTester; - private final OrganizationDbTester organizationTester; private final PermissionTemplateDbTester permissionTemplateTester; private final PropertyDbTester propertyTester; private final QualityGateDbTester qualityGateDbTester; @@ -111,7 +109,6 @@ public class DbTester extends AbstractDbTester { this.componentLinkTester = new ProjectLinkDbTester(this); this.favoriteTester = new FavoriteDbTester(this); this.eventTester = new EventDbTester(this); - this.organizationTester = new OrganizationDbTester(this); this.permissionTemplateTester = new PermissionTemplateDbTester(this); this.propertyTester = new PropertyDbTester(this); this.qualityGateDbTester = new QualityGateDbTester(this); @@ -159,7 +156,7 @@ public class DbTester extends AbstractDbTester { client = new DbClient(db.getDatabase(), db.getMyBatis(), new TestDBSessions(db.getMyBatis()), daos.toArray(new Dao[daos.size()])); } - //TODO remove + // TODO remove @Deprecated public DbTester setDisableDefaultOrganization(boolean b) { checkState(!started, "DbTester is already started"); @@ -167,7 +164,7 @@ public class DbTester extends AbstractDbTester { return this; } - //TODO remove + // TODO remove @Deprecated public DbTester setDefaultOrganizationUuid(String uuid) { checkState(!started, "DbTester is already started"); @@ -175,7 +172,7 @@ public class DbTester extends AbstractDbTester { return this; } - //TODO remove + // TODO remove @Deprecated public DbTester setDefaultOrganizationKey(String key) { checkState(!started, "DbTester is already started"); @@ -194,10 +191,20 @@ public class DbTester extends AbstractDbTester { started = true; } - //TODO remove + // TODO remove @Deprecated private void insertDefaultOrganization() { - defaultOrganization = OrganizationTesting.newOrganizationDto().setUuid(defaultOrganizationUuid).setKey(defaultOrganizationKey); + defaultOrganization = new OrganizationDto() + .setName(randomAlphanumeric(64)) + .setDescription(randomAlphanumeric(256)) + .setAvatarUrl(randomAlphanumeric(256)) + // Default quality gate should be set explicitly when needed in tests + .setDefaultQualityGateUuid("_NOT_SET_") + .setSubscription(FREE) + .setUrl(randomAlphanumeric(256)) + .setUuid(defaultOrganizationUuid) + .setKey(defaultOrganizationKey); + try (DbSession dbSession = db.getMyBatis().openSession(false)) { client.organizationDao().insert(dbSession, defaultOrganization, false); client.internalPropertiesDao().save(dbSession, "organization.default", defaultOrganization.getUuid()); @@ -205,7 +212,7 @@ public class DbTester extends AbstractDbTester { } } - //TODO remove + // TODO remove @Deprecated public OrganizationDto getDefaultOrganization() { checkState(defaultOrganization != null, "Default organization has not been created"); @@ -232,10 +239,6 @@ public class DbTester extends AbstractDbTester { return eventTester; } - public OrganizationDbTester organizations() { - return organizationTester; - } - public PermissionTemplateDbTester permissionTemplates() { return permissionTemplateTester; } @@ -300,7 +303,7 @@ public class DbTester extends AbstractDbTester { return almSettingsDbTester; } - public AlmPatsDbTester almPats(){ + public AlmPatsDbTester almPats() { return almPatsDbtester; } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java index 57409686f6b..187534fa923 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java @@ -27,7 +27,6 @@ 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.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import static com.google.common.base.Preconditions.checkArgument; @@ -65,7 +64,7 @@ public class ComponentDbTester { } public ComponentDto insertPrivateProject() { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, + return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, defaults(), defaults(), defaults()); } @@ -79,7 +78,11 @@ public class ComponentDbTester { } public ComponentDto insertPublicProject() { - return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false); + return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(), false); + } + + public ComponentDto insertPublicProject(String uuid) { + return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(uuid), false); } public ComponentDto insertPublicProject(ComponentDto componentDto) { @@ -87,69 +90,29 @@ public class ComponentDbTester { } public ComponentDto insertPrivateProject(String uuid) { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), uuid), true); + return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true); } public final ComponentDto insertPrivateProject(Consumer dtoPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, defaults(), + return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, defaults(), dtoPopulator); } public final ComponentDto insertPrivateProject(Consumer componentDtoPopulator, Consumer projectDtoPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), + return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, defaults(), componentDtoPopulator, projectDtoPopulator); } public final ComponentDto insertPublicProject(Consumer dtoPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, defaults(), + return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(), false, defaults(), dtoPopulator); } public final ComponentDto insertPublicProject(Consumer componentDtoPopulator, Consumer projectDtoPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, defaults(), componentDtoPopulator, - projectDtoPopulator); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer componentDtoPopulator) { - return insertPrivateProject(organizationDto, componentDtoPopulator, defaults()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer componentDtoPopulator, - Consumer projectDtoPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, defaults(), - componentDtoPopulator, projectDtoPopulator); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer componentDtoPopulator) { - return insertPublicProject(organizationDto, componentDtoPopulator, defaults()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer componentDtoPopulator, - Consumer projectDtoPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false, defaults(), componentDtoPopulator, + return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(), false, defaults(), componentDtoPopulator, projectDtoPopulator); } - // TODO remove after getting rid of organization code - @Deprecated - public ComponentDto insertPrivateProject(OrganizationDto organizationDto) { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true); - } - - // TODO remove after getting rid of organization code - @Deprecated - public ComponentDto insertPublicProject(OrganizationDto organizationDto) { - return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false); - } - public ProjectDto insertPublicProjectDto() { ComponentDto componentDto = insertPublicProject(); return getProjectDto(componentDto); @@ -160,32 +123,11 @@ public class ComponentDbTester { return getProjectDto(componentDto); } - // TODO remove after getting rid of organization code - @Deprecated - public ProjectDto insertPublicProjectDto(OrganizationDto organization) { - ComponentDto componentDto = insertPublicProject(organization); - return getProjectDto(componentDto); - } - public ProjectDto insertPublicProjectDto(Consumer dtoPopulator) { ComponentDto componentDto = insertPublicProject(dtoPopulator); return getProjectDto(componentDto); } - // TODO remove after getting rid of organization code - @Deprecated - public final ProjectDto insertPublicProjectDto(OrganizationDto organization, Consumer dtoPopulator) { - ComponentDto componentDto = insertPublicProject(organization, dtoPopulator); - return getProjectDto(componentDto); - } - - // TODO remove after getting rid of organization code - @Deprecated - public ProjectDto insertPrivateProjectDto(OrganizationDto organization) { - ComponentDto componentDto = insertPrivateProject(organization); - return getProjectDto(componentDto); - } - public final ProjectDto insertPrivateProjectDto(Consumer componentDtoPopulator) { return insertPrivateProjectDto(componentDtoPopulator, defaults()); } @@ -195,122 +137,31 @@ public class ComponentDbTester { return getProjectDto(componentDto); } - public final ComponentDto insertPrivateProject(String uuid, Consumer dtoPopulator) { - return insertPrivateProject(db.getDefaultOrganization(), uuid, dtoPopulator); - } - - // TODO remove after getting rid of organization code - @Deprecated - public ProjectDto insertPrivateProjectDto(OrganizationDto organization, Consumer branchConsumer) { - ComponentDto componentDto = insertPrivateProjectWithCustomBranch(organization, branchConsumer, defaults()); + public ProjectDto insertPrivateProjectDto(Consumer branchPopulator, Consumer componentDtoPopulator, + Consumer projectDtoPopulator) { + ComponentDto componentDto = insertPrivateProjectWithCustomBranch(branchPopulator, componentDtoPopulator, projectDtoPopulator); return getProjectDto(componentDto); } - // TODO remove after getting rid of organization code - @Deprecated - public ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid) { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true); - } - - // TODO remove after getting rid of organization code - @Deprecated - public ComponentDto insertPublicProject(OrganizationDto organizationDto, String uuid) { - return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto, uuid), false); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid, Consumer dtoPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, defaults(), dtoPopulator); + public final ComponentDto insertPrivateProject(String uuid, Consumer dtoPopulator) { + return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true, defaults(), dtoPopulator); } public final ComponentDto insertPrivateProjectWithCustomBranch(String branchKey) { - return insertPrivateProjectWithCustomBranch(db.getDefaultOrganization(), b -> b.setBranchType(BRANCH).setKey(branchKey), defaults()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivateProjectWithCustomBranch(OrganizationDto organizationDto, Consumer branchPopulator, - Consumer componentPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, branchPopulator, componentPopulator); - } - - /** - * @see #insertPublicPortfolio(java.util.function.Consumer) - * @deprecated since 6.6 - */ - @Deprecated - public ComponentDto insertView() { - return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()), false); - } - - /** - * @see #insertPublicPortfolio(java.util.function.Consumer) - * @deprecated since 6.6 - */ - @Deprecated - public ComponentDto insertView(Consumer dtoPopulator) { - return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()), false, dtoPopulator); - } - - /** - * @see #insertPublicPortfolio(java.util.function.Consumer) - * @deprecated since 6.6 - */ - // TODO remove after getting rid of organization code - @Deprecated - public ComponentDto insertView(OrganizationDto organizationDto) { - return insertComponentImpl(ComponentTesting.newView(organizationDto), false, defaults()); - } - - /** - * @see #insertPublicPortfolio(java.util.function.Consumer) - * @deprecated since 6.6 - */ - // TODO remove after getting rid of organization code - @Deprecated - public ComponentDto insertView(OrganizationDto organizationDto, Consumer dtoPopulator) { - return insertComponentImpl(ComponentTesting.newView(organizationDto), false, dtoPopulator); + return insertPrivateProjectWithCustomBranch(b -> b.setBranchType(BRANCH).setKey(branchKey), defaults()); } - /** - * @see #insertPublicPortfolio(java.util.function.Consumer) - * @deprecated since 6.6 - */ - public ComponentDto insertView(String uuid) { - return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization(), uuid), false, defaults()); + public final ComponentDto insertPrivateProjectWithCustomBranch(Consumer branchPopulator, Consumer componentPopulator) { + return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, branchPopulator, componentPopulator); } - /** - * @see #insertPublicPortfolio(java.util.function.Consumer) - * @deprecated since 6.6 - */ - // TODO remove after getting rid of organization code - @Deprecated - public ComponentDto insertView(OrganizationDto organizationDto, String uuid) { - return insertComponentImpl(ComponentTesting.newView(organizationDto, uuid), false, defaults()); + public final ComponentDto insertPrivateProjectWithCustomBranch(Consumer branchPopulator, Consumer componentPopulator, + Consumer projectPopulator) { + return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, branchPopulator, componentPopulator, projectPopulator); } public final ComponentDto insertPublicPortfolio() { - return insertPublicPortfolio(db.getDefaultOrganization(), defaults()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPublicPortfolio(OrganizationDto organization) { - return insertPublicPortfolio(organization, defaults()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPublicPortfolio(OrganizationDto organization, Consumer dtoPopulator) { - return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(false), false, dtoPopulator); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPublicPortfolio(OrganizationDto organization, String uuid, Consumer dtoPopulator) { - return insertComponentImpl(ComponentTesting.newView(organization, uuid).setPrivate(false), false, dtoPopulator); + return insertPublicPortfolio(defaults()); } public final ComponentDto insertPublicPortfolio(String uuid, Consumer dtoPopulator) { @@ -334,65 +185,39 @@ public class ComponentDbTester { } public final ComponentDto insertPublicApplication() { - return insertPublicApplication(db.getDefaultOrganization(), defaults()); + return insertPublicApplication(defaults()); } public final ComponentDto insertPublicApplication(Consumer dtoPopulator) { - return insertPublicApplication(db.getDefaultOrganization(), dtoPopulator); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPublicApplication(OrganizationDto organization) { - return insertPublicApplication(organization, defaults()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPublicApplication(OrganizationDto organization, Consumer dtoPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(false), false, defaults(), dtoPopulator); - } - - public final ComponentDto insertPrivateApplication() { - return insertPrivateApplication(db.getDefaultOrganization()); + return insertComponentAndBranchAndProject(ComponentTesting.newApplication().setPrivate(false), false, defaults(), dtoPopulator); } public final ProjectDto insertPrivateApplicationDto() { - return getProjectDto(insertPrivateApplication(db.getDefaultOrganization())); + return getProjectDto(insertPrivateApplication()); } public final ProjectDto insertPublicApplicationDto() { - return getProjectDto(insertPublicApplication(db.getDefaultOrganization())); + return getProjectDto(insertPublicApplication()); } public final ProjectDto insertPrivateApplicationDto(Consumer dtoPopulator) { - return getProjectDto(insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, defaults())); + return getProjectDto(insertPrivateApplication(dtoPopulator, defaults())); } public final ProjectDto insertPrivateApplicationDto(Consumer dtoPopulator, Consumer appPopulator) { - return getProjectDto(insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, appPopulator)); + return getProjectDto(insertPrivateApplication(dtoPopulator, appPopulator)); } public final ComponentDto insertPrivateApplication(Consumer dtoPopulator) { - return insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, defaults()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer dtoPopulator) { - return insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, defaults()); + return insertPrivateApplication(dtoPopulator, defaults()); } - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivateApplication(OrganizationDto organization) { - return insertPrivateApplication(organization, defaults(), defaults()); + public final ComponentDto insertPrivateApplication() { + return insertPrivateApplication(defaults(), defaults()); } - // TODO remove after getting rid of organization code - @Deprecated - public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer dtoPopulator, Consumer projectPopulator) { - return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(true), true, defaults(), dtoPopulator, projectPopulator); + public final ComponentDto insertPrivateApplication(Consumer dtoPopulator, Consumer projectPopulator) { + return insertComponentAndBranchAndProject(ComponentTesting.newApplication().setPrivate(true), true, defaults(), dtoPopulator, projectPopulator); } public final ComponentDto insertSubView(ComponentDto view) { @@ -539,14 +364,6 @@ public class ComponentDbTester { return branchDto; } - // TODO remove after getting rid of organization code - @Deprecated - @SafeVarargs - public final ComponentDto insertProjectBranch(OrganizationDto organization, Consumer... dtoPopulators) { - ComponentDto project = ComponentTesting.newPrivateProjectDto(organization); - return insertProjectBranch(project, dtoPopulators); - } - public final ComponentDto insertProjectBranch(ProjectDto project, BranchDto branchDto) { checkArgument(branchDto.getProjectUuid().equals(project.getUuid())); ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java index 4445f7863d8..0a565c03006 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java @@ -217,59 +217,10 @@ public class ComponentTesting { .setPrivate(false); } - // TODO remove after getting rid of organization code - @Deprecated - public static ComponentDto newView(OrganizationDto organizationDto) { - return newView(organizationDto.getUuid(), Uuids.createFast()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public static ComponentDto newView(OrganizationDto organizationDto, String uuid) { - return newPrivateProjectDto(organizationDto, uuid) - .setUuid(uuid) - .setScope(Scopes.PROJECT) - .setQualifier(Qualifiers.VIEW) - .setPrivate(false); - } - - // TODO remove after getting rid of organization code - @Deprecated - private static ComponentDto newView(String organizationUuid, String uuid) { - return newProjectDto(organizationUuid, uuid, false) - .setUuid(uuid) - .setScope(Scopes.PROJECT) - .setQualifier(Qualifiers.VIEW); - } - public static ComponentDto newApplication() { return newView(Uuids.createFast()).setQualifier(Qualifiers.APP); } - // TODO remove after getting rid of organization code - @Deprecated - public static ComponentDto newApplication(OrganizationDto organizationDto) { - return newApplication(organizationDto.getUuid()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public static ComponentDto newApplication(OrganizationDto organizationDto, String uuid) { - return newApplication(organizationDto.getUuid(), uuid); - } - - // TODO remove after getting rid of organization code - @Deprecated - public static ComponentDto newApplication(String organizationUuid) { - return newApplication(organizationUuid, Uuids.createFast()); - } - - // TODO remove after getting rid of organization code - @Deprecated - public static ComponentDto newApplication(String organizationUuid, String uuid) { - return newView(organizationUuid, uuid).setQualifier(Qualifiers.APP); - } - public static ComponentDto newProjectCopy(ComponentDto project, ComponentDto view) { return newProjectCopy(Uuids.createFast(), project, view); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java index e4e8a894188..67db0fd90ea 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java @@ -30,7 +30,6 @@ import org.sonar.core.issue.FieldDiffs; import org.sonar.core.util.Uuids; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.user.UserDto; @@ -119,23 +118,15 @@ public class IssueDbTester { return insert(issueDto); } - /** - * Inserts an issue. - */ - @SafeVarargs - public final IssueDto insertIssue(Consumer... populateIssueDto) { - return insertIssue(db.getDefaultOrganization(), populateIssueDto); - } - /** * Inserts an issue. * * @throws AssertionError if rule is not Security Hotspot */ @SafeVarargs - public final IssueDto insertIssue(OrganizationDto organizationDto, Consumer... populators) { + public final IssueDto insertIssue(Consumer... populators) { RuleDefinitionDto rule = db.rules().insertIssueRule(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = newIssue(rule, project, file) .setType(RULE_TYPES_EXCEPT_HOTSPOTS[new Random().nextInt(RULE_TYPES_EXCEPT_HOTSPOTS.length)]); @@ -190,17 +181,9 @@ public class IssueDbTester { * Inserts a Security Hotspot. */ @SafeVarargs - public final IssueDto insertHotspot(Consumer... populateIssueDto) { - return insertHotspot(db.getDefaultOrganization(), populateIssueDto); - } - - /** - * Inserts a Security Hotspot. - */ - @SafeVarargs - public final IssueDto insertHotspot(OrganizationDto organizationDto, Consumer... populators) { + public final IssueDto insertHotspot(Consumer... populators) { RuleDefinitionDto rule = db.rules().insertHotspotRule(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IssueDto issue = newIssue(rule, project, file) .setType(SECURITY_HOTSPOT) @@ -231,7 +214,7 @@ public class IssueDbTester { public void insertFieldDiffs(IssueDto issueDto, FieldDiffs... diffs) { Arrays.stream(diffs).forEach(diff -> db.getDbClient().issueChangeDao().insert(db.getSession(), IssueChangeDto.of(issueDto.getKey(), diff, issueDto.getProjectUuid()) - .setUuid(Uuids.createFast()))); + .setUuid(Uuids.createFast()))); db.commit(); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java deleted file mode 100644 index 674545c8267..00000000000 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.organization; - -import java.util.function.Consumer; -import javax.annotation.Nullable; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; -import org.sonar.db.permission.template.DefaultTemplates; - -//TODO remove -@Deprecated -public class OrganizationDbTester { - private final DbTester db; - - public OrganizationDbTester(DbTester db) { - this.db = db; - } - - public OrganizationDto getDefaultOrganization() { - return db.getDefaultOrganization(); - } - - /** - * Insert an {@link OrganizationDto} and commit the session - */ - public OrganizationDto insert() { - return insert(OrganizationTesting.newOrganizationDto()); - } - - public OrganizationDto insert(Consumer populator) { - OrganizationDto dto = OrganizationTesting.newOrganizationDto(); - populator.accept(dto); - return insert(dto); - } - - public OrganizationDto insertForKey(String key) { - return insert(dto -> dto.setKey(key)); - } - - public OrganizationDto insertForUuid(String organizationUuid) { - return insert(dto -> dto.setUuid(organizationUuid)); - } - - /** - * Insert the provided {@link OrganizationDto} and commit the session - */ - public OrganizationDto insert(OrganizationDto dto) { - DbSession dbSession = db.getSession(); - db.getDbClient().organizationDao().insert(dbSession, dto, false); - dbSession.commit(); - return dto; - } - - public void setDefaultTemplates(String projectDefaultTemplateUuid, @Nullable String applicationDefaultTemplateUuid, @Nullable String portfoliosDefaultTemplateUuid) { - DbSession dbSession = db.getSession(); - db.getDbClient().organizationDao().setDefaultTemplates(dbSession, db.getDefaultOrganization().getUuid(), - new DefaultTemplates() - .setProjectUuid(projectDefaultTemplateUuid) - .setApplicationsUuid(applicationDefaultTemplateUuid) - .setPortfoliosUuid(portfoliosDefaultTemplateUuid)); - dbSession.commit(); - } -} diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationTesting.java deleted file mode 100644 index 23dc2e44722..00000000000 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationTesting.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.db.organization; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.sonar.db.organization.OrganizationDto.Subscription.FREE; - -public class OrganizationTesting { - - private OrganizationTesting() { - // only statics - } - - /** - * Creates a new {@link OrganizationDto} with randomly generated field values. - */ - public static OrganizationDto newOrganizationDto() { - return new OrganizationDto() - .setKey(randomAlphanumeric(32)) - .setUuid(randomAlphanumeric(40)) - .setName(randomAlphanumeric(64)) - .setDescription(randomAlphanumeric(256)) - .setAvatarUrl(randomAlphanumeric(256)) - // Default quality gate should be set explicitly when needed in tests - .setDefaultQualityGateUuid("_NOT_SET_") - .setSubscription(FREE) - .setUrl(randomAlphanumeric(256)); - } -} diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java index 30073889618..04595c63b80 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java @@ -32,7 +32,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentUpdateDto; import org.sonar.db.es.EsQueueDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.es.EsClient; import org.sonar.server.es.EsTester; import org.sonar.server.es.IndexingResult; @@ -95,8 +94,7 @@ public class ComponentIndexerTest { @Test public void map_fields() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); underTest.indexOnStartup(emptySet()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/ProjectIndexersImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/ProjectIndexersImplTest.java index 2d2dc82d710..7f034559d9b 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/ProjectIndexersImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/ProjectIndexersImplTest.java @@ -26,8 +26,6 @@ import org.junit.Test; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.server.es.ProjectIndexer.Cause; import static java.util.Collections.singletonList; @@ -38,8 +36,7 @@ public class ProjectIndexersImplTest { @Test public void commitAndIndex_indexes_project() { - OrganizationDto organization = OrganizationTesting.newOrganizationDto(); - ComponentDto project = ComponentTesting.newPublicProjectDto(organization); + ComponentDto project = ComponentTesting.newPublicProjectDto(); FakeIndexers underTest = new FakeIndexers(); underTest.commitAndIndexComponents(mock(DbSession.class), singletonList(project), Cause.PROJECT_CREATION); @@ -49,8 +46,7 @@ public class ProjectIndexersImplTest { @Test public void commitAndIndex_of_module_indexes_the_project() { - OrganizationDto organization = OrganizationTesting.newOrganizationDto(); - ComponentDto project = ComponentTesting.newPublicProjectDto(organization); + ComponentDto project = ComponentTesting.newPublicProjectDto(); ComponentDto module = ComponentTesting.newModuleDto(project); FakeIndexers underTest = new FakeIndexers(); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java index baf22b047f8..e5c8ff1a338 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java @@ -31,7 +31,6 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import static org.assertj.core.api.Assertions.assertThat; @@ -47,8 +46,7 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_one_issue() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project) .setPath("src/main/java/Action.java")); IssueDto expected = dbTester.issues().insert(rule, project, file, @@ -100,8 +98,7 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_issues() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto directory = dbTester.components().insertComponent(newDirectory(module, "src/main/java")); ComponentDto file = dbTester.components().insertComponent(newFileDto(module, directory) @@ -131,14 +128,13 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_issue_from_project() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project1 = dbTester.components().insertPrivateProject(organization); + ComponentDto project1 = dbTester.components().insertPrivateProject(); ComponentDto module1 = dbTester.components().insertComponent(newModuleDto(project1)); ComponentDto file1 = dbTester.components().insertComponent(newFileDto(module1)); String[] project1IssueKeys = Stream.of(project1, module1, file1) .map(project1Component -> dbTester.issues().insert(rule, project1, project1Component).getKey()) .toArray(String[]::new); - ComponentDto project2 = dbTester.components().insertPrivateProject(organization); + ComponentDto project2 = dbTester.components().insertPrivateProject(); ComponentDto module2 = dbTester.components().insertComponent(newModuleDto(project2)); ComponentDto file2 = dbTester.components().insertComponent(newFileDto(module2)); String[] project2IssueKeys = Stream.of(project2, module2, file2) @@ -156,8 +152,7 @@ public class IssueIteratorFactoryTest { @Test public void extract_directory_path() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml")); ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(module).setPath("src/main/java/Action.java")); @@ -178,8 +173,7 @@ public class IssueIteratorFactoryTest { @Test public void extract_file_path() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml")); ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(module).setPath("src/main/java/Action.java")); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java index d03deb7c831..83c12e18bbb 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java @@ -35,7 +35,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.es.EsQueueDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.IndexingResult; @@ -98,10 +97,9 @@ public class ProjectMeasuresIndexerTest { @Test public void indexOnStartup_indexes_all_projects() { - OrganizationDto organization = db.organizations().insert(); - SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); - SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); - SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); + SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); + SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); + SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); underTest.indexOnStartup(emptySet()); @@ -111,10 +109,9 @@ public class ProjectMeasuresIndexerTest { @Test public void indexAll_indexes_all_projects() { - OrganizationDto organization = db.organizations().insert(); - SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); - SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); - SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); + SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); + SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); + SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); underTest.indexAll(); @@ -146,10 +143,9 @@ public class ProjectMeasuresIndexerTest { @Test public void indexOnStartup_indexes_all_applications() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto application1 = db.components().insertPrivateApplication(organization); - ComponentDto application2 = db.components().insertPrivateApplication(organization); - ComponentDto application3 = db.components().insertPrivateApplication(organization); + ComponentDto application1 = db.components().insertPrivateApplication(); + ComponentDto application2 = db.components().insertPrivateApplication(); + ComponentDto application3 = db.components().insertPrivateApplication(); underTest.indexOnStartup(emptySet()); @@ -159,15 +155,13 @@ public class ProjectMeasuresIndexerTest { @Test public void indexOnStartup_indexes_projects_and_applications() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto project3 = db.components().insertPrivateProject(); - ComponentDto application1 = db.components().insertPrivateApplication(organization); - ComponentDto application2 = db.components().insertPrivateApplication(organization); - ComponentDto application3 = db.components().insertPrivateApplication(organization); + ComponentDto application1 = db.components().insertPrivateApplication(); + ComponentDto application2 = db.components().insertPrivateApplication(); + ComponentDto application3 = db.components().insertPrivateApplication(); underTest.indexOnStartup(emptySet()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java index d879f705589..f7279a67979 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java @@ -28,17 +28,24 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.organization.OrganizationDto; +import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.db.organization.OrganizationDao.DEFAULT_ORGANIZATION; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; +import static org.sonar.db.organization.OrganizationDto.Subscription.FREE; public class DefaultOrganizationProviderImplTest { - private static final OrganizationDto ORGANIZATION_DTO_1 = newOrganizationDto() + private static final OrganizationDto ORGANIZATION_DTO_1 = new OrganizationDto() .setUuid("uuid1") .setName("the name of 1") - .setKey("the key 1"); + .setKey("the key 1") + .setDescription(randomAlphanumeric(256)) + .setAvatarUrl(randomAlphanumeric(256)) + // Default quality gate should be set explicitly when needed in tests + .setDefaultQualityGateUuid("_NOT_SET_") + .setSubscription(FREE) + .setUrl(randomAlphanumeric(256)); private static final long DATE_1 = 1_999_888L; private final System2 system2 = mock(System2.class); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java index 58a0429d748..67fc57965ee 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java @@ -40,7 +40,6 @@ import org.sonar.api.utils.log.LoggerLevel; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Scope; @@ -235,7 +234,6 @@ public class RuleIndexerTest { "bar\n" + "

Recommended Secure Coding Practices

\n" + "foo")); - OrganizationDto organization = dbTester.organizations().insert(); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); assertThat(logTester.getLogs()).hasSize(1); @@ -252,7 +250,6 @@ public class RuleIndexerTest { .setDescription("bar\n" + "

Recommended Secure Coding Practices

\n" + "foo")); - OrganizationDto organization = dbTester.organizations().insert(); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); assertThat(logTester.getLogs()).hasSize(1); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java index 2c49c00ba21..a1371bb19a4 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java @@ -20,6 +20,7 @@ package org.sonar.server.view.index; import com.google.common.collect.Maps; +import java.util.Collections; import java.util.List; import java.util.Map; import org.junit.Rule; @@ -52,9 +53,9 @@ public class ViewIndexerTest { @Rule public EsTester es = EsTester.create(); - private DbClient dbClient = db.getDbClient(); - private DbSession dbSession = db.getSession(); - private ViewIndexer underTest = new ViewIndexer(dbClient, es.client()); + private final DbClient dbClient = db.getDbClient(); + private final DbSession dbSession = db.getSession(); + private final ViewIndexer underTest = new ViewIndexer(dbClient, es.client()); @Test public void index_nothing() { @@ -66,19 +67,19 @@ public class ViewIndexerTest { public void index_on_startup() { // simple view ComponentDto project1 = db.components().insertPrivateProject(); - ComponentDto view1 = db.components().insertView(); + ComponentDto view1 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view1, t -> t.setLast(true)); db.components().insertComponent(newProjectCopy(project1, view1)); // view with subview ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto project3 = db.components().insertPrivateProject(); - ComponentDto view2 = db.components().insertView(); + ComponentDto view2 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view2, t -> t.setLast(true)); db.components().insertComponent(newProjectCopy(project2, view2)); ComponentDto subView = db.components().insertComponent(newSubView(view2)); db.components().insertComponent(newProjectCopy(project3, subView)); // view without project - ComponentDto view3 = db.components().insertView(); + ComponentDto view3 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view3, t -> t.setLast(true)); underTest.indexOnStartup(emptySet()); @@ -98,19 +99,19 @@ public class ViewIndexerTest { public void index_root_view() { // simple view ComponentDto project1 = db.components().insertPrivateProject(); - ComponentDto view1 = db.components().insertView(); + ComponentDto view1 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view1, t -> t.setLast(true)); db.components().insertComponent(newProjectCopy(project1, view1)); // view with subview ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto project3 = db.components().insertPrivateProject(); - ComponentDto view2 = db.components().insertView(); + ComponentDto view2 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view2, t -> t.setLast(true)); db.components().insertComponent(newProjectCopy(project2, view2)); ComponentDto subView = db.components().insertComponent(newSubView(view2)); db.components().insertComponent(newProjectCopy(project3, subView)); // view without project - ComponentDto view3 = db.components().insertView(); + ComponentDto view3 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view3, t -> t.setLast(true)); underTest.index(view2.uuid()); @@ -138,7 +139,7 @@ public class ViewIndexerTest { @Test public void index_application() { - ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPrivateApplication(); ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy("PC1", project, application)); @@ -153,7 +154,7 @@ public class ViewIndexerTest { @Test public void index_application_on_startup() { - ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPrivateApplication(); ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy("PC1", project, application)); @@ -168,7 +169,7 @@ public class ViewIndexerTest { @Test public void index_application_with_indexAll() { - ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPrivateApplication(); ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy("PC1", project, application)); @@ -208,7 +209,7 @@ public class ViewIndexerTest { @Test public void delete_should_delete_the_view() { - ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(asList("P1")); + ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(Collections.singletonList("P1")); ViewDoc view2 = new ViewDoc().setUuid("UUID2").setProjects(asList("P2", "P3", "P4")); ViewDoc view3 = new ViewDoc().setUuid("UUID3").setProjects(asList("P2", "P3", "P4")); es.putDocuments(TYPE_VIEW, view1); diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java index 823804ff893..a84ee7fd7f4 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/project/ProjectLifeCycleListenersImplTest.java @@ -39,20 +39,19 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; @RunWith(DataProviderRunner.class) public class ProjectLifeCycleListenersImplTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private ProjectLifeCycleListener listener1 = mock(ProjectLifeCycleListener.class); - private ProjectLifeCycleListener listener2 = mock(ProjectLifeCycleListener.class); - private ProjectLifeCycleListener listener3 = mock(ProjectLifeCycleListener.class); - private ProjectLifeCycleListenersImpl underTestNoListeners = new ProjectLifeCycleListenersImpl(); - private ProjectLifeCycleListenersImpl underTestWithListeners = new ProjectLifeCycleListenersImpl( + private final ProjectLifeCycleListener listener1 = mock(ProjectLifeCycleListener.class); + private final ProjectLifeCycleListener listener2 = mock(ProjectLifeCycleListener.class); + private final ProjectLifeCycleListener listener3 = mock(ProjectLifeCycleListener.class); + private final ProjectLifeCycleListenersImpl underTestNoListeners = new ProjectLifeCycleListenersImpl(); + private final ProjectLifeCycleListenersImpl underTestWithListeners = new ProjectLifeCycleListenersImpl( new ProjectLifeCycleListener[] {listener1, listener2, listener3}); @Test @@ -76,7 +75,7 @@ public class ProjectLifeCycleListenersImplTest { underTestNoListeners.onProjectsDeleted(Collections.emptySet()); underTestWithListeners.onProjectsDeleted(Collections.emptySet()); - verifyZeroInteractions(listener1, listener2, listener3); + verifyNoInteractions(listener1, listener2, listener3); } @Test @@ -151,7 +150,7 @@ public class ProjectLifeCycleListenersImplTest { underTestNoListeners.onProjectBranchesDeleted(Collections.emptySet()); underTestWithListeners.onProjectBranchesDeleted(Collections.emptySet()); - verifyZeroInteractions(listener1, listener2, listener3); + verifyNoInteractions(listener1, listener2, listener3); } @Test @@ -235,7 +234,7 @@ public class ProjectLifeCycleListenersImplTest { underTestNoListeners.onProjectsRekeyed(Collections.emptySet()); underTestWithListeners.onProjectsRekeyed(Collections.emptySet()); - verifyZeroInteractions(listener1, listener2, listener3); + verifyNoInteractions(listener1, listener2, listener3); } @Test @@ -298,14 +297,14 @@ public class ProjectLifeCycleListenersImplTest { } private static Project newUniqueProject() { - return Project.from(newPrivateProjectDto(newOrganizationDto())); + return Project.from(newPrivateProjectDto()); } private static int counter = 3_989; private static RekeyedProject newUniqueRekeyedProject() { int base = counter++; - Project project = Project.from(newPrivateProjectDto(newOrganizationDto())); + Project project = Project.from(newPrivateProjectDto()); return new RekeyedProject(project, base + "_old_key"); } } diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/project/RekeyedProjectTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/project/RekeyedProjectTest.java index e37d1bafdd5..285d724d654 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/project/RekeyedProjectTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/project/RekeyedProjectTest.java @@ -27,7 +27,6 @@ import static java.util.Collections.emptyList; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class RekeyedProjectTest { @Rule @@ -97,6 +96,6 @@ public class RekeyedProjectTest { } private static Project newRandomProject() { - return Project.from(newPrivateProjectDto(newOrganizationDto())); + return Project.from(newPrivateProjectDto()); } } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java index cdb2ec0261b..baf9eea6719 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usergroups/DefaultGroupCreatorImplTest.java @@ -25,8 +25,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.core.util.SequenceUuidFactory; import org.sonar.db.DbTester; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.db.user.GroupDto; import org.sonar.server.organization.TestDefaultOrganizationProvider; @@ -40,7 +38,7 @@ public class DefaultGroupCreatorImplTest { @Rule public DbTester db = DbTester.create(); - private DefaultGroupCreator underTest = new DefaultGroupCreatorImpl(db.getDbClient(), new SequenceUuidFactory(), TestDefaultOrganizationProvider.from(db)); + private final DefaultGroupCreator underTest = new DefaultGroupCreatorImpl(db.getDbClient(), new SequenceUuidFactory(), TestDefaultOrganizationProvider.from(db)); @Test public void create_default_group() { @@ -55,9 +53,7 @@ public class DefaultGroupCreatorImplTest { @Test public void fail_with_IAE_when_default_group_already_exist() { - OrganizationDto organizationDto = db.organizations().insert(); - PermissionTemplateDto permissionTemplate = db.permissionTemplates().insertTemplate(); - db.organizations().setDefaultTemplates(permissionTemplate.getUuid(), null, null); + db.permissionTemplates().insertTemplate(); db.users().insertGroup("Members"); expectedException.expect(IllegalArgumentException.class); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java index 581b78ee09e..7bd80d56850 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java @@ -37,7 +37,6 @@ import org.sonar.db.metric.MetricDto; import org.sonar.server.es.EsTester; import org.sonar.server.measure.index.ProjectMeasuresIndex; import org.sonar.server.measure.index.ProjectMeasuresIndexer; -import org.sonar.server.organization.DefaultOrganizationProviderImpl; import org.sonar.server.platform.DockerSupport; import org.sonar.server.property.InternalProperties; import org.sonar.server.property.MapInternalProperties; @@ -105,14 +104,14 @@ public class TelemetryDataLoaderImplTest { MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY)); MetricDto nclocDistrib = db.measures().insertMetric(m -> m.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY)); - ComponentDto project1 = db.components().insertPublicProject(db.getDefaultOrganization()); + ComponentDto project1 = db.components().insertPublicProject(); ComponentDto project1Branch = db.components().insertProjectBranch(project1); db.measures().insertLiveMeasure(project1, lines, m -> m.setValue(200d)); db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(100d)); db.measures().insertLiveMeasure(project1, coverage, m -> m.setValue(80d)); db.measures().insertLiveMeasure(project1, nclocDistrib, m -> m.setValue(null).setData("java=200;js=50")); - ComponentDto project2 = db.components().insertPublicProject(db.getDefaultOrganization()); + ComponentDto project2 = db.components().insertPublicProject(); db.measures().insertLiveMeasure(project2, lines, m -> m.setValue(300d)); db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(200d)); db.measures().insertLiveMeasure(project2, coverage, m -> m.setValue(80d)); @@ -150,7 +149,7 @@ public class TelemetryDataLoaderImplTest { public void take_largest_branches() { server.setId("AU-TpxcB-iU5OvuD2FL7").setVersion("7.5.4"); MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(NCLOC_KEY)); - ComponentDto project = db.components().insertPublicProject(db.getDefaultOrganization()); + ComponentDto project = db.components().insertPublicProject(); ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH)); ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); db.measures().insertLiveMeasure(project, ncloc, m -> m.setValue(10d)); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/webhook/WebhookQGChangeEventListenerTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/webhook/WebhookQGChangeEventListenerTest.java index 12cfc351d89..ad1ad814f25 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/webhook/WebhookQGChangeEventListenerTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/webhook/WebhookQGChangeEventListenerTest.java @@ -45,7 +45,6 @@ import org.sonar.db.component.AnalysisPropertyDto; import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import org.sonar.server.qualitygate.EvaluatedQualityGate; import org.sonar.server.qualitygate.changeevent.QGChangeEvent; @@ -141,8 +140,7 @@ public class WebhookQGChangeEventListenerTest { @Test @UseDataProvider("newQGorNot") public void onIssueChanges_calls_webhook_for_changeEvent_with_webhook_enabled(@Nullable EvaluatedQualityGate newQualityGate) { - OrganizationDto organization = dbTester.organizations().insert(); - ProjectAndBranch projectBranch = insertBranch(organization, BRANCH, "foo"); + ProjectAndBranch projectBranch = insertBranch(BRANCH, "foo"); SnapshotDto analysis = insertAnalysisTask(projectBranch); Configuration configuration = mock(Configuration.class); mockPayloadSupplierConsumedByWebhooks(); @@ -170,8 +168,7 @@ public class WebhookQGChangeEventListenerTest { @Test @UseDataProvider("newQGorNot") public void onIssueChanges_calls_webhook_on_main_branch(@Nullable EvaluatedQualityGate newQualityGate) { - OrganizationDto organization = dbTester.organizations().insert(); - ProjectAndBranch mainBranch = insertMainBranch(organization); + ProjectAndBranch mainBranch = insertMainBranch(); SnapshotDto analysis = insertAnalysisTask(mainBranch); Configuration configuration = mock(Configuration.class); QGChangeEvent qualityGateEvent = newQGChangeEvent(mainBranch, analysis, configuration, newQualityGate); @@ -193,8 +190,7 @@ public class WebhookQGChangeEventListenerTest { } public void onIssueChangesCallsWebhookOnBranch(BranchType branchType) { - OrganizationDto organization = dbTester.organizations().insert(); - ProjectAndBranch nonMainBranch = insertBranch(organization, branchType, "foo"); + ProjectAndBranch nonMainBranch = insertBranch(branchType, "foo"); SnapshotDto analysis = insertAnalysisTask(nonMainBranch); Configuration configuration = mock(Configuration.class); QGChangeEvent qualityGateEvent = newQGChangeEvent(nonMainBranch, analysis, configuration, null); @@ -270,15 +266,15 @@ public class WebhookQGChangeEventListenerTest { return projectAnalysisCaptor.getAllValues(); } - public ProjectAndBranch insertMainBranch(OrganizationDto organization) { - ProjectDto project = dbTester.components().insertPrivateProjectDto(organization); + public ProjectAndBranch insertMainBranch() { + ProjectDto project = dbTester.components().insertPrivateProjectDto(); BranchDto branch = dbTester.getDbClient().branchDao().selectByUuid(dbTester.getSession(), project.getUuid()).get(); dbTester.commit(); return new ProjectAndBranch(project, branch); } - public ProjectAndBranch insertBranch(OrganizationDto organization, BranchType type, String branchKey) { - ProjectDto project = dbTester.components().insertPrivateProjectDto(organization); + public ProjectAndBranch insertBranch(BranchType type, String branchKey) { + ProjectDto project = dbTester.components().insertPrivateProjectDto(); BranchDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchKey).setBranchType(type)); return new ProjectAndBranch(project, branch); } diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresQuery.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresQuery.java index 9c745f56ce9..0ed4cea432f 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresQuery.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresQuery.java @@ -68,11 +68,15 @@ public class ProjectMeasuresQuery { return Optional.ofNullable(qualityGateStatus); } + //TODO remove in organization removal + @Deprecated public ProjectMeasuresQuery setOrganizationUuid(@Nullable String organizationUuid) { this.organizationUuid = organizationUuid; return this; } + //TODO remove in organization removal + @Deprecated public Optional getOrganizationUuid() { return Optional.ofNullable(organizationUuid); } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java index 7b288e55076..fa6c7595bde 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java @@ -30,7 +30,6 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.SearchIdResult; import org.sonar.server.es.SearchOptions; @@ -53,10 +52,9 @@ public class ComponentIndexSearchTest { @Rule public ComponentTextSearchFeatureRule features = new ComponentTextSearchFeatureRule(); - private ComponentIndexer indexer = new ComponentIndexer(db.getDbClient(), es.client()); - private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, indexer); - - private ComponentIndex underTest = new ComponentIndex(es.client(), new WebAuthorizationTypeSupport(userSession), System2.INSTANCE); + private final ComponentIndexer indexer = new ComponentIndexer(db.getDbClient(), es.client()); + private final PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, indexer); + private final ComponentIndex underTest = new ComponentIndex(es.client(), new WebAuthorizationTypeSupport(userSession), System2.INSTANCE); @Test public void filter_by_name() { @@ -93,19 +91,6 @@ public class ComponentIndexSearchTest { assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid()); } - @Test - public void filter_by_organization() { - OrganizationDto organization = db.organizations().insert(); - OrganizationDto anotherOrganization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); - ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization); - index(project, anotherProject); - - SearchIdResult result = underTest.search(ComponentQuery.builder().setOrganization(organization.getUuid()).build(), new SearchOptions()); - - assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid()); - } - @Test public void order_by_name_case_insensitive() { ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("PROJECT 2")); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java index 02e6ded8ce3..2efce7294dd 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java @@ -24,14 +24,11 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import org.assertj.core.api.ListAssert; -import org.junit.Before; import org.junit.Rule; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.server.es.EsTester; import org.sonar.server.es.textsearch.ComponentTextSearchFeatureRule; import org.sonar.server.permission.index.PermissionIndexerTester; @@ -59,12 +56,6 @@ public abstract class ComponentIndexTest { protected ComponentIndexer indexer = new ComponentIndexer(db.getDbClient(), es.client()); protected ComponentIndex index = new ComponentIndex(es.client(), new WebAuthorizationTypeSupport(userSession), System2.INSTANCE); protected PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, indexer); - private OrganizationDto organization; - - @Before - public void setUp() { - organization = OrganizationTesting.newOrganizationDto(); - } protected void assertFileMatches(String query, String... fileNames) { ComponentDto[] files = Arrays.stream(fileNames) @@ -99,7 +90,7 @@ public abstract class ComponentIndexTest { } protected ListAssert assertSearch(SuggestionQuery query) { - return (ListAssert)assertThat(index.searchSuggestions(query, features.get()).getQualifiers()) + return (ListAssert) assertThat(index.searchSuggestions(query, features.get()).getQualifiers()) .flatExtracting(ComponentHitsPerQualifier::getHits) .extracting(ComponentHit::getUuid); } @@ -122,13 +113,13 @@ public abstract class ComponentIndexTest { protected ComponentDto indexProject(String key, String name) { return index( - ComponentTesting.newPrivateProjectDto(organization, "UUID_" + key) + ComponentTesting.newPrivateProjectDto("UUID_" + key) .setDbKey(key) .setName(name)); } protected ComponentDto newProject(String key, String name) { - return ComponentTesting.newPrivateProjectDto(organization, "UUID_" + key) + return ComponentTesting.newPrivateProjectDto("UUID_" + key) .setDbKey(key) .setName(name); } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java index 35ed6595a36..8507574ff89 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java @@ -25,13 +25,11 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.impl.utils.TestSystem2; import org.sonar.api.issue.Issue; -import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.Facets; import org.sonar.server.es.SearchOptions; @@ -48,16 +46,16 @@ import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.mockito.Mockito.mock; import static org.sonar.api.issue.Issue.STATUS_CLOSED; import static org.sonar.api.issue.Issue.STATUS_OPEN; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.api.utils.DateUtils.parseDateTime; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_EFFORT; public class IssueIndexDebtTest { - private System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(TimeZone.getTimeZone("GMT-01:00")); + private final System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(TimeZone.getTimeZone("GMT-01:00")); @Rule public EsTester es = EsTester.create(); @@ -66,15 +64,15 @@ public class IssueIndexDebtTest { @Rule public DbTester db = DbTester.create(system2); - private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null); - private PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, issueIndexer); - private IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule)); + private final AsyncIssueIndexing asyncIssueIndexing = mock(AsyncIssueIndexing.class); + private final IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), asyncIssueIndexing); + private final PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, issueIndexer); + private final IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule)); @Test public void facets_on_projects() { - OrganizationDto organizationDto = newOrganizationDto(); - ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD"); - ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organizationDto, "EFGH"); + ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD"); + ComponentDto project2 = ComponentTesting.newPrivateProjectDto("EFGH"); indexIssues( IssueDocTesting.newDoc("I1", ComponentTesting.newFileDto(project, null)).setEffort(10L), @@ -89,7 +87,7 @@ public class IssueIndexDebtTest { @Test public void facets_on_components() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto(), "A"); + ComponentDto project = ComponentTesting.newPrivateProjectDto("A"); ComponentDto file1 = ComponentTesting.newFileDto(project, null, "ABCD"); ComponentDto file2 = ComponentTesting.newFileDto(project, null, "BCDE"); ComponentDto file3 = ComponentTesting.newFileDto(project, null, "CDEF"); @@ -110,7 +108,7 @@ public class IssueIndexDebtTest { @Test public void facets_on_directories() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file1 = ComponentTesting.newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); ComponentDto file2 = ComponentTesting.newFileDto(project, null).setPath("F2.xoo"); @@ -126,7 +124,7 @@ public class IssueIndexDebtTest { @Test public void facets_on_severities() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file = ComponentTesting.newFileDto(project, null); indexIssues( @@ -142,7 +140,7 @@ public class IssueIndexDebtTest { @Test public void facets_on_statuses() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file = ComponentTesting.newFileDto(project, null); indexIssues( @@ -158,7 +156,7 @@ public class IssueIndexDebtTest { @Test public void facets_on_resolutions() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file = ComponentTesting.newFileDto(project, null); indexIssues( @@ -174,9 +172,8 @@ public class IssueIndexDebtTest { @Test public void facets_on_languages() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file = ComponentTesting.newFileDto(project, null); - RuleKey ruleKey = RuleKey.of("repo", "X1"); indexIssues(IssueDocTesting.newDoc("I1", file).setLanguage("xoo").setEffort(10L)); @@ -188,7 +185,7 @@ public class IssueIndexDebtTest { @Test public void facets_on_assignees() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file = ComponentTesting.newFileDto(project, null); indexIssues( @@ -197,7 +194,7 @@ public class IssueIndexDebtTest { IssueDocTesting.newDoc("I3", file).setAssigneeUuid("uuid-simon").setEffort(10L), IssueDocTesting.newDoc("I4", file).setAssigneeUuid(null).setEffort(10L)); - Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(asList("assignees"))), system2.getDefaultTimeZone().toZoneId()); + Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(singletonList("assignees"))), system2.getDefaultTimeZone().toZoneId()); assertThat(facets.getNames()).containsOnly("assignees", FACET_MODE_EFFORT); assertThat(facets.get("assignees")).containsOnly(entry("uuid-steph", 10L), entry("uuid-simon", 20L), entry("", 10L)); assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 40L)); @@ -205,7 +202,7 @@ public class IssueIndexDebtTest { @Test public void facets_on_authors() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file = ComponentTesting.newFileDto(project, null); indexIssues( @@ -214,7 +211,7 @@ public class IssueIndexDebtTest { IssueDocTesting.newDoc("I3", file).setAuthorLogin("simon").setEffort(10L), IssueDocTesting.newDoc("I4", file).setAuthorLogin(null).setEffort(10L)); - Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(asList("authors"))), system2.getDefaultTimeZone().toZoneId()); + Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(singletonList("authors"))), system2.getDefaultTimeZone().toZoneId()); assertThat(facets.getNames()).containsOnly("authors", FACET_MODE_EFFORT); assertThat(facets.get("authors")).containsOnly(entry("steph", 10L), entry("simon", 20L)); assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 40L)); @@ -235,7 +232,7 @@ public class IssueIndexDebtTest { } private SearchOptions fixtureForCreatedAtFacet() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); ComponentDto file = ComponentTesting.newFileDto(project, null); IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", file).setEffort(10L).setFuncCreationDate(parseDateTime("2011-04-25T01:05:13+0100")); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java index fb9bbaa04eb..7906cc8438d 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFacetsTest.java @@ -32,7 +32,6 @@ import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.Facets; @@ -71,7 +70,6 @@ import static org.sonar.api.utils.DateUtils.parseDateTime; import static org.sonar.db.component.ComponentTesting.newDirectory; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; import static org.sonar.db.rule.RuleTesting.newRule; import static org.sonar.server.issue.IssueDocTesting.newDoc; @@ -95,9 +93,8 @@ public class IssueIndexFacetsTest { @Test public void facet_on_projectUuids() { - OrganizationDto organizationDto = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(organizationDto, "ABCD"); - ComponentDto project2 = newPrivateProjectDto(organizationDto, "EFGH"); + ComponentDto project = newPrivateProjectDto("ABCD"); + ComponentDto project2 = newPrivateProjectDto("EFGH"); indexIssues( newDoc("I1", newFileDto(project, null)), @@ -109,10 +106,10 @@ public class IssueIndexFacetsTest { @Test public void facet_on_projectUuids_return_100_entries_plus_selected_values() { - OrganizationDto organizationDto = newOrganizationDto(); - indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newPrivateProjectDto(organizationDto, "a" + i))).toArray(IssueDoc[]::new)); - IssueDoc issue1 = newDoc(newPrivateProjectDto(organizationDto, "project1")); - IssueDoc issue2 = newDoc(newPrivateProjectDto(organizationDto, "project2")); + + indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newPrivateProjectDto("a" + i))).toArray(IssueDoc[]::new)); + IssueDoc issue1 = newDoc(newPrivateProjectDto("project1")); + IssueDoc issue2 = newDoc(newPrivateProjectDto("project2")); indexIssues(issue1, issue2); assertThatFacetHasSize(IssueQuery.builder().build(), "projects", 100); @@ -121,7 +118,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_files() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto(), "A"); + ComponentDto project = newPrivateProjectDto("A"); ComponentDto dir = newDirectory(project, "src"); ComponentDto file1 = newFileDto(project, dir, "ABCD"); ComponentDto file2 = newFileDto(project, dir, "BCDE"); @@ -139,8 +136,7 @@ public class IssueIndexFacetsTest { @Test public void facet_on_files_return_100_entries_plus_selected_values() { - OrganizationDto organizationDto = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(organizationDto); + ComponentDto project = newPrivateProjectDto(); indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null, "a" + i))).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, null, "file1")); IssueDoc issue2 = newDoc(newFileDto(project, null, "file2")); @@ -152,7 +148,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_directories() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo"); @@ -165,8 +161,7 @@ public class IssueIndexFacetsTest { @Test public void facet_on_directories_return_100_entries_plus_selected_values() { - OrganizationDto organizationDto = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(organizationDto); + ComponentDto project = newPrivateProjectDto(); indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, newDirectory(project, "dir" + i))).setDirectoryPath("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, newDirectory(project, "path1"))).setDirectoryPath("directory1"); IssueDoc issue2 = newDoc(newFileDto(project, newDirectory(project, "path2"))).setDirectoryPath("directory2"); @@ -178,7 +173,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_cwe() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -195,7 +190,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_owaspTop10() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -211,7 +206,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_sansTop25() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -227,7 +222,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_sonarSourceSecurity() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -242,7 +237,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_severities() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -255,7 +250,7 @@ public class IssueIndexFacetsTest { @Test public void facet_on_severities_return_5_entries_max() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -271,7 +266,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_statuses() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -284,7 +279,7 @@ public class IssueIndexFacetsTest { @Test public void facet_on_statuses_return_5_entries_max() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -300,7 +295,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_resolutions() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -313,7 +308,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_resolutions_return_5_entries_max() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -328,7 +323,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_languages() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); RuleDefinitionDto ruleDefinitionDto = newRule(); db.rules().insert(ruleDefinitionDto); @@ -340,8 +335,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_languages_return_100_entries_plus_selected_values() { - OrganizationDto organizationDto = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(organizationDto); + ComponentDto project = newPrivateProjectDto(); indexIssues(rangeClosed(1, 100).mapToObj(i -> newDoc(newFileDto(project, null)).setLanguage("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, null)).setLanguage("language1"); IssueDoc issue2 = newDoc(newFileDto(project, null)).setLanguage("language2"); @@ -353,7 +347,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_assignees() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -367,8 +361,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_assignees_return_only_100_entries_plus_selected_values() { - OrganizationDto organizationDto = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(organizationDto); + ComponentDto project = newPrivateProjectDto(); indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null)).setAssigneeUuid("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, null)).setAssigneeUuid("user1"); IssueDoc issue2 = newDoc(newFileDto(project, null)).setAssigneeUuid("user2"); @@ -380,7 +373,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_assignees_supports_dashes() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -395,7 +388,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_author() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -409,7 +402,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_deprecated_authors() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -423,8 +416,7 @@ public class IssueIndexFacetsTest { @Test public void facets_on_authors_return_100_entries_plus_selected_values() { - OrganizationDto organizationDto = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(organizationDto); + ComponentDto project = newPrivateProjectDto(); indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null)).setAuthorLogin("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, null)).setAuthorLogin("user1"); IssueDoc issue2 = newDoc(newFileDto(project, null)).setAuthorLogin("user2"); @@ -461,7 +453,6 @@ public class IssueIndexFacetsTest { final ZoneId plus14 = ZoneId.of("Pacific/Kiritimati"); final ZoneId minus11 = ZoneId.of("Pacific/Pago_Pago"); - SearchOptions options = fixtureForCreatedAtFacet(); final Date startDate = parseDateTime("2014-09-01T00:00:00+0000"); @@ -613,7 +604,7 @@ public class IssueIndexFacetsTest { } private SearchOptions fixtureForCreatedAtFacet() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); IssueDoc issue0 = newDoc("ISSUE0", file).setFuncCreationDate(parseDateTime("2011-04-25T00:05:13+0000")); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexProjectStatisticsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexProjectStatisticsTest.java index 3dbf32d727c..792b00f7244 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexProjectStatisticsTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexProjectStatisticsTest.java @@ -46,7 +46,6 @@ import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.db.component.ComponentTesting.newBranchDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; import static org.sonar.db.component.ComponentTesting.newBranchComponent; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; import static org.sonar.server.issue.IssueDocTesting.newDoc; public class IssueIndexProjectStatisticsTest { @@ -76,8 +75,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_returns_something() { - OrganizationDto organization = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(organization); + ComponentDto project = newPrivateProjectDto(); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; indexIssues(newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L))); @@ -89,8 +87,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_does_not_return_results_if_assignee_does_not_match() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org1); + ComponentDto project = newPrivateProjectDto(); String user1Uuid = randomAlphanumeric(40); String user2Uuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; @@ -103,8 +100,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_returns_results_if_assignee_matches() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org1); + ComponentDto project = newPrivateProjectDto(); String user1Uuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; indexIssues(newDoc("issue1", project).setAssigneeUuid(user1Uuid).setFuncCreationDate(new Date(from + 1L))); @@ -116,8 +112,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_returns_results_if_functional_date_is_strictly_after_from_date() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org1); + ComponentDto project = newPrivateProjectDto(); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; indexIssues(newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L))); @@ -129,8 +124,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_does_not_return_results_if_functional_date_is_same_as_from_date() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org1); + ComponentDto project = newPrivateProjectDto(); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; indexIssues(newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from))); @@ -142,8 +136,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_does_not_return_resolved_issues() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org1); + ComponentDto project = newPrivateProjectDto(); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; indexIssues( @@ -159,8 +152,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_does_not_return_results_if_functional_date_is_before_from_date() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org1); + ComponentDto project = newPrivateProjectDto(); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; indexIssues(newDoc("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from - 1000L))); @@ -172,8 +164,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_returns_issue_count() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org1); + ComponentDto project = newPrivateProjectDto(); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; indexIssues( @@ -188,10 +179,9 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_returns_issue_count_for_multiple_projects() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project1 = newPrivateProjectDto(org1); - ComponentDto project2 = newPrivateProjectDto(org1); - ComponentDto project3 = newPrivateProjectDto(org1); + ComponentDto project1 = newPrivateProjectDto(); + ComponentDto project2 = newPrivateProjectDto(); + ComponentDto project3 = newPrivateProjectDto(); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; indexIssues( @@ -216,10 +206,9 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_returns_max_date_for_multiple_projects() { - OrganizationDto org1 = newOrganizationDto(); - ComponentDto project1 = newPrivateProjectDto(org1); - ComponentDto project2 = newPrivateProjectDto(org1); - ComponentDto project3 = newPrivateProjectDto(org1); + ComponentDto project1 = newPrivateProjectDto(); + ComponentDto project2 = newPrivateProjectDto(); + ComponentDto project3 = newPrivateProjectDto(); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_000L; indexIssues( @@ -244,8 +233,7 @@ public class IssueIndexProjectStatisticsTest { @Test public void searchProjectStatistics_return_branch_issues() { - OrganizationDto organization = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(organization); + ComponentDto project = newPrivateProjectDto(); ComponentDto branch = newBranchComponent(project, newBranchDto(project).setKey("branch")); String userUuid = randomAlphanumeric(40); long from = 1_111_234_567_890L; diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java index cb5e38dcd29..1d9d3c4d22d 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityHotspotsTest.java @@ -58,7 +58,6 @@ import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; import static org.sonar.api.rules.RuleType.VULNERABILITY; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; import static org.sonar.server.issue.IssueDocTesting.newDoc; public class IssueIndexSecurityHotspotsTest { @@ -80,7 +79,7 @@ public class IssueIndexSecurityHotspotsTest { @Test public void filter_by_security_hotspots_type() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -98,7 +97,7 @@ public class IssueIndexSecurityHotspotsTest { @Test public void filter_by_severities_ignore_hotspots() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -116,7 +115,7 @@ public class IssueIndexSecurityHotspotsTest { @Test public void facet_on_severities_ignore_hotspots() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityReportsTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityReportsTest.java index 8ebde33671c..82f681e1fbb 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityReportsTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSecurityReportsTest.java @@ -33,7 +33,6 @@ import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.es.EsTester; import org.sonar.server.permission.index.IndexPermissions; import org.sonar.server.permission.index.PermissionIndexerTester; @@ -52,7 +51,6 @@ import static org.assertj.core.api.Assertions.tuple; import static org.junit.rules.ExpectedException.none; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; import static org.sonar.server.issue.IssueDocTesting.newDoc; import static org.sonar.server.security.SecurityStandards.SANS_TOP_25_INSECURE_INTERACTION; import static org.sonar.server.security.SecurityStandards.SANS_TOP_25_POROUS_DEFENSES; @@ -79,9 +77,8 @@ public class IssueIndexSecurityReportsTest { @Test public void getOwaspTop10Report_dont_count_vulnerabilities_from_other_projects() { - OrganizationDto org = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org); - ComponentDto another = newPrivateProjectDto(org); + ComponentDto project = newPrivateProjectDto(); + ComponentDto another = newPrivateProjectDto(); indexIssues( newDoc("anotherProject", another).setOwaspTop10(singletonList("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.CRITICAL), newDoc("openvul1", project).setOwaspTop10(singletonList("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR)); @@ -97,8 +94,7 @@ public class IssueIndexSecurityReportsTest { @Test public void getOwaspTop10Report_dont_count_closed_vulnerabilities() { - OrganizationDto org = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org); + ComponentDto project = newPrivateProjectDto(); indexIssues( newDoc("openvul1", project).setOwaspTop10(asList("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR), newDoc("notopenvul", project).setOwaspTop10(asList("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED) @@ -114,8 +110,7 @@ public class IssueIndexSecurityReportsTest { @Test public void getOwaspTop10Report_dont_count_old_vulnerabilities() { - OrganizationDto org = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org); + ComponentDto project = newPrivateProjectDto(); indexIssues( // Previous vulnerabilities in projects that are not reanalyzed will have no owasp nor cwe attributes (not even 'unknown') newDoc("openvulNotReindexed", project).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR)); @@ -130,9 +125,8 @@ public class IssueIndexSecurityReportsTest { @Test public void getOwaspTop10Report_dont_count_hotspots_from_other_projects() { - OrganizationDto org = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org); - ComponentDto another = newPrivateProjectDto(org); + ComponentDto project = newPrivateProjectDto(); + ComponentDto another = newPrivateProjectDto(); indexIssues( newDoc("openhotspot1", project).setOwaspTop10(asList("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW), newDoc("anotherProject", another).setOwaspTop10(asList("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW)); @@ -146,8 +140,7 @@ public class IssueIndexSecurityReportsTest { @Test public void getOwaspTop10Report_dont_count_closed_hotspots() { - OrganizationDto org = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org); + ComponentDto project = newPrivateProjectDto(); indexIssues( newDoc("openhotspot1", project).setOwaspTop10(asList("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW), newDoc("closedHotspot", project).setOwaspTop10(asList("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_CLOSED) @@ -193,8 +186,7 @@ public class IssueIndexSecurityReportsTest { } private List indexIssuesAndAssertOwaspReport(boolean includeCwe) { - OrganizationDto org = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org); + ComponentDto project = newPrivateProjectDto(); indexIssues( newDoc("openvul1", project).setOwaspTop10(asList("a1", "a3")).setCwe(asList("123", "456")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN) .setSeverity(Severity.MAJOR), @@ -229,8 +221,7 @@ public class IssueIndexSecurityReportsTest { @Test public void getSansTop25Report_aggregation() { - OrganizationDto org = newOrganizationDto(); - ComponentDto project = newPrivateProjectDto(org); + ComponentDto project = newPrivateProjectDto(); indexIssues( newDoc("openvul1", project).setSansTop25(asList(SANS_TOP_25_INSECURE_INTERACTION, SANS_TOP_25_RISKY_RESOURCE)).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN) .setSeverity(Severity.MAJOR), @@ -265,8 +256,8 @@ public class IssueIndexSecurityReportsTest { @Test public void getSansTop25Report_aggregation_on_portfolio() { - ComponentDto portfolio1 = db.components().insertPrivateApplication(db.getDefaultOrganization()); - ComponentDto portfolio2 = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto portfolio1 = db.components().insertPrivateApplication(); + ComponentDto portfolio2 = db.components().insertPrivateApplication(); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java index 619b105dc54..5cb3156d119 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSortTest.java @@ -33,7 +33,6 @@ import org.sonar.api.rule.Severity; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.SearchOptions; import org.sonar.server.permission.index.IndexPermissions; @@ -47,11 +46,11 @@ import static java.util.TimeZone.getTimeZone; import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.rules.ExpectedException.none; +import static org.mockito.Mockito.mock; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.api.utils.DateUtils.parseDateTime; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; import static org.sonar.server.issue.IssueDocTesting.newDoc; public class IssueIndexSortTest { @@ -62,18 +61,18 @@ public class IssueIndexSortTest { public UserSessionRule userSessionRule = UserSessionRule.standalone(); @Rule public ExpectedException expectedException = none(); - private System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(getTimeZone("GMT-01:00")); + private final System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(getTimeZone("GMT-01:00")); @Rule public DbTester db = DbTester.create(system2); - private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null); - private PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, issueIndexer); - - private IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule)); + private final AsyncIssueIndexing asyncIssueIndexing = mock(AsyncIssueIndexing.class); + private final IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), asyncIssueIndexing); + private final PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, issueIndexer); + private final IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new WebAuthorizationTypeSupport(userSessionRule)); @Test public void sort_by_status() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -90,7 +89,7 @@ public class IssueIndexSortTest { @Test public void sort_by_severity() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -109,7 +108,7 @@ public class IssueIndexSortTest { @Test public void sort_by_creation_date() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -126,7 +125,7 @@ public class IssueIndexSortTest { @Test public void sort_by_update_date() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -143,7 +142,7 @@ public class IssueIndexSortTest { @Test public void sort_by_close_date() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); indexIssues( @@ -161,7 +160,7 @@ public class IssueIndexSortTest { @Test public void sort_by_file_and_line() { - ComponentDto project = newPrivateProjectDto(newOrganizationDto()); + ComponentDto project = newPrivateProjectDto(); ComponentDto file1 = newFileDto(project, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo"); ComponentDto file2 = newFileDto(project, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo"); @@ -188,12 +187,11 @@ public class IssueIndexSortTest { @Test public void default_sort_is_by_creation_date_then_project_then_file_then_line_then_issue_key() { - OrganizationDto organizationDto = newOrganizationDto(); - ComponentDto project1 = newPrivateProjectDto(organizationDto, "P1"); + ComponentDto project1 = newPrivateProjectDto("P1"); ComponentDto file1 = newFileDto(project1, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo"); ComponentDto file2 = newFileDto(project1, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo"); - ComponentDto project2 = newPrivateProjectDto(organizationDto, "P2"); + ComponentDto project2 = newPrivateProjectDto("P2"); ComponentDto file3 = newFileDto(project2, null, "F3").setPath("src/main/xoo/org/sonar/samples/File3.xoo"); indexIssues( diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java index f3cbe525ab4..8a69a2f5056 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexSyncProgressCheckerTest.java @@ -307,7 +307,9 @@ public class IssueIndexSyncProgressCheckerTest { private ProjectDto insertProjectWithBranches(boolean needIssueSync, int numberOfBranches) { ProjectDto projectDto = db.components() - .insertPrivateProjectDto(db.getDefaultOrganization(), branchDto -> branchDto.setNeedIssueSync(needIssueSync)); + .insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(needIssueSync), c -> { + }, p -> { + }); IntStream.range(0, numberOfBranches).forEach( i -> db.components().insertProjectBranch(projectDto, branchDto -> branchDto.setNeedIssueSync(needIssueSync))); return projectDto; diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java index 1f276419a88..fd42f293bbf 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java @@ -34,7 +34,6 @@ import org.sonar.api.rule.RuleKey; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDbTester; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.user.UserDto; @@ -75,8 +74,7 @@ public class IssueQueryFactoryTest { @Test public void create_from_parameters() { UserDto user = db.users().insertUser(u -> u.setLogin("joanna")); - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(project)); @@ -259,9 +257,9 @@ public class IssueQueryFactoryTest { @Test public void param_componentUuids_enables_search_in_view_tree_if_user_has_permission_on_view() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPublicPortfolio(); SearchRequest request = new SearchRequest() - .setComponentUuids(asList(view.uuid())); + .setComponentUuids(singletonList(view.uuid())); userSession.registerComponents(view); IssueQuery query = underTest.create(request); @@ -274,7 +272,7 @@ public class IssueQueryFactoryTest { public void application_search_project_issues() { ComponentDto project1 = db.components().insertPublicProject(); ComponentDto project2 = db.components().insertPublicProject(); - ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPublicApplication(); db.components().insertComponents(newProjectCopy("PC1", project1, application)); db.components().insertComponents(newProjectCopy("PC2", project2, application)); userSession.registerComponents(application, project1, project2); @@ -293,7 +291,7 @@ public class IssueQueryFactoryTest { ComponentDto project2 = db.components().insertPublicProject(); db.components().insertSnapshot(project2, s -> s.setPeriodDate(null)); ComponentDto project3 = db.components().insertPublicProject(); - ComponentDto application = db.components().insertPublicApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPublicApplication(); db.components().insertComponents(newProjectCopy("PC1", project1, application)); db.components().insertComponents(newProjectCopy("PC2", project2, application)); db.components().insertComponents(newProjectCopy("PC3", project3, application)); @@ -311,10 +309,10 @@ public class IssueQueryFactoryTest { @Test public void return_empty_results_if_not_allowed_to_search_for_subview() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subView = db.components().insertComponent(newSubView(view)); SearchRequest request = new SearchRequest() - .setComponentUuids(asList(subView.uuid())); + .setComponentUuids(singletonList(subView.uuid())); IssueQuery query = underTest.create(request); @@ -474,7 +472,7 @@ public class IssueQueryFactoryTest { @Test public void search_by_application_key() { - ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPrivateApplication(); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); db.components().insertComponents(newProjectCopy(project1, application)); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java index 7a4315ac9c9..1cff79dd267 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java @@ -37,8 +37,6 @@ import org.junit.runner.RunWith; import org.sonar.api.utils.System2; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; @@ -95,13 +93,12 @@ public class ProjectMeasuresIndexTest { private static final String NEW_LINES = "new_lines"; private static final String LANGUAGES = "languages"; - private static final OrganizationDto ORG = OrganizationTesting.newOrganizationDto(); - private static final ComponentDto PROJECT1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-1").setName("Project 1").setDbKey("key-1"); - private static final ComponentDto PROJECT2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-2").setName("Project 2").setDbKey("key-2"); - private static final ComponentDto PROJECT3 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-3").setName("Project 3").setDbKey("key-3"); - private static final ComponentDto APP1 = ComponentTesting.newApplication(ORG).setUuid("App-1").setName("App 1").setDbKey("app-key-1"); - private static final ComponentDto APP2 = ComponentTesting.newApplication(ORG).setUuid("App-2").setName("App 2").setDbKey("app-key-2"); - private static final ComponentDto APP3 = ComponentTesting.newApplication(ORG).setUuid("App-3").setName("App 3").setDbKey("app-key-3"); + private static final ComponentDto PROJECT1 = ComponentTesting.newPrivateProjectDto().setUuid("Project-1").setName("Project 1").setDbKey("key-1"); + private static final ComponentDto PROJECT2 = ComponentTesting.newPrivateProjectDto().setUuid("Project-2").setName("Project 2").setDbKey("key-2"); + private static final ComponentDto PROJECT3 = ComponentTesting.newPrivateProjectDto().setUuid("Project-3").setName("Project 3").setDbKey("key-3"); + private static final ComponentDto APP1 = ComponentTesting.newApplication().setUuid("App-1").setName("App 1").setDbKey("app-key-1"); + private static final ComponentDto APP2 = ComponentTesting.newApplication().setUuid("App-2").setName("App 2").setDbKey("app-key-2"); + private static final ComponentDto APP3 = ComponentTesting.newApplication().setUuid("App-3").setName("App 3").setDbKey("app-key-3"); private static final UserDto USER1 = newUserDto(); private static final UserDto USER2 = newUserDto(); private static final GroupDto GROUP1 = newGroupDto(); @@ -131,10 +128,10 @@ public class ProjectMeasuresIndexTest { @Test public void default_sort_is_by_ascending_case_insensitive_name_then_by_key() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows").setDbKey("project1"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee").setDbKey("project2"); - ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setDbKey("project3"); - ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setDbKey("project4"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setDbKey("project1"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setDbKey("project2"); + ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setDbKey("project3"); + ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setDbKey("project4"); index(newDoc(windows), newDoc(apachee), newDoc(apache1), newDoc(apache2)); assertResults(new ProjectMeasuresQuery(), apache1, apache2, apachee, windows); @@ -142,9 +139,9 @@ public class ProjectMeasuresIndexTest { @Test public void sort_by_insensitive_name() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee"); - ComponentDto apache = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache").setName("Apache"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee"); + ComponentDto apache = ComponentTesting.newPrivateProjectDto().setUuid("apache").setName("Apache"); index(newDoc(windows), newDoc(apachee), newDoc(apache)); assertResults(new ProjectMeasuresQuery().setSort("name").setAsc(true), apache, apachee, windows); @@ -164,10 +161,10 @@ public class ProjectMeasuresIndexTest { @Test public void sort_by_a_metric_then_by_name_then_by_key() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows").setDbKey("project1"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee").setDbKey("project2"); - ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setDbKey("project3"); - ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setDbKey("project4"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setDbKey("project1"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setDbKey("project2"); + ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setDbKey("project3"); + ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setDbKey("project4"); index( newDoc(windows, NCLOC, 10_000d), newDoc(apachee, NCLOC, 5_000d), @@ -180,7 +177,7 @@ public class ProjectMeasuresIndexTest { @Test public void sort_by_quality_gate_status() { - ComponentDto project4 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-4").setName("Project 4").setDbKey("key-4"); + ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setDbKey("key-4"); index( newDoc(PROJECT1).setQualityGateStatus(OK.name()), newDoc(PROJECT2).setQualityGateStatus(ERROR.name()), @@ -192,10 +189,10 @@ public class ProjectMeasuresIndexTest { @Test public void sort_by_quality_gate_status_then_by_name_then_by_key() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows").setDbKey("project1"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee").setDbKey("project2"); - ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setDbKey("project3"); - ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setDbKey("project4"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setDbKey("project1"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setDbKey("project2"); + ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setDbKey("project3"); + ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setDbKey("project4"); index( newDoc(windows).setQualityGateStatus(ERROR.name()), newDoc(apachee).setQualityGateStatus(OK.name()), @@ -209,7 +206,7 @@ public class ProjectMeasuresIndexTest { @Test public void paginate_results() { IntStream.rangeClosed(1, 9) - .forEach(i -> index(newDoc(newPrivateProjectDto(ORG, "P" + i)))); + .forEach(i -> index(newDoc(newPrivateProjectDto("P" + i)))); SearchIdResult result = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().setPage(2, 3)); @@ -298,7 +295,7 @@ public class ProjectMeasuresIndexTest { @Test public void filter_on_no_data_should_not_return_projects_with_data_and_other_measures() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(ORG); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); index(newDoc(project, DUPLICATION, 80d, NCLOC, 1d)); ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(MetricCriterion.createNoData(DUPLICATION)); @@ -308,7 +305,7 @@ public class ProjectMeasuresIndexTest { @Test public void filter_on_no_data_should_not_return_projects_with_data() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(ORG); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); index(newDoc(project, DUPLICATION, 80d)); ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(MetricCriterion.createNoData(DUPLICATION)); @@ -318,7 +315,7 @@ public class ProjectMeasuresIndexTest { @Test public void filter_on_no_data_should_return_projects_with_no_data() { - ComponentDto project = ComponentTesting.newPrivateProjectDto(ORG); + ComponentDto project = ComponentTesting.newPrivateProjectDto(); index(newDoc(project, NCLOC, 1d)); ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(MetricCriterion.createNoData(DUPLICATION)); @@ -427,7 +424,7 @@ public class ProjectMeasuresIndexTest { @Test public void filter_on_languages() { - ComponentDto project4 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("Project-4").setName("Project 4").setDbKey("key-4"); + ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setDbKey("key-4"); index( newDoc(PROJECT1).setLanguages(singletonList("java")), newDoc(PROJECT2).setLanguages(singletonList("xoo")), @@ -441,10 +438,10 @@ public class ProjectMeasuresIndexTest { @Test public void filter_on_query_text() { - ComponentDto windows = ComponentTesting.newPrivateProjectDto(ORG).setUuid("windows").setName("Windows").setDbKey("project1"); - ComponentDto apachee = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apachee").setName("apachee").setDbKey("project2"); - ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setDbKey("project3"); - ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setDbKey("project4"); + ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setDbKey("project1"); + ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setDbKey("project2"); + ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setDbKey("project3"); + ComponentDto apache2 = ComponentTesting.newPrivateProjectDto().setUuid("apache-2").setName("Apache").setDbKey("project4"); index(newDoc(windows), newDoc(apachee), newDoc(apache1), newDoc(apache2)); assertResults(new ProjectMeasuresQuery().setQueryText("windows"), windows); @@ -477,24 +474,6 @@ public class ProjectMeasuresIndexTest { assertNoResults(new ProjectMeasuresQuery().setTags(newHashSet("tag 42"))); } - @Test - public void filter_on_organization() { - OrganizationDto org1 = OrganizationTesting.newOrganizationDto(); - OrganizationDto org2 = OrganizationTesting.newOrganizationDto(); - ComponentDto projectInOrg1 = ComponentTesting.newPrivateProjectDto(org1); - ComponentDto projectInOrg2 = ComponentTesting.newPrivateProjectDto(org2); - index(newDoc(projectInOrg1), newDoc(projectInOrg2)); - - ProjectMeasuresQuery query1 = new ProjectMeasuresQuery().setOrganizationUuid(org1.getUuid()); - assertResults(query1, projectInOrg1); - - ProjectMeasuresQuery query2 = new ProjectMeasuresQuery().setOrganizationUuid(org2.getUuid()); - assertResults(query2, projectInOrg2); - - ProjectMeasuresQuery query3 = new ProjectMeasuresQuery().setOrganizationUuid("another_org"); - assertNoResults(query3); - } - @Test public void filter_on_qualifier() { index(newDoc(PROJECT1), newDoc(PROJECT2), newDoc(PROJECT3), @@ -516,7 +495,7 @@ public class ProjectMeasuresIndexTest { @Test public void return_correct_number_of_total_if_exceeds_index_max_results() { index(IntStream.range(0, 12_000) - .mapToObj(operand -> newDoc(ComponentTesting.newPrivateProjectDto(ORG))) + .mapToObj(operand -> newDoc(ComponentTesting.newPrivateProjectDto())) .toArray(ProjectMeasuresDoc[]::new)); ProjectMeasuresQuery query = new ProjectMeasuresQuery(); @@ -1627,18 +1606,18 @@ public class ProjectMeasuresIndexTest { public void search_statistics_should_ignore_applications() { es.putDocuments(TYPE_PROJECT_MEASURES, // insert projects - newDoc(ComponentTesting.newPrivateProjectDto(ORG), "lines", 10, "coverage", 80) + newDoc(ComponentTesting.newPrivateProjectDto(), "lines", 10, "coverage", 80) .setLanguages(Arrays.asList("java", "cs", "js")) .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 200, "cs", 250, "js", 50)), - newDoc(ComponentTesting.newPrivateProjectDto(ORG), "lines", 20, "coverage", 80) + newDoc(ComponentTesting.newPrivateProjectDto(), "lines", 20, "coverage", 80) .setLanguages(Arrays.asList("java", "python", "kotlin")) .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)), // insert applications - newDoc(ComponentTesting.newApplication(ORG), "lines", 1000, "coverage", 70) + newDoc(ComponentTesting.newApplication(), "lines", 1000, "coverage", 70) .setLanguages(Arrays.asList("java", "python", "kotlin")) .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)), - newDoc(ComponentTesting.newApplication(ORG), "lines", 20, "coverage", 80) + newDoc(ComponentTesting.newApplication(), "lines", 20, "coverage", 80) .setLanguages(Arrays.asList("java", "python", "kotlin")) .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404))); @@ -1655,10 +1634,10 @@ public class ProjectMeasuresIndexTest { public void search_statistics_should_count_0_if_no_projects() { es.putDocuments(TYPE_PROJECT_MEASURES, // insert applications - newDoc(ComponentTesting.newApplication(ORG), "lines", 1000, "coverage", 70) + newDoc(ComponentTesting.newApplication(), "lines", 1000, "coverage", 70) .setLanguages(Arrays.asList("java", "python", "kotlin")) .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)), - newDoc(ComponentTesting.newApplication(ORG), "lines", 20, "coverage", 80) + newDoc(ComponentTesting.newApplication(), "lines", 20, "coverage", 80) .setLanguages(Arrays.asList("java", "python", "kotlin")) .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404))); @@ -1701,7 +1680,7 @@ public class ProjectMeasuresIndexTest { } private static ProjectMeasuresDoc newDoc() { - return newDoc(ComponentTesting.newPrivateProjectDto(ORG)); + return newDoc(ComponentTesting.newPrivateProjectDto()); } private static ProjectMeasuresDoc newDoc(ComponentDto project, String metric1, Object value1) { @@ -1721,19 +1700,19 @@ public class ProjectMeasuresIndexTest { } private static ProjectMeasuresDoc newDocWithNoMeasure() { - return newDoc(ComponentTesting.newPrivateProjectDto(ORG)); + return newDoc(ComponentTesting.newPrivateProjectDto()); } private static ProjectMeasuresDoc newDoc(String metric1, Object value1) { - return newDoc(ComponentTesting.newPrivateProjectDto(ORG), metric1, value1); + return newDoc(ComponentTesting.newPrivateProjectDto(), metric1, value1); } private static ProjectMeasuresDoc newDoc(String metric1, Object value1, String metric2, Object value2) { - return newDoc(ComponentTesting.newPrivateProjectDto(ORG), metric1, value1, metric2, value2); + return newDoc(ComponentTesting.newPrivateProjectDto(), metric1, value1, metric2, value2); } private static ProjectMeasuresDoc newDoc(String metric1, Object value1, String metric2, Object value2, String metric3, Object value3) { - return newDoc(ComponentTesting.newPrivateProjectDto(ORG), metric1, value1, metric2, value2, metric3, value3); + return newDoc(ComponentTesting.newPrivateProjectDto(), metric1, value1, metric2, value2, metric3, value3); } private void assertResults(ProjectMeasuresQuery query, ComponentDto... expectedProjects) { diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java index 37b4b87ebb1..3b95bd0c718 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTextSearchTest.java @@ -27,8 +27,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.utils.System2; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.server.es.EsTester; import org.sonar.server.es.Facets; import org.sonar.server.es.SearchOptions; @@ -54,8 +52,6 @@ public class ProjectMeasuresIndexTextSearchTest { private static final String NCLOC = "ncloc"; - private static final OrganizationDto ORG = OrganizationTesting.newOrganizationDto(); - @Rule public EsTester es = EsTester.create(); @Rule @@ -70,8 +66,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_exact_case_insensitive_name() { index( - newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("Apache Struts")), - newDoc(newPrivateProjectDto(ORG).setUuid("sonarqube").setName("SonarQube"))); + newDoc(newPrivateProjectDto().setUuid("struts").setName("Apache Struts")), + newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube"))); assertTextQueryResults("Apache Struts", "struts"); assertTextQueryResults("APACHE STRUTS", "struts"); @@ -80,7 +76,7 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_from_sub_name() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("Apache Struts"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("Apache Struts"))); assertTextQueryResults("truts", "struts"); assertTextQueryResults("pache", "struts"); @@ -90,70 +86,70 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_name_with_dot() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("Apache.Struts"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("Apache.Struts"))); assertTextQueryResults("apache struts", "struts"); } @Test public void match_partial_name() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("XstrutsxXjavax"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("XstrutsxXjavax"))); assertTextQueryResults("struts java", "struts"); } @Test public void match_partial_name_prefix_word1() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("MyStruts.java"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("MyStruts.java"))); assertTextQueryResults("struts java", "struts"); } @Test public void match_partial_name_suffix_word1() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("StrutsObject.java"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("StrutsObject.java"))); assertTextQueryResults("struts java", "struts"); } @Test public void match_partial_name_prefix_word2() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("MyStruts.xjava"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("MyStruts.xjava"))); assertTextQueryResults("struts java", "struts"); } @Test public void match_partial_name_suffix_word2() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("MyStrutsObject.xjavax"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("MyStrutsObject.xjavax"))); assertTextQueryResults("struts java", "struts"); } @Test public void match_subset_of_document_terms() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("Some.Struts.Project.java.old"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("Some.Struts.Project.java.old"))); assertTextQueryResults("struts java", "struts"); } @Test public void match_partial_match_prefix_and_suffix_everywhere() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("MyStruts.javax"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("MyStruts.javax"))); assertTextQueryResults("struts java", "struts"); } @Test public void ignore_empty_words() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("Struts"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("Struts"))); assertTextQueryResults(" struts \n \n\n", "struts"); } @Test public void match_name_from_prefix() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("Apache Struts"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("Apache Struts"))); assertTextQueryResults("apach", "struts"); assertTextQueryResults("ApA", "struts"); @@ -162,7 +158,7 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_name_from_two_words() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("project").setName("ApacheStrutsFoundation"))); + index(newDoc(newPrivateProjectDto().setUuid("project").setName("ApacheStrutsFoundation"))); assertTextQueryResults("apache struts", "project"); assertTextQueryResults("struts apache", "project"); @@ -174,15 +170,15 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_long_name() { index( - newDoc(newPrivateProjectDto(ORG).setUuid("project1").setName("LongNameLongNameLongNameLongNameSonarQube")), - newDoc(newPrivateProjectDto(ORG).setUuid("project2").setName("LongNameLongNameLongNameLongNameSonarQubeX"))); + newDoc(newPrivateProjectDto().setUuid("project1").setName("LongNameLongNameLongNameLongNameSonarQube")), + newDoc(newPrivateProjectDto().setUuid("project2").setName("LongNameLongNameLongNameLongNameSonarQubeX"))); assertTextQueryResults("LongNameLongNameLongNameLongNameSonarQube", "project1", "project2"); } @Test public void match_name_with_two_characters() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("struts").setName("Apache Struts"))); + index(newDoc(newPrivateProjectDto().setUuid("struts").setName("Apache Struts"))); assertTextQueryResults("st", "struts"); assertTextQueryResults("tr", "struts"); @@ -191,8 +187,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_exact_case_insensitive_key() { index( - newDoc(newPrivateProjectDto(ORG).setUuid("project1").setName("Windows").setDbKey("project1")), - newDoc(newPrivateProjectDto(ORG).setUuid("project2").setName("apachee").setDbKey("project2"))); + newDoc(newPrivateProjectDto().setUuid("project1").setName("Windows").setDbKey("project1")), + newDoc(newPrivateProjectDto().setUuid("project2").setName("apachee").setDbKey("project2"))); assertTextQueryResults("project1", "project1"); assertTextQueryResults("PROJECT1", "project1"); @@ -202,8 +198,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_key_with_dot() { index( - newDoc(newPrivateProjectDto(ORG).setUuid("sonarqube").setName("SonarQube").setDbKey("org.sonarqube")), - newDoc(newPrivateProjectDto(ORG).setUuid("sq").setName("SQ").setDbKey("sonarqube"))); + newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org.sonarqube")), + newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setDbKey("sonarqube"))); assertTextQueryResults("org.sonarqube", "sonarqube"); assertNoResults("orgsonarqube"); @@ -215,8 +211,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_key_with_dash() { index( - newDoc(newPrivateProjectDto(ORG).setUuid("sonarqube").setName("SonarQube").setDbKey("org-sonarqube")), - newDoc(newPrivateProjectDto(ORG).setUuid("sq").setName("SQ").setDbKey("sonarqube"))); + newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org-sonarqube")), + newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setDbKey("sonarqube"))); assertTextQueryResults("org-sonarqube", "sonarqube"); assertNoResults("orgsonarqube"); @@ -228,8 +224,8 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_key_with_colon() { index( - newDoc(newPrivateProjectDto(ORG).setUuid("sonarqube").setName("SonarQube").setDbKey("org:sonarqube")), - newDoc(newPrivateProjectDto(ORG).setUuid("sq").setName("SQ").setDbKey("sonarqube"))); + newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org:sonarqube")), + newDoc(newPrivateProjectDto().setUuid("sq").setName("SQ").setDbKey("sonarqube"))); assertTextQueryResults("org:sonarqube", "sonarqube"); assertNoResults("orgsonarqube"); @@ -240,14 +236,14 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void match_key_having_all_special_characters() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("sonarqube").setName("SonarQube").setDbKey("org.sonarqube:sonar-sérvèr_ç"))); + index(newDoc(newPrivateProjectDto().setUuid("sonarqube").setName("SonarQube").setDbKey("org.sonarqube:sonar-sérvèr_ç"))); assertTextQueryResults("org.sonarqube:sonar-sérvèr_ç", "sonarqube"); } @Test public void does_not_match_partial_key() { - index(newDoc(newPrivateProjectDto(ORG).setUuid("project").setName("some name").setDbKey("theKey"))); + index(newDoc(newPrivateProjectDto().setUuid("project").setName("some name").setDbKey("theKey"))); assertNoResults("theke"); assertNoResults("hekey"); @@ -257,12 +253,12 @@ public class ProjectMeasuresIndexTextSearchTest { public void facets_take_into_account_text_search() { index( // docs with ncloc<1K - newDoc(newPrivateProjectDto(ORG).setName("Windows").setDbKey("project1"), NCLOC, 0d), - newDoc(newPrivateProjectDto(ORG).setName("apachee").setDbKey("project2"), NCLOC, 999d), + newDoc(newPrivateProjectDto().setName("Windows").setDbKey("project1"), NCLOC, 0d), + newDoc(newPrivateProjectDto().setName("apachee").setDbKey("project2"), NCLOC, 999d), // docs with ncloc>=1K and ncloc<10K - newDoc(newPrivateProjectDto(ORG).setName("Apache").setDbKey("project3"), NCLOC, 1_000d), + newDoc(newPrivateProjectDto().setName("Apache").setDbKey("project3"), NCLOC, 1_000d), // docs with ncloc>=100K and ncloc<500K - newDoc(newPrivateProjectDto(ORG).setName("Apache Foundation").setDbKey("project4"), NCLOC, 100_000d)); + newDoc(newPrivateProjectDto().setName("Apache Foundation").setDbKey("project4"), NCLOC, 100_000d)); assertNclocFacet(new ProjectMeasuresQuery().setQueryText("apache"), 1L, 1L, 0L, 1L, 0L); assertNclocFacet(new ProjectMeasuresQuery().setQueryText("PAch"), 1L, 1L, 0L, 1L, 0L); @@ -274,10 +270,10 @@ public class ProjectMeasuresIndexTextSearchTest { @Test public void filter_by_metric_take_into_account_text_search() { index( - newDoc(newPrivateProjectDto(ORG).setUuid("project1").setName("Windows").setDbKey("project1"), NCLOC, 30_000d), - newDoc(newPrivateProjectDto(ORG).setUuid("project2").setName("apachee").setDbKey("project2"), NCLOC, 40_000d), - newDoc(newPrivateProjectDto(ORG).setUuid("project3").setName("Apache").setDbKey("project3"), NCLOC, 50_000d), - newDoc(newPrivateProjectDto(ORG).setUuid("project4").setName("Apache").setDbKey("project4"), NCLOC, 60_000d)); + newDoc(newPrivateProjectDto().setUuid("project1").setName("Windows").setDbKey("project1"), NCLOC, 30_000d), + newDoc(newPrivateProjectDto().setUuid("project2").setName("apachee").setDbKey("project2"), NCLOC, 40_000d), + newDoc(newPrivateProjectDto().setUuid("project3").setName("Apache").setDbKey("project3"), NCLOC, 50_000d), + newDoc(newPrivateProjectDto().setUuid("project4").setName("Apache").setDbKey("project4"), NCLOC, 60_000d)); assertResults(new ProjectMeasuresQuery().setQueryText("apache").addMetricCriterion(MetricCriterion.create(NCLOC, GT, 20_000d)), "project3", "project4", "project2"); assertResults(new ProjectMeasuresQuery().setQueryText("apache").addMetricCriterion(MetricCriterion.create(NCLOC, LT, 55_000d)), "project3", "project2"); diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java index 639c52d07b9..2bac560ac5f 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java @@ -36,8 +36,6 @@ 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.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.permission.GroupPermissionDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDbTester; @@ -57,13 +55,11 @@ public class PermissionIndexerDaoTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - private DbClient dbClient = dbTester.getDbClient(); - private DbSession dbSession = dbTester.getSession(); + private final DbClient dbClient = dbTester.getDbClient(); + private final DbSession dbSession = dbTester.getSession(); + private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); + private final UserDbTester userDbTester = new UserDbTester(dbTester); - private ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); - private UserDbTester userDbTester = new UserDbTester(dbTester); - - private OrganizationDto organization; private ComponentDto publicProject; private ComponentDto privateProject1; private ComponentDto privateProject2; @@ -74,17 +70,16 @@ public class PermissionIndexerDaoTest { private UserDto user2; private GroupDto group; - private PermissionIndexerDao underTest = new PermissionIndexerDao(); + private final PermissionIndexerDao underTest = new PermissionIndexerDao(); @Before public void setUp() { - organization = dbTester.organizations().insert(); - publicProject = componentDbTester.insertPublicProject(organization); - privateProject1 = componentDbTester.insertPrivateProject(organization); - privateProject2 = componentDbTester.insertPrivateProject(organization); - view1 = componentDbTester.insertView(organization); - view2 = componentDbTester.insertView(organization); - application = componentDbTester.insertPublicApplication(organization); + publicProject = componentDbTester.insertPublicProject(); + privateProject1 = componentDbTester.insertPrivateProject(); + privateProject2 = componentDbTester.insertPrivateProject(); + view1 = componentDbTester.insertPublicPortfolio(); + view2 = componentDbTester.insertPublicPortfolio(); + application = componentDbTester.insertPublicApplication(); user1 = userDbTester.insertUser(); user2 = userDbTester.insertUser(); group = userDbTester.insertGroup(); @@ -161,7 +156,7 @@ public class PermissionIndexerDaoTest { public void selectByUuids_returns_empty_list_when_project_does_not_exist() { insertTestDataForProjectsAndViews(); - List dtos = underTest.selectByUuids(dbClient, dbSession, asList("missing")); + List dtos = underTest.selectByUuids(dbClient, dbSession, singletonList("missing")); Assertions.assertThat(dtos).isEmpty(); } @@ -169,8 +164,7 @@ public class PermissionIndexerDaoTest { public void select_by_projects_with_high_number_of_projects() { List projectUuids = new ArrayList<>(); for (int i = 0; i < 350; i++) { - ComponentDto project = ComponentTesting.newPrivateProjectDto(organization, Integer.toString(i)); - dbClient.componentDao().insert(dbSession, project); + ComponentDto project = dbTester.components().insertPrivateProject(Integer.toString(i)); projectUuids.add(project.uuid()); GroupPermissionDto dto = new GroupPermissionDto() .setUuid(Uuids.createFast()) diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java index c2e3289101f..e1b0ffed173 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java @@ -28,7 +28,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.es.EsQueueDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; @@ -237,17 +236,14 @@ public class PermissionIndexerTest { } @Test - public void public_projects_are_visible_to_anybody_whatever_the_organization() { - ComponentDto projectOnOrg1 = createAndIndexPublicProject(db.organizations().insert()); - ComponentDto projectOnOrg2 = createAndIndexPublicProject(db.organizations().insert()); + public void public_projects_are_visible_to_anybody() { + ComponentDto projectOnOrg1 = createAndIndexPublicProject(); UserDto user = db.users().insertUser(); indexOnStartup(); verifyAnyoneAuthorized(projectOnOrg1); - verifyAnyoneAuthorized(projectOnOrg2); verifyAuthorized(projectOnOrg1, user); - verifyAuthorized(projectOnOrg2, user); } @Test @@ -420,17 +416,11 @@ public class PermissionIndexerTest { } private ComponentDto createAndIndexView() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPublicPortfolio(); fooIndexer.indexOnAnalysis(view.uuid()); return view; } - private ComponentDto createAndIndexPublicProject(OrganizationDto org) { - ComponentDto project = db.components().insertPublicProject(org); - fooIndexer.indexOnAnalysis(project.uuid()); - return project; - } - private IndexingResult recover() { Collection items = db.getDbClient().esQueueDao().selectForRecovery(db.getSession(), System.currentTimeMillis() + 1_000L, 10); return underTest.index(db.getSession(), items); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java index d10f564f694..da14a96ca72 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java @@ -40,7 +40,6 @@ import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.UserDto; import org.sonar.server.badge.ws.SvgGenerator.Color; import org.sonar.server.component.ComponentFinder; @@ -245,8 +244,7 @@ public class MeasureActionTest { @Test public void measure_on_application() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto application = db.components().insertPublicApplication(organization); + ComponentDto application = db.components().insertPublicApplication(); userSession.registerComponents(application); MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name())); db.measures().insertLiveMeasure(application, metric, m -> m.setValue(10_000d)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java index b70c9b67745..09b8f23f925 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java @@ -36,7 +36,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.measure.LiveMeasureDto; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.tester.UserSessionRule; @@ -61,7 +60,7 @@ public class QualityGateActionTest { @Rule public DbTester db = DbTester.create(); - private MapSettings mapSettings = new MapSettings().setProperty("sonar.sonarcloud.enabled", false); + private final MapSettings mapSettings = new MapSettings().setProperty("sonar.sonarcloud.enabled", false); private WsActionTester ws = new WsActionTester( new QualityGateAction(db.getDbClient(), @@ -163,8 +162,7 @@ public class QualityGateActionTest { @Test public void quality_gate_on_application() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto application = db.components().insertPublicApplication(organization); + ComponentDto application = db.components().insertPublicApplication(); userSession.registerComponents(application); MetricDto metric = createQualityGateMetric(); db.measures().insertLiveMeasure(application, metric, m -> m.setData(ERROR.name())); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java index c435c7daac8..61675d4d5f0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java @@ -31,7 +31,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ResourceTypesRule; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.source.FileSourceDto; import org.sonar.scanner.protocol.input.FileData; import org.sonar.scanner.protocol.input.MultiModuleProjectRepository; @@ -69,8 +68,7 @@ public class ProjectDataLoaderTest { @Test public void throws_NotFoundException_when_branch_does_not_exist() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); expectedException.expect(NotFoundException.class); @@ -83,8 +81,7 @@ public class ProjectDataLoaderTest { @Test public void return_file_data_from_single_project() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); ComponentDto file = db.components().insertComponent(newFileDto(project)); dbClient.fileSourceDao().insert(dbSession, newFileSourceDto(file).setSrcHash("123456")); @@ -102,8 +99,7 @@ public class ProjectDataLoaderTest { @Test public void return_file_data_from_multi_modules() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); ComponentDto module = db.components().insertComponent(newModuleDto(project)); // File on project @@ -124,8 +120,7 @@ public class ProjectDataLoaderTest { @Test public void return_file_data_from_branch() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); ComponentDto moduleBranch = db.components().insertComponent(newModuleDto(branch)); @@ -180,14 +175,13 @@ public class ProjectDataLoaderTest { {Scopes.DIRECTORY, null} }; - OrganizationDto organizationDto = db.organizations().insert(); for (String[] scopeAndQualifier : allScopesAndQualifierButProjectAndModule) { String scope = scopeAndQualifier[0]; String moduleUuid = scopeAndQualifier[1]; String key = "theKey_" + scope + "_" + moduleUuid; String uuid = "uuid_" + uuidCounter++; dbClient.componentDao().insert(dbSession, new ComponentDto() - .setOrganizationUuid(organizationDto.getUuid()) + .setOrganizationUuid(db.getDefaultOrganization().getUuid()) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/pr/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/pr/ws/ListActionTest.java index 66d889ba396..fbe8472f193 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/pr/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/pr/ws/ListActionTest.java @@ -35,7 +35,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.ResourceTypesRule; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.protobuf.DbProjectBranches; import org.sonar.db.rule.RuleDefinitionDto; @@ -385,10 +384,9 @@ public class ListActionTest { } @Test - public void does_not_fail_when_only_scan_permission_on_organization() { - OrganizationDto organization = db.organizations().insert(); + public void does_not_fail_when_only_scan_permission() { userSession.logIn().addPermission(GlobalPermission.SCAN); - ComponentDto project = db.components().insertPublicProject(organization); + ComponentDto project = db.components().insertPublicProject(); db.components().insertProjectBranch(project, b -> b.setKey("123") .setBranchType(PULL_REQUEST) @@ -406,8 +404,7 @@ public class ListActionTest { @Test public void fail_when_using_branch_db_key() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); userSession.logIn().addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java index b630da11b5b..2fb5082b318 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java @@ -31,11 +31,11 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.ResourceTypesRule; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.NotFoundException; +import org.sonar.server.issue.index.AsyncIssueIndexing; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.issue.index.IssueIteratorFactory; import org.sonar.server.permission.index.PermissionIndexerTester; @@ -49,6 +49,7 @@ import org.sonarqube.ws.ProjectBranches.ListWsResponse; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; +import static org.mockito.Mockito.mock; import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY; import static org.sonar.api.resources.Qualifiers.PROJECT; import static org.sonar.api.rules.RuleType.BUG; @@ -71,9 +72,10 @@ public class ListActionTest { @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - private ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(PROJECT); - private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null); - private PermissionIndexerTester permissionIndexerTester = new PermissionIndexerTester(es, issueIndexer); + private final AsyncIssueIndexing asyncIssueIndexing = mock(AsyncIssueIndexing.class); + private final ResourceTypes resourceTypes = new ResourceTypesRule().setRootQualifiers(PROJECT); + private final IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), asyncIssueIndexing); + private final PermissionIndexerTester permissionIndexerTester = new PermissionIndexerTester(es, issueIndexer); private MetricDto qualityGateStatus; @@ -166,8 +168,7 @@ public class ListActionTest { @Test public void main_branch_with_specified_name() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); db.getDbClient().branchDao().updateMainBranchName(db.getSession(), project.uuid(), "head"); db.commit(); userSession.logIn().addProjectPermission(USER, project); @@ -247,7 +248,7 @@ public class ListActionTest { @Test public void application_branches() { - ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPrivateApplication(); db.components().insertProjectBranch(application, b -> b.setKey("feature/bar")); db.components().insertProjectBranch(application, b -> b.setKey("feature/foo")); userSession.logIn().addProjectPermission(USER, application); @@ -265,9 +266,8 @@ public class ListActionTest { } @Test - public void fail_when_using_branch_db_key() throws Exception { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + public void fail_when_using_branch_db_key() { + ComponentDto project = db.components().insertPrivateProject(); userSession.logIn().addProjectPermission(USER, project); ComponentDto branch = db.components().insertProjectBranch(project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java index d7d0c08160a..089fae78118 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java @@ -89,9 +89,9 @@ public class ActivityActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private TaskFormatter formatter = new TaskFormatter(db.getDbClient(), System2.INSTANCE); - private ActivityAction underTest = new ActivityAction(userSession, db.getDbClient(), formatter, new CeTaskProcessor[] {mock(CeTaskProcessor.class)}); - private WsActionTester ws = new WsActionTester(underTest); + private final TaskFormatter formatter = new TaskFormatter(db.getDbClient(), System2.INSTANCE); + private final ActivityAction underTest = new ActivityAction(userSession, db.getDbClient(), formatter, new CeTaskProcessor[] {mock(CeTaskProcessor.class)}); + private final WsActionTester ws = new WsActionTester(underTest); @Test public void get_all_past_activity() { @@ -309,7 +309,7 @@ public class ActivityActionTest { @Test public void search_activity_returns_views() { - ComponentDto apacheView = db.components().insertView(v -> v.setName("Apache View")); + ComponentDto apacheView = db.components().insertPrivatePortfolio(v -> v.setName("Apache View")); db.components().insertSnapshot(apacheView); logInAsSystemAdministrator(); insertActivity("T2", apacheView, SUCCESS); @@ -321,7 +321,7 @@ public class ActivityActionTest { @Test public void search_activity_returns_application() { - ComponentDto apacheApp = db.components().insertPublicApplication(db.getDefaultOrganization(), a -> a.setName("Apache App")); + ComponentDto apacheApp = db.components().insertPublicApplication(a -> a.setName("Apache App")); db.components().insertSnapshot(apacheApp); logInAsSystemAdministrator(); insertActivity("T2", apacheApp, SUCCESS); @@ -363,7 +363,7 @@ public class ActivityActionTest { // WS api/ce/task must be used in order to search by task id. // Here it's a convenient feature of search by text query, which // is reserved to roots - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); insertActivity("T1", view, SUCCESS); userSession.logIn().addProjectPermission(UserRole.ADMIN, view); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java index bdbdaa351ee..dc990b1ad69 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java @@ -224,9 +224,9 @@ public class ShowActionTest { } @Test - public void should_return_visibility_for_view() { + public void should_return_visibility_for_portfolio() { userSession.logIn().setRoot(); - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ShowWsResponse result = newRequest(view.getDbKey()); assertThat(result.getComponent().hasVisibility()).isTrue(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java index a60e4808dee..367c89df05f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java @@ -553,7 +553,7 @@ public class SuggestionsActionTest { String query = randomAlphabetic(10); ComponentDto app = db.components().insertPublicApplication(v -> v.setName(query)); - ComponentDto view = db.components().insertView(v -> v.setName(query)); + ComponentDto view = db.components().insertPublicPortfolio(v -> v.setName(query)); ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubView(view).setName(query)); ComponentDto project = db.components().insertPrivateProject(p -> p.setName(query)); ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java index e590d713419..2bde112ba1a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java @@ -32,7 +32,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -241,8 +240,7 @@ public class ShowActionTest { @Test public void fail_when_using_branch_db_key() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); ComponentDto branch = db.components().insertProjectBranch(project); @@ -256,8 +254,7 @@ public class ShowActionTest { @Test public void fail_when_using_branch_uuid() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); ComponentDto branch = db.components().insertProjectBranch(project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index fa0d97ee2f3..c70daeafce5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -228,7 +228,7 @@ public class ComponentActionTest { public void reference_uuid_in_the_response() { userSession.logIn().setRoot(); ComponentDto project = db.components().insertPrivateProject(); - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view); ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-uuid-copy", project, view)); MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java index 0cb3acca313..ae0266df337 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/PermissionTemplateServiceTest.java @@ -322,7 +322,7 @@ public class PermissionTemplateServiceTest { @Test public void apply_project_default_template_on_view_when_no_view_default_template() { - ComponentDto view = dbTester.components().insertView(); + ComponentDto view = dbTester.components().insertPrivatePortfolio(); PermissionTemplateDto projectPermissionTemplate = dbTester.permissionTemplates().insertTemplate(); GroupDto group = dbTester.users().insertGroup(); dbTester.permissionTemplates().addGroupToTemplate(projectPermissionTemplate, group, PROVISION_PROJECTS.getKey()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index 4a27f57f9c9..5146f3d4094 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -134,7 +134,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest @Test public void remove_with_view_uuid() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, view); db.users().insertProjectPermissionOnUser(user, ADMIN, view); loginAsAdmin(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java index fd7cc360d51..f44d0fd427e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java @@ -189,7 +189,7 @@ public class BulkDeleteActionTest { public void projects_and_views() { userSession.logIn().addPermission(ADMINISTER); ComponentDto project = db.components().insertPrivateProject(); - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ws.newRequest() .setParam(PARAM_PROJECTS, project.getKey() + "," + view.getKey()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java index 0a9b0f2c719..b1a0d03909b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java @@ -188,7 +188,7 @@ public class UpdateVisibilityActionTest { ComponentDto file = ComponentTesting.newFileDto(project); dbTester.components().insertComponents(module, dir, file); ComponentDto application = dbTester.components().insertPublicApplication(); - ComponentDto portfolio = dbTester.components().insertView(); + ComponentDto portfolio = dbTester.components().insertPrivatePortfolio(); ComponentDto subView = ComponentTesting.newSubView(portfolio); ComponentDto projectCopy = newProjectCopy("foo", project, subView); dbTester.components().insertComponents(subView, projectCopy); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java index c54b1019750..7588bc06632 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java @@ -103,10 +103,9 @@ public class SearchActionTest { @Rule public LogTester logTester = new LogTester(); - private DbClient dbClient = db.getDbClient(); - - private WsActionTester ws = new WsActionTester(new SearchAction(dbClient, TestComponentFinder.from(db), userSession)); - private UuidFactoryFast uuidFactoryFast = UuidFactoryFast.getInstance(); + private final DbClient dbClient = db.getDbClient(); + private final WsActionTester ws = new WsActionTester(new SearchAction(dbClient, TestComponentFinder.from(db), userSession)); + private final UuidFactoryFast uuidFactoryFast = UuidFactoryFast.getInstance(); @DataProvider public static Object[][] changedBranches() { @@ -413,7 +412,7 @@ public class SearchActionTest { @Test public void return_analyses_of_portfolio() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPublicPortfolio(); userSession.registerComponents(view); SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(1_000_000L)); SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(2_000_000L)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java index 280866642f6..80cad7e16ec 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java @@ -215,7 +215,7 @@ public class CreateActionTest { @Test public void fail_if_view() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); failIfNotAProjectWithKey(view, view); failIfNotAProjectWithUuid(view, view); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java index c761361334a..42863ec3bb1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java @@ -200,7 +200,7 @@ public class SearchActionTest { @Test public void fail_if_view() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); failIfNotAProjectWithKey(view, view); failIfNotAProjectWithUuid(view, view); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java index 152311b5ff7..5b717018d66 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java @@ -30,7 +30,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.es.TestProjectIndexers; @@ -150,7 +149,7 @@ public class SetActionTest { @Test public void fail_if_component_is_a_view() { - ComponentDto view = db.components().insertView(v -> v.setDbKey("VIEW_KEY")); + ComponentDto view = db.components().insertPrivatePortfolio(v -> v.setDbKey("VIEW_KEY")); String viewKey = view.getKey(); assertThatThrownBy(() -> call(viewKey, "point-of-view")) @@ -182,8 +181,7 @@ public class SetActionTest { @Test public void fail_when_using_branch_db_key() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); userSession.logIn().addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java index 4f6d7f5a9c0..5d7fccd5f12 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java @@ -90,7 +90,7 @@ public class ListDefinitionsActionTest { @Before public void setUp() { - project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert())); + project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto()); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java index 6609556ffe7..523fd419e80 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java @@ -37,7 +37,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.property.PropertyDbTester; import org.sonar.db.property.PropertyQuery; import org.sonar.db.user.UserDto; @@ -89,8 +88,8 @@ public class ResetActionTest { private WsActionTester ws = new WsActionTester(underTest); @Before - public void setUp() throws Exception { - project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert())); + public void setUp() { + project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto()); } @Test @@ -343,29 +342,28 @@ public class ResetActionTest { @Test public void succeed_for_property_without_definition_when_set_on_view_component() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPublicPortfolio(); succeedForPropertyWithoutDefinitionAndValidComponent(view, view); } @Test public void succeed_for_property_without_definition_when_set_on_subview_component() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPublicPortfolio(); ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view)); succeedForPropertyWithoutDefinitionAndValidComponent(view, subview); } @Test public void fail_for_property_without_definition_when_set_on_projectCopy_component() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPublicPortfolio(); ComponentDto projectCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", db.components().insertPrivateProject(), view)); failForPropertyWithoutDefinitionOnUnsupportedComponent(view, projectCopy); } @Test - public void fail_when_using_branch_db_key() throws Exception { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPublicProject(organization); + public void fail_when_using_branch_db_key() { + ComponentDto project = db.components().insertPublicProject(); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); ComponentDto branch = db.components().insertProjectBranch(project); definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java index 41000bffc1a..a7e0a66d865 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java @@ -43,7 +43,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.property.PropertyDbTester; import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; @@ -558,7 +557,7 @@ public class SetActionTest { .defaultValue("default") .onQualifiers(Qualifiers.PROJECT) .build()); - ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid")); + ComponentDto view = db.components().insertComponent(newView("view-uuid")); i18n.put("qualifier." + Qualifiers.VIEW, "View"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Setting 'my.key' cannot be set on a View"); @@ -619,20 +618,20 @@ public class SetActionTest { @Test public void succeed_for_property_without_definition_when_set_on_view_component() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); succeedForPropertyWithoutDefinitionAndValidComponent(view, view); } @Test public void succeed_for_property_without_definition_when_set_on_subview_component() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view)); succeedForPropertyWithoutDefinitionAndValidComponent(view, subview); } @Test public void fail_for_property_without_definition_when_set_on_projectCopy_component() { - ComponentDto view = db.components().insertView(); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto projectCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", db.components().insertPrivateProject(), view)); failForPropertyWithoutDefinitionOnUnsupportedComponent(view, projectCopy); @@ -907,8 +906,7 @@ public class SetActionTest { @Test public void fail_when_using_branch_db_key() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPublicProject(organization); + ComponentDto project = db.components().insertPublicProject(); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); ComponentDto branch = db.components().insertProjectBranch(project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java index f57833e9e07..e720603a93f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java @@ -62,11 +62,11 @@ public class SettingsUpdaterTest { PropertyDefinitions definitions = new PropertyDefinitions(System2.INSTANCE); ComponentDto project; - SettingsUpdater underTest= new SettingsUpdater(dbClient, definitions); + SettingsUpdater underTest = new SettingsUpdater(dbClient, definitions); @Before public void setUp() { - project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert())); + project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto()); } @Test @@ -215,9 +215,9 @@ public class SettingsUpdaterTest { private void assertUserPropertyExists(String key, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setKey(key) + .setKey(key) .setUserUuid(user.getUuid()) - .build(), + .build(), dbSession)).isNotEmpty(); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index a1fe7dc40cd..01973d71f7a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -41,7 +41,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.property.PropertyDbTester; import org.sonar.process.ProcessProperties; @@ -93,7 +92,7 @@ public class ValuesActionTest { @Before public void setUp() { - project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert())); + project = componentDb.insertComponent(ComponentTesting.newPrivateProjectDto()); } @Test @@ -745,8 +744,7 @@ public class ValuesActionTest { @Test public void fail_when_using_branch_db_key() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); userSession.logIn().addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/HashActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/HashActionTest.java index faf4cedde18..3a295ce58bb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/HashActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/HashActionTest.java @@ -25,7 +25,6 @@ import org.junit.rules.ExpectedException; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.source.FileSourceDto; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; @@ -49,12 +48,11 @@ public class HashActionTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); - private WsActionTester tester = new WsActionTester(new HashAction(db.getDbClient(), userSessionRule, TestComponentFinder.from(db))); + private final WsActionTester tester = new WsActionTester(new HashAction(db.getDbClient(), userSessionRule, TestComponentFinder.from(db))); @Test public void show_hashes() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); FileSourceDto fileSource = db.fileSources().insertFileSource(file, f -> f.setLineHashes(singletonList("ABC"))); loginAsProjectViewer(project); @@ -66,8 +64,7 @@ public class HashActionTest { @Test public void hashes_empty_if_no_source() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); loginAsProjectViewer(project); @@ -97,8 +94,7 @@ public class HashActionTest { @Test public void fail_on_missing_permission() { - OrganizationDto organizationDto = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organizationDto); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); FileSourceDto fileSource = db.fileSources().insertFileSource(file); userSessionRule.logIn(db.users().insertUser()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java index d759dfcab7b..c8c3783b936 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java @@ -78,7 +78,7 @@ public class IssueSnippetsActionTest { @Before public void setUp() { - project = db.components().insertPrivateProject(db.getDefaultOrganization(), "projectUuid"); + project = db.components().insertPrivateProject("projectUuid"); HtmlSourceDecorator htmlSourceDecorator = mock(HtmlSourceDecorator.class); when(htmlSourceDecorator.getDecoratedSourceAsHtml(anyString(), anyString(), anyString())) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java index 6b1fc02e841..d92aabd90ae 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java @@ -30,10 +30,8 @@ import org.sonar.core.util.Uuids; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.protobuf.DbFileSources; import org.sonar.db.source.FileSourceDto; import org.sonar.db.user.UserDto; @@ -64,26 +62,23 @@ public class LinesActionTest { @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - private ComponentDao componentDao = new ComponentDao(); - private SnapshotDao snapshotDao = new SnapshotDao(); - private ComponentDto privateProject; - private OrganizationDto organization; - private HtmlSourceDecorator htmlSourceDecorator = mock(HtmlSourceDecorator.class); - private SourceService sourceService = new SourceService(db.getDbClient(), htmlSourceDecorator); - private LinesJsonWriter linesJsonWriter = new LinesJsonWriter(htmlSourceDecorator); - private LinesAction underTest = new LinesAction(TestComponentFinder.from(db), db.getDbClient(), sourceService, linesJsonWriter, userSession); - private WsActionTester tester = new WsActionTester(underTest); + private final ComponentDao componentDao = new ComponentDao(); + private final SnapshotDao snapshotDao = new SnapshotDao(); + private final HtmlSourceDecorator htmlSourceDecorator = mock(HtmlSourceDecorator.class); + private final SourceService sourceService = new SourceService(db.getDbClient(), htmlSourceDecorator); + private final LinesJsonWriter linesJsonWriter = new LinesJsonWriter(htmlSourceDecorator); + private final LinesAction underTest = new LinesAction(TestComponentFinder.from(db), db.getDbClient(), sourceService, linesJsonWriter, userSession); + private final WsActionTester tester = new WsActionTester(underTest); @Before public void setUp() { when(htmlSourceDecorator.getDecoratedSourceAsHtml(anyString(), anyString(), anyString())) .then((Answer) invocationOnMock -> "

" + invocationOnMock.getArguments()[0] + "

"); - organization = db.organizations().insert(); - privateProject = ComponentTesting.newPrivateProjectDto(organization); } @Test public void show_source() { + ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(3).build(), privateProject); setUserWithValidPermission(file); @@ -96,6 +91,7 @@ public class LinesActionTest { @Test public void fail_to_show_source_if_no_source_found() { + ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto file = insertFile(privateProject); setUserWithValidPermission(file); @@ -109,6 +105,7 @@ public class LinesActionTest { @Test public void show_paginated_lines() { + ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(3).build(), privateProject); setUserWithValidPermission(file); @@ -193,8 +190,9 @@ public class LinesActionTest { @Test public void fail_when_file_is_removed() { + ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto file = newFileDto(privateProject).setDbKey("file-key").setEnabled(false); - db.components().insertComponents(privateProject, file); + db.components().insertComponents(file); setUserWithValidPermission(file); expectedException.expect(NotFoundException.class); @@ -205,6 +203,7 @@ public class LinesActionTest { @Test(expected = ForbiddenException.class) public void check_permission() { + ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(1).build(), privateProject); userSession.logIn("login"); @@ -216,6 +215,7 @@ public class LinesActionTest { @Test public void display_deprecated_fields() { + ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(1).build(), privateProject); setUserWithValidPermission(file); @@ -245,6 +245,7 @@ public class LinesActionTest { @Test public void use_deprecated_overall_coverage_fields_if_exists() { + ComponentDto privateProject = db.components().insertPrivateProject(); DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder(); ComponentDto file = insertFileWithData(dataBuilder.addLines(newLineBuilder() .setDeprecatedOverallLineHits(1) @@ -266,6 +267,7 @@ public class LinesActionTest { @Test public void use_deprecated_ut_coverage_fields_if_exists() { + ComponentDto privateProject = db.components().insertPrivateProject(); DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder(); ComponentDto file = insertFileWithData(dataBuilder.addLines(newLineBuilder() .setDeprecatedUtLineHits(1) @@ -284,6 +286,7 @@ public class LinesActionTest { @Test public void use_deprecated_it_coverage_fields_if_exists() { + ComponentDto privateProject = db.components().insertPrivateProject(); DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder(); ComponentDto file = insertFileWithData(dataBuilder.addLines(newLineBuilder() .setDeprecatedItLineHits(1) @@ -358,9 +361,8 @@ public class LinesActionTest { } @Test - public void hide_scmAuthors_if_not_member_of_organization() { - OrganizationDto org = db.organizations().insert(); - ComponentDto publicProject = db.components().insertPublicProject(org); + public void hide_scmAuthors() { + ComponentDto publicProject = db.components().insertPublicProject(); userSession.registerComponents(publicProject); DbFileSources.Data data = DbFileSources.Data.newBuilder() @@ -376,9 +378,8 @@ public class LinesActionTest { } @Test - public void show_scmAuthors_if_member_of_organization() { - OrganizationDto org = db.organizations().insert(); - ComponentDto publicProject = db.components().insertPublicProject(org); + public void show_scmAuthors() { + ComponentDto publicProject = db.components().insertPublicProject(); UserDto user = db.users().insertUser(); userSession.logIn(user) .registerComponents(publicProject); @@ -407,6 +408,7 @@ public class LinesActionTest { } private void setUserWithValidPermission(ComponentDto file) { + ComponentDto privateProject = db.components().insertPrivateProject(); userSession.logIn("login") .addProjectPermission(UserRole.CODEVIEWER, privateProject, file); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java index 030749fc64c..a7e1491fc03 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java @@ -58,19 +58,19 @@ public class ScmActionTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); - private DbClient dbClient = dbTester.getDbClient(); - private DbSession dbSession = dbTester.getSession(); + private final DbClient dbClient = dbTester.getDbClient(); + private final DbSession dbSession = dbTester.getSession(); + private final ScmAction underTest = new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()), + userSessionRule, TestComponentFinder.from(dbTester)); + private final WsActionTester tester = new WsActionTester(underTest); private ComponentDto project; private ComponentDto file; - private ScmAction underTest = new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()), - userSessionRule, TestComponentFinder.from(dbTester)); - private WsActionTester tester = new WsActionTester(underTest); @Before public void setUp() { - project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), PROJECT_UUID); + project = dbTester.components().insertPrivateProject(PROJECT_UUID); file = ComponentTesting.newFileDto(project, null, FILE_UUID).setDbKey(FILE_KEY); - dbClient.componentDao().insert(dbTester.getSession(), project, file); + dbClient.componentDao().insert(dbTester.getSession(), file); dbTester.getSession().commit(); } @@ -135,7 +135,7 @@ public class ScmActionTest { tester.newRequest() .setParam("key", FILE_KEY) - .setParam("commits_by_line","true") + .setParam("commits_by_line", "true") .execute() .assertJson(getClass(), "not_group_lines_by_commit.json"); } @@ -159,7 +159,7 @@ public class ScmActionTest { tester.newRequest() .setParam("key", FILE_KEY) - .setParam("commits_by_line","false") + .setParam("commits_by_line", "false") .execute() .assertJson(getClass(), "group_lines_by_commit.json"); } @@ -182,7 +182,7 @@ public class ScmActionTest { tester.newRequest() .setParam("key", FILE_KEY) - .setParam("from","-2") + .setParam("from", "-2") .setParam("to", "3") .execute() .assertJson(getClass(), "accept_negative_value_in_from_parameter.json"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ShowActionTest.java index c871a6641e4..33199e84e3b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ShowActionTest.java @@ -31,7 +31,6 @@ import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.ResourceTypesRule; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.server.component.ComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.source.SourceService; @@ -54,7 +53,7 @@ public class ShowActionTest { private DbClient dbClient = mock(DbClient.class); private DbSession session = mock(DbSession.class); private ComponentDao componentDao = mock(ComponentDao.class); - private ComponentDto project = ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto()); + private ComponentDto project = ComponentTesting.newPrivateProjectDto(); private ComponentDto file = ComponentTesting.newFileDto(project, null); private ShowAction underTest = new ShowAction(sourceService, dbClient, userSessionRule, new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT))); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java index 852479854f5..21c7c3b4dc1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java @@ -28,7 +28,6 @@ import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.server.ws.WebService.SelectionMode; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.exceptions.ForbiddenException; @@ -133,7 +132,6 @@ public class UsersActionTest { @Test public void references_group_by_its_name() { - OrganizationDto org = db.organizations().insert(); GroupDto group = db.users().insertGroup("the-group"); UserDto lovelace = db.users().insertUser(newUserDto().setLogin("ada.login").setName("Ada Lovelace")); UserDto hopper = db.users().insertUser(newUserDto().setLogin("grace").setName("Grace Hopper")); @@ -141,7 +139,6 @@ public class UsersActionTest { loginAsAdmin(); String result = newUsersRequest() - .setParam("organization", org.getKey()) .setParam("name", group.getName()) .setParam(Param.SELECTED, SelectionMode.ALL.value()) .execute() diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java index e79d59e8886..1338618065a 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java @@ -44,7 +44,6 @@ import org.sonarqube.ws.client.metrics.MetricsService; import org.sonarqube.ws.client.navigation.NavigationService; import org.sonarqube.ws.client.newcodeperiods.NewCodePeriodsService; import org.sonarqube.ws.client.notifications.NotificationsService; -import org.sonarqube.ws.client.organizations.OrganizationsService; import org.sonarqube.ws.client.permissions.PermissionsService; import org.sonarqube.ws.client.plugins.PluginsService; import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService; @@ -110,7 +109,6 @@ class DefaultWsClient implements WsClient { private final NavigationService navigationService; private final NewCodePeriodsService newCodePeriodsService; private final NotificationsService notificationsService; - private final OrganizationsService organizationsService; private final PermissionsService permissionsService; private final PluginsService pluginsService; private final ProjectAnalysesService projectAnalysesService; @@ -169,7 +167,6 @@ class DefaultWsClient implements WsClient { this.navigationService = new NavigationService(wsConnector); this.newCodePeriodsService = new NewCodePeriodsService(wsConnector); this.notificationsService = new NotificationsService(wsConnector); - this.organizationsService = new OrganizationsService(wsConnector); this.permissionsService = new PermissionsService(wsConnector); this.pluginsService = new PluginsService(wsConnector); this.projectAnalysesService = new ProjectAnalysesService(wsConnector); @@ -324,11 +321,6 @@ class DefaultWsClient implements WsClient { return notificationsService; } - @Override - public OrganizationsService organizations() { - return organizationsService; - } - @Override public PermissionsService permissions() { return permissionsService; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java index 3f7243d0520..ad279d4d446 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java @@ -44,7 +44,6 @@ import org.sonarqube.ws.client.metrics.MetricsService; import org.sonarqube.ws.client.navigation.NavigationService; import org.sonarqube.ws.client.newcodeperiods.NewCodePeriodsService; import org.sonarqube.ws.client.notifications.NotificationsService; -import org.sonarqube.ws.client.organizations.OrganizationsService; import org.sonarqube.ws.client.permissions.PermissionsService; import org.sonarqube.ws.client.plugins.PluginsService; import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService; @@ -145,8 +144,6 @@ public interface WsClient { NotificationsService notifications(); - OrganizationsService organizations(); - PermissionsService permissions(); PluginsService plugins(); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/OrganizationsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/OrganizationsService.java deleted file mode 100644 index fad2afd2bdc..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/OrganizationsService.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.sonarqube.ws.client.organizations; - -import java.util.stream.Collectors; -import javax.annotation.Generated; -import org.sonarqube.ws.MediaTypes; -import org.sonarqube.ws.Organizations.SearchMembersWsResponse; -import org.sonarqube.ws.Organizations.SearchWsResponse; -import org.sonarqube.ws.client.BaseService; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.PostRequest; -import org.sonarqube.ws.client.WsConnector; - -/** - * @see Further information about this web service online - */ -@Generated("sonar-ws-generator") -public class OrganizationsService extends BaseService { - - public OrganizationsService(WsConnector wsConnector) { - super(wsConnector, "api/organizations"); - } - - /** - * - * This is part of the internal API. - * This is a POST request. - * @see Further information about this action online (including a response example) - * @since 6.3 - */ - public void enableSupport() { - call( - new PostRequest(path("enable_support")) - .setMediaType(MediaTypes.JSON)).content(); - } - - /** - * - * This is part of the internal API. - * This is a GET request. - * @see Further information about this action online (including a response example) - * @since 6.2 - */ - public SearchWsResponse search(SearchRequest request) { - return call( - new GetRequest(path("search")) - .setParam("member", request.getMember()) - .setParam("organizations", request.getOrganizations() == null ? null : request.getOrganizations().stream().collect(Collectors.joining(","))) - .setParam("p", request.getP()) - .setParam("ps", request.getPs()), - SearchWsResponse.parser()); - } - - /** - * - * This is part of the internal API. - * This is a GET request. - * @see Further information about this action online (including a response example) - * @since 6.4 - */ - public SearchMembersWsResponse searchMembers(SearchMembersRequest request) { - return call( - new GetRequest(path("search_members")) - .setParam("organization", request.getOrganization()) - .setParam("p", request.getP()) - .setParam("ps", request.getPs()) - .setParam("q", request.getQ()) - .setParam("selected", request.getSelected()), - SearchMembersWsResponse.parser()); - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/SearchMembersRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/SearchMembersRequest.java deleted file mode 100644 index 0e93fb3acad..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/SearchMembersRequest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.sonarqube.ws.client.organizations; - -import javax.annotation.Generated; - -/** - * This is part of the internal API. - * This is a POST request. - * @see Further information about this action online (including a response example) - * @since 6.4 - */ -@Generated("sonar-ws-generator") -public class SearchMembersRequest { - - private String organization; - private String p; - private String ps; - private String q; - private String selected; - - /** - * This is part of the internal API. - */ - public SearchMembersRequest setOrganization(String organization) { - this.organization = organization; - return this; - } - - public String getOrganization() { - return organization; - } - - /** - * Example value: "42" - */ - public SearchMembersRequest setP(String p) { - this.p = p; - return this; - } - - public String getP() { - return p; - } - - /** - * Example value: "20" - */ - public SearchMembersRequest setPs(String ps) { - this.ps = ps; - return this; - } - - public String getPs() { - return ps; - } - - /** - * Example value: "orwe" - */ - public SearchMembersRequest setQ(String q) { - this.q = q; - return this; - } - - public String getQ() { - return q; - } - - /** - * This is part of the internal API. - * Possible values: - *
    - *
  • "selected"
  • - *
  • "deselected"
  • - *
- */ - public SearchMembersRequest setSelected(String selected) { - this.selected = selected; - return this; - } - - public String getSelected() { - return selected; - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/SearchRequest.java deleted file mode 100644 index 145f632cf93..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/SearchRequest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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.sonarqube.ws.client.organizations; - -import java.util.List; -import javax.annotation.Generated; - -/** - * This is part of the internal API. - * This is a POST request. - * @see Further information about this action online (including a response example) - * @since 6.2 - */ -@Generated("sonar-ws-generator") -public class SearchRequest { - - private String member; - private List organizations; - private String p; - private String ps; - - /** - * Possible values: - *
    - *
  • "true"
  • - *
  • "false"
  • - *
  • "yes"
  • - *
  • "no"
  • - *
- */ - public SearchRequest setMember(String member) { - this.member = member; - return this; - } - - public String getMember() { - return member; - } - - /** - * Example value: "my-org-1,foocorp" - */ - public SearchRequest setOrganizations(List organizations) { - this.organizations = organizations; - return this; - } - - public List getOrganizations() { - return organizations; - } - - /** - * Example value: "42" - */ - public SearchRequest setP(String p) { - this.p = p; - return this; - } - - public String getP() { - return p; - } - - /** - * Example value: "20" - */ - public SearchRequest setPs(String ps) { - this.ps = ps; - return this; - } - - public String getPs() { - return ps; - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/package-info.java deleted file mode 100644 index 0740d543c20..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/organizations/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program 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. - * - * This program 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. - */ -@ParametersAreNonnullByDefault -@Generated("sonar-ws-generator") -package org.sonarqube.ws.client.organizations; - -import javax.annotation.ParametersAreNonnullByDefault; -import javax.annotation.Generated; - diff --git a/sonar-ws/src/main/protobuf/ws-organizations.proto b/sonar-ws/src/main/protobuf/ws-organizations.proto deleted file mode 100644 index d4a87d2b74d..00000000000 --- a/sonar-ws/src/main/protobuf/ws-organizations.proto +++ /dev/null @@ -1,81 +0,0 @@ -// SonarQube, open source software quality management tool. -// Copyright (C) 2008-2016 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. - -syntax = "proto2"; - -package sonarqube.ws.organizations; - -import "ws-commons.proto"; - -option java_package = "org.sonarqube.ws"; -option java_outer_classname = "Organizations"; -option optimize_for = SPEED; - -// WS api/organizations/search -message SearchWsResponse { - repeated Organization organizations = 1; - optional sonarqube.ws.commons.Paging paging = 2; -} - -// WS api/organizations/search_members -message SearchMembersWsResponse { - optional sonarqube.ws.commons.Paging paging = 1; - repeated User users = 2; -} - -message Organization { - optional string key = 1; - optional string name = 2; - optional string description = 3; - optional string url = 4; - optional string avatar = 5; - optional Alm alm = 8; - optional Actions actions = 9; - optional Subscription subscription = 10; - - message Alm { - optional string key = 1; - optional string url = 2; - optional bool personal = 3; - } - - message Actions { - optional bool admin = 1; - optional bool delete = 2; - optional bool provision = 3; - } -} - -message User { - optional string login = 1; - optional string name = 2; - optional string avatar = 3; - optional int32 groupCount = 4; -} - - -// See org.sonar.db.organization.OrganizationDto.Subscription -enum Subscription { - // Zero is required in order to not get LONG as default value - // See http://androiddevblog.com/protocol-buffers-pitfall-adding-enum-values/ - UNKNOWN = 0; - - SONARQUBE = 1; - FREE = 2; - PAID = 3; -} -- 2.39.5