rather than passing them as method parameterstags/6.5-M1
@@ -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); |
@@ -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) { |
@@ -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 { |
@@ -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() { |
@@ -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 |
@@ -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() { |
@@ -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)); | |||
} | |||
} |
@@ -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 |
@@ -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 { |
@@ -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); | |||
} |
@@ -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(); |
@@ -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() { |
@@ -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() { |
@@ -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") |
@@ -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); | |||
} |
@@ -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); | |||
@@ -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() { |
@@ -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 |
@@ -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; |
@@ -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); | |||
} | |||
@@ -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); | |||
} | |||
@@ -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() { |
@@ -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)); | |||
} | |||
@@ -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)); |
@@ -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))); | |||
} |
@@ -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() { |
@@ -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); | |||
@@ -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() { |
@@ -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); | |||
} |
@@ -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); | |||
} |
@@ -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() { |
@@ -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); | |||
@@ -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() { |
@@ -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 |
@@ -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(); |
@@ -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 |
@@ -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 |
@@ -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 { |
@@ -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); |
@@ -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(); |
@@ -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 { |
@@ -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 |
@@ -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 { |
@@ -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); | |||
} |
@@ -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 |
@@ -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); |
@@ -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 |
@@ -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 { |
@@ -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)); | |||
} | |||
@@ -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")); |
@@ -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")); |