diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-05-19 14:29:20 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-06-09 08:26:48 +0200 |
commit | b1072e470eeeed332b9f6ef5b221486712648749 (patch) | |
tree | 5f43747aee7771701f9285a89a9ff5a114f92169 /server/sonar-server | |
parent | b6ad5cfbba96fd03e03ec12a2fd45b96874368c3 (diff) | |
download | sonarqube-b1072e470eeeed332b9f6ef5b221486712648749.tar.gz sonarqube-b1072e470eeeed332b9f6ef5b221486712648749.zip |
SONAR-9245 facet new_security_rating in search_projects WS
Diffstat (limited to 'server/sonar-server')
4 files changed, 115 insertions, 183 deletions
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 3e2b76526ea..3ba1ba13a3d 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 @@ -66,6 +66,7 @@ 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_RELIABILITY_RATING_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY; @@ -93,6 +94,7 @@ public class ProjectMeasuresIndex { RELIABILITY_RATING_KEY, NEW_RELIABILITY_RATING_KEY, SECURITY_RATING_KEY, + NEW_SECURITY_RATING_KEY, ALERT_STATUS_KEY, FILTER_LANGUAGES, FILTER_TAGS); @@ -108,6 +110,7 @@ public class ProjectMeasuresIndex { .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)) + .put(NEW_SECURITY_RATING_KEY, (esSearch, query, facetBuilder) -> addRatingFacet(esSearch, NEW_SECURITY_RATING_KEY, facetBuilder)) .put(ALERT_STATUS_KEY, (esSearch, query, facetBuilder) -> esSearch.addAggregation(createStickyFacet(ALERT_STATUS_KEY, facetBuilder, createQualityGateFacet()))) .put(FILTER_LANGUAGES, ProjectMeasuresIndex::addLanguagesFacet) .put(FIELD_TAGS, ProjectMeasuresIndex::addTagsFacet) 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 5344cb879ec..9697fc92644 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 @@ -20,6 +20,9 @@ package org.sonar.server.component.ws; import com.google.common.base.Joiner; +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.util.Arrays; import java.util.Date; import java.util.function.Consumer; @@ -28,6 +31,7 @@ import java.util.stream.Stream; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; import org.sonar.api.config.MapSettings; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.WebService; @@ -64,7 +68,10 @@ 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_RELIABILITY_RATING_KEY; +import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY; +import static org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY; +import static org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY; import static org.sonar.api.measures.Metric.ValueType.INT; import static org.sonar.api.measures.Metric.ValueType.LEVEL; import static org.sonar.api.server.ws.WebService.Param.ASCENDING; @@ -84,6 +91,7 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORG import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES; import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS; +@RunWith(DataProviderRunner.class) public class SearchProjectsActionTest { private static final String NCLOC = "ncloc"; @@ -100,6 +108,16 @@ public class SearchProjectsActionTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); + @DataProvider + public static Object[][] rating_metric_keys() { + return new Object[][] {{SQALE_RATING_KEY}, {RELIABILITY_RATING_KEY}, {SECURITY_RATING_KEY}}; + } + + @DataProvider + public static Object[][] new_rating_metric_keys() { + return new Object[][] {{NEW_RELIABILITY_RATING_KEY}, {NEW_SECURITY_RATING_KEY}}; + } + private DbClient dbClient = db.getDbClient(); private DbSession dbSession = db.getSession(); @@ -148,7 +166,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"); + "languages", "tags", "new_reliability_rating", "new_security_rating"); } @Test @@ -293,29 +311,31 @@ public class SearchProjectsActionTest { } @Test - public void filter_projects_by_reliability_rating() { + @UseDataProvider("rating_metric_keys") + public void filter_projects_by_rating(String metricKey) { userSession.logIn(); OrganizationDto organizationDto = db.organizations().insert(); - MetricDto reliabilityRating = db.measureDbTester().insertMetric(c -> c.setKey(RELIABILITY_RATING_KEY).setValueType(INT.name())); - ComponentDto project1 = insertProject(organizationDto, new Measure(reliabilityRating, c -> c.setValue(1d))); - ComponentDto project2 = insertProject(organizationDto, new Measure(reliabilityRating, c -> c.setValue(2d))); - ComponentDto project3 = insertProject(organizationDto, new Measure(reliabilityRating, c -> c.setValue(3d))); + MetricDto ratingMetric = db.measureDbTester().insertMetric(c -> c.setKey(metricKey).setValueType(INT.name())); + ComponentDto project1 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(1d))); + ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(2d))); + ComponentDto project3 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(3d))); - SearchProjectsWsResponse result = call(request.setFilter("reliability_rating = 2")); + SearchProjectsWsResponse result = call(request.setFilter(metricKey + " = 2")); assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getKey()); } @Test - public void filter_projects_by_new_reliability_rating() { + @UseDataProvider("new_rating_metric_keys") + public void filter_projects_by_new_rating(String newMetricKey) { userSession.logIn(); OrganizationDto organizationDto = db.organizations().insert(); - MetricDto newReliabilityRating = db.measureDbTester().insertMetric(c -> c.setKey(NEW_RELIABILITY_RATING_KEY).setValueType(INT.name())); - ComponentDto project1 = insertProject(organizationDto, new Measure(newReliabilityRating, c -> c.setVariation(1d))); - ComponentDto project2 = insertProject(organizationDto, new Measure(newReliabilityRating, c -> c.setVariation(2d))); - ComponentDto project3 = insertProject(organizationDto, new Measure(newReliabilityRating, c -> c.setVariation(3d))); + MetricDto ratingMetric = db.measureDbTester().insertMetric(c -> c.setKey(newMetricKey).setValueType(INT.name())); + ComponentDto project1 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(1d))); + ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(2d))); + ComponentDto project3 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(3d))); - SearchProjectsWsResponse result = call(request.setFilter("new_reliability_rating = 2")); + SearchProjectsWsResponse result = call(request.setFilter(newMetricKey + " = 2")); assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getKey()); } @@ -547,19 +567,20 @@ public class SearchProjectsActionTest { } @Test - public void return_reliability_rating_facet() throws Exception { + @UseDataProvider("rating_metric_keys") + public void return_rating_facet(String ratingMetricKey) throws Exception { userSession.logIn(); OrganizationDto organization = db.organizations().insert(); - MetricDto reliabilityRating = db.measureDbTester().insertMetric(c -> c.setKey(RELIABILITY_RATING_KEY).setValueType(RATING.name())); - insertProject(organization, new Measure(reliabilityRating, c -> c.setValue(1d))); - insertProject(organization, new Measure(reliabilityRating, c -> c.setValue(1d))); - insertProject(organization, new Measure(reliabilityRating, c -> c.setValue(3d))); - insertProject(organization, new Measure(reliabilityRating, c -> c.setValue(5d))); + MetricDto ratingMetric = db.measureDbTester().insertMetric(c -> c.setKey(ratingMetricKey).setValueType(RATING.name())); + insertProject(organization, new Measure(ratingMetric, c -> c.setValue(1d))); + insertProject(organization, new Measure(ratingMetric, c -> c.setValue(1d))); + insertProject(organization, new Measure(ratingMetric, c -> c.setValue(3d))); + insertProject(organization, new Measure(ratingMetric, c -> c.setValue(5d))); - SearchProjectsWsResponse result = call(request.setFacets(singletonList(RELIABILITY_RATING_KEY))); + SearchProjectsWsResponse result = call(request.setFacets(singletonList(ratingMetricKey))); Common.Facet facet = result.getFacets().getFacetsList().stream() - .filter(oneFacet -> RELIABILITY_RATING_KEY.equals(oneFacet.getProperty())) + .filter(oneFacet -> ratingMetricKey.equals(oneFacet.getProperty())) .findFirst().orElseThrow(IllegalStateException::new); assertThat(facet.getValuesList()) .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) @@ -572,19 +593,20 @@ public class SearchProjectsActionTest { } @Test - public void return_new_reliability_rating_facet() throws Exception { + @UseDataProvider("new_rating_metric_keys") + public void return_new_rating_facet(String newRatingMetricKey) throws Exception { userSession.logIn(); OrganizationDto organization = db.organizations().insert(); - MetricDto newReliabilityRating = db.measureDbTester().insertMetric(c -> c.setKey(NEW_RELIABILITY_RATING_KEY).setValueType(RATING.name())); - insertProject(organization, new Measure(newReliabilityRating, c -> c.setVariation(1d))); - insertProject(organization, new Measure(newReliabilityRating, c -> c.setVariation(1d))); - insertProject(organization, new Measure(newReliabilityRating, c -> c.setVariation(3d))); - insertProject(organization, new Measure(newReliabilityRating, c -> c.setVariation(5d))); + MetricDto newRatingMetric = db.measureDbTester().insertMetric(c -> c.setKey(newRatingMetricKey).setValueType(RATING.name())); + insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(1d))); + insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(1d))); + insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(3d))); + insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(5d))); - SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_RELIABILITY_RATING_KEY))); + SearchProjectsWsResponse result = call(request.setFacets(singletonList(newRatingMetricKey))); Common.Facet facet = result.getFacets().getFacetsList().stream() - .filter(oneFacet -> NEW_RELIABILITY_RATING_KEY.equals(oneFacet.getProperty())) + .filter(oneFacet -> newRatingMetricKey.equals(oneFacet.getProperty())) .findFirst().orElseThrow(IllegalStateException::new); assertThat(facet.getValuesList()) .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) 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 2276b5edf5a..d25bf19031a 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 @@ -21,6 +21,9 @@ package org.sonar.server.measure.index; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; @@ -29,6 +32,7 @@ import java.util.stream.IntStream; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; import org.sonar.api.config.MapSettings; import org.sonar.api.resources.Qualifiers; import org.sonar.db.component.ComponentDto; @@ -65,12 +69,14 @@ import static org.sonar.db.user.UserTesting.newUserDto; import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_TAGS; import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.INDEX_TYPE_PROJECT_MEASURES; +@RunWith(DataProviderRunner.class) public class ProjectMeasuresIndexTest { private static final String MAINTAINABILITY_RATING = "sqale_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"; + private static final String NEW_SECURITY_RATING = "new_security_rating"; private static final String COVERAGE = "coverage"; private static final String DUPLICATION = "duplicated_lines_density"; private static final String NCLOC = "ncloc"; @@ -94,6 +100,11 @@ public class ProjectMeasuresIndexTest { @Rule public UserSessionRule userSession = UserSessionRule.standalone(); + @DataProvider + public static Object[][] rating_metric_keys() { + return new Object[][] {{MAINTAINABILITY_RATING}, {RELIABILITY_RATING}, {NEW_RELIABILITY_RATING}, {SECURITY_RATING}, {NEW_SECURITY_RATING}}; + } + private ProjectMeasuresIndexer projectMeasureIndexer = new ProjectMeasuresIndexer(null, es.client()); private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, projectMeasureIndexer); private ProjectMeasuresIndex underTest = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession)); @@ -727,33 +738,34 @@ public class ProjectMeasuresIndexTest { } @Test - public void facet_maintainability_rating() { + @UseDataProvider("rating_metric_keys") + public void facet_on_rating(String metricKey) { index( // 3 docs with rating A - newDoc(MAINTAINABILITY_RATING, 1d), - newDoc(MAINTAINABILITY_RATING, 1d), - newDoc(MAINTAINABILITY_RATING, 1d), + newDoc(metricKey, 1d), + newDoc(metricKey, 1d), + newDoc(metricKey, 1d), // 2 docs with rating B - newDoc(MAINTAINABILITY_RATING, 2d), - newDoc(MAINTAINABILITY_RATING, 2d), + newDoc(metricKey, 2d), + newDoc(metricKey, 2d), // 4 docs with rating C - newDoc(MAINTAINABILITY_RATING, 3d), - newDoc(MAINTAINABILITY_RATING, 3d), - newDoc(MAINTAINABILITY_RATING, 3d), - newDoc(MAINTAINABILITY_RATING, 3d), + newDoc(metricKey, 3d), + newDoc(metricKey, 3d), + newDoc(metricKey, 3d), + newDoc(metricKey, 3d), // 2 docs with rating D - newDoc(MAINTAINABILITY_RATING, 4d), - newDoc(MAINTAINABILITY_RATING, 4d), + newDoc(metricKey, 4d), + newDoc(metricKey, 4d), // 5 docs with rating E - newDoc(MAINTAINABILITY_RATING, 5d), - newDoc(MAINTAINABILITY_RATING, 5d), - newDoc(MAINTAINABILITY_RATING, 5d), - newDoc(MAINTAINABILITY_RATING, 5d), - newDoc(MAINTAINABILITY_RATING, 5d)); + newDoc(metricKey, 5d), + newDoc(metricKey, 5d), + newDoc(metricKey, 5d), + newDoc(metricKey, 5d), + newDoc(metricKey, 5d)); - Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets(); + Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(metricKey)).getFacets(); - assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly( + assertThat(facets.get(metricKey)).containsExactly( entry("1", 3L), entry("2", 2L), entry("3", 4L), @@ -762,34 +774,35 @@ public class ProjectMeasuresIndexTest { } @Test - public void facet_maintainability_rating_is_sticky() { + @UseDataProvider("rating_metric_keys") + public void facet_on_rating_is_sticky(String metricKey) { index( // docs with rating A - newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 100d, COVERAGE, 0d), - newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 200d, COVERAGE, 0d), - newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 999d, COVERAGE, 0d), + newDoc(metricKey, 1d, NCLOC, 100d, COVERAGE, 0d), + newDoc(metricKey, 1d, NCLOC, 200d, COVERAGE, 0d), + newDoc(metricKey, 1d, NCLOC, 999d, COVERAGE, 0d), // docs with rating B - newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 2000d, COVERAGE, 0d), - newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 5000d, COVERAGE, 0d), + newDoc(metricKey, 2d, NCLOC, 2000d, COVERAGE, 0d), + newDoc(metricKey, 2d, NCLOC, 5000d, COVERAGE, 0d), // docs with rating C - newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 20000d, COVERAGE, 0d), - newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 30000d, COVERAGE, 0d), - newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 40000d, COVERAGE, 0d), - newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 50000d, COVERAGE, 0d), + newDoc(metricKey, 3d, NCLOC, 20000d, COVERAGE, 0d), + newDoc(metricKey, 3d, NCLOC, 30000d, COVERAGE, 0d), + newDoc(metricKey, 3d, NCLOC, 40000d, COVERAGE, 0d), + newDoc(metricKey, 3d, NCLOC, 50000d, COVERAGE, 0d), // docs with rating D - newDoc(MAINTAINABILITY_RATING, 4d, NCLOC, 120000d, COVERAGE, 0d), + newDoc(metricKey, 4d, NCLOC, 120000d, COVERAGE, 0d), // docs with rating E - newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 600000d, COVERAGE, 40d), - newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 700000d, COVERAGE, 50d), - newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 800000d, COVERAGE, 60d)); + newDoc(metricKey, 5d, NCLOC, 600000d, COVERAGE, 40d), + newDoc(metricKey, 5d, NCLOC, 700000d, COVERAGE, 50d), + newDoc(metricKey, 5d, NCLOC, 800000d, COVERAGE, 60d)); Facets facets = underTest.search(new ProjectMeasuresQuery() - .addMetricCriterion(new MetricCriterion(MAINTAINABILITY_RATING, Operator.LT, 3d)) + .addMetricCriterion(new MetricCriterion(metricKey, Operator.LT, 3d)) .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)), - new SearchOptions().addFacets(MAINTAINABILITY_RATING, NCLOC)).getFacets(); + new SearchOptions().addFacets(metricKey, NCLOC)).getFacets(); // Sticky facet on maintainability rating does not take into account maintainability rating filter - assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly( + assertThat(facets.get(metricKey)).containsExactly( entry("1", 3L), entry("2", 2L), entry("3", 4L), @@ -805,30 +818,31 @@ public class ProjectMeasuresIndexTest { } @Test - public void facet_maintainability_rating_contains_only_projects_authorized_for_user() throws Exception { + @UseDataProvider("rating_metric_keys") + public void facet_on_rating_contains_only_projects_authorized_for_user(String metricKey) throws Exception { // User can see these projects indexForUser(USER1, // 3 docs with rating A - newDoc(MAINTAINABILITY_RATING, 1d), - newDoc(MAINTAINABILITY_RATING, 1d), - newDoc(MAINTAINABILITY_RATING, 1d), + newDoc(metricKey, 1d), + newDoc(metricKey, 1d), + newDoc(metricKey, 1d), // 2 docs with rating B - newDoc(MAINTAINABILITY_RATING, 2d), - newDoc(MAINTAINABILITY_RATING, 2d)); + newDoc(metricKey, 2d), + newDoc(metricKey, 2d)); // User cannot see these projects indexForUser(USER2, // docs with rating C - newDoc(MAINTAINABILITY_RATING, 3d), + newDoc(metricKey, 3d), // docs with rating D - newDoc(MAINTAINABILITY_RATING, 4d), + newDoc(metricKey, 4d), // docs with rating E - newDoc(MAINTAINABILITY_RATING, 5d)); + newDoc(metricKey, 5d)); userSession.logIn(USER1); - Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets(); + Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(metricKey)).getFacets(); - assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly( + assertThat(facets.get(metricKey)).containsExactly( entry("1", 3L), entry("2", 2L), entry("3", 0L), @@ -837,111 +851,6 @@ public class ProjectMeasuresIndexTest { } @Test - public void facet_reliability_rating() { - index( - // 3 docs with rating A - newDoc(RELIABILITY_RATING, 1d), - newDoc(RELIABILITY_RATING, 1d), - newDoc(RELIABILITY_RATING, 1d), - // 2 docs with rating B - newDoc(RELIABILITY_RATING, 2d), - newDoc(RELIABILITY_RATING, 2d), - // 4 docs with rating C - newDoc(RELIABILITY_RATING, 3d), - newDoc(RELIABILITY_RATING, 3d), - newDoc(RELIABILITY_RATING, 3d), - newDoc(RELIABILITY_RATING, 3d), - // 2 docs with rating D - newDoc(RELIABILITY_RATING, 4d), - newDoc(RELIABILITY_RATING, 4d), - // 5 docs with rating E - newDoc(RELIABILITY_RATING, 5d), - newDoc(RELIABILITY_RATING, 5d), - newDoc(RELIABILITY_RATING, 5d), - newDoc(RELIABILITY_RATING, 5d), - newDoc(RELIABILITY_RATING, 5d)); - - Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(RELIABILITY_RATING)).getFacets(); - - assertThat(facets.get(RELIABILITY_RATING)).containsExactly( - entry("1", 3L), - entry("2", 2L), - entry("3", 4L), - entry("4", 2L), - entry("5", 5L)); - } - - @Test - public void facet_new_reliability_rating() { - index( - // 3 docs with rating A - newDoc(NEW_RELIABILITY_RATING, 1d), - newDoc(NEW_RELIABILITY_RATING, 1d), - newDoc(NEW_RELIABILITY_RATING, 1d), - // 2 docs with rating B - newDoc(NEW_RELIABILITY_RATING, 2d), - newDoc(NEW_RELIABILITY_RATING, 2d), - // 4 docs with rating C - newDoc(NEW_RELIABILITY_RATING, 3d), - newDoc(NEW_RELIABILITY_RATING, 3d), - newDoc(NEW_RELIABILITY_RATING, 3d), - newDoc(NEW_RELIABILITY_RATING, 3d), - // 2 docs with rating D - newDoc(NEW_RELIABILITY_RATING, 4d), - newDoc(NEW_RELIABILITY_RATING, 4d), - // 5 docs with rating E - newDoc(NEW_RELIABILITY_RATING, 5d), - newDoc(NEW_RELIABILITY_RATING, 5d), - newDoc(NEW_RELIABILITY_RATING, 5d), - newDoc(NEW_RELIABILITY_RATING, 5d), - newDoc(NEW_RELIABILITY_RATING, 5d)); - - Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(NEW_RELIABILITY_RATING)).getFacets(); - - assertThat(facets.get(NEW_RELIABILITY_RATING)).containsExactly( - entry("1", 3L), - entry("2", 2L), - entry("3", 4L), - entry("4", 2L), - entry("5", 5L)); - } - - @Test - public void facet_security_rating() { - index( - // 3 docs with rating A - newDoc(SECURITY_RATING, 1.0d), - newDoc(SECURITY_RATING, 1.0d), - newDoc(SECURITY_RATING, 1.0d), - // 2 docs with rating B - newDoc(SECURITY_RATING, 2.0d), - newDoc(SECURITY_RATING, 2.0d), - // 4 docs with rating C - newDoc(SECURITY_RATING, 3.0d), - newDoc(SECURITY_RATING, 3.0d), - newDoc(SECURITY_RATING, 3.0d), - newDoc(SECURITY_RATING, 3.0d), - // 2 docs with rating D - newDoc(SECURITY_RATING, 4.0d), - newDoc(SECURITY_RATING, 4.0d), - // 5 docs with rating E - newDoc(SECURITY_RATING, 5.0d), - newDoc(SECURITY_RATING, 5.0d), - newDoc(SECURITY_RATING, 5.0d), - newDoc(SECURITY_RATING, 5.0d), - newDoc(SECURITY_RATING, 5.0d)); - - Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(SECURITY_RATING)).getFacets(); - - assertThat(facets.get(SECURITY_RATING)).containsExactly( - entry("1", 3L), - entry("2", 2L), - entry("3", 4L), - entry("4", 2L), - entry("5", 5L)); - } - - @Test public void facet_quality_gate() { index( // 2 docs with QG OK diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java index def243184f8..9461055492f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java @@ -49,8 +49,6 @@ import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIEL import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_TAGS; import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.INDEX_TYPE_PROJECT_MEASURES; -; - public class ProjectMeasuresIndexerTest { private System2 system2 = System2.INSTANCE; |