From c043d942075a8abe288d20974406afd265f4249d Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 21 Jul 2017 09:59:28 +0200 Subject: [PATCH] SONAR-8918 Fix api/qualityprofile/search when no language available --- .../db/qualityprofile/QualityProfileDao.java | 4 +- .../qualityprofile/QualityProfileDaoTest.java | 5 ++- .../qualityprofile/ws/SearchActionTest.java | 39 +++++++++++++++---- 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 selectDefaultProfiles(DbSession dbSession, OrganizationDto organization, Collection 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 selectAssociatedToProjectUuidAndLanguages(DbSession dbSession, ComponentDto project, Collection languages) { - return mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.uuid(), languages); + return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.uuid(), partition)); } public List 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 sharedData = createSharedData(); + createSharedData(); List 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 @@ -121,6 +121,23 @@ public class SearchActionTest { assertThat(profileName.description()).isEqualTo("Profile name"); } + @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(); @@ -288,6 +305,21 @@ public class SearchActionTest { .doesNotContain(defaultProfileOnXoo1.getKee(), profileOnXoo1.getKee()); } + @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); @@ -356,13 +388,6 @@ public class SearchActionTest { .containsExactlyInAnyOrder(tuple(true, 2L), tuple(false, 0L)); } - @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(); -- 2.39.5