*/
package org.sonar.server.measure.index;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
-import java.time.Instant;
import java.util.Arrays;
-import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.stream.IntStream;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.sonar.api.utils.System2;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static java.util.Collections.singletonList;
-import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.sonar.server.measure.index.ProjectMeasuresQuery.Operator;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER;
-@RunWith(DataProviderRunner.class)
-public class ProjectMeasuresIndexTest {
+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 NEW_SECURITY_RATING = "new_security_rating";
private static final String SECURITY_REVIEW_RATING = "security_review_rating";
private static final String NEW_SECURITY_REVIEW_RATING = "new_security_review_rating";
+
+ //Software quality ratings
+ private static final String SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY = "software_quality_maintainability_rating";
+ private static final String NEW_SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY = "new_software_quality_maintainability_rating";
+ private static final String SOFTWARE_QUALITY_RELIABILITY_RATING_KEY = "software_quality_reliability_rating";
+ private static final String NEW_SOFTWARE_QUALITY_RELIABILITY_RATING_KEY = "new_software_quality_reliability_rating";
+ private static final String SOFTWARE_QUALITY_SECURITY_RATING_KEY = "software_quality_security_rating";
+ private static final String NEW_SOFTWARE_QUALITY_SECURITY_RATING_KEY = "new_software_quality_security_rating";
+ private static final String SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY = "software_quality_security_review_rating";
+ private static final String NEW_SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY = "new_software_quality_security_review_rating";
+
private static final String SECURITY_HOTSPOTS_REVIEWED = "security_hotspots_reviewed";
private static final String NEW_SECURITY_HOTSPOTS_REVIEWED = "new_security_hotspots_reviewed";
private static final String COVERAGE = "coverage";
private static final GroupDto GROUP1 = newGroupDto();
private static final GroupDto GROUP2 = newGroupDto();
- @Rule
- public EsTester es = EsTester.create();
- @Rule
- public UserSessionRule userSession = UserSessionRule.standalone();
+ @RegisterExtension
+ private final EsTester es = EsTester.create();
+ @RegisterExtension
+ private final UserSessionRule userSession = UserSessionRule.standalone();
+
+ private static String[] rating_metric_keys() {
+ return new String[]{
+ MAINTAINABILITY_RATING, NEW_MAINTAINABILITY_RATING_KEY,
+ RELIABILITY_RATING, NEW_RELIABILITY_RATING,
+ SECURITY_RATING, NEW_SECURITY_RATING,
+ SECURITY_REVIEW_RATING, NEW_SECURITY_REVIEW_RATING
+ };
+ }
- @DataProvider
- public static Object[][] rating_metric_keys() {
- return new Object[][] {{MAINTAINABILITY_RATING}, {NEW_MAINTAINABILITY_RATING_KEY}, {RELIABILITY_RATING}, {NEW_RELIABILITY_RATING}, {SECURITY_RATING}, {NEW_SECURITY_RATING},
- {SECURITY_REVIEW_RATING}, {NEW_SECURITY_REVIEW_RATING}};
+ private static String[] software_quality_rating_metric_keys() {
+ return new String[]{
+ SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY, NEW_SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY,
+ SOFTWARE_QUALITY_RELIABILITY_RATING_KEY, NEW_SOFTWARE_QUALITY_RELIABILITY_RATING_KEY,
+ SOFTWARE_QUALITY_SECURITY_RATING_KEY, NEW_SOFTWARE_QUALITY_SECURITY_RATING_KEY,
+ SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY, NEW_SOFTWARE_QUALITY_SECURITY_REVIEW_RATING_KEY
+ };
}
- private ProjectMeasuresIndexer projectMeasureIndexer = new ProjectMeasuresIndexer(null, es.client());
- private PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, projectMeasureIndexer);
- private ProjectMeasuresIndex underTest = new ProjectMeasuresIndex(es.client(), new WebAuthorizationTypeSupport(userSession), System2.INSTANCE);
+ private final ProjectMeasuresIndexer projectMeasureIndexer = new ProjectMeasuresIndexer(null, es.client());
+ private final PermissionIndexerTester authorizationIndexer = new PermissionIndexerTester(es, projectMeasureIndexer);
+ private final ProjectMeasuresIndex underTest = new ProjectMeasuresIndex(es.client(), new WebAuthorizationTypeSupport(userSession),
+ System2.INSTANCE);
@Test
- public void return_empty_if_no_projects() {
+ void return_empty_if_no_projects() {
assertNoResults(new ProjectMeasuresQuery());
}
@Test
- public void default_sort_is_by_ascending_case_insensitive_name_then_by_key() {
+ void default_sort_is_by_ascending_case_insensitive_name_then_by_key() {
ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setKey("project1");
ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setKey("project2");
ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setKey("project3");
}
@Test
- public void sort_by_insensitive_name() {
+ void sort_by_insensitive_name() {
ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows");
ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee");
ComponentDto apache = ComponentTesting.newPrivateProjectDto().setUuid("apache").setName("Apache");
}
@Test
- public void sort_by_ncloc() {
+ void sort_by_ncloc() {
index(
newDoc(PROJECT1, NCLOC, 15_000d),
newDoc(PROJECT2, NCLOC, 30_000d),
}
@Test
- public void sort_by_a_metric_then_by_name_then_by_key() {
+ void sort_by_a_metric_then_by_name_then_by_key() {
ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setKey("project1");
ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setKey("project2");
ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setKey("project3");
}
@Test
- public void sort_by_quality_gate_status() {
+ void sort_by_quality_gate_status() {
ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setKey("key-4");
index(
newDoc(PROJECT1).setQualityGateStatus(OK.name()),
assertResults(new ProjectMeasuresQuery().setSort("alert_status").setAsc(false), PROJECT2, PROJECT1, project4);
}
- public void sort_by_creation_date() {
- Instant now = Instant.ofEpochMilli(1000L);
- Date nowMinus10 = Date.from(now.minusSeconds(10));
- Date nowMinus20 = Date.from(now.minusSeconds(20));
- Date nowMinus30 = Date.from(now.minusSeconds(30));
-
- ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setKey("key-4");
- index(
- newDoc(PROJECT1).setCreatedAt(nowMinus10),
- newDoc(PROJECT2).setCreatedAt(nowMinus30),
- newDoc(project4).setCreatedAt(nowMinus20));
-
- assertResults(new ProjectMeasuresQuery().setSort("creation_date").setAsc(true), PROJECT1, project4, PROJECT2);
- assertResults(new ProjectMeasuresQuery().setSort("creation_date").setAsc(false), PROJECT2, PROJECT1, project4);
- }
-
- public void sort_by_analysis_date() {
- Instant now = Instant.ofEpochMilli(1000L);
- Date nowMinus10 = Date.from(now.minusSeconds(10));
- Date nowMinus20 = Date.from(now.minusSeconds(20));
- Date nowMinus30 = Date.from(now.minusSeconds(30));
-
- ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setKey("key-4");
- index(
- newDoc(PROJECT1).setAnalysedAt(nowMinus10),
- newDoc(PROJECT2).setAnalysedAt(nowMinus30),
- newDoc(project4).setAnalysedAt(nowMinus20));
-
- assertResults(new ProjectMeasuresQuery().setSort("analysis_date").setAsc(true), PROJECT1, project4, PROJECT2);
- assertResults(new ProjectMeasuresQuery().setSort("analysis_date").setAsc(false), PROJECT2, PROJECT1, project4);
- }
-
@Test
- public void sort_by_quality_gate_status_then_by_name_then_by_key() {
+ void sort_by_quality_gate_status_then_by_name_then_by_key() {
ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setKey("project1");
ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setKey("project2");
ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setKey("project3");
}
@Test
- public void paginate_results() {
+ void paginate_results() {
IntStream.rangeClosed(1, 9)
.forEach(i -> index(newDoc(newPrivateProjectDto("P" + i))));
}
@Test
- public void filter_with_lower_than() {
+ void filter_with_lower_than() {
index(
newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
}
@Test
- public void filter_with_lower_than_or_equals() {
+ void filter_with_lower_than_or_equals() {
index(
newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
}
@Test
- public void filter_with_greater_than() {
+ void filter_with_greater_than() {
index(
newDoc(PROJECT1, COVERAGE, 80d, NCLOC, 30_000d),
newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 30_001d),
}
@Test
- public void filter_with_greater_than_or_equals() {
+ void filter_with_greater_than_or_equals() {
index(
newDoc(PROJECT1, COVERAGE, 80d, NCLOC, 30_000d),
newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 30_001d),
}
@Test
- public void filter_with_equals() {
+ void filter_with_equals() {
index(
newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
}
@Test
- public void filter_on_no_data_with_several_projects() {
+ void filter_on_no_data_with_several_projects() {
index(
newDoc(PROJECT1, NCLOC, 1d),
newDoc(PROJECT2, DUPLICATION, 80d));
}
@Test
- public void filter_on_no_data_should_not_return_projects_with_data_and_other_measures() {
+ void filter_on_no_data_should_not_return_projects_with_data_and_other_measures() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
index(newDoc(project, DUPLICATION, 80d, NCLOC, 1d));
}
@Test
- public void filter_on_no_data_should_not_return_projects_with_data() {
+ void filter_on_no_data_should_not_return_projects_with_data() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
index(newDoc(project, DUPLICATION, 80d));
}
@Test
- public void filter_on_no_data_should_return_projects_with_no_data() {
+ void filter_on_no_data_should_return_projects_with_no_data() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
index(newDoc(project, NCLOC, 1d));
}
@Test
- public void filter_on_several_metrics() {
+ void filter_on_several_metrics() {
index(
newDoc(PROJECT1, COVERAGE, 81d, NCLOC, 10_001d),
newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_001d),
}
@Test
- public void facet_security_hotspots_reviewed() {
+ void facet_security_hotspots_reviewed() {
index(
// 2 docs with no measure
newDocWithNoMeasure(),
}
@Test
- public void facet_new_security_hotspots_reviewed() {
+ void facet_new_security_hotspots_reviewed() {
index(
// 2 docs with no measure
newDocWithNoMeasure(),
}
@Test
- public void filter_on_quality_gate_status() {
+ void filter_on_quality_gate_status() {
index(
newDoc(PROJECT1).setQualityGateStatus(OK.name()),
newDoc(PROJECT2).setQualityGateStatus(OK.name()),
}
@Test
- public void filter_on_languages() {
+ void filter_on_languages() {
ComponentDto project4 = ComponentTesting.newPrivateProjectDto().setUuid("Project-4").setName("Project 4").setKey("key-4");
index(
newDoc(PROJECT1).setLanguages(singletonList("java")),
}
@Test
- public void filter_on_query_text() {
+ void filter_on_query_text() {
ComponentDto windows = ComponentTesting.newPrivateProjectDto().setUuid("windows").setName("Windows").setKey("project1");
ComponentDto apachee = ComponentTesting.newPrivateProjectDto().setUuid("apachee").setName("apachee").setKey("project2");
ComponentDto apache1 = ComponentTesting.newPrivateProjectDto().setUuid("apache-1").setName("Apache").setKey("project3");
}
@Test
- public void filter_on_ids() {
+ void filter_on_ids() {
index(
newDoc(PROJECT1),
newDoc(PROJECT2),
}
@Test
- public void filter_on_tags() {
+ void filter_on_tags() {
index(
newDoc(PROJECT1).setTags(newArrayList("finance", "platform")),
newDoc(PROJECT2).setTags(newArrayList("marketing", "platform")),
}
@Test
- public void filter_on_qualifier() {
+ void filter_on_qualifier() {
index(newDoc(PROJECT1), newDoc(PROJECT2), newDoc(PROJECT3),
newDoc(APP1), newDoc(APP2), newDoc(APP3));
}
@Test
- public void return_correct_number_of_total_if_exceeds_index_max_results() {
+ void return_correct_number_of_total_if_exceeds_index_max_results() {
index(IntStream.range(0, 12_000)
.mapToObj(operand -> newDoc(ComponentTesting.newPrivateProjectDto()))
.toArray(ProjectMeasuresDoc[]::new));
}
@Test
- public void return_only_projects_and_applications_authorized_for_user() {
+ void return_only_projects_and_applications_authorized_for_user() {
indexForUser(USER1, newDoc(PROJECT1), newDoc(PROJECT2),
newDoc(APP1), newDoc(APP2));
indexForUser(USER2, newDoc(PROJECT3), newDoc(APP3));
}
@Test
- public void return_only_projects_and_applications_authorized_for_user_groups() {
+ void return_only_projects_and_applications_authorized_for_user_groups() {
indexForGroup(GROUP1, newDoc(PROJECT1), newDoc(PROJECT2),
newDoc(APP1), newDoc(APP2));
indexForGroup(GROUP2, newDoc(PROJECT3));
}
@Test
- public void return_only_projects_and_applications_authorized_for_user_and_groups() {
+ void return_only_projects_and_applications_authorized_for_user_and_groups() {
indexForUser(USER1, newDoc(PROJECT1), newDoc(PROJECT2),
newDoc(APP1), newDoc(APP2));
indexForGroup(GROUP1, newDoc(PROJECT3));
}
@Test
- public void anonymous_user_can_only_access_projects_and_applications_authorized_for_anyone() {
+ void anonymous_user_can_only_access_projects_and_applications_authorized_for_anyone() {
index(newDoc(PROJECT1), newDoc(APP1));
indexForUser(USER1, newDoc(PROJECT2), newDoc(APP2));
}
@Test
- public void return_all_projects_and_applications_when_setIgnoreAuthorization_is_true() {
+ void return_all_projects_and_applications_when_setIgnoreAuthorization_is_true() {
indexForUser(USER1, newDoc(PROJECT1), newDoc(PROJECT2), newDoc(APP1), newDoc(APP2));
indexForUser(USER2, newDoc(PROJECT3), newDoc(APP3));
userSession.logIn(USER1);
}
@Test
- public void does_not_return_facet_when_no_facets_in_options() {
+ void does_not_return_facet_when_no_facets_in_options() {
index(
newDoc(PROJECT1, NCLOC, 10d, COVERAGE_KEY, 30d, MAINTAINABILITY_RATING, 3d)
.setQualityGateStatus(OK.name()));
}
@Test
- public void facet_ncloc() {
+ void facet_ncloc() {
index(
// 3 docs with ncloc<1K
newDoc(NCLOC, 0d),
}
@Test
- public void facet_ncloc_is_sticky() {
+ void facet_ncloc_is_sticky() {
index(
// 1 docs with ncloc<1K
newDoc(NCLOC, 999d, COVERAGE, 0d, DUPLICATION, 0d),
}
@Test
- public void facet_ncloc_contains_only_projects_authorized_for_user() {
+ void facet_ncloc_contains_only_projects_authorized_for_user() {
// User can see these projects
indexForUser(USER1,
// docs with ncloc<1K
}
@Test
- public void facet_new_lines() {
+ void facet_new_lines() {
index(
// 3 docs with ncloc<1K
newDoc(NEW_LINES, 0d),
}
@Test
- public void facet_coverage() {
+ void facet_coverage() {
index(
// 1 doc with no coverage
newDocWithNoMeasure(),
}
@Test
- public void facet_coverage_is_sticky() {
+ void facet_coverage_is_sticky() {
index(
// docs with no coverage
newDoc(NCLOC, 999d, DUPLICATION, 0d),
}
@Test
- public void facet_coverage_contains_only_projects_authorized_for_user() {
+ void facet_coverage_contains_only_projects_authorized_for_user() {
// User can see these projects
indexForUser(USER1,
// 1 doc with no coverage
}
@Test
- public void facet_new_coverage() {
+ void facet_new_coverage() {
index(
// 1 doc with no coverage
newDocWithNoMeasure(),
}
@Test
- public void facet_duplicated_lines_density() {
+ void facet_duplicated_lines_density() {
index(
// 1 doc with no duplication
newDocWithNoMeasure(),
}
@Test
- public void facet_duplicated_lines_density_is_sticky() {
+ void facet_duplicated_lines_density_is_sticky() {
index(
// docs with no duplication
newDoc(NCLOC, 50_001d, COVERAGE, 29d),
}
@Test
- public void facet_duplicated_lines_density_contains_only_projects_authorized_for_user() {
+ void facet_duplicated_lines_density_contains_only_projects_authorized_for_user() {
// User can see these projects
indexForUser(USER1,
// docs with no duplication
}
@Test
- public void facet_new_duplicated_lines_density() {
+ void facet_new_duplicated_lines_density() {
index(
// 2 docs with no measure
newDocWithNoMeasure(),
entry("20.0-*", 5L));
}
- @Test
- @UseDataProvider("rating_metric_keys")
- public void facet_on_rating(String metricKey) {
+ @ParameterizedTest
+ @MethodSource("rating_metric_keys")
+ void facet_on_rating(String metricKey) {
index(
// 3 docs with rating A
newDoc(metricKey, 1d),
entry("5", 5L));
}
- @Test
- @UseDataProvider("rating_metric_keys")
- public void facet_on_rating_is_sticky(String metricKey) {
+ @ParameterizedTest
+ @MethodSource("software_quality_rating_metric_keys")
+ void facet_on_software_quality_rating(String metricKey) {
+ index(
+ // 3 docs with rating A
+ newDoc(metricKey, 1d),
+ newDoc(metricKey, 1d),
+ newDoc(metricKey, 1d),
+ // 2 docs with rating B
+ newDoc(metricKey, 2d),
+ newDoc(metricKey, 2d),
+ // 4 docs with rating C
+ newDoc(metricKey, 3d),
+ newDoc(metricKey, 3d),
+ newDoc(metricKey, 3d),
+ newDoc(metricKey, 3d),
+ // 2 docs with rating D
+ newDoc(metricKey, 4d),
+ newDoc(metricKey, 4d));
+
+ Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(metricKey)).getFacets();
+
+ assertThat(facets.get(metricKey)).containsExactly(
+ entry("1", 3L),
+ entry("2", 2L),
+ entry("3", 4L),
+ entry("4", 2L));
+ }
+
+ @ParameterizedTest
+ @MethodSource("rating_metric_keys")
+ void facet_on_rating_is_sticky(String metricKey) {
index(
// docs with rating A
newDoc(metricKey, 1d, NCLOC, 100d, COVERAGE, 0d),
entry("500000.0-*", 0L));
}
- @Test
- @UseDataProvider("rating_metric_keys")
- public void facet_on_rating_contains_only_projects_authorized_for_user(String metricKey) {
+ @ParameterizedTest
+ @MethodSource("software_quality_rating_metric_keys")
+ void facet_on_software_quality_rating_is_sticky(String metricKey) {
+ index(
+ // docs with rating A
+ 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(metricKey, 2d, NCLOC, 2000d, COVERAGE, 0d),
+ newDoc(metricKey, 2d, NCLOC, 5000d, COVERAGE, 0d),
+ // docs with rating C
+ 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(metricKey, 4d, NCLOC, 120000d, COVERAGE, 0d));
+
+ Facets facets = underTest.search(new ProjectMeasuresQuery()
+ .addMetricCriterion(MetricCriterion.create(metricKey, Operator.LT, 3d))
+ .addMetricCriterion(MetricCriterion.create(COVERAGE, Operator.LT, 30d)),
+ new SearchOptions().addFacets(metricKey, NCLOC)).getFacets();
+
+ // Sticky facet on maintainability rating does not take into account maintainability rating filter
+ assertThat(facets.get(metricKey)).containsExactly(
+ entry("1", 3L),
+ entry("2", 2L),
+ entry("3", 4L),
+ entry("4", 1L));
+ // But facet on ncloc does well take into into filters
+ assertThat(facets.get(NCLOC)).containsExactly(
+ entry("*-1000.0", 3L),
+ entry("1000.0-10000.0", 2L),
+ entry("10000.0-100000.0", 0L),
+ entry("100000.0-500000.0", 0L),
+ entry("500000.0-*", 0L));
+ }
+
+ @ParameterizedTest
+ @MethodSource("rating_metric_keys")
+ void facet_on_rating_contains_only_projects_authorized_for_user(String metricKey) {
// User can see these projects
indexForUser(USER1,
// 3 docs with rating A
entry("5", 0L));
}
+ @ParameterizedTest
+ @MethodSource("software_quality_rating_metric_keys")
+ void facet_on_software_quality_rating_contains_only_projects_authorized_for_user(String metricKey) {
+ // User can see these projects
+ indexForUser(USER1,
+ // 3 docs with rating A
+ newDoc(metricKey, 1d),
+ newDoc(metricKey, 1d),
+ newDoc(metricKey, 1d),
+ // 2 docs with rating B
+ newDoc(metricKey, 2d),
+ newDoc(metricKey, 2d));
+
+ // User cannot see these projects
+ indexForUser(USER2,
+ // docs with rating C
+ newDoc(metricKey, 3d),
+ // docs with rating D
+ newDoc(metricKey, 4d));
+
+ userSession.logIn(USER1);
+ Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(metricKey)).getFacets();
+
+ assertThat(facets.get(metricKey)).containsExactly(
+ entry("1", 3L),
+ entry("2", 2L),
+ entry("3", 0L),
+ entry("4", 0L));
+ }
+
@Test
- public void facet_quality_gate() {
+ void facet_quality_gate() {
index(
// 2 docs with QG OK
newDoc().setQualityGateStatus(OK.name()),
}
@Test
- public void facet_quality_gate_is_sticky() {
+ void facet_quality_gate_is_sticky() {
index(
// 2 docs with QG OK
newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGateStatus(OK.name()),
}
@Test
- public void facet_quality_gate_contains_only_projects_authorized_for_user() {
+ void facet_quality_gate_contains_only_projects_authorized_for_user() {
// User can see these projects
indexForUser(USER1,
// 2 docs with QG OK
}
@Test
- public void facet_languages() {
+ void facet_languages() {
index(
newDoc().setLanguages(singletonList("java")),
newDoc().setLanguages(singletonList("java")),
}
@Test
- public void facet_languages_is_limited_to_10_languages() {
+ void facet_languages_is_limited_to_10_languages() {
index(
newDoc().setLanguages(asList("<null>", "java", "xoo", "css", "cpp")),
newDoc().setLanguages(asList("xml", "php", "python", "perl", "ruby")),
}
@Test
- public void facet_languages_is_sticky() {
+ void facet_languages_is_sticky() {
index(
newDoc(NCLOC, 10d).setLanguages(singletonList("java")),
newDoc(NCLOC, 10d).setLanguages(singletonList("java")),
newDoc(NCLOC, 5000d).setLanguages(asList("<null>", "java", "xoo")));
Facets facets = underTest.search(
- new ProjectMeasuresQuery().setLanguages(ImmutableSet.of("java")),
+ new ProjectMeasuresQuery().setLanguages(Set.of("java")),
new SearchOptions().addFacets(LANGUAGES, NCLOC)).getFacets();
// Sticky facet on language does not take into account language filter
}
@Test
- public void facet_languages_returns_more_than_10_languages_when_languages_filter_contains_value_not_in_top_10() {
+ void facet_languages_returns_more_than_10_languages_when_languages_filter_contains_value_not_in_top_10() {
index(
newDoc().setLanguages(asList("<null>", "java", "xoo", "css", "cpp")),
newDoc().setLanguages(asList("xml", "php", "python", "perl", "ruby")),
newDoc().setLanguages(asList("js", "scala")));
- Facets facets = underTest.search(new ProjectMeasuresQuery().setLanguages(ImmutableSet.of("xoo", "xml")), new SearchOptions().addFacets(LANGUAGES)).getFacets();
+ Facets facets = underTest.search(new ProjectMeasuresQuery().setLanguages(Set.of("xoo", "xml")),
+ new SearchOptions().addFacets(LANGUAGES)).getFacets();
assertThat(facets.get(LANGUAGES)).containsOnly(
entry("<null>", 1L),
}
@Test
- public void facet_languages_contains_only_projects_authorized_for_user() {
+ void facet_languages_contains_only_projects_authorized_for_user() {
// User can see these projects
indexForUser(USER1,
newDoc().setLanguages(singletonList("java")),
}
@Test
- public void facet_qualifier() {
+ void facet_qualifier() {
index(
// 2 docs with qualifier APP
newDoc().setQualifier(APP),
}
@Test
- public void facet_qualifier_is_sticky() {
+ void facet_qualifier_is_sticky() {
index(
// 2 docs with qualifier APP
newDoc(NCLOC, 10d, COVERAGE, 0d).setQualifier(APP),
}
@Test
- public void facet_qualifier_contains_only_app_and_projects_authorized_for_user() {
+ void facet_qualifier_contains_only_app_and_projects_authorized_for_user() {
// User can see these projects
indexForUser(USER1,
// 3 docs with qualifier APP, PROJECT
}
@Test
- public void facet_tags() {
+ void facet_tags() {
index(
newDoc().setTags(newArrayList("finance", "offshore", "java")),
newDoc().setTags(newArrayList("finance", "javascript")),
}
@Test
- public void facet_tags_is_sticky() {
+ void facet_tags_is_sticky() {
index(
newDoc().setTags(newArrayList("finance")).setQualityGateStatus(OK.name()),
newDoc().setTags(newArrayList("finance")).setQualityGateStatus(ERROR.name()),
}
@Test
- public void facet_tags_returns_10_elements_by_default() {
+ void facet_tags_returns_10_elements_by_default() {
index(
newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")),
newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")),
}
@Test
- public void facet_tags_returns_more_than_10_tags_when_tags_filter_contains_value_not_in_top_10() {
+ void facet_tags_returns_more_than_10_tags_when_tags_filter_contains_value_not_in_top_10() {
index(
newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")),
newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")),
newDoc().setTags(newArrayList("solo", "solo2")));
- Map<String, Long> result = underTest.search(new ProjectMeasuresQuery().setTags(ImmutableSet.of("solo", "solo2")), new SearchOptions().addFacets(FIELD_TAGS)).getFacets()
+ Map<String, Long> result = underTest.search(new ProjectMeasuresQuery().setTags(Set.of("solo", "solo2")),
+ new SearchOptions().addFacets(FIELD_TAGS)).getFacets()
.get(FIELD_TAGS);
assertThat(result).hasSize(12).containsOnlyKeys("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10", "solo",
}
@Test
- public void search_tags() {
+ void search_tags() {
index(
newDoc().setTags(newArrayList("finance", "offshore", "java")),
newDoc().setTags(newArrayList("official", "javascript")),
}
@Test
- public void search_tags_return_all_tags() {
+ void search_tags_return_all_tags() {
index(
newDoc().setTags(newArrayList("finance", "offshore", "java")),
newDoc().setTags(newArrayList("official", "javascript")),
}
@Test
- public void search_tags_in_lexical_order() {
+ void search_tags_in_lexical_order() {
index(
newDoc().setTags(newArrayList("finance", "offshore", "java")),
newDoc().setTags(newArrayList("official", "javascript")),
}
@Test
- public void search_tags_follows_paging() {
+ void search_tags_follows_paging() {
index(
newDoc().setTags(newArrayList("finance", "offshore", "java")),
newDoc().setTags(newArrayList("official", "javascript")),
}
@Test
- public void search_tags_returns_nothing_if_page_too_large() {
+ void search_tags_returns_nothing_if_page_too_large() {
index(
newDoc().setTags(newArrayList("finance", "offshore", "java")),
newDoc().setTags(newArrayList("official", "javascript")),
}
@Test
- public void search_tags_only_of_authorized_projects() {
+ void search_tags_only_of_authorized_projects() {
indexForUser(USER1,
newDoc(PROJECT1).setTags(singletonList("finance")),
newDoc(PROJECT2).setTags(singletonList("marketing")));
}
@Test
- public void search_tags_with_no_tags() {
+ void search_tags_with_no_tags() {
List<String> result = underTest.searchTags("whatever", 1, 10);
assertThat(result).isEmpty();
}
@Test
- public void search_tags_with_page_size_at_0() {
+ void search_tags_with_page_size_at_0() {
index(newDoc().setTags(newArrayList("offshore")));
List<String> result = underTest.searchTags(null, 1, 0);
}
@Test
- public void search_statistics() {
+ void search_statistics() {
es.putDocuments(TYPE_PROJECT_MEASURES,
newDoc("lines", 10, "coverage", 80)
.setLanguages(Arrays.asList("java", "cs", "js"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 200, "cs", 250, "js", 50)),
+ .setNclocLanguageDistributionFromMap(Map.of("java", 200, "cs", 250, "js", 50)),
newDoc("lines", 20, "coverage", 80)
.setLanguages(Arrays.asList("java", "python", "kotlin"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)));
+ .setNclocLanguageDistributionFromMap(Map.of("java", 300, "python", 100, "kotlin", 404)));
ProjectMeasuresStatistics result = underTest.searchSupportStatistics();
}
@Test
- public void search_statistics_for_large_instances() {
+ void search_statistics_for_large_instances() {
int nbProjects = 25000;
int javaLocByProjects = 100;
int jsLocByProjects = 900;
ProjectMeasuresDoc[] documents = IntStream.range(0, nbProjects).mapToObj(i -> newDoc("lines", 10, "coverage", 80)
.setLanguages(asList("java", "cs", "js"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", javaLocByProjects, "cs", csLocByProjects, "js", jsLocByProjects))).toArray(ProjectMeasuresDoc[]::new);
+ .setNclocLanguageDistributionFromMap(Map.of("java", javaLocByProjects, "cs", csLocByProjects, "js", jsLocByProjects))).toArray(ProjectMeasuresDoc[]::new);
es.putDocuments(TYPE_PROJECT_MEASURES, documents);
}
@Test
- public void search_statistics_should_ignore_applications() {
+ void search_statistics_should_ignore_applications() {
es.putDocuments(TYPE_PROJECT_MEASURES,
// insert projects
newDoc(ComponentTesting.newPrivateProjectDto(), "lines", 10, "coverage", 80)
.setLanguages(Arrays.asList("java", "cs", "js"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 200, "cs", 250, "js", 50)),
+ .setNclocLanguageDistributionFromMap(Map.of("java", 200, "cs", 250, "js", 50)),
newDoc(ComponentTesting.newPrivateProjectDto(), "lines", 20, "coverage", 80)
.setLanguages(Arrays.asList("java", "python", "kotlin"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)),
+ .setNclocLanguageDistributionFromMap(Map.of("java", 300, "python", 100, "kotlin", 404)),
// insert applications
newDoc(ComponentTesting.newApplication(), "lines", 1000, "coverage", 70)
.setLanguages(Arrays.asList("java", "python", "kotlin"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)),
+ .setNclocLanguageDistributionFromMap(Map.of("java", 300, "python", 100, "kotlin", 404)),
newDoc(ComponentTesting.newApplication(), "lines", 20, "coverage", 80)
.setLanguages(Arrays.asList("java", "python", "kotlin"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)));
+ .setNclocLanguageDistributionFromMap(Map.of("java", 300, "python", 100, "kotlin", 404)));
ProjectMeasuresStatistics result = underTest.searchSupportStatistics();
}
@Test
- public void search_statistics_should_count_0_if_no_projects() {
+ void search_statistics_should_count_0_if_no_projects() {
es.putDocuments(TYPE_PROJECT_MEASURES,
// insert applications
newDoc(ComponentTesting.newApplication(), "lines", 1000, "coverage", 70)
- .setLanguages(Arrays.asList("java", "python", "kotlin"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)),
+ .setLanguages(Arrays.asList("java", "Map", "kotlin"))
+ .setNclocLanguageDistributionFromMap(Map.of("java", 300, "python", 100, "kotlin", 404)),
newDoc(ComponentTesting.newApplication(), "lines", 20, "coverage", 80)
.setLanguages(Arrays.asList("java", "python", "kotlin"))
- .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)));
+ .setNclocLanguageDistributionFromMap(Map.of("java", 300, "python", 100, "kotlin", 404)));
ProjectMeasuresStatistics result = underTest.searchSupportStatistics();
}
@Test
- public void fail_if_page_size_greater_than_100() {
+ void fail_if_page_size_greater_than_100() {
assertThatThrownBy(() -> underTest.searchTags("whatever", 1, 101))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Page size must be lower than or equals to 100");
}
@Test
- public void fail_if_page_greater_than_20() {
+ void fail_if_page_greater_than_20() {
assertThatThrownBy(() -> underTest.searchTags("whatever", 21, 100))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Page must be between 0 and 20");
private void index(ProjectMeasuresDoc... docs) {
es.putDocuments(TYPE_PROJECT_MEASURES, docs);
- authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).allowAnyone()).collect(toList()));
+ authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).allowAnyone()).toList());
}
private void indexForUser(UserDto user, ProjectMeasuresDoc... docs) {
es.putDocuments(TYPE_PROJECT_MEASURES, docs);
- authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addUserUuid(user.getUuid())).collect(toList()));
+ authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addUserUuid(user.getUuid())).toList());
}
private void indexForGroup(GroupDto group, ProjectMeasuresDoc... docs) {
es.putDocuments(TYPE_PROJECT_MEASURES, docs);
- authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addGroupUuid(group.getUuid())).collect(toList()));
+ authorizationIndexer.allow(stream(docs).map(doc -> new IndexPermissions(doc.getId(), PROJECT).addGroupUuid(group.getUuid())).toList());
}
private static ProjectMeasuresDoc newDoc(ComponentDto project) {
}
private static Map<String, Object> newMeasure(String key, Object value) {
- return ImmutableMap.of("key", key, "value", value);
+ return Map.of("key", key, "value", value);
}
private static ProjectMeasuresDoc newDocWithNoMeasure() {