diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-05-30 13:33:15 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-06-01 15:18:55 +0200 |
commit | e899ee47d6823c857a59f08ef166a1715572e8b4 (patch) | |
tree | 55b7a0dcc1105799a0189b43cc2500cceff7394e | |
parent | cfa1b2e92b7cf94e661653fb1dd233e744d02da3 (diff) | |
download | sonarqube-e899ee47d6823c857a59f08ef166a1715572e8b4.tar.gz sonarqube-e899ee47d6823c857a59f08ef166a1715572e8b4.zip |
SONAR-9346 move ResourceTypes down to ComponentFinder
rather than passing them as method parameters
51 files changed, 157 insertions, 121 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java index 751581e7257..8a8d4b4c89a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java @@ -43,9 +43,11 @@ public class ComponentFinder { private static final String MSG_PARAMETER_MUST_NOT_BE_EMPTY = "The '%s' parameter must not be empty"; private final DbClient dbClient; + private final ResourceTypes resourceTypes; - public ComponentFinder(DbClient dbClient) { + public ComponentFinder(DbClient dbClient, ResourceTypes resourceTypes) { this.dbClient = dbClient; + this.resourceTypes = resourceTypes; } public ComponentDto getByUuidOrKey(DbSession dbSession, @Nullable String componentUuid, @Nullable String componentKey, ParamNames parameterNames) { @@ -68,7 +70,7 @@ public class ComponentFinder { return checkFoundWithOptional(dbClient.componentDao().selectByUuid(dbSession, uuid), "Component id '%s' not found", uuid); } - public ComponentDto getRootComponentByUuidOrKey(DbSession dbSession, @Nullable String projectUuid, @Nullable String projectKey, ResourceTypes resourceTypes) { + public ComponentDto getRootComponentByUuidOrKey(DbSession dbSession, @Nullable String projectUuid, @Nullable String projectKey) { ComponentDto project; if (projectUuid != null) { project = checkFoundWithOptional(dbClient.componentDao().selectByUuid(dbSession, projectUuid), "Project id '%s' not found", projectUuid); diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java index f24ce5df943..623d74ccb9a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java @@ -21,7 +21,6 @@ package org.sonar.server.permission.ws; import java.util.Optional; import javax.annotation.Nullable; -import org.sonar.api.resources.ResourceTypes; import org.sonar.api.server.ws.Request; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -49,13 +48,11 @@ public class PermissionWsSupport { private final DbClient dbClient; private final ComponentFinder componentFinder; private final GroupWsSupport groupWsSupport; - private final ResourceTypes resourceTypes; - public PermissionWsSupport(DbClient dbClient, ComponentFinder componentFinder, GroupWsSupport groupWsSupport, ResourceTypes resourceTypes) { + public PermissionWsSupport(DbClient dbClient, ComponentFinder componentFinder, GroupWsSupport groupWsSupport) { this.dbClient = dbClient; this.componentFinder = componentFinder; this.groupWsSupport = groupWsSupport; - this.resourceTypes = resourceTypes; } public OrganizationDto findOrganization(DbSession dbSession, @Nullable String organizationKey) { @@ -72,13 +69,13 @@ public class PermissionWsSupport { String key = request.param(PermissionsWsParameters.PARAM_PROJECT_KEY); if (uuid != null || key != null) { ProjectWsRef ref = ProjectWsRef.newWsProjectRef(uuid, key); - return Optional.of(componentFinder.getRootComponentByUuidOrKey(dbSession, ref.uuid(), ref.key(), resourceTypes)); + return Optional.of(componentFinder.getRootComponentByUuidOrKey(dbSession, ref.uuid(), ref.key())); } return Optional.empty(); } public ComponentDto getRootComponentOrModule(DbSession dbSession, ProjectWsRef projectRef) { - return componentFinder.getRootComponentByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key(), resourceTypes); + return componentFinder.getRootComponentByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key()); } public GroupIdOrAnyone findGroup(DbSession dbSession, Request request) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java index 8be279269b5..576821ca300 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java @@ -34,7 +34,7 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.scanner.protocol.Constants.Severity; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.issue.index.IssueIndex; @@ -67,13 +67,10 @@ public class IssuesActionTest { @Rule public ExpectedException thrown = ExpectedException.none(); - @Rule public DbTester db = DbTester.create(system2); - @Rule public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings())); - @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); @@ -83,7 +80,7 @@ public class IssuesActionTest { private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, issueIndexer); private WsActionTester tester = new WsActionTester(new IssuesAction(db.getDbClient(), new IssueIndex(es.client(), system2, userSessionRule, new AuthorizationTypeSupport(userSessionRule)), - userSessionRule, new ComponentFinder(db.getDbClient()))); + userSessionRule, TestComponentFinder.from(db))); @Test public void return_minimal_fields() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java index 966563767e9..c959131069e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java @@ -34,7 +34,7 @@ import org.sonar.db.ce.CeQueueDto; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.organization.OrganizationDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -60,7 +60,7 @@ public class ActivityStatusActionTest { private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); - private WsActionTester ws = new WsActionTester(new ActivityStatusAction(userSession, dbClient, new ComponentFinder(dbClient))); + private WsActionTester ws = new WsActionTester(new ActivityStatusAction(userSession, dbClient, TestComponentFinder.from(db))); @Test public void json_example() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java index 9af2de6248c..e25a4138a3d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java @@ -30,7 +30,7 @@ import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -47,15 +47,13 @@ public class ComponentActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); private TaskFormatter formatter = new TaskFormatter(dbTester.getDbClient(), System2.INSTANCE); - private ComponentAction underTest = new ComponentAction(userSession, dbTester.getDbClient(), formatter, new ComponentFinder(dbTester.getDbClient())); + private ComponentAction underTest = new ComponentAction(userSession, dbTester.getDbClient(), formatter, TestComponentFinder.from(dbTester)); private WsActionTester ws = new WsActionTester(underTest); @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java index 60bcef4ae33..f624dc6cfed 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentFinderTest.java @@ -38,12 +38,11 @@ public class ComponentFinderTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); private final DbSession dbSession = db.getSession(); - private ComponentFinder underTest = new ComponentFinder(db.getDbClient()); + private ComponentFinder underTest = TestComponentFinder.from(db); @Test public void fail_when_the_uuid_and_key_are_null() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/TestComponentFinder.java b/server/sonar-server/src/test/java/org/sonar/server/component/TestComponentFinder.java new file mode 100644 index 00000000000..75082119b84 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/component/TestComponentFinder.java @@ -0,0 +1,36 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.server.component; + +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.ResourceTypes; +import org.sonar.db.DbClient; +import org.sonar.db.DbTester; +import org.sonar.db.component.ResourceTypesRule; + +public class TestComponentFinder extends ComponentFinder { + private TestComponentFinder(DbClient dbClient, ResourceTypes resourceTypes) { + super(dbClient, resourceTypes); + } + + public static TestComponentFinder from(DbTester dbTester) { + return new TestComponentFinder(dbTester.getDbClient(), new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java index 124a2ed055c..619cd59f550 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java @@ -36,7 +36,7 @@ import org.sonar.db.component.SnapshotTesting; import org.sonar.db.measure.MeasureDto; import org.sonar.db.measure.MeasureTesting; import org.sonar.db.metric.MetricDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.startup.RegisterMetrics; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestRequest; @@ -66,11 +66,10 @@ public class AppActionTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); - @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - private AppAction underTest = new AppAction(dbTester.getDbClient(), userSessionRule, new ComponentFinder(dbTester.getDbClient())); + private AppAction underTest = new AppAction(dbTester.getDbClient(), userSessionRule, TestComponentFinder.from(dbTester)); private WsActionTester wsTester = new WsActionTester(underTest); @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java index 8a174072af9..db7306aff57 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java @@ -35,7 +35,7 @@ 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.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -67,7 +67,7 @@ public class ShowActionTest { private ComponentDbTester componentDb = new ComponentDbTester(db); - private WsActionTester ws = new WsActionTester(new ShowAction(userSession, db.getDbClient(), new ComponentFinder(db.getDbClient()))); + private WsActionTester ws = new WsActionTester(new ShowAction(userSession, db.getDbClient(), TestComponentFinder.from(db))); @Test public void verify_definition() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index 471210dd147..72d6b501f04 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -75,7 +75,7 @@ public class TreeActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private ResourceTypesRule resourceTypes = new ResourceTypesRule(); + private ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT); private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); @@ -83,7 +83,7 @@ public class TreeActionTest { @Before public void setUp() { - ws = new WsActionTester(new TreeAction(dbClient, new ComponentFinder(dbClient), resourceTypes, userSession, Mockito.mock(I18n.class))); + ws = new WsActionTester(new TreeAction(dbClient, new ComponentFinder(dbClient, resourceTypes), resourceTypes, userSession, Mockito.mock(I18n.class))); resourceTypes.setChildrenQualifiers(Qualifiers.MODULE, Qualifiers.FILE, Qualifiers.DIRECTORY); resourceTypes.setLeavesQualifiers(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java index 44e68849ebe..2300f6e3ff2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java @@ -30,7 +30,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.metric.MetricDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.startup.RegisterMetrics; @@ -45,10 +45,8 @@ public class ShowActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(); @@ -59,7 +57,7 @@ public class ShowActionTest { @Before public void setUp() { - tester = new WsTester(new DuplicationsWs(new ShowAction(db.getDbClient(), parser, duplicationsJsonWriter, userSessionRule, new ComponentFinder(db.getDbClient())))); + tester = new WsTester(new DuplicationsWs(new ShowAction(db.getDbClient(), parser, duplicationsJsonWriter, userSessionRule, TestComponentFinder.from(db)))); db.getDbClient().metricDao().insert(db.getSession(), dataMetric); db.commit(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java index 5277adc84b6..cd4c470484d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java @@ -32,7 +32,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; @@ -60,11 +60,12 @@ public class AddActionTest { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(); + private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient); - private WsActionTester ws = new WsActionTester(new AddAction(userSession, dbClient, favoriteUpdater, new ComponentFinder(dbClient))); + private WsActionTester ws = new WsActionTester(new AddAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db))); @Test public void add_a_project() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java index f23f571b5c8..35a28e81755 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/favorite/ws/RemoveActionTest.java @@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; @@ -55,10 +55,11 @@ public class RemoveActionTest { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(); + private DbClient dbClient = db.getDbClient(); private FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient); - private WsActionTester ws = new WsActionTester(new RemoveAction(userSession, dbClient, favoriteUpdater, new ComponentFinder(dbClient))); + private WsActionTester ws = new WsActionTester(new RemoveAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db))); @Test public void remove_a_favorite_project() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java index b69556f374d..7870e00dc4c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java @@ -41,7 +41,7 @@ import org.sonar.db.metric.MetricDto; import org.sonar.db.metric.MetricTesting; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.UserDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; @@ -86,7 +86,7 @@ public class CreateActionTest { @Before public void setUp() { ws = new WsTester(new CustomMeasuresWs(new CreateAction(dbClient, userSession, System2.INSTANCE, new CustomMeasureValidator(newFullTypeValidations()), - new CustomMeasureJsonWriter(new UserJsonWriter(userSession)), new ComponentFinder(dbClient)))); + new CustomMeasureJsonWriter(new UserJsonWriter(userSession)), TestComponentFinder.from(db)))); db.getDbClient().userDao().insert(dbSession, new UserDto() .setLogin("login") diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java index a0c5d48fbb6..da3ea281ce2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java @@ -34,7 +34,7 @@ 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.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.tester.UserSessionRule; @@ -61,7 +61,8 @@ public class MetricsActionTest { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(System2.INSTANCE); - DbClient dbClient = db.getDbClient(); + + final DbClient dbClient = db.getDbClient(); final DbSession dbSession = db.getSession(); WsTester ws; @@ -74,7 +75,7 @@ public class MetricsActionTest { .setName("Login") .setEmail("login@login.com") .setActive(true)); - ws = new WsTester(new CustomMeasuresWs(new MetricsAction(dbClient, userSession, new ComponentFinder(dbClient)))); + ws = new WsTester(new CustomMeasuresWs(new MetricsAction(dbClient, userSession, TestComponentFinder.from(db)))); defaultProject = insertDefaultProject(); userSession.logIn().addProjectPermission(UserRole.ADMIN, defaultProject); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java index 171a4d5ef79..448f72bf841 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java @@ -40,7 +40,7 @@ import org.sonar.db.component.SnapshotTesting; import org.sonar.db.measure.custom.CustomMeasureDto; import org.sonar.db.metric.MetricDto; import org.sonar.db.user.UserDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -61,13 +61,10 @@ public class SearchActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); - @Rule public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings())); @@ -79,7 +76,7 @@ public class SearchActionTest { @Before public void setUp() { CustomMeasureJsonWriter customMeasureJsonWriter = new CustomMeasureJsonWriter(new UserJsonWriter(userSessionRule)); - ws = new WsTester(new CustomMeasuresWs(new SearchAction(dbClient, customMeasureJsonWriter, userSessionRule, new ComponentFinder(dbClient)))); + ws = new WsTester(new CustomMeasuresWs(new SearchAction(dbClient, customMeasureJsonWriter, userSessionRule, TestComponentFinder.from(db)))); defaultProject = insertDefaultProject(); userSessionRule.logIn().addProjectPermission(UserRole.ADMIN, defaultProject); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index 8978622eee0..a06f24e0b6c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -35,7 +35,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotTesting; import org.sonar.db.metric.MetricDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -64,14 +64,14 @@ public class ComponentActionTest { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); + private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private final DbSession dbSession = db.getSession(); - private WsActionTester ws = new WsActionTester(new ComponentAction(dbClient, new ComponentFinder(dbClient), userSession)); + private WsActionTester ws = new WsActionTester(new ComponentAction(dbClient, TestComponentFinder.from(db), userSession)); @Before public void setUp() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 268b0c409c1..2c368c0adcd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -88,14 +88,14 @@ public class ComponentTreeActionTest { public DbTester db = DbTester.create(System2.INSTANCE); private I18nRule i18n = new I18nRule(); - private ResourceTypesRule resourceTypes = new ResourceTypesRule(); + private ResourceTypesRule resourceTypes = new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT); private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private WsActionTester ws = new WsActionTester( new ComponentTreeAction( - new ComponentTreeDataLoader(dbClient, new ComponentFinder(dbClient), userSession, resourceTypes), + new ComponentTreeDataLoader(dbClient, new ComponentFinder(dbClient, resourceTypes), userSession, resourceTypes), i18n, resourceTypes)); @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java index 3b77d736887..eedd01e21c0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java @@ -39,7 +39,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; import org.sonar.db.metric.MetricDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -77,10 +77,11 @@ public class SearchHistoryActionTest { public ExpectedException expectedException = ExpectedException.none(); @Rule public DbTester db = DbTester.create(); + private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); - private WsActionTester ws = new WsActionTester(new SearchHistoryAction(dbClient, new ComponentFinder(dbClient), userSession)); + private WsActionTester ws = new WsActionTester(new SearchHistoryAction(dbClient, TestComponentFinder.from(db), userSession)); private ComponentDto project; private SnapshotDto analysis; diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/ws/AddActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/ws/AddActionTest.java index 3cc9e0de99f..327e90db3b6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notification/ws/AddActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notification/ws/AddActionTest.java @@ -29,7 +29,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.user.UserDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -59,12 +59,14 @@ public class AddActionTest { private static final String NOTIF_NEW_ISSUES = "Dispatcher2"; private static final String NOTIF_NEW_QUALITY_GATE_STATUS = "Dispatcher3"; private static final String USER_LOGIN = "george.orwell"; + @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule public UserSessionRule userSession; @Rule public DbTester db = DbTester.create(); + private DbClient dbClient = db.getDbClient(); private NotificationChannel emailChannel = new FakeNotificationChannel("EmailChannel"); @@ -98,7 +100,7 @@ public class AddActionTest { notificationCenter = new NotificationCenter( new NotificationDispatcherMetadata[] {metadata1, metadata2, metadata3}, new NotificationChannel[] {emailChannel, twitterChannel, defaultChannel}); - underTest = new AddAction(notificationCenter, new NotificationUpdater(dbClient), dbClient, new ComponentFinder(dbClient), userSession); + underTest = new AddAction(notificationCenter, new NotificationUpdater(dbClient), dbClient, TestComponentFinder.from(db), userSession); ws = new WsActionTester(underTest); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java index 8cc3f5ccf87..d4d16117e2c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java @@ -30,7 +30,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.user.UserDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -100,7 +100,7 @@ public class RemoveActionTest { new NotificationDispatcherMetadata[] {metadata1, metadata2, metadata3}, new NotificationChannel[] {emailChannel, twitterChannel, defaultChannel}); notificationUpdater = new NotificationUpdater(dbClient); - underTest = new RemoveAction(notificationCenter, notificationUpdater, dbClient, new ComponentFinder(dbClient), userSession); + underTest = new RemoveAction(notificationCenter, notificationUpdater, dbClient, TestComponentFinder.from(db), userSession); ws = new WsActionTester(underTest); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java index 53c75ed7e2a..cadf166786c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java @@ -69,7 +69,7 @@ public abstract class BasePermissionWsTest<A extends PermissionsWsAction> { protected PermissionWsSupport newPermissionWsSupport() { DbClient dbClient = db.getDbClient(); - return new PermissionWsSupport(dbClient, new ComponentFinder(dbClient), newGroupWsSupport(), newRootResourceTypes()); + return new PermissionWsSupport(dbClient, new ComponentFinder(dbClient, newRootResourceTypes()), newGroupWsSupport()); } protected ResourceTypesRule newRootResourceTypes() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java index 100ca5a6247..da69a19e9a0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java @@ -80,10 +80,10 @@ public class DeleteTemplateActionTest { public void setUp() throws Exception { GroupWsSupport groupWsSupport = new GroupWsSupport(dbClient, TestDefaultOrganizationProvider.from(db), new DefaultGroupFinder(db.getDbClient())); this.underTestWithoutViews = new WsActionTester(new DeleteTemplateAction(dbClient, userSession, - new PermissionWsSupport(dbClient, new ComponentFinder(dbClient), groupWsSupport, resourceTypes), + new PermissionWsSupport(dbClient, new ComponentFinder(dbClient, resourceTypes), groupWsSupport), defaultTemplatesResolver)); this.underTestWithViews = new WsActionTester(new DeleteTemplateAction(dbClient, userSession, - new PermissionWsSupport(dbClient, new ComponentFinder(dbClient), groupWsSupport, resourceTypesWithViews), + new PermissionWsSupport(dbClient, new ComponentFinder(dbClient, resourceTypes), groupWsSupport), defaultTemplatesResolverWithViews)); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java index 25ec4e611d4..115d0549b01 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java @@ -37,6 +37,7 @@ import org.sonar.db.component.ComponentTesting; import org.sonar.db.organization.OrganizationDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.ComponentService; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.component.index.ComponentIndexDefinition; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.BadRequestException; @@ -83,7 +84,7 @@ public class BulkUpdateKeyActionTest { private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); - private ComponentFinder componentFinder = new ComponentFinder(dbClient); + private ComponentFinder componentFinder = TestComponentFinder.from(db); private ComponentService componentService = mock(ComponentService.class); private WsActionTester ws = new WsActionTester( new BulkUpdateKeyAction(dbClient, componentFinder, componentService, userSession)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java index 7f80e9b4cf9..eb40ddaf9de 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java @@ -32,7 +32,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.server.component.ComponentCleanerService; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.tester.UserSessionRule; @@ -55,10 +55,8 @@ public class DeleteActionTest { @Rule public DbTester db = DbTester.create(system2); - @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); - @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -72,7 +70,7 @@ public class DeleteActionTest { ws = new WsTester(new ProjectsWs( new DeleteAction( componentCleanerService, - new ComponentFinder(dbClient), + TestComponentFinder.from(db), dbClient, userSessionRule))); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java index 67f3007b1de..0aebe3ab86a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java @@ -33,8 +33,8 @@ 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.server.component.ComponentFinder; import org.sonar.server.component.ComponentService; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; @@ -50,16 +50,18 @@ import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_TO; public class UpdateKeyActionTest { private static final String ANOTHER_KEY = "another_key"; + @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule public DbTester db = DbTester.create(System2.INSTANCE); + ComponentDbTester componentDb = new ComponentDbTester(db); DbClient dbClient = db.getDbClient(); ComponentService componentService = mock(ComponentService.class); - WsActionTester ws = new WsActionTester(new org.sonar.server.project.ws.UpdateKeyAction(dbClient, new ComponentFinder(dbClient), componentService)); + WsActionTester ws = new WsActionTester(new org.sonar.server.project.ws.UpdateKeyAction(dbClient, TestComponentFinder.from(db), componentService)); @Test public void call_by_key() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java index 9c4c23d3d47..ea4b748a6da 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java @@ -44,7 +44,7 @@ import org.sonar.db.permission.OrganizationPermission; import org.sonar.db.permission.UserPermissionDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -91,7 +91,7 @@ public class UpdateVisibilityActionTest { private PermissionIndexer permissionIndexer = mock(PermissionIndexer.class); private BillingValidationsProxy billingValidations = mock(BillingValidationsProxy.class); - private UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, new ComponentFinder(dbClient), userSessionRule, permissionIndexer, + private UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, TestComponentFinder.from(dbTester), userSessionRule, permissionIndexer, new ProjectsWsSupport(dbClient, billingValidations)); private WsActionTester actionTester = new WsActionTester(underTest); diff --git a/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java index 2a5567bb891..5189afc99f9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java @@ -36,7 +36,7 @@ import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; import org.sonar.db.event.EventDto; import org.sonar.db.organization.OrganizationDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -72,9 +72,10 @@ public class SearchActionTest { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(); + private DbClient dbClient = db.getDbClient(); - private WsActionTester ws = new WsActionTester(new SearchAction(dbClient, new ComponentFinder(dbClient), userSession)); + private WsActionTester ws = new WsActionTester(new SearchAction(dbClient, TestComponentFinder.from(db), userSession)); @Test public void json_example() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java index 6ff4fb3cb61..86ec3d850ba 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java @@ -35,6 +35,7 @@ import org.sonar.db.component.ComponentLinkDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.organization.OrganizationDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -57,12 +58,11 @@ public class CreateActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); + private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); @@ -72,7 +72,7 @@ public class CreateActionTest { @Before public void setUp() { - ComponentFinder componentFinder = new ComponentFinder(dbClient); + ComponentFinder componentFinder = TestComponentFinder.from(db); underTest = new CreateAction(dbClient, userSession, componentFinder); ws = new WsActionTester(underTest); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java index f6b7d0cc31b..47e48b8ca2c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java @@ -33,6 +33,7 @@ import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentLinkDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -70,7 +71,7 @@ public class SearchActionTest { @Before public void setUp() { - ComponentFinder componentFinder = new ComponentFinder(dbClient); + ComponentFinder componentFinder = TestComponentFinder.from(db); underTest = new SearchAction(dbClient, userSession, componentFinder); ws = new WsActionTester(underTest); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java index 00443b49bc9..9f2871c6b3b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java @@ -31,7 +31,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.es.ProjectIndexer; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; @@ -57,13 +57,14 @@ public class SetActionTest { public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot(); @Rule public DbTester db = DbTester.create(); + private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private ComponentDto project; private ProjectIndexer indexer = mock(ProjectIndexer.class); - private WsActionTester ws = new WsActionTester(new SetAction(dbClient, new ComponentFinder(dbClient), userSession, singletonList(indexer))); + private WsActionTester ws = new WsActionTester(new SetAction(dbClient, TestComponentFinder.from(db), userSession, singletonList(indexer))); @Before public void setUp() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java index 2bde5265686..5c7e6dae89a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java @@ -33,6 +33,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.property.PropertyDto; import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.qualitygate.QualityGates; @@ -48,10 +49,8 @@ public class DeselectActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); @@ -65,7 +64,7 @@ public class DeselectActionTest { @Before public void setUp() { - ComponentFinder componentFinder = new ComponentFinder(dbClient); + ComponentFinder componentFinder = TestComponentFinder.from(db); underTest = new DeselectAction(qualityGates, dbClient, componentFinder); ws = new WsActionTester(underTest); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java index 37a429cdd46..ca6494ce105 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java @@ -34,7 +34,7 @@ import org.sonar.db.component.ComponentTesting; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.property.PropertyDto; import org.sonar.db.qualitygate.QualityGateDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.qualitygate.QualityGateFinder; @@ -56,12 +56,13 @@ public class GetByProjectActionTest { public ExpectedException expectedException = ExpectedException.none(); @Rule public DbTester db = DbTester.create(System2.INSTANCE); + private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); private WsActionTester ws = new WsActionTester( - new GetByProjectAction(userSession, dbClient, new ComponentFinder(dbClient), new QualityGateFinder(dbClient))); + new GetByProjectAction(userSession, dbClient, TestComponentFinder.from(db), new QualityGateFinder(dbClient))); @Test public void json_example() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java index c38b9cd0a1a..26f57cc4383 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java @@ -35,7 +35,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; import org.sonar.db.metric.MetricDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -72,7 +72,7 @@ public class ProjectStatusActionTest { dbClient = db.getDbClient(); dbSession = db.getSession(); - ws = new WsActionTester(new ProjectStatusAction(dbClient, new ComponentFinder(dbClient), userSession)); + ws = new WsActionTester(new ProjectStatusAction(dbClient, TestComponentFinder.from(db), userSession)); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java index dd777aa47c6..3ae7f8d37fa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java @@ -31,6 +31,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -44,10 +45,8 @@ public class SelectActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); @@ -60,7 +59,7 @@ public class SelectActionTest { @Before public void setUp() { - ComponentFinder componentFinder = new ComponentFinder(dbClient); + ComponentFinder componentFinder = TestComponentFinder.from(db); underTest = new SelectAction(dbClient, userSession, componentFinder); ws = new WsActionTester(underTest); project = db.components().insertPrivateProject(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java index 50ff1f7738e..9f3ade74fe6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java @@ -31,7 +31,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.qualityprofile.QualityProfileDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; @@ -60,7 +60,7 @@ public class AddProjectActionTest { private DbClient dbClient = db.getDbClient(); private Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2); private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db)); - private AddProjectAction underTest = new AddProjectAction(dbClient, userSession, languages, new ComponentFinder(dbClient), wsSupport); + private AddProjectAction underTest = new AddProjectAction(dbClient, userSession, languages, TestComponentFinder.from(db), wsSupport); private WsActionTester tester = new WsActionTester(underTest); @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java index e90381ee12b..6af18221f5c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java @@ -24,11 +24,13 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.resources.Languages; +import org.sonar.api.resources.Qualifiers; import org.sonar.api.server.ws.WebService; import org.sonar.api.web.UserRole; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ResourceTypesRule; import org.sonar.db.qualityprofile.QualityProfileDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.exceptions.ForbiddenException; @@ -58,7 +60,8 @@ public class RemoveProjectActionTest { private DbClient dbClient = db.getDbClient(); private Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2); private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db)); - private RemoveProjectAction underTest = new RemoveProjectAction(dbClient, userSession, languages, new ComponentFinder(dbClient), wsSupport); + private RemoveProjectAction underTest = new RemoveProjectAction(dbClient, userSession, languages, + new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)), wsSupport); private WsActionTester tester = new WsActionTester(underTest); @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java index a0f097c0820..0de19099026 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java @@ -36,7 +36,7 @@ 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.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.organization.TestDefaultOrganizationProvider; @@ -74,10 +74,8 @@ public class ListDefinitionsActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); @@ -88,7 +86,7 @@ public class ListDefinitionsActionTest { private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); private SettingsWsSupport support = new SettingsWsSupport(defaultOrganizationProvider, userSession); private WsActionTester ws = new WsActionTester( - new ListDefinitionsAction(dbClient, new ComponentFinder(dbClient), userSession, propertyDefinitions, support)); + new ListDefinitionsAction(dbClient, TestComponentFinder.from(db), userSession, propertyDefinitions, support)); @Before public void setUp() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java index 2410d16610d..dbb33021482 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java @@ -39,6 +39,7 @@ import org.sonar.db.property.PropertyQuery; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserTesting; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.i18n.I18nRule; @@ -62,10 +63,8 @@ public class ResetActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); @@ -74,7 +73,7 @@ public class ResetActionTest { private ComponentDbTester componentDb = new ComponentDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); - private ComponentFinder componentFinder = new ComponentFinder(dbClient); + private ComponentFinder componentFinder = TestComponentFinder.from(db); private PropertyDefinitions definitions = new PropertyDefinitions(); private SettingsUpdater settingsUpdater = new SettingsUpdater(dbClient, definitions); private SettingValidations settingValidations = new SettingValidations(definitions, dbClient, i18n); diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java index 44b20cea5df..dbf371d3e84 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java @@ -46,6 +46,7 @@ import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; import org.sonar.scanner.protocol.GsonHelper; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.i18n.I18nRule; @@ -73,13 +74,13 @@ public class SetActionTest { public ExpectedException expectedException = ExpectedException.none(); @Rule public UserSessionRule userSession = UserSessionRule.standalone().logIn(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); + private PropertyDbTester propertyDb = new PropertyDbTester(db); private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); - private ComponentFinder componentFinder = new ComponentFinder(dbClient); + private ComponentFinder componentFinder = TestComponentFinder.from(db); private I18nRule i18n = new I18nRule(); private PropertyDefinitions definitions = new PropertyDefinitions(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index 7f2820b8a14..c7c072ebaa4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -40,7 +40,7 @@ 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.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.organization.TestDefaultOrganizationProvider; @@ -75,10 +75,8 @@ public class ValuesActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); @@ -93,7 +91,7 @@ public class ValuesActionTest { private ComponentDto project; private WsActionTester ws = new WsActionTester( - new ValuesAction(dbClient, new ComponentFinder(dbClient), userSession, definitions, settingsFinder, support, scannerSettings)); + new ValuesAction(dbClient, TestComponentFinder.from(db), userSession, definitions, settingsFinder, support, scannerSettings)); @Before public void setUp() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java index e0ee6f3bfa1..eb6e254cf62 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java @@ -27,7 +27,7 @@ import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbTester; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -45,7 +45,6 @@ public class HashActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); - @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); @@ -55,7 +54,7 @@ public class HashActionTest { public void before() { DbClient dbClient = db.getDbClient(); - tester = new WsTester(new SourcesWs(new HashAction(dbClient, userSessionRule, new ComponentFinder(dbClient)))); + tester = new WsTester(new SourcesWs(new HashAction(dbClient, userSessionRule, TestComponentFinder.from(db)))); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/IndexActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/IndexActionTest.java index 9c0f2768270..ea7a6459049 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/IndexActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/IndexActionTest.java @@ -28,7 +28,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.protobuf.DbFileSources; import org.sonar.db.source.FileSourceDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.source.HtmlSourceDecorator; @@ -46,15 +46,13 @@ public class IndexActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public DbTester db = DbTester.create(System2.INSTANCE); WsActionTester tester = new WsActionTester( - new IndexAction(db.getDbClient(), new SourceService(db.getDbClient(), new HtmlSourceDecorator()), userSession, new ComponentFinder(db.getDbClient()))); + new IndexAction(db.getDbClient(), new SourceService(db.getDbClient(), new HtmlSourceDecorator()), userSession, TestComponentFinder.from(db))); @Test public void get_json() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java index 749930e3498..ddd4147a7d5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java @@ -34,7 +34,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.protobuf.DbFileSources; import org.sonar.db.source.FileSourceDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.source.HtmlSourceDecorator; @@ -83,7 +83,7 @@ public class LinesActionTest { sourceService = new SourceService(dbTester.getDbClient(), htmlSourceDecorator); componentDao = new ComponentDao(); wsTester = new WsTester(new SourcesWs( - new LinesAction(new ComponentFinder(dbTester.getDbClient()), dbTester.getDbClient(), sourceService, htmlSourceDecorator, userSessionRule))); + new LinesAction(TestComponentFinder.from(dbTester), dbTester.getDbClient(), sourceService, htmlSourceDecorator, userSessionRule))); project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), PROJECT_UUID); file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/RawActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/RawActionTest.java index 52d764e9669..a6dac2f6a9d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/RawActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/RawActionTest.java @@ -26,12 +26,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.sonar.api.resources.Qualifiers; import org.sonar.api.web.UserRole; import org.sonar.db.DbClient; import org.sonar.db.DbSession; 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; @@ -70,7 +72,8 @@ public class RawActionTest { public void setUp() { when(dbClient.componentDao()).thenReturn(componentDao); when(dbClient.openSession(false)).thenReturn(session); - tester = new WsTester(new SourcesWs(new RawAction(dbClient, sourceService, userSessionRule, new ComponentFinder(dbClient)))); + tester = new WsTester(new SourcesWs(new RawAction(dbClient, sourceService, userSessionRule, + new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT))))); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java index 23cb2b7effe..636a521fc51 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java @@ -33,7 +33,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.protobuf.DbFileSources; import org.sonar.db.source.FileSourceDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.source.HtmlSourceDecorator; import org.sonar.server.source.SourceService; @@ -61,7 +61,7 @@ public class ScmActionTest { @Before public void setUp() { tester = new WsTester( - new SourcesWs(new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()), userSessionRule, new ComponentFinder(dbClient)))); + new SourcesWs(new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()), userSessionRule, TestComponentFinder.from(dbTester)))); project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), PROJECT_UUID); file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY); diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java index 42c34112420..0364186f084 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java @@ -26,12 +26,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.sonar.api.resources.Qualifiers; import org.sonar.api.web.UserRole; import org.sonar.db.DbClient; import org.sonar.db.DbSession; 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; @@ -72,7 +74,8 @@ public class ShowActionTest { public void setUp() { when(dbClient.componentDao()).thenReturn(componentDao); when(dbClient.openSession(false)).thenReturn(session); - tester = new WsTester(new SourcesWs(new ShowAction(sourceService, dbClient, userSessionRule, new ComponentFinder(dbClient)))); + tester = new WsTester(new SourcesWs(new ShowAction(sourceService, dbClient, userSessionRule, + new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT))))); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java index 9420aa0dda9..87d3d72e8d8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java @@ -30,7 +30,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.protobuf.DbFileSources; import org.sonar.db.source.FileSourceDto; -import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -78,7 +78,7 @@ public class ListActionTest { private ComponentDto mainFile; private ComponentDto testFile; - private WsActionTester ws = new WsActionTester(new ListAction(dbClient, testIndex, userSessionRule, new ComponentFinder(dbClient))); + private WsActionTester ws = new WsActionTester(new ListAction(dbClient, testIndex, userSessionRule, TestComponentFinder.from(db))); @Before public void setUp() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index e1d07d42b6f..74ad74ed8f9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -505,7 +505,7 @@ public class ComponentActionTest { }}); pageRepository.start(); ws = new WsActionTester( - new ComponentAction(dbClient, pageRepository, resourceTypes, userSession, new ComponentFinder(dbClient), + new ComponentAction(dbClient, pageRepository, resourceTypes, userSession, new ComponentFinder(dbClient, resourceTypes), new QualityGateFinder(dbClient), billingValidations)); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java index 307993ffb59..34528ec49e1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java @@ -32,6 +32,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.webhook.WebhookDeliveryDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.tester.UserSessionRule; @@ -59,7 +60,7 @@ public class WebhookDeliveriesActionTest { @Before public void setUp() { - ComponentFinder componentFinder = new ComponentFinder(dbClient); + ComponentFinder componentFinder = TestComponentFinder.from(db); WebhookDeliveriesAction underTest = new WebhookDeliveriesAction(dbClient, userSession, componentFinder); ws = new WsActionTester(underTest); project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("my-project")); diff --git a/server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java index 057b3cc094a..b9fa4d05adc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java @@ -32,6 +32,7 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.webhook.WebhookDeliveryDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; @@ -61,7 +62,7 @@ public class WebhookDeliveryActionTest { @Before public void setUp() { - ComponentFinder componentFinder = new ComponentFinder(dbClient); + ComponentFinder componentFinder = TestComponentFinder.from(db); WebhookDeliveryAction underTest = new WebhookDeliveryAction(dbClient, userSession, componentFinder); ws = new WsActionTester(underTest); project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.organizations().insert()).setKey("my-project")); |