analyzeProject(projectKey, "shared/xoo-history-v2");
SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().setOrganization(organizationKey).setFacets(asList(
- "new_reliability_rating", "new_security_rating", "new_maintainability_rating", "new_coverage", "new_duplicated_lines_density")).build());
+ "new_reliability_rating", "new_security_rating", "new_maintainability_rating", "new_coverage", "new_duplicated_lines_density", "new_lines")).build());
checkFacet(response, "new_reliability_rating",
tuple("1", 1L),
tuple("5.0-10.0", 0L),
tuple("10.0-20.0", 0L),
tuple("20.0-*", 0L));
+ checkFacet(response, "new_lines",
+ tuple("*-1000.0", 0L),
+ tuple("1000.0-10000.0", 0L),
+ tuple("10000.0-100000.0", 0L),
+ tuple("100000.0-500000.0", 0L),
+ tuple("500000.0-*", 0L));
}
private void checkFacet(SearchProjectsWsResponse response, String facetKey, Tuple... values) {
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_LINES_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;
public static final List<String> SUPPORTED_FACETS = ImmutableList.of(
NCLOC_KEY,
+ NEW_LINES_KEY,
DUPLICATED_LINES_DENSITY_KEY,
NEW_DUPLICATED_LINES_DENSITY_KEY,
COVERAGE_KEY,
FILTER_LANGUAGES,
FILTER_TAGS);
+ private static final Double[] LINES_THRESHOLDS = new Double[]{1_000d, 10_000d, 100_000d, 500_000d};
private static final Double[] COVERAGE_THRESHOLDS = new Double[]{30d, 50d, 70d, 80d};
private static final Double[] DUPLICATIONS_THRESHOLDS = new Double[]{3d, 5d, 10d, 20d};
private static final String FIELD_MEASURES_VALUE = FIELD_MEASURES + "." + ProjectMeasuresIndexDefinition.FIELD_MEASURES_VALUE;
private static final Map<String, FacetSetter> FACET_FACTORIES = ImmutableMap.<String, FacetSetter>builder()
- .put(NCLOC_KEY, (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, NCLOC_KEY, facetBuilder, 1_000d, 10_000d, 100_000d, 500_000d))
+ .put(NCLOC_KEY, (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, NCLOC_KEY, facetBuilder, LINES_THRESHOLDS))
+ .put(NEW_LINES_KEY, (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, NEW_LINES_KEY, facetBuilder, LINES_THRESHOLDS))
.put(DUPLICATED_LINES_DENSITY_KEY, (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, DUPLICATED_LINES_DENSITY_KEY, facetBuilder, DUPLICATIONS_THRESHOLDS))
.put(NEW_DUPLICATED_LINES_DENSITY_KEY, (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, NEW_DUPLICATED_LINES_DENSITY_KEY, facetBuilder, DUPLICATIONS_THRESHOLDS))
.put(COVERAGE_KEY, (esSearch, query, facetBuilder) -> addRangeFacet(esSearch, COVERAGE_KEY, facetBuilder, COVERAGE_THRESHOLDS))
import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY;
import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY;
+import static org.sonar.api.measures.CoreMetrics.NEW_LINES_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;
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", "new_maintainability_rating", "new_coverage", "new_duplicated_lines_density");
+ "languages", "tags", "new_reliability_rating", "new_security_rating", "new_maintainability_rating", "new_coverage", "new_duplicated_lines_density", "new_lines");
}
@Test
assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.key());
}
+ @Test
+ public void filter_projects_by_ncloc() {
+ userSession.logIn();
+ OrganizationDto organizationDto = db.organizations().insert();
+ MetricDto ncloc = db.measureDbTester().insertMetric(c -> c.setKey(NCLOC).setValueType(INT.name()));
+ ComponentDto project1 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(80d)));
+ ComponentDto project2 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(85d)));
+ ComponentDto project3 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(10d)));
+
+ SearchProjectsWsResponse result = call(request.setFilter("ncloc <= 80"));
+
+ assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.key());
+ }
+
+ @Test
+ public void filter_projects_by_new_lines() {
+ userSession.logIn();
+ OrganizationDto organizationDto = db.organizations().insert();
+ MetricDto newLines = db.measureDbTester().insertMetric(c -> c.setKey(NEW_LINES_KEY).setValueType(INT.name()));
+ ComponentDto project1 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(80d)));
+ ComponentDto project2 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(85d)));
+ ComponentDto project3 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(10d)));
+
+ SearchProjectsWsResponse result = call(request.setFilter("new_lines <= 80"));
+
+ assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getKey(), project3.key());
+ }
+
@Test
public void filter_projects_by_text_query() {
userSession.logIn();
tuple("20.0-*", 0L));
}
+ @Test
+ public void return_ncloc_facet() {
+ userSession.logIn();
+ OrganizationDto organizationDto = db.organizations().insert();
+ MetricDto coverage = db.measureDbTester().insertMetric(c -> c.setKey(NCLOC).setValueType(INT.name()));
+ insertProject(organizationDto, new Measure(coverage, c -> c.setValue(100d)));
+ insertProject(organizationDto, new Measure(coverage, c -> c.setValue(15_000d)));
+ insertProject(organizationDto, new Measure(coverage, c -> c.setValue(50_000d)));
+
+ SearchProjectsWsResponse result = call(request.setFacets(singletonList(NCLOC)));
+
+ Common.Facet facet = result.getFacets().getFacetsList().stream()
+ .filter(oneFacet -> NCLOC.equals(oneFacet.getProperty()))
+ .findFirst().orElseThrow(IllegalStateException::new);
+ assertThat(facet.getValuesList())
+ .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount)
+ .containsExactly(
+ tuple("*-1000.0", 1L),
+ tuple("1000.0-10000.0", 0L),
+ tuple("10000.0-100000.0", 2L),
+ tuple("100000.0-500000.0", 0L),
+ tuple("500000.0-*", 0L));
+ }
+
+ @Test
+ public void return_new_lines_facet() {
+ userSession.logIn();
+ OrganizationDto organizationDto = db.organizations().insert();
+ MetricDto coverage = db.measureDbTester().insertMetric(c -> c.setKey(NEW_LINES_KEY).setValueType(INT.name()));
+ insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(100d)));
+ insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(15_000d)));
+ insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(50_000d)));
+
+ SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_LINES_KEY)));
+
+ Common.Facet facet = result.getFacets().getFacetsList().stream()
+ .filter(oneFacet -> NEW_LINES_KEY.equals(oneFacet.getProperty()))
+ .findFirst().orElseThrow(IllegalStateException::new);
+ assertThat(facet.getValuesList())
+ .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount)
+ .containsExactly(
+ tuple("*-1000.0", 1L),
+ tuple("1000.0-10000.0", 0L),
+ tuple("10000.0-100000.0", 2L),
+ tuple("100000.0-500000.0", 0L),
+ tuple("500000.0-*", 0L));
+ }
+
@Test
public void default_sort_is_by_ascending_name() throws Exception {
userSession.logIn();
private static final String DUPLICATION = "duplicated_lines_density";
private static final String NEW_DUPLICATION = "new_duplicated_lines_density";
private static final String NCLOC = "ncloc";
+ private static final String NEW_LINES = "new_lines";
private static final String LANGUAGES = "languages";
private static final OrganizationDto ORG = OrganizationTesting.newOrganizationDto();
entry("500000.0-*", 0L));
}
+ @Test
+ public void facet_new_lines() {
+ index(
+ // 3 docs with ncloc<1K
+ newDoc(NEW_LINES, 0d),
+ newDoc(NEW_LINES, 0d),
+ newDoc(NEW_LINES, 999d),
+ // 2 docs with ncloc>=1K and ncloc<10K
+ newDoc(NEW_LINES, 1_000d),
+ newDoc(NEW_LINES, 9_999d),
+ // 4 docs with ncloc>=10K and ncloc<100K
+ newDoc(NEW_LINES, 10_000d),
+ newDoc(NEW_LINES, 10_000d),
+ newDoc(NEW_LINES, 11_000d),
+ newDoc(NEW_LINES, 99_000d),
+ // 2 docs with ncloc>=100K and ncloc<500K
+ newDoc(NEW_LINES, 100_000d),
+ newDoc(NEW_LINES, 499_000d),
+ // 5 docs with ncloc>= 500K
+ newDoc(NEW_LINES, 500_000d),
+ newDoc(NEW_LINES, 100_000_000d),
+ newDoc(NEW_LINES, 500_000d),
+ newDoc(NEW_LINES, 1_000_000d),
+ newDoc(NEW_LINES, 100_000_000_000d));
+
+ Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(NEW_LINES)).getFacets();
+
+ assertThat(facets.get(NEW_LINES)).containsExactly(
+ entry("*-1000.0", 3L),
+ entry("1000.0-10000.0", 2L),
+ entry("10000.0-100000.0", 4L),
+ entry("100000.0-500000.0", 2L),
+ entry("500000.0-*", 5L));
+ }
+
@Test
public void facet_coverage() {
index(