From e3c1868a9b9cd320e4bfbc3dc6b17e9518a92cca Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 27 Jun 2017 11:58:11 +0200 Subject: [PATCH] SONAR-8918 Drop QProfileLookup --- .../platformlevel/PlatformLevel4.java | 6 +- .../server/qualityprofile/QProfileLookup.java | 72 -------- .../qualityprofile/ws/InheritanceAction.java | 32 +++- .../qualityprofile/ws/SearchAction.java | 9 - .../qualityprofile/ws/SearchDataLoader.java | 171 ------------------ .../ws/InheritanceActionTest.java | 2 - .../qualityprofile/ws/QProfilesWsTest.java | 2 +- .../ws/SearchDataLoaderTest.java | 132 -------------- 8 files changed, 29 insertions(+), 397 deletions(-) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index abf786f89c0..8321a4ba0ff 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -47,9 +47,9 @@ import org.sonar.server.component.ws.ComponentsWsModule; import org.sonar.server.debt.DebtModelPluginRepository; import org.sonar.server.debt.DebtModelXMLExporter; import org.sonar.server.debt.DebtRulesXMLImporter; -import org.sonar.server.duplication.ws.ShowResponseBuilder; import org.sonar.server.duplication.ws.DuplicationsParser; import org.sonar.server.duplication.ws.DuplicationsWs; +import org.sonar.server.duplication.ws.ShowResponseBuilder; import org.sonar.server.email.ws.EmailsWsModule; import org.sonar.server.es.IndexCreator; import org.sonar.server.es.IndexDefinitions; @@ -147,7 +147,6 @@ import org.sonar.server.qualityprofile.QProfileComparison; import org.sonar.server.qualityprofile.QProfileCopier; import org.sonar.server.qualityprofile.QProfileExporters; import org.sonar.server.qualityprofile.QProfileFactoryImpl; -import org.sonar.server.qualityprofile.QProfileLookup; import org.sonar.server.qualityprofile.QProfileResetImpl; import org.sonar.server.qualityprofile.RuleActivator; import org.sonar.server.qualityprofile.RuleActivatorContextFactory; @@ -156,7 +155,6 @@ import org.sonar.server.qualityprofile.index.ActiveRuleIteratorFactory; import org.sonar.server.qualityprofile.ws.OldRestoreAction; import org.sonar.server.qualityprofile.ws.ProfilesWs; import org.sonar.server.qualityprofile.ws.QProfilesWsModule; -import org.sonar.server.qualityprofile.ws.SearchDataLoader; import org.sonar.server.root.ws.RootWsModule; import org.sonar.server.rule.CommonRuleDefinitionsImpl; import org.sonar.server.rule.DeprecatedRulesDefinitionLoader; @@ -265,9 +263,7 @@ public class PlatformLevel4 extends PlatformLevel { XMLProfileParser.class, XMLProfileSerializer.class, AnnotationProfileParser.class, - QProfileLookup.class, QProfileComparison.class, - SearchDataLoader.class, ProfilesWs.class, OldRestoreAction.class, RuleActivator.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java deleted file mode 100644 index df0e39812e0..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.qualityprofile; - -import java.util.Collection; -import java.util.List; -import org.sonar.api.server.ServerSide; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.qualityprofile.QProfileDto; - -import static com.google.common.collect.Lists.newArrayList; - -@ServerSide -public class QProfileLookup { - - private final DbClient dbClient; - - public QProfileLookup(DbClient dbClient) { - this.dbClient = dbClient; - } - - public List allProfiles(DbSession dbSession, OrganizationDto organization) { - return dbClient.qualityProfileDao().selectOrderedByOrganizationUuid(dbSession, organization); - } - - public Collection profiles(DbSession dbSession, String language, OrganizationDto organization) { - return dbClient.qualityProfileDao().selectByLanguage(dbSession, organization, language); - } - - public List ancestors(QProfileDto profile, DbSession dbSession) { - List ancestors = newArrayList(); - collectAncestors(profile, ancestors, dbSession); - return ancestors; - } - - private void collectAncestors(QProfileDto profile, List ancestors, DbSession session) { - if (profile.getParentKee() == null) { - return; - } - - QProfileDto parent = getParent(session, profile); - ancestors.add(parent); - collectAncestors(parent, ancestors, session); - } - - private QProfileDto getParent(DbSession dbSession, QProfileDto profile) { - QProfileDto parent = dbClient.qualityProfileDao().selectByUuid(dbSession, profile.getParentKee()); - if (parent == null) { - throw new IllegalStateException("Cannot find parent of profile: " + profile.getKee()); - } - return parent; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java index ec7f3e408af..1dc37834cfc 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java @@ -33,10 +33,10 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.qualityprofile.ActiveRuleDao; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.server.qualityprofile.QProfileLookup; import org.sonarqube.ws.QualityProfiles.InheritanceWsResponse; import org.sonarqube.ws.QualityProfiles.InheritanceWsResponse.QualityProfile; +import static com.google.common.collect.Lists.newArrayList; import static org.sonar.core.util.Protobuf.setNullable; import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; import static org.sonar.server.ws.WsUtils.writeProtobuf; @@ -44,13 +44,11 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf; public class InheritanceAction implements QProfileWsAction { private final DbClient dbClient; - private final QProfileLookup profileLookup; private final QProfileWsSupport wsSupport; private final Languages languages; - public InheritanceAction(DbClient dbClient, QProfileLookup profileLookup, QProfileWsSupport wsSupport, Languages languages) { + public InheritanceAction(DbClient dbClient, QProfileWsSupport wsSupport, Languages languages) { this.dbClient = dbClient; - this.profileLookup = profileLookup; this.wsSupport = wsSupport; this.languages = languages; } @@ -74,7 +72,7 @@ public class InheritanceAction implements QProfileWsAction { try (DbSession dbSession = dbClient.openSession(false)) { QProfileDto profile = wsSupport.getProfile(dbSession, reference); OrganizationDto organization = wsSupport.getOrganization(dbSession, profile); - List ancestors = profileLookup.ancestors(profile, dbSession); + List ancestors = ancestors(profile, dbSession); List children = dbClient.qualityProfileDao().selectChildren(dbSession, profile); Statistics statistics = new Statistics(dbSession, organization); @@ -82,6 +80,30 @@ public class InheritanceAction implements QProfileWsAction { } } + public List ancestors(QProfileDto profile, DbSession dbSession) { + List ancestors = newArrayList(); + collectAncestors(profile, ancestors, dbSession); + return ancestors; + } + + private void collectAncestors(QProfileDto profile, List ancestors, DbSession session) { + if (profile.getParentKee() == null) { + return; + } + + QProfileDto parent = getParent(session, profile); + ancestors.add(parent); + collectAncestors(parent, ancestors, session); + } + + private QProfileDto getParent(DbSession dbSession, QProfileDto profile) { + QProfileDto parent = dbClient.qualityProfileDao().selectByUuid(dbSession, profile.getParentKee()); + if (parent == null) { + throw new IllegalStateException("Cannot find parent of profile: " + profile.getKee()); + } + return parent; + } + private static InheritanceWsResponse buildResponse(QProfileDto profile, List ancestors, List children, Statistics statistics) { return InheritanceWsResponse.newBuilder() .setProfile(buildProfile(profile, statistics)) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java index ccb4d363021..866a33dc734 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java @@ -59,7 +59,6 @@ import static java.util.function.Function.identity; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.core.util.Protobuf.setNullable; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; -import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS; @@ -231,14 +230,6 @@ public class SearchAction implements QProfileWsAction { return Arrays.stream(languages.all()).map(Language::getKey).collect(MoreCollectors.toSet()); } - private ComponentDto getProject(String moduleKey, DbSession dbSession) { - ComponentDto module = checkFoundWithOptional(dbClient.componentDao().selectByKey(dbSession, moduleKey), "Component key '%s' not found", moduleKey); - if (module.isRootProject()) { - return module; - } - return dbClient.componentDao().selectOrFailByUuid(dbSession, module.projectUuid()); - } - private SearchWsResponse buildResponse(SearchData data) { List profiles = data.getProfiles(); Map profilesByKey = profiles.stream().collect(Collectors.toMap(QProfileDto::getKee, identity())); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java deleted file mode 100644 index dcc7f8cadcb..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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.qualityprofile.ws; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Sets; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nullable; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Languages; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.component.ComponentDto; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.qualityprofile.QProfileDto; -import org.sonar.server.qualityprofile.QProfileLookup; -import org.sonarqube.ws.client.qualityprofile.SearchWsRequest; - -import static java.lang.String.format; - -public class SearchDataLoader { - - private static final Comparator Q_PROFILE_COMPARATOR = Comparator - .comparing(QProfileDto::getLanguage) - .thenComparing(QProfileDto::getName); - - private final Languages languages; - private final QProfileLookup profileLookup; - private final DbClient dbClient; - - public SearchDataLoader(Languages languages, QProfileLookup profileLookup, DbClient dbClient) { - this.languages = languages; - this.profileLookup = profileLookup; - this.dbClient = dbClient; - } - - @VisibleForTesting - List findProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, @Nullable ComponentDto project) { - Collection profiles; - if (askDefaultProfiles(request)) { - profiles = findDefaultProfiles(dbSession, request, organization); - } else if (project != null) { - profiles = findProjectProfiles(dbSession, request, organization, project); - } else { - profiles = findAllProfiles(dbSession, request, organization); - } - - return profiles.stream().sorted(Q_PROFILE_COMPARATOR).collect(Collectors.toList()); - } - - private Collection findDefaultProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) { - String profileName = request.getProfileName(); - - Set languageKeys = getLanguageKeys(); - Map qualityProfiles = new HashMap<>(languageKeys.size()); - - Set missingLanguageKeys = lookupByProfileName(dbSession, organization, qualityProfiles, languageKeys, profileName); - Set noDefaultProfileLanguageKeys = lookupDefaults(dbSession, organization, qualityProfiles, missingLanguageKeys); - - if (!noDefaultProfileLanguageKeys.isEmpty()) { - throw new IllegalStateException(format("No quality profile can been found on language(s) '%s'", noDefaultProfileLanguageKeys)); - } - - return qualityProfiles.values(); - } - - private Collection findProjectProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, ComponentDto project) { - String profileName = request.getProfileName(); - - Set languageKeys = getLanguageKeys(); - Map qualityProfiles = new HashMap<>(languageKeys.size()); - - // look up profiles by profileName (if any) for each language - Set unresolvedLanguages = lookupByProfileName(dbSession, organization, qualityProfiles, languageKeys, profileName); - // look up profile by componentKey for each language for which we don't have one yet - Set stillUnresolvedLanguages = lookupByModule(dbSession, qualityProfiles, unresolvedLanguages, project); - // look up profile by default for each language for which we don't have one yet - Set noDefaultProfileLanguages = lookupDefaults(dbSession, organization, qualityProfiles, stillUnresolvedLanguages); - - if (!noDefaultProfileLanguages.isEmpty()) { - throw new IllegalStateException(format("No quality profile can been found on language(s) '%s' for project '%s'", noDefaultProfileLanguages, project.getKey())); - } - - return qualityProfiles.values(); - } - - private Collection findAllProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) { - String language = request.getLanguage(); - - if (language == null) { - return profileLookup.allProfiles(dbSession, organization).stream().filter(qProfile -> languages.get(qProfile.getLanguage()) != null).collect(Collectors.toList()); - } - return profileLookup.profiles(dbSession, language, organization); - } - - private Set lookupByProfileName(DbSession dbSession, OrganizationDto organization, Map qualityProfiles, Set languageKeys, - @Nullable String profileName) { - if (languageKeys.isEmpty() || profileName == null) { - return languageKeys; - } - - dbClient.qualityProfileDao().selectByNameAndLanguages(dbSession, organization, profileName, languageKeys) - .forEach(qualityProfile -> qualityProfiles - .put(qualityProfile.getLanguage(), qualityProfile)); - return difference(languageKeys, qualityProfiles.keySet()); - } - - private Set lookupByModule(DbSession dbSession, Map qualityProfiles, Set languageKeys, - ComponentDto project) { - if (languageKeys.isEmpty()) { - return languageKeys; - } - - dbClient.qualityProfileDao().selectAssociatedToProjectUuidAndLanguages(dbSession, project, languageKeys) - .forEach(qualityProfile -> qualityProfiles.put(qualityProfile.getLanguage(), qualityProfile)); - return difference(languageKeys, qualityProfiles.keySet()); - } - - private Set lookupDefaults(DbSession dbSession, OrganizationDto organization, Map qualityProfiles, Set languageKeys) { - if (languageKeys.isEmpty()) { - return languageKeys; - } - - addAll(qualityProfiles, findDefaultProfiles(dbSession, organization, languageKeys)); - return difference(languageKeys, qualityProfiles.keySet()); - } - - private static Set difference(Set languageKeys, Set set2) { - return Sets.newHashSet(Sets.difference(languageKeys, set2)); - } - - private static void addAll(Map qualityProfiles, Collection list) { - list.forEach(qualityProfile -> qualityProfiles.put(qualityProfile.getLanguage(), qualityProfile)); - } - - private Set getLanguageKeys() { - return Arrays.stream(languages.all()).map(Language::getKey).collect(Collectors.toSet()); - } - - private List findDefaultProfiles(final DbSession dbSession, OrganizationDto organization, Set languageKeys) { - return dbClient.qualityProfileDao().selectDefaultProfiles(dbSession, organization, languageKeys); - } - - private static boolean askDefaultProfiles(SearchWsRequest request) { - return request.getDefaults(); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java index 89a2c524942..df88fa461d7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java @@ -45,7 +45,6 @@ import org.sonar.server.es.EsClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.organization.TestDefaultOrganizationProvider; -import org.sonar.server.qualityprofile.QProfileLookup; import org.sonar.server.qualityprofile.QProfileName; import org.sonar.server.qualityprofile.RuleActivation; import org.sonar.server.qualityprofile.RuleActivator; @@ -96,7 +95,6 @@ public class InheritanceActionTest { TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db); underTest = new InheritanceAction( dbClient, - new QProfileLookup(dbClient), new QProfileWsSupport(dbClient, userSession, defaultOrganizationProvider), new Languages()); ws = new WsActionTester(underTest); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java index 26cd142d965..40fc22c8f41 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java @@ -68,7 +68,7 @@ public class QProfilesWsTest { new CompareAction(null, null, languages), new DeleteAction(languages, null, null, userSessionRule, wsSupport), new ExportersAction(), - new InheritanceAction(null, null, null, languages), + new InheritanceAction(null, null, languages), new RenameAction(dbClient, userSessionRule, wsSupport))).controller(QProfilesWs.API_ENDPOINT); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java deleted file mode 100644 index 55f4c182d47..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchDataLoaderTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.qualityprofile.ws; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.ExpectedException; -import org.sonar.api.resources.Languages; -import org.sonar.api.utils.System2; -import org.sonar.db.DbClient; -import org.sonar.db.DbTester; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.server.component.ComponentFinder; -import org.sonar.server.qualityprofile.QProfileLookup; - -import static org.mockito.Mockito.mock; - -public class SearchDataLoaderTest { - - @Rule - public DbTester dbTester = DbTester.create(System2.INSTANCE); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private Languages languages; - private QProfileLookup profileLookup; - private ComponentFinder componentFinder; - private OrganizationDto organization; - - @Before - public void before() { - organization = dbTester.organizations().insert(); - languages = new Languages(); - DbClient dbClient = dbTester.getDbClient(); - profileLookup = new QProfileLookup(dbClient); - componentFinder = mock(ComponentFinder.class); - } - -// @Test -// public void find_no_profiles_if_database_is_empty() throws Exception { -// assertThat(findProfiles( -// new SearchWsRequest(), -// null)).isEmpty(); -// } -// -// @Test -// public void findAll() throws Exception { -// insertQualityProfile(organization); -// assertThat(findProfiles( -// new SearchWsRequest() -// .setOrganizationKey(organization.getKey()), -// null)).hasSize(1); -// } -// -// @Test -// public void findDefaults() throws Exception { -// QProfileDto profile = insertQualityProfile(organization); -// dbTester.qualityProfiles().setAsDefault(profile); -// assertThat(findProfiles( -// new SearchWsRequest() -// .setOrganizationKey(organization.getKey()) -// .setDefaults(true), -// null)).hasSize(1); -// } -// -// @Test -// public void findForProject() throws Exception { -// QProfileDto profile = insertQualityProfile(organization); -// dbTester.qualityProfiles().setAsDefault(profile); -// ComponentDto project1 = insertProject(); -// assertThat(findProfiles( -// new SearchWsRequest() -// .setOrganizationKey(organization.getKey()), -// project1)).hasSize(1); -// } -// -// @Test -// public void findAllForLanguage() throws Exception { -// QProfileDto profile = insertQualityProfile(organization); -// dbTester.qualityProfiles().setAsDefault(profile); -// assertThat(findProfiles( -// new SearchWsRequest() -// .setOrganizationKey(organization.getKey()) -// .setLanguage(profile.getLanguage()), -// null)).hasSize(1); -// assertThat(findProfiles( -// new SearchWsRequest() -// .setOrganizationKey(organization.getKey()) -// .setLanguage("other language"), -// null)).hasSize(0); -// } -// -// private List findProfiles(SearchWsRequest request, @Nullable ComponentDto project) { -// return new SearchDataLoader(languages, profileLookup, dbTester.getDbClient()) -// .findProfiles(dbTester.getSession(), request, organization, project); -// } -// -// private QProfileDto insertQualityProfile(OrganizationDto organization) { -// Language language = insertLanguage(); -// return dbTester.qualityProfiles().insert(organization, p -> p.setLanguage(language.getKey())); -// } -// -// private Language insertLanguage() { -// Language language = LanguageTesting.newLanguage(randomAlphanumeric(20)); -// languages.add(language); -// return language; -// } -// -// private ComponentDto insertProject() { -// ComponentDto project = dbTester.components().insertPrivateProject(organization); -// doReturn(project).when(componentFinder).getByKey(any(DbSession.class), eq(project.getKey())); -// return project; -// } -} -- 2.39.5