diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-07-21 09:59:28 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-07-21 10:40:43 +0200 |
commit | c043d942075a8abe288d20974406afd265f4249d (patch) | |
tree | 2b078d46c36b153e9af082b9b03055e974f25ed7 | |
parent | f1d8457e3eb8d1104f63da028c7aaa8fc83a45c9 (diff) | |
download | sonarqube-c043d942075a8abe288d20974406afd265f4249d.tar.gz sonarqube-c043d942075a8abe288d20974406afd265f4249d.zip |
SONAR-8918 Fix api/qualityprofile/search when no language available
3 files changed, 38 insertions, 10 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java index ee81f42b8d1..094483b18bb 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java @@ -127,7 +127,7 @@ public class QualityProfileDao implements Dao { } public List<QProfileDto> selectDefaultProfiles(DbSession dbSession, OrganizationDto organization, Collection<String> languages) { - return mapper(dbSession).selectDefaultProfiles(organization.getUuid(), languages); + return executeLargeInputs(languages, partition -> mapper(dbSession).selectDefaultProfiles(organization.getUuid(), partition)); } @CheckForNull @@ -141,7 +141,7 @@ public class QualityProfileDao implements Dao { } public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession dbSession, ComponentDto project, Collection<String> languages) { - return mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.uuid(), languages); + return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.uuid(), partition)); } public List<QProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index 3d8255b6005..8c2bab469c1 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -312,7 +312,7 @@ public class QualityProfileDaoTest { @Test public void selectDefaultProfiles() { - List<QProfileDto> sharedData = createSharedData(); + createSharedData(); List<QProfileDto> java = underTest.selectDefaultProfiles(dbSession, organization, singletonList("java")); assertThat(java).extracting(QProfileDto::getKee).containsOnly("java_sonar_way"); @@ -320,6 +320,7 @@ public class QualityProfileDaoTest { assertThat(underTest.selectDefaultProfiles(dbSession, organization, singletonList("js"))).isEmpty(); assertThat(underTest.selectDefaultProfiles(dbSession, organization, of("java", "js"))).extracting(QProfileDto::getKee).containsOnly("java_sonar_way"); assertThat(underTest.selectDefaultProfiles(dbSession, organization, of("js", "java"))).extracting(QProfileDto::getKee).containsOnly("java_sonar_way"); + assertThat(underTest.selectDefaultProfiles(dbSession, organization, Collections.emptyList())).isEmpty(); } @Test @@ -540,6 +541,8 @@ public class QualityProfileDaoTest { .extracting(QProfileDto::getKee).containsExactlyInAnyOrder(javaProfile.getKee(), jsProfile.getKee()); assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project2, singletonList("java"))) .isEmpty(); + assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project2, Collections.emptyList())) + .isEmpty(); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index ab8c20e38e7..96e02b96a42 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -122,6 +122,23 @@ public class SearchActionTest { } @Test + public void no_profile() { + SearchWsResponse result = call(ws.newRequest()); + + assertThat(result.getProfilesList()).isEmpty(); + } + + @Test + public void empty_when_no_language_installed() { + WsActionTester ws = new WsActionTester(new SearchAction(new Languages(), dbClient, qProfileWsSupport, new ComponentFinder(dbClient, null))); + db.qualityProfiles().insert(db.getDefaultOrganization()); + + SearchWsResponse result = call(ws.newRequest()); + + assertThat(result.getProfilesList()).isEmpty(); + } + + @Test public void default_organization() { OrganizationDto defaultOrganization = db.getDefaultOrganization(); OrganizationDto anotherOrganization = db.organizations().insert(); @@ -289,6 +306,21 @@ public class SearchActionTest { } @Test + public void empty_when_filtering_on_project_and_no_language_installed() { + WsActionTester ws = new WsActionTester(new SearchAction(new Languages(), dbClient, qProfileWsSupport, new ComponentFinder(dbClient, null))); + db.qualityProfiles().insert(db.getDefaultOrganization()); + ComponentDto project = db.components().insertPrivateProject(); + QProfileDto profileOnXoo1 = db.qualityProfiles().insert(db.getDefaultOrganization(), q -> q.setLanguage(XOO1.getKey())); + db.qualityProfiles().associateWithProject(project, profileOnXoo1); + + SearchWsResponse result = call(ws.newRequest() + .setParam(PARAM_PROJECT_KEY, project.key()) + .setParam(PARAM_DEFAULTS, "true")); + + assertThat(result.getProfilesList()).isEmpty(); + } + + @Test public void fail_if_project_does_not_exist() { expectedException.expect(NotFoundException.class); expectedException.expectMessage("Component key 'unknown-project' not found"); @@ -357,13 +389,6 @@ public class SearchActionTest { } @Test - public void no_profile() { - SearchWsResponse result = call(ws.newRequest()); - - assertThat(result.getProfilesList()).isEmpty(); - } - - @Test public void map_dates() { long time = DateUtils.parseDateTime("2016-12-22T19:10:03+0100").getTime(); qualityProfileDb.insert(newQualityProfileDto() |