From 65556c25122bf9fc25e6750420cdea849e3fa53d Mon Sep 17 00:00:00 2001 From: Jacek Date: Thu, 17 Dec 2020 11:09:43 +0100 Subject: [PATCH] SONAR-13999 drop leftovers of organization from Measures WSs --- .../measure/custom/ws/CreateActionTest.java | 7 +--- .../measure/custom/ws/MetricsActionTest.java | 10 ++--- .../live/LiveMeasureComputerImplTest.java | 5 +-- .../live/LiveQualityGateComputerImplTest.java | 7 ++-- .../measure/live/MeasureMatrixTest.java | 5 +-- .../measure/ws/ComponentActionTest.java | 6 +-- .../measure/ws/ComponentTreeActionTest.java | 33 ++++++--------- .../server/measure/ws/SearchActionTest.java | 42 ++++++++----------- .../measure/ws/SearchHistoryActionTest.java | 14 +++---- 9 files changed, 49 insertions(+), 80 deletions(-) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java index 1e6c45b9260..1da74f0cf67 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java @@ -31,7 +31,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.measure.custom.CustomMeasureDto; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.es.EsTester; @@ -284,8 +283,7 @@ public class CreateActionTest { @Test public void create_custom_measure_on_a_view() { MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true).setValueType(BOOL.name())); - OrganizationDto organization = db.organizations().insert(); - ComponentDto view = db.components().insertPrivatePortfolio(organization); + ComponentDto view = db.components().insertPrivatePortfolio(); UserDto user = db.users().insertUser(); userSession.logIn(user).addProjectPermission(ADMIN, view); @@ -304,8 +302,7 @@ public class CreateActionTest { @Test public void create_custom_measure_on_a_sub_view() { MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true).setValueType(BOOL.name())); - OrganizationDto organization = db.organizations().insert(); - ComponentDto view = db.components().insertPrivatePortfolio(organization); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subView = db.components().insertSubView(view); UserDto user = db.users().insertUser(); userSession.logIn(user).addProjectPermission(ADMIN, view); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java index b314dc970bc..c20f4656ecd 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java @@ -60,8 +60,8 @@ public class MetricsActionTest { private final DbClient dbClient = db.getDbClient(); private final DbSession dbSession = db.getSession(); private ComponentDto defaultProject; - private MetricsAction underTest = new MetricsAction(dbClient, userSession, TestComponentFinder.from(db)); - private WsActionTester tester = new WsActionTester(underTest); + private final MetricsAction underTest = new MetricsAction(dbClient, userSession, TestComponentFinder.from(db)); + private final WsActionTester tester = new WsActionTester(underTest); @Before public void setUp() { @@ -217,11 +217,9 @@ public class MetricsActionTest { } private ComponentDto insertProject(String projectUuid, String projectKey) { - ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), projectUuid) + ComponentDto project = ComponentTesting.newPrivateProjectDto(projectUuid) .setDbKey(projectKey); - dbClient.componentDao().insert(dbSession, project); - dbSession.commit(); - + db.components().insertComponent(project); return project; } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java index e626c7205d1..91ebe0fe811 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java @@ -49,7 +49,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.project.ProjectDto; import org.sonar.server.es.ProjectIndexer; import org.sonar.server.es.TestProjectIndexers; @@ -85,7 +84,6 @@ public class LiveMeasureComputerImplTest { private MetricDto intMetric; private MetricDto ratingMetric; private MetricDto alertStatusMetric; - private OrganizationDto organization; private ComponentDto project; private ProjectDto projectDto; private ComponentDto dir; @@ -102,8 +100,7 @@ public class LiveMeasureComputerImplTest { intMetric = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.INT.name())); ratingMetric = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.RATING.name())); alertStatusMetric = db.measures().insertMetric(m -> m.setKey(CoreMetrics.ALERT_STATUS_KEY)); - organization = db.organizations().insert(); - project = db.components().insertPublicProject(organization); + project = db.components().insertPublicProject(); projectDto = db.components().getProjectDto(project); dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java")); file1 = db.components().insertComponent(ComponentTesting.newFileDto(project, dir)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java index 0416ed408b3..63ed07d0191 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java @@ -52,7 +52,6 @@ import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.groups.Tuple.tuple; import static org.sonar.db.metric.MetricTesting.newMetricDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class LiveQualityGateComputerImplTest { @@ -83,7 +82,7 @@ public class LiveQualityGateComputerImplTest { } @Test - public void loadQualityGate_on_branch_returns_organization_default_gate() { + public void loadQualityGate_on_branch_returns_default_gate() { ProjectDto project = db.components().insertPublicProjectDto(); BranchDto branch = db.components().insertProjectBranch(project).setBranchType(BranchType.BRANCH); @@ -117,7 +116,7 @@ public class LiveQualityGateComputerImplTest { @Test public void refreshGateStatus_generates_gate_related_measures() { - ComponentDto project = ComponentTesting.newPublicProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPublicProjectDto(); MetricDto conditionMetric = newMetricDto(); MetricDto statusMetric = newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY); MetricDto detailsMetric = newMetricDto().setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY); @@ -143,7 +142,7 @@ public class LiveQualityGateComputerImplTest { @Test public void refreshGateStatus_provides_measures_to_evaluator() { - ComponentDto project = ComponentTesting.newPublicProjectDto(newOrganizationDto()); + ComponentDto project = ComponentTesting.newPublicProjectDto(); MetricDto numericMetric = newMetricDto().setValueType(Metric.ValueType.FLOAT.name()); MetricDto numericNewMetric = newMetricDto().setValueType(Metric.ValueType.FLOAT.name()).setKey("new_metric"); MetricDto stringMetric = newMetricDto().setValueType(Metric.ValueType.STRING.name()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java index f71f39a1600..ceedfb972fb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java @@ -30,18 +30,15 @@ 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 static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.metric.MetricTesting.newMetricDto; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class MeasureMatrixTest { - private static final OrganizationDto ORGANIZATION = newOrganizationDto(); - private static final ComponentDto PROJECT = ComponentTesting.newPublicProjectDto(ORGANIZATION); + private static final ComponentDto PROJECT = ComponentTesting.newPublicProjectDto(); private static final ComponentDto FILE = ComponentTesting.newFileDto(PROJECT); private static final MetricDto METRIC_1 = newMetricDto().setUuid("100"); private static final MetricDto METRIC_2 = newMetricDto().setUuid("200"); 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 68ace74a17d..fa0d97ee2f3 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 @@ -32,7 +32,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.measure.LiveMeasureDto; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; @@ -69,7 +68,7 @@ public class ComponentActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private WsActionTester ws = new WsActionTester(new ComponentAction(db.getDbClient(), TestComponentFinder.from(db), userSession)); + private final WsActionTester ws = new WsActionTester(new ComponentAction(db.getDbClient(), TestComponentFinder.from(db), userSession)); @Test public void definition() { @@ -396,8 +395,7 @@ public class ComponentActionTest { @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); MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 4790e657094..7d36d999000 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -40,7 +40,6 @@ import org.sonar.db.component.SnapshotDto; import org.sonar.db.measure.LiveMeasureDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.metric.MetricTesting; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; @@ -106,14 +105,14 @@ public class ComponentTreeActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private I18nRule i18n = new I18nRule(); - private ResourceTypesRule resourceTypes = new ResourceTypesRule() + private final I18nRule i18n = new I18nRule(); + private final ResourceTypesRule resourceTypes = new ResourceTypesRule() .setRootQualifiers(PROJECT) .setLeavesQualifiers(FILE, UNIT_TEST_FILE); - private DbClient dbClient = db.getDbClient(); - private DbSession dbSession = db.getSession(); + private final DbClient dbClient = db.getDbClient(); + private final DbSession dbSession = db.getSession(); - private WsActionTester ws = new WsActionTester( + private final WsActionTester ws = new WsActionTester( new ComponentTreeAction( dbClient, new ComponentFinder(dbClient, resourceTypes), userSession, i18n, resourceTypes)); @@ -529,8 +528,7 @@ public class ComponentTreeActionTest { @Test public void branch() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); SnapshotDto analysis = db.components().insertSnapshot(branch); ComponentDto file = db.components().insertComponent(newFileDto(branch)); @@ -552,8 +550,7 @@ public class ComponentTreeActionTest { @Test public void pull_request() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST)); SnapshotDto analysis = db.components().insertSnapshot(branch); ComponentDto file = db.components().insertComponent(newFileDto(branch)); @@ -575,8 +572,7 @@ public class ComponentTreeActionTest { @Test public void fix_pull_request_new_issue_count_metrics() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST)); SnapshotDto analysis = db.components().insertSnapshot(branch); ComponentDto file = db.components().insertComponent(newFileDto(branch)); @@ -604,8 +600,7 @@ public class ComponentTreeActionTest { @Test public void new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_pr() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey("pr").setBranchType(PULL_REQUEST)); SnapshotDto analysis = db.components().insertSnapshot(pr); ComponentDto file = db.components().insertComponent(newFileDto(pr)); @@ -694,7 +689,7 @@ public class ComponentTreeActionTest { @Test public void project_reference_from_portfolio() { ComponentDto project = db.components().insertPrivateProject(); - ComponentDto view = db.components().insertPrivatePortfolio(db.getDefaultOrganization()); + ComponentDto view = db.components().insertPrivatePortfolio(); SnapshotDto viewAnalysis = db.components().insertSnapshot(view); ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(project, view)); MetricDto ncloc = insertNclocMetric(); @@ -978,9 +973,8 @@ public class ComponentTreeActionTest { } @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(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); insertNclocMetric(); @@ -996,8 +990,7 @@ public class ComponentTreeActionTest { @Test public void fail_when_using_branch_uuid() { - 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); insertNclocMetric(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java index 18b35e2d157..8aeb6d3a8f2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java @@ -34,7 +34,6 @@ import org.sonar.api.web.UserRole; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.metric.MetricDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestRequest; @@ -55,9 +54,9 @@ import static org.sonar.db.component.ComponentTesting.newDirectory; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newModuleDto; import static org.sonar.db.component.ComponentTesting.newSubView; -import static org.sonar.test.JsonAssert.assertJson; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PROJECT_KEYS; +import static org.sonar.test.JsonAssert.assertJson; public class SearchActionTest { @@ -70,15 +69,13 @@ public class SearchActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private WsActionTester ws = new WsActionTester(new SearchAction(userSession, db.getDbClient())); + private final WsActionTester ws = new WsActionTester(new SearchAction(userSession, db.getDbClient())); @Test public void json_example() { - OrganizationDto organization = db.organizations().insert(); - - ComponentDto project1 = db.components().insertPrivateProject(organization, p -> p.setDbKey("MY_PROJECT_1").setName("Project 1")); - ComponentDto project2 = db.components().insertPrivateProject(organization, p -> p.setDbKey("MY_PROJECT_2").setName("Project 2")); - ComponentDto project3 = db.components().insertPrivateProject(organization, p -> p.setDbKey("MY_PROJECT_3").setName("Project 3")); + ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_1").setName("Project 1")); + ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_2").setName("Project 2")); + ComponentDto project3 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_3").setName("Project 3")); userSession.addProjectPermission(UserRole.USER, project1); userSession.addProjectPermission(UserRole.USER, project2); @@ -112,7 +109,7 @@ public class SearchActionTest { @Test public void return_measures() { - ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); + ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d)); @@ -128,7 +125,7 @@ public class SearchActionTest { @Test public void return_best_value() { - ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization()); + ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); MetricDto matchBestValue = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()).setBestValue(15.5d)); db.measures().insertLiveMeasure(project, matchBestValue, m -> m.setValue(15.5d)); @@ -151,8 +148,7 @@ public class SearchActionTest { @Test public void return_measures_on_new_code_period() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d).setVariation(10d)); @@ -173,10 +169,9 @@ public class SearchActionTest { public void sort_by_metric_key_then_project_name() { MetricDto coverage = db.measures().insertMetric(m -> m.setKey("coverage").setValueType(FLOAT.name())); MetricDto complexity = db.measures().insertMetric(m -> m.setKey("complexity").setValueType(INT.name())); - OrganizationDto organization = db.organizations().insert(); - ComponentDto project1 = db.components().insertPrivateProject(organization, p -> p.setName("C")); - ComponentDto project2 = db.components().insertPrivateProject(organization, p -> p.setName("A")); - ComponentDto project3 = db.components().insertPrivateProject(organization, p -> p.setName("B")); + ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("C")); + ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("A")); + ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("B")); userSession.addProjectPermission(UserRole.USER, project1); userSession.addProjectPermission(UserRole.USER, project2); userSession.addProjectPermission(UserRole.USER, project3); @@ -197,8 +192,7 @@ public class SearchActionTest { @Test public void return_measures_on_view() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto view = db.components().insertPrivatePortfolio(organization); + ComponentDto view = db.components().insertPrivatePortfolio(); userSession.addProjectPermission(UserRole.USER, view); MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(view, coverage, m -> m.setValue(15.5d)); @@ -214,8 +208,7 @@ public class SearchActionTest { @Test public void return_measures_on_application() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto application = db.components().insertPrivateApplication(organization); + ComponentDto application = db.components().insertPrivateApplication(); userSession.addProjectPermission(UserRole.USER, application); MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); db.measures().insertLiveMeasure(application, coverage, m -> m.setValue(15.5d)); @@ -231,8 +224,7 @@ public class SearchActionTest { @Test public void return_measures_on_sub_view() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto view = db.components().insertPrivatePortfolio(organization); + ComponentDto view = db.components().insertPrivatePortfolio(); ComponentDto subView = db.components().insertComponent(newSubView(view)); userSession.addProjectPermission(UserRole.USER, subView); MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); @@ -250,8 +242,8 @@ public class SearchActionTest { @Test public void only_returns_authorized_projects() { MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); - ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization()); - ComponentDto project2 = db.components().insertPrivateProject(db.getDefaultOrganization()); + ComponentDto project1 = db.components().insertPrivateProject(); + ComponentDto project2 = db.components().insertPrivateProject(); db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d)); db.measures().insertLiveMeasure(project2, metric, m -> m.setValue(42.0d)); Arrays.stream(new ComponentDto[] {project1}).forEach(p -> userSession.addProjectPermission(UserRole.USER, p)); @@ -264,7 +256,7 @@ public class SearchActionTest { @Test public void do_not_verify_permissions_if_user_is_root() { MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name())); - ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization()); + ComponentDto project1 = db.components().insertPrivateProject(); db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d)); userSession.setNonRoot(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java index b2209f6c6a8..56bdc57d527 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java @@ -38,7 +38,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.measure.MeasureDto; 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; @@ -84,10 +83,10 @@ public class SearchHistoryActionTest { @Rule public DbTester db = DbTester.create(); - private DbClient dbClient = db.getDbClient(); - private DbSession dbSession = db.getSession(); + private final DbClient dbClient = db.getDbClient(); + private final DbSession dbSession = db.getSession(); - private WsActionTester ws = new WsActionTester(new SearchHistoryAction(dbClient, TestComponentFinder.from(db), userSession)); + private final WsActionTester ws = new WsActionTester(new SearchHistoryAction(dbClient, TestComponentFinder.from(db), userSession)); private ComponentDto project; private SnapshotDto analysis; @@ -98,7 +97,7 @@ public class SearchHistoryActionTest { @Before public void setUp() { - project = newPrivateProjectDto(db.getDefaultOrganization()); + project = newPrivateProjectDto(); analysis = db.components().insertProjectAndSnapshot(project); userSession.addProjectPermission(UserRole.USER, project); nclocMetric = insertNclocMetric(); @@ -342,8 +341,7 @@ public class SearchHistoryActionTest { @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); @@ -396,7 +394,7 @@ public class SearchHistoryActionTest { @Test public void fail_when_component_is_removed() { - ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization())); + ComponentDto project = db.components().insertComponent(newPrivateProjectDto()); db.components().insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false)); userSession.addProjectPermission(UserRole.USER, project); -- 2.39.5