From 226049fc27425f1dc7a7232864fe5da5f93eb022 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 19 May 2017 16:58:47 +0200 Subject: [PATCH] SONAR-9245 facet new_maintainability_rating in search_projects WS --- .../test/java/it/projectSearch/SearchProjectsTest.java | 8 +++++++- .../sonar/server/measure/index/ProjectMeasuresIndex.java | 3 +++ .../server/component/ws/SearchProjectsActionTest.java | 5 +++-- .../server/measure/index/ProjectMeasuresIndexTest.java | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java b/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java index 048cafe626b..1f6e2c9cae9 100644 --- a/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java +++ b/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java @@ -200,7 +200,7 @@ public class SearchProjectsTest { analyzeProject(projectKey, "shared/xoo-history-v2"); SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().setOrganization(organizationKey).setFacets(asList( - "new_reliability_rating", "new_security_rating")).build()); + "new_reliability_rating", "new_security_rating", "new_maintainability_rating")).build()); checkFacet(response, "new_reliability_rating", tuple("1", 1L), @@ -214,6 +214,12 @@ public class SearchProjectsTest { tuple("3", 0L), tuple("4", 0L), tuple("5", 0L)); + checkFacet(response, "new_maintainability_rating", + tuple("1", 1L), + tuple("2", 0L), + tuple("3", 0L), + tuple("4", 0L), + tuple("5", 0L)); } private void checkFacet(SearchProjectsWsResponse response, String facetKey, Tuple... values) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java b/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java index 3ba1ba13a3d..e548ddec2ec 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java @@ -65,6 +65,7 @@ import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY; import static org.sonar.api.measures.CoreMetrics.COVERAGE_KEY; import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY; import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY; @@ -91,6 +92,7 @@ public class ProjectMeasuresIndex { DUPLICATED_LINES_DENSITY_KEY, COVERAGE_KEY, SQALE_RATING_KEY, + NEW_MAINTAINABILITY_RATING_KEY, RELIABILITY_RATING_KEY, NEW_RELIABILITY_RATING_KEY, SECURITY_RATING_KEY, @@ -107,6 +109,7 @@ public class ProjectMeasuresIndex { .put(DUPLICATED_LINES_DENSITY_KEY, (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, DUPLICATED_LINES_DENSITY_KEY, facetBuilder, 3d, 5d, 10d, 20d)) .put(COVERAGE_KEY, (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, COVERAGE_KEY, facetBuilder, 30d, 50d, 70d, 80d)) .put(SQALE_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, SQALE_RATING_KEY, facetBuilder)) + .put(NEW_MAINTAINABILITY_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, NEW_MAINTAINABILITY_RATING_KEY, facetBuilder)) .put(RELIABILITY_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, RELIABILITY_RATING_KEY, facetBuilder)) .put(NEW_RELIABILITY_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, NEW_RELIABILITY_RATING_KEY, facetBuilder)) .put(SECURITY_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, SECURITY_RATING_KEY, facetBuilder)) diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index 9697fc92644..398f78ab8a9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -67,6 +67,7 @@ import static java.util.Optional.ofNullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY; @@ -115,7 +116,7 @@ public class SearchProjectsActionTest { @DataProvider public static Object[][] new_rating_metric_keys() { - return new Object[][] {{NEW_RELIABILITY_RATING_KEY}, {NEW_SECURITY_RATING_KEY}}; + return new Object[][] {{NEW_MAINTAINABILITY_RATING_KEY}, {NEW_RELIABILITY_RATING_KEY}, {NEW_SECURITY_RATING_KEY}}; } private DbClient dbClient = db.getDbClient(); @@ -166,7 +167,7 @@ public class SearchProjectsActionTest { Param facets = def.param("facets"); assertThat(facets.defaultValue()).isNull(); assertThat(facets.possibleValues()).containsOnly("ncloc", "duplicated_lines_density", "coverage", "sqale_rating", "reliability_rating", "security_rating", "alert_status", - "languages", "tags", "new_reliability_rating", "new_security_rating"); + "languages", "tags", "new_reliability_rating", "new_security_rating", "new_maintainability_rating"); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java index d25bf19031a..87734139552 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java @@ -73,6 +73,7 @@ import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.INDE public class ProjectMeasuresIndexTest { private static final String MAINTAINABILITY_RATING = "sqale_rating"; + private static final String NEW_MAINTAINABILITY_RATING_KEY = "new_maintainability_rating"; private static final String RELIABILITY_RATING = "reliability_rating"; private static final String NEW_RELIABILITY_RATING = "new_reliability_rating"; private static final String SECURITY_RATING = "security_rating"; @@ -102,7 +103,7 @@ public class ProjectMeasuresIndexTest { @DataProvider public static Object[][] rating_metric_keys() { - return new Object[][] {{MAINTAINABILITY_RATING}, {RELIABILITY_RATING}, {NEW_RELIABILITY_RATING}, {SECURITY_RATING}, {NEW_SECURITY_RATING}}; + return new Object[][] {{MAINTAINABILITY_RATING}, {NEW_MAINTAINABILITY_RATING_KEY}, {RELIABILITY_RATING}, {NEW_RELIABILITY_RATING}, {SECURITY_RATING}, {NEW_SECURITY_RATING}}; } private ProjectMeasuresIndexer projectMeasureIndexer = new ProjectMeasuresIndexer(null, es.client()); -- 2.39.5