--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.issue;
+
+import org.sonar.api.SonarRuntime;
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.server.ServerSide;
+import org.sonar.server.feature.SonarQubeFeature;
+
+import static org.sonar.api.SonarEdition.DATACENTER;
+import static org.sonar.api.SonarEdition.ENTERPRISE;
+
+@ServerSide
+@ComputeEngineSide
+public class PrioritizedRulesFeature implements SonarQubeFeature {
+
+ private final SonarRuntime sonarRuntime;
+
+ public PrioritizedRulesFeature (SonarRuntime sonarRuntime) {
+ this.sonarRuntime = sonarRuntime;
+ }
+
+ @Override
+ public String getName() {
+ return "prioritized-rules";
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return sonarRuntime.getEdition() == ENTERPRISE || sonarRuntime.getEdition() == DATACENTER;
+ }
+
+}
private List<String> projectKeys;
private List<String> resolutions;
private Boolean resolved;
+ private Boolean prioritizedRule;
private List<String> rules;
private String sort;
private List<String> severities;
return this;
}
+ @CheckForNull
+ public Boolean getPrioritizedRule() {
+ return prioritizedRule;
+ }
+
+ public SearchRequest setPrioritizedRule(@Nullable Boolean prioritizedRule) {
+ this.prioritizedRule = prioritizedRule;
+ return this;
+ }
+
@CheckForNull
public List<String> getRules() {
return rules;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.issue;
+
+import org.junit.jupiter.api.Test;
+import org.sonar.api.SonarEdition;
+import org.sonar.api.SonarRuntime;
+
+import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+class PrioritizedRulesFeatureTest {
+ SonarRuntime sonarRuntime = mock();
+ private final PrioritizedRulesFeature underTest = new PrioritizedRulesFeature(sonarRuntime);
+
+ @Test
+ void isAvailable_shouldOnlyBeEnabledInEnterpriseEditionPlus() {
+ testForEdition(SonarEdition.COMMUNITY, false);
+ testForEdition(SonarEdition.DEVELOPER, false);
+ testForEdition(SonarEdition.ENTERPRISE, true);
+ testForEdition(SonarEdition.DATACENTER, true);
+ }
+
+ private void testForEdition(SonarEdition edition, boolean expectedResult) {
+ doReturn(edition).when(sonarRuntime).getEdition();
+ assertThat(underTest.isAvailable()).isEqualTo(expectedResult);
+ }
+
+ @Test
+ void getName_ShouldReturn_Announcement() {
+ assertEquals("prioritized-rules", underTest.getName());
+ }
+
+}
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequest;
import static org.sonar.server.issue.index.IssueIndex.Facet.OWASP_TOP_10_2021;
import static org.sonar.server.issue.index.IssueIndex.Facet.PCI_DSS_32;
import static org.sonar.server.issue.index.IssueIndex.Facet.PCI_DSS_40;
+import static org.sonar.server.issue.index.IssueIndex.Facet.PRIORITIZED_RULE;
import static org.sonar.server.issue.index.IssueIndex.Facet.PROJECT_UUIDS;
import static org.sonar.server.issue.index.IssueIndex.Facet.RESOLUTIONS;
import static org.sonar.server.issue.index.IssueIndex.Facet.RULES;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_TAGS;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_TYPE;
import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_VULNERABILITY_PROBABILITY;
+import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_PRIORITIZED_RULE;
import static org.sonar.server.issue.index.IssueIndexDefinition.TYPE_ISSUE;
import static org.sonar.server.security.SecurityReviewRating.computePercent;
import static org.sonar.server.security.SecurityReviewRating.computeRating;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_TOP_10_2021;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PCI_DSS_32;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PCI_DSS_40;
+import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PRIORITIZED_RULE;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RESOLUTIONS;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SANS_TOP_25;
CWE(PARAM_CWE, FIELD_ISSUE_CWE, STICKY, DEFAULT_FACET_SIZE),
CREATED_AT(PARAM_CREATED_AT, FIELD_ISSUE_FUNC_CREATED_AT, NON_STICKY),
SONARSOURCE_SECURITY(PARAM_SONARSOURCE_SECURITY, FIELD_ISSUE_SQ_SECURITY_CATEGORY, STICKY, DEFAULT_FACET_SIZE),
- CODE_VARIANTS(PARAM_CODE_VARIANTS, FIELD_ISSUE_CODE_VARIANTS, STICKY, MAX_FACET_SIZE);
+ CODE_VARIANTS(PARAM_CODE_VARIANTS, FIELD_ISSUE_CODE_VARIANTS, STICKY, MAX_FACET_SIZE),
+ PRIORITIZED_RULE(PARAM_PRIORITIZED_RULE, FIELD_PRIORITIZED_RULE, STICKY, 2);
private final String name;
private final TopAggregationDefinition<FilterScope> topAggregation;
filters.addFilter(FIELD_ISSUE_STATUS, STATUSES.getFilterScope(), createTermsFilter(FIELD_ISSUE_STATUS, query.statuses()));
filters.addFilter(FIELD_ISSUE_NEW_STATUS, ISSUE_STATUSES.getFilterScope(), createTermsFilter(FIELD_ISSUE_NEW_STATUS, query.issueStatuses()));
filters.addFilter(FIELD_ISSUE_CODE_VARIANTS, CODE_VARIANTS.getFilterScope(), createTermsFilter(FIELD_ISSUE_CODE_VARIANTS, query.codeVariants()));
+ filters.addFilter(FIELD_PRIORITIZED_RULE, PRIORITIZED_RULE.getFilterScope(), createTermFilter(FIELD_PRIORITIZED_RULE, query.prioritizedRule()));
// security category
addSecurityCategoryPrefixFilter(FIELD_ISSUE_PCI_DSS_32, PCI_DSS_32, query.pciDss32(), filters);
return value == null ? null : termQuery(field, value);
}
+ @CheckForNull
+ private static QueryBuilder createTermFilter(String field, @Nullable Boolean value) {
+ return value == null ? null : termQuery(field, value);
+ }
+
private static QueryBuilder createPrefixFilter(String field, String value) {
return prefixQuery(field, value);
}
addFacetIfNeeded(options, aggregationHelper, esRequest, TYPES, query.types().toArray());
addFacetIfNeeded(options, aggregationHelper, esRequest, CODE_VARIANTS, query.codeVariants().toArray());
addFacetIfNeeded(options, aggregationHelper, esRequest, CLEAN_CODE_ATTRIBUTE_CATEGORY, query.cleanCodeAttributesCategories().toArray());
+ addFacetIfNeeded(options, aggregationHelper, esRequest, PRIORITIZED_RULE, ArrayUtils.EMPTY_OBJECT_ARRAY);
addSecurityCategoryFacetIfNeeded(PARAM_PCI_DSS_32, PCI_DSS_32, options, aggregationHelper, esRequest, query.pciDss32().toArray());
addSecurityCategoryFacetIfNeeded(PARAM_PCI_DSS_40, PCI_DSS_40, options, aggregationHelper, esRequest, query.pciDss40().toArray());
private final Boolean onComponentOnly;
private final Boolean assigned;
private final Boolean resolved;
+ private final Boolean prioritizedRule;
private final Date createdAt;
private final PeriodStart createdAfter;
private final Date createdBefore;
this.onComponentOnly = builder.onComponentOnly;
this.assigned = builder.assigned;
this.resolved = builder.resolved;
+ this.prioritizedRule = builder.prioritizedRule;
this.createdAt = builder.createdAt;
this.createdAfter = builder.createdAfter;
this.createdBefore = builder.createdBefore;
return resolved;
}
+ @CheckForNull
+ public Boolean prioritizedRule() {
+ return prioritizedRule;
+ }
+
@CheckForNull
public PeriodStart createdAfter() {
return createdAfter;
private Boolean onComponentOnly = false;
private Boolean assigned = null;
private Boolean resolved = null;
+ private Boolean prioritizedRule = null;
private Date createdAt;
private PeriodStart createdAfter;
private Date createdBefore;
return this;
}
+ public Builder prioritizedRule(@Nullable Boolean prioritizedRule) {
+ this.prioritizedRule = prioritizedRule;
+ return this;
+ }
+
+
public Builder createdAt(@Nullable Date d) {
this.createdAt = d == null ? null : new Date(d.getTime());
return this;
.resolutions(request.getResolutions())
.issueStatuses(request.getIssueStatuses())
.resolved(request.getResolved())
+ .prioritizedRule(request.getPrioritizedRule())
.rules(ruleDtos)
.ruleUuids(ruleUuids)
.assigneeUuids(request.getAssigneeUuids())
package org.sonar.server.issue.index;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.Severity;
import org.sonar.db.component.ComponentDto;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_EFFORT;
-public class IssueIndexDebtTest extends IssueIndexTestCommon {
+class IssueIndexDebtTest extends IssueIndexTestCommon {
@Test
- public void facets_on_projects() {
+ void facets_on_projects() {
ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD");
ComponentDto project2 = ComponentTesting.newPrivateProjectDto("EFGH");
}
@Test
- public void facets_on_components() {
+ void facets_on_components() {
ComponentDto project = ComponentTesting.newPrivateProjectDto("A");
ComponentDto file1 = ComponentTesting.newFileDto(project, null, "ABCD");
ComponentDto file2 = ComponentTesting.newFileDto(project, null, "BCDE");
}
@Test
- public void facets_on_directories() {
+ void facets_on_directories() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
ComponentDto file1 = ComponentTesting.newFileDto(project).setPath("src/main/xoo/F1.xoo");
ComponentDto file2 = ComponentTesting.newFileDto(project).setPath("F2.xoo");
}
@Test
- public void facets_on_severities() {
+ void facets_on_severities() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
ComponentDto file = ComponentTesting.newFileDto(project);
}
@Test
- public void facets_on_statuses() {
+ void facets_on_statuses() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
ComponentDto file = ComponentTesting.newFileDto(project);
}
@Test
- public void facets_on_resolutions() {
+ void facets_on_resolutions() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
ComponentDto file = ComponentTesting.newFileDto(project);
}
@Test
- public void facets_on_languages() {
+ void facets_on_languages() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
ComponentDto file = ComponentTesting.newFileDto(project);
}
@Test
- public void facets_on_assignees() {
+ void facets_on_assignees() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
ComponentDto file = ComponentTesting.newFileDto(project);
}
@Test
- public void facets_on_author() {
+ void facets_on_author() {
ComponentDto project = ComponentTesting.newPrivateProjectDto();
ComponentDto file = ComponentTesting.newFileDto(project);
}
@Test
- public void facet_on_created_at() {
+ void facet_on_created_at() {
SearchOptions searchOptions = fixtureForCreatedAtFacet();
Builder query = newQueryBuilder().createdBefore(parseDateTime("2016-01-01T00:00:00+0100"));
import java.util.Map;
import java.util.Set;
import org.elasticsearch.action.search.SearchResponse;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.IssueStatus;
import org.sonar.api.issue.impact.Severity;
import org.sonar.api.rules.RuleType;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
-public class IssueIndexFacetsTest extends IssueIndexTestCommon {
+class IssueIndexFacetsTest extends IssueIndexTestCommon {
@Test
- public void facet_on_projectUuids() {
+ void facet_on_projectUuids() {
ComponentDto project = newPrivateProjectDto("ABCD");
ComponentDto project2 = newPrivateProjectDto("EFGH");
}
@Test
- public void facet_on_projectUuids_return_100_entries_plus_selected_values() {
+ void facet_on_projectUuids_return_100_entries_plus_selected_values() {
indexIssues(rangeClosed(1, 110).mapToObj(i -> newDocForProject(newPrivateProjectDto("a" + i))).toArray(IssueDoc[]::new));
IssueDoc issue1 = newDocForProject(newPrivateProjectDto("project1"));
}
@Test
- public void facets_on_files() {
+ void facets_on_files() {
ComponentDto project = newPrivateProjectDto("A");
ComponentDto dir = newDirectory(project, "src");
ComponentDto file1 = newFileDto(project, dir, "ABCD");
}
@Test
- public void facet_on_files_return_100_entries_plus_selected_values() {
+ void facet_on_files_return_100_entries_plus_selected_values() {
ComponentDto project = newPrivateProjectDto();
indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null, "a" + i), project.uuid())).toArray(IssueDoc[]::new));
IssueDoc issue1 = newDoc(newFileDto(project, null, "file1"), project.uuid());
}
@Test
- public void facets_on_directories() {
+ void facets_on_directories() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project).setPath("src/main/xoo/F1.xoo");
ComponentDto file2 = newFileDto(project).setPath("F2.xoo");
}
@Test
- public void facet_on_directories_return_100_entries_plus_selected_values() {
+ void facet_on_directories_return_100_entries_plus_selected_values() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, newDirectory(project, "dir" + i)), project.uuid()).setDirectoryPath("a" + i)).toArray(IssueDoc[]::new));
}
@Test
- public void facets_on_cwe() {
+ void facets_on_cwe() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_pciDss32() {
+ void facets_on_pciDss32() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_pciDss40() {
+ void facets_on_pciDss40() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_owaspAsvs40() {
+ void facets_on_owaspAsvs40() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_owaspTop10() {
+ void facets_on_owaspTop10() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_owaspTop10_2021() {
+ void facets_on_owaspTop10_2021() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_owaspTop10_2021_stay_ordered() {
+ void facets_on_owaspTop10_2021_stay_ordered() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_sansTop25() {
+ void facets_on_sansTop25() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_sonarSourceSecurity() {
+ void facets_on_sonarSourceSecurity() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_severities() {
+ void facets_on_severities() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facet_on_severities_return_5_entries_max() {
+ void facet_on_severities_return_5_entries_max() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_statuses() {
+ void facets_on_statuses() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facet_on_statuses_return_5_entries_max() {
+ void facet_on_statuses_return_5_entries_max() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_resolutions() {
+ void facets_on_resolutions() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_shouldReturnIssueStatusesFacet() {
+ void search_shouldReturnIssueStatusesFacet() {
ComponentDto mainBranch = newPrivateProjectDto();
ComponentDto file = newFileDto(mainBranch);
}
@Test
- public void facets_on_resolutions_return_5_entries_max() {
+ void facets_on_resolutions_return_5_entries_max() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_languages() {
+ void facets_on_languages() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
RuleDto ruleDefinitionDto = newRule();
}
@Test
- public void facets_on_languages_return_100_entries_plus_selected_values() {
+ void facets_on_languages_return_100_entries_plus_selected_values() {
ComponentDto project = newPrivateProjectDto();
indexIssues(rangeClosed(1, 100).mapToObj(i -> newDoc(newFileDto(project), project.uuid()).setLanguage("a" + i)).toArray(IssueDoc[]::new));
IssueDoc issue1 = newDoc(newFileDto(project), project.uuid()).setLanguage("language1");
}
@Test
- public void facets_on_assignees() {
+ void facets_on_assignees() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_assignees_return_only_100_entries_plus_selected_values() {
+ void facets_on_assignees_return_only_100_entries_plus_selected_values() {
ComponentDto project = newPrivateProjectDto();
indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project), project.uuid()).setAssigneeUuid("a" + i)).toArray(IssueDoc[]::new));
IssueDoc issue1 = newDoc(newFileDto(project), project.uuid()).setAssigneeUuid("user1");
}
@Test
- public void facets_on_assignees_supports_dashes() {
+ void facets_on_assignees_supports_dashes() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_author() {
+ void facets_on_author() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facets_on_authors_return_100_entries_plus_selected_values() {
+ void facets_on_prioritized_rule() {
+ ComponentDto project = newPrivateProjectDto();
+ ComponentDto file = newFileDto(project);
+
+ indexIssues(
+ newDoc("I1", project.uuid(), file).setPrioritizedRule(false),
+ newDoc("I2", project.uuid(), file).setPrioritizedRule(true),
+ newDoc("I3", project.uuid(), file).setPrioritizedRule(true)
+ );
+
+ assertThatFacetHasOnly(IssueQuery.builder(), "prioritizedRule", entry("true", 2L), entry("false", 1L));
+ }
+
+ @Test
+ void facets_on_authors_return_100_entries_plus_selected_values() {
ComponentDto project = newPrivateProjectDto();
indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project), project.uuid()).setAuthorLogin("a" + i)).toArray(IssueDoc[]::new));
IssueDoc issue1 = newDoc(newFileDto(project), project.uuid()).setAuthorLogin("user1");
}
@Test
- public void facet_on_created_at_with_less_than_20_days_use_system_timezone_by_default() {
+ void facet_on_created_at_with_less_than_20_days_use_system_timezone_by_default() {
SearchOptions options = fixtureForCreatedAtFacet();
IssueQuery query = IssueQuery.builder()
}
@Test
- public void facet_on_created_at_with_less_than_20_days_use_user_timezone_if_provided() {
+ void facet_on_created_at_with_less_than_20_days_use_user_timezone_if_provided() {
// Use timezones very far from each other in order to see some issues moving to a different calendar day
final ZoneId plus14 = ZoneId.of("Pacific/Kiritimati");
final ZoneId minus11 = ZoneId.of("Pacific/Pago_Pago");
}
@Test
- public void facet_on_created_at_with_less_than_20_weeks() {
+ void facet_on_created_at_with_less_than_20_weeks() {
SearchOptions options = fixtureForCreatedAtFacet();
SearchResponse result = underTest.search(IssueQuery.builder()
}
@Test
- public void facet_on_created_at_with_less_than_20_months() {
+ void facet_on_created_at_with_less_than_20_months() {
SearchOptions options = fixtureForCreatedAtFacet();
SearchResponse result = underTest.search(IssueQuery.builder()
}
@Test
- public void facet_on_created_at_with_more_than_20_months() {
+ void facet_on_created_at_with_more_than_20_months() {
SearchOptions options = fixtureForCreatedAtFacet();
SearchResponse result = underTest.search(IssueQuery.builder()
}
@Test
- public void facet_on_created_at_with_one_day() {
+ void facet_on_created_at_with_one_day() {
SearchOptions options = fixtureForCreatedAtFacet();
SearchResponse result = underTest.search(IssueQuery.builder()
}
@Test
- public void facet_on_created_at_with_bounds_outside_of_data() {
+ void facet_on_created_at_with_bounds_outside_of_data() {
SearchOptions options = fixtureForCreatedAtFacet();
SearchResponse result = underTest.search(IssueQuery.builder()
}
@Test
- public void facet_on_created_at_without_start_bound() {
+ void facet_on_created_at_without_start_bound() {
SearchOptions searchOptions = fixtureForCreatedAtFacet();
SearchResponse result = underTest.search(IssueQuery.builder()
}
@Test
- public void facet_on_created_at_without_issues() {
+ void facet_on_created_at_without_issues() {
SearchOptions searchOptions = new SearchOptions().addFacets("createdAt");
SearchResponse result = underTest.search(IssueQuery.builder().build(), searchOptions);
}
@Test
- public void search_shouldReturnCodeVariantsFacet() {
+ void search_shouldReturnCodeVariantsFacet() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_shouldReturnImpactSoftwareQualitiesFacet() {
+ void search_shouldReturnImpactSoftwareQualitiesFacet() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_whenFilteredOnSeverity_shouldReturnImpactSoftwareQualitiesFacet() {
+ void search_whenFilteredOnSeverity_shouldReturnImpactSoftwareQualitiesFacet() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_whenFilteredOnSeverityAndSoftwareQuality_shouldReturnImpactFacets() {
+ void search_whenFilteredOnSeverityAndSoftwareQuality_shouldReturnImpactFacets() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_shouldReturnImpactSeverityFacet() {
+ void search_shouldReturnImpactSeverityFacet() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_whenFilteredOnSoftwareQuality_shouldReturnImpactSeverityFacet() {
+ void search_whenFilteredOnSoftwareQuality_shouldReturnImpactSeverityFacet() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_shouldReturnCleanCodeAttributeCategoryFacet() {
+ void search_shouldReturnCleanCodeAttributeCategoryFacet() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_whenFilteredByTags_shouldReturnCleanCodeAttributeCategoryFacet() {
+ void search_whenFilteredByTags_shouldReturnCleanCodeAttributeCategoryFacet() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
import java.util.Map;
import java.util.Set;
import org.assertj.core.api.Fail;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.IssueStatus;
import org.sonar.api.rule.Severity;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
-public class IssueIndexFiltersTest extends IssueIndexTestCommon {
+class IssueIndexFiltersTest extends IssueIndexTestCommon {
@Test
- public void filter_by_keys() {
+ void filter_by_keys() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
}
@Test
- public void filter_by_projects() {
+ void filter_by_projects() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
}
@Test
- public void filter_by_components_on_contextualized_search() {
+ void filter_by_components_on_contextualized_search() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project);
String view = "ABCD";
}
@Test
- public void filter_by_components_on_non_contextualized_search() {
+ void filter_by_components_on_non_contextualized_search() {
ComponentDto project = newPrivateProjectDto("project");
ComponentDto file1 = newFileDto(project, null, "file1");
String view = "ABCD";
}
@Test
- public void filter_by_directories() {
+ void filter_by_directories() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project).setPath("src/main/xoo/F1.xoo");
ComponentDto file2 = newFileDto(project).setPath("F2.xoo");
}
@Test
- public void filter_by_portfolios() {
+ void filter_by_portfolios() {
ComponentDto portfolio1 = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto portfolio2 = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
}
@Test
- public void filter_by_portfolios_not_having_projects() {
+ void filter_by_portfolios_not_having_projects() {
ComponentDto project1 = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project1);
indexIssues(newDoc("I2", project1.uuid(), file1));
}
@Test
- public void do_not_return_issues_from_project_branch_when_filtering_by_portfolios() {
+ void do_not_return_issues_from_project_branch_when_filtering_by_portfolios() {
ComponentDto portfolio = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto projectBranch = db.components().insertProjectBranch(project);
}
@Test
- public void filter_one_issue_by_project_and_branch() {
+ void filter_one_issue_by_project_and_branch() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto branch = db.components().insertProjectBranch(project);
ComponentDto anotherbBranch = db.components().insertProjectBranch(project);
}
@Test
- public void issues_from_branch_component_children() {
+ void issues_from_branch_component_children() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
}
@Test
- public void issues_from_main_branch() {
+ void issues_from_main_branch() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto branch = db.components().insertProjectBranch(project);
}
@Test
- public void branch_issues_are_ignored_when_no_branch_param() {
+ void branch_issues_are_ignored_when_no_branch_param() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
}
@Test
- public void filter_by_main_application() {
+ void filter_by_main_application() {
ComponentDto application1 = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto application2 = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
}
@Test
- public void filter_by_application_branch() {
+ void filter_by_application_branch() {
ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP)).getMainBranchComponent();
ComponentDto branch1 = db.components().insertProjectBranch(application);
ComponentDto branch2 = db.components().insertProjectBranch(application);
}
@Test
- public void filter_by_application_branch_having_project_branches() {
+ void filter_by_application_branch_having_project_branches() {
ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app")).getMainBranchComponent();
ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1"));
ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2"));
}
@Test
- public void filter_by_created_after_by_projects() {
+ void filter_by_created_after_by_projects() {
Date now = new Date();
ComponentDto project1 = newPrivateProjectDto();
IssueDoc project1Issue1 = newDocForProject(project1).setFuncCreationDate(addDays(now, -10));
}
@Test
- public void filter_by_created_after_by_project_branches() {
+ void filter_by_created_after_by_project_branches() {
Date now = new Date();
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
}
@Test
- public void filter_by_new_code_reference_by_projects() {
+ void filter_by_new_code_reference_by_projects() {
ComponentDto project1 = newPrivateProjectDto();
IssueDoc project1Issue1 = newDocForProject(project1).setIsNewCodeReference(true);
IssueDoc project1Issue2 = newDocForProject(project1).setIsNewCodeReference(false);
}
@Test
- public void filter_by_new_code_reference_branches() {
+ void filter_by_new_code_reference_branches() {
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
IssueDoc project1Issue1 = newDocForProject(project1).setIsNewCodeReference(true);
IssueDoc project1Issue2 = newDocForProject(project1).setIsNewCodeReference(false);
}
@Test
- public void filter_by_severities() {
+ void filter_by_severities() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_statuses() {
+ void filter_by_statuses() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_resolutions() {
+ void filter_by_resolutions() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_resolved() {
+ void filter_by_resolved() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_rules() {
+ void filter_by_rules() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
RuleDto ruleDefinitionDto = newRule();
}
@Test
- public void filter_by_languages() {
+ void filter_by_languages() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
RuleDto ruleDefinitionDto = newRule();
}
@Test
- public void filter_by_assignees() {
+ void filter_by_assignees() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_assigned() {
+ void filter_by_assigned() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_authors() {
+ void filter_by_authors() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_created_after() {
+ void filter_by_prioritized_rule() {
+ ComponentDto project = newPrivateProjectDto();
+ ComponentDto file = newFileDto(project);
+
+ indexIssues(
+ newDoc("I1", project.uuid(), file).setPrioritizedRule(true),
+ newDoc("I2", project.uuid(), file).setPrioritizedRule(true),
+ newDoc("I3", project.uuid(), file).setPrioritizedRule(false));
+
+ assertThatSearchReturnsOnly(IssueQuery.builder().prioritizedRule(null), "I1", "I2", "I3");
+ assertThatSearchReturnsOnly(IssueQuery.builder().prioritizedRule(true), "I1", "I2");
+ assertThatSearchReturnsOnly(IssueQuery.builder().prioritizedRule(false), "I3");
+ }
+
+ @Test
+ void filter_by_created_after() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_created_before() {
+ void filter_by_created_before() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_created_after_and_before() {
+ void filter_by_created_after_and_before() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_created_after_and_before_take_into_account_timezone() {
+ void filter_by_created_after_and_before_take_into_account_timezone() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_created_before_must_be_lower_than_after() {
+ void filter_by_created_before_must_be_lower_than_after() {
try {
underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-19")).build(),
new SearchOptions());
}
@Test
- public void fail_if_created_before_equals_created_after() {
+ void fail_if_created_before_equals_created_after() {
assertThatThrownBy(() -> underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-20"))
.createdBefore(parseDate("2014-09-20")).build(), new SearchOptions()))
.isInstanceOf(IllegalArgumentException.class)
}
@Test
- public void filter_by_created_after_must_not_be_in_future() {
+ void filter_by_created_after_must_not_be_in_future() {
try {
underTest.search(IssueQuery.builder().createdAfter(new Date(Long.MAX_VALUE)).build(), new SearchOptions());
Fail.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
}
@Test
- public void filter_by_created_at() {
+ void filter_by_created_at() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_new_code_reference() {
+ void filter_by_new_code_reference() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_cwe() {
+ void filter_by_cwe() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_owaspAsvs40_category() {
+ void filter_by_owaspAsvs40_category() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_owaspAsvs40_specific_requirement() {
+ void filter_by_owaspAsvs40_specific_requirement() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_owaspAsvs40_level() {
+ void filter_by_owaspAsvs40_level() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_owaspTop10() {
+ void filter_by_owaspTop10() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_sansTop25() {
+ void filter_by_sansTop25() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_sonarSecurity() {
+ void filter_by_sonarSecurity() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_whenFilteringByCodeVariants_shouldReturnRelevantIssues() {
+ void search_whenFilteringByCodeVariants_shouldReturnRelevantIssues() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_whenFilteringBySoftwareQualities_shouldReturnRelevantIssues() {
+ void search_whenFilteringBySoftwareQualities_shouldReturnRelevantIssues() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_whenFilteringByCleanCodeAttributeCategory_shouldReturnRelevantIssues() {
+ void search_whenFilteringByCleanCodeAttributeCategory_shouldReturnRelevantIssues() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void search_whenFilteringByIssueStatus_shouldReturnRelevantIssues() {
+ void search_whenFilteringByIssueStatus_shouldReturnRelevantIssues() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
import java.util.Date;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.db.component.ComponentDto;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
-public class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
+class IssueIndexProjectStatisticsTest extends IssueIndexTestCommon {
@Test
- public void searchProjectStatistics_returns_empty_list_if_no_input() {
+ void searchProjectStatistics_returns_empty_list_if_no_input() {
List<ProjectStatistics> result = underTest.searchProjectStatistics(emptyList(), emptyList(), "unknownUser");
assertThat(result).isEmpty();
}
@Test
- public void searchProjectStatistics_returns_empty_list_if_the_input_does_not_match_anything() {
+ void searchProjectStatistics_returns_empty_list_if_the_input_does_not_match_anything() {
List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList("unknownProjectUuid"), singletonList(1_111_234_567_890L), "unknownUser");
assertThat(result).isEmpty();
}
@Test
- public void searchProjectStatistics_returns_something() {
- ComponentDto project = newPrivateProjectDto();
- String userUuid = randomAlphanumeric(40);
- long from = 1_111_234_567_890L;
- indexIssues(newDocForProject("issue1", project).setAssigneeUuid(userUuid).setFuncCreationDate(new Date(from + 1L)));
-
- List<ProjectStatistics> result = underTest.searchProjectStatistics(singletonList(project.uuid()), singletonList(from), userUuid);
-
- assertThat(result).extracting(ProjectStatistics::getProjectUuid).containsExactly(project.uuid());
- }
-
- @Test
- public void searchProjectStatistics_does_not_return_results_if_assignee_does_not_match() {
+ void searchProjectStatistics_does_not_return_results_if_assignee_does_not_match() {
ComponentDto project = newPrivateProjectDto();
String user1Uuid = randomAlphanumeric(40);
String user2Uuid = randomAlphanumeric(40);
}
@Test
- public void searchProjectStatistics_returns_results_if_assignee_matches() {
+ void searchProjectStatistics_returns_results_if_assignee_matches() {
ComponentDto project = newPrivateProjectDto();
String user1Uuid = randomAlphanumeric(40);
long from = 1_111_234_567_890L;
}
@Test
- public void searchProjectStatistics_returns_results_if_functional_date_is_strictly_after_from_date() {
+ void searchProjectStatistics_returns_results_if_functional_date_is_strictly_after_from_date() {
ComponentDto project = newPrivateProjectDto();
String userUuid = randomAlphanumeric(40);
long from = 1_111_234_567_890L;
}
@Test
- public void searchProjectStatistics_does_not_return_results_if_functional_date_is_same_as_from_date() {
+ void searchProjectStatistics_does_not_return_results_if_functional_date_is_same_as_from_date() {
ComponentDto project = newPrivateProjectDto();
String userUuid = randomAlphanumeric(40);
long from = 1_111_234_567_890L;
}
@Test
- public void searchProjectStatistics_does_not_return_resolved_issues() {
+ void searchProjectStatistics_does_not_return_resolved_issues() {
ComponentDto project = newPrivateProjectDto();
String userUuid = randomAlphanumeric(40);
long from = 1_111_234_567_890L;
}
@Test
- public void searchProjectStatistics_does_not_return_results_if_functional_date_is_before_from_date() {
+ void searchProjectStatistics_does_not_return_results_if_functional_date_is_before_from_date() {
ComponentDto project = newPrivateProjectDto();
String userUuid = randomAlphanumeric(40);
long from = 1_111_234_567_890L;
}
@Test
- public void searchProjectStatistics_returns_issue_count() {
+ void searchProjectStatistics_returns_issue_count() {
ComponentDto project = newPrivateProjectDto();
String userUuid = randomAlphanumeric(40);
long from = 1_111_234_567_890L;
}
@Test
- public void searchProjectStatistics_returns_issue_count_for_multiple_projects() {
+ void searchProjectStatistics_returns_issue_count_for_multiple_projects() {
ComponentDto project1 = newPrivateProjectDto();
ComponentDto project2 = newPrivateProjectDto();
ComponentDto project3 = newPrivateProjectDto();
}
@Test
- public void searchProjectStatistics_returns_max_date_for_multiple_projects() {
+ void searchProjectStatistics_returns_max_date_for_multiple_projects() {
ComponentDto project1 = newPrivateProjectDto();
ComponentDto project2 = newPrivateProjectDto();
ComponentDto project3 = newPrivateProjectDto();
}
@Test
- public void searchProjectStatistics_return_branch_issues() {
+ void searchProjectStatistics_return_branch_issues() {
ComponentDto project = newPrivateProjectDto();
ComponentDto branch = newBranchComponent(project, newBranchDto(project).setKey("branch"));
String userUuid = randomAlphanumeric(40);
package org.sonar.server.issue.index;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
-public class IssueIndexSecurityCategoriesTest extends IssueIndexTestCommon {
+class IssueIndexSecurityCategoriesTest extends IssueIndexTestCommon {
@Test
- public void searchSinglePciDss32Category() {
+ void searchSinglePciDss32Category() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
}
@Test
- public void searchMultiplePciDss32Categories() {
+ void searchMultiplePciDss32Categories() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
}
@Test
- public void searchSinglePciDss40Category() {
+ void searchSinglePciDss40Category() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
}
@Test
- public void searchMultiplePciDss40Categories() {
+ void searchMultiplePciDss40Categories() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
}
@Test
- public void searchMixedPciDssCategories() {
+ void searchMixedPciDssCategories() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
import java.util.Map;
import org.elasticsearch.action.search.SearchResponse;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.rule.Severity;
import org.sonar.db.component.ComponentDto;
import org.sonar.server.es.Facets;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
-public class IssueIndexSecurityHotspotsTest extends IssueIndexTestCommon {
+class IssueIndexSecurityHotspotsTest extends IssueIndexTestCommon {
@Test
- public void filter_by_security_hotspots_type() {
+ void filter_by_security_hotspots_type() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void filter_by_severities_ignore_hotspots() {
+ void filter_by_severities_ignore_hotspots() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void facet_on_severities_ignore_hotspots() {
+ void facet_on_severities_ignore_hotspots() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
import java.util.OptionalInt;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
import static org.sonar.server.security.SecurityStandards.UNKNOWN_STANDARD;
-public class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
+class IssueIndexSecurityReportsTest extends IssueIndexTestCommon {
@Test
- public void getOwaspTop10Report_dont_count_vulnerabilities_from_other_projects() {
+ void getOwaspTop10Report_dont_count_vulnerabilities_from_other_projects() {
ComponentDto project = newPrivateProjectDto();
ComponentDto another = newPrivateProjectDto();
}
@Test
- public void getOwaspTop10Report_dont_count_closed_vulnerabilities() {
+ void getOwaspTop10Report_dont_count_closed_vulnerabilities() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
newDocForProject("openvul1", project).setOwaspTop10(List.of("a1")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR),
}
@Test
- public void getOwaspTop10Report_dont_count_old_vulnerabilities() {
+ void getOwaspTop10Report_dont_count_old_vulnerabilities() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
// Previous vulnerabilities in projects that are not reanalyzed will have no owasp nor cwe attributes (not even 'unknown')
}
@Test
- public void getOwaspTop10Report_dont_count_hotspots_from_other_projects() {
+ void getOwaspTop10Report_dont_count_hotspots_from_other_projects() {
ComponentDto project = newPrivateProjectDto();
ComponentDto another = newPrivateProjectDto();
indexIssues(
}
@Test
- public void getOwaspTop10Report_dont_count_closed_hotspots() {
+ void getOwaspTop10Report_dont_count_closed_hotspots() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
newDocForProject("openhotspot1", project).setOwaspTop10(List.of("a1")).setType(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW),
}
@Test
- public void getOwaspTop10Report_aggregation_no_cwe() {
+ void getOwaspTop10Report_aggregation_no_cwe() {
List<SecurityStandardCategoryStatistics> owaspTop10Report = indexIssuesAndAssertOwaspReport(false);
assertThat(owaspTop10Report)
}
@Test
- public void getPciDss32Report_aggregation() {
+ void getPciDss32Report_aggregation() {
List<SecurityStandardCategoryStatistics> pciDss32Report = indexIssuesAndAssertPciDss32Report();
assertThat(pciDss32Report)
}
@Test
- public void getOwaspAsvs40Report_aggregation() {
+ void getOwaspAsvs40Report_aggregation() {
List<SecurityStandardCategoryStatistics> owaspAsvsReport = indexIssuesAndAssertOwaspAsvsReport();
assertThat(owaspAsvsReport)
}
@Test
- public void getOwaspAsvs40ReportGroupedByLevel_aggregation() {
+ void getOwaspAsvs40ReportGroupedByLevel_aggregation() {
List<SecurityStandardCategoryStatistics> owaspAsvsReportGroupedByLevel = indexIssuesAndAssertOwaspAsvsReportGroupedByLevel();
assertThat(owaspAsvsReportGroupedByLevel)
}
@Test
- public void getOwaspTop10Report_aggregation_with_cwe() {
+ void getOwaspTop10Report_aggregation_with_cwe() {
List<SecurityStandardCategoryStatistics> owaspTop10Report = indexIssuesAndAssertOwaspReport(true);
Map<String, List<SecurityStandardCategoryStatistics>> cweByOwasp = owaspTop10Report.stream()
}
@Test
- public void getOwaspTop10For2021Report_aggregation_with_cwe() {
+ void getOwaspTop10For2021Report_aggregation_with_cwe() {
List<SecurityStandardCategoryStatistics> owaspTop10Report = indexIssuesAndAssertOwasp2021Report(true);
Map<String, List<SecurityStandardCategoryStatistics>> cweByOwasp = owaspTop10Report.stream()
}
@Test
- public void getPciDssReport_aggregation_on_portfolio() {
+ void getPciDssReport_aggregation_on_portfolio() {
ComponentDto portfolio1 = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto portfolio2 = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
}
@Test
- public void getOwaspAsvsReport_aggregation_on_portfolio() {
+ void getOwaspAsvsReport_aggregation_on_portfolio() {
ComponentDto portfolio1 = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto portfolio2 = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
}
@Test
- public void getCWETop25Report_aggregation() {
+ void getCWETop25Report_aggregation() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
newDocForProject("openvul", project).setCwe(List.of("119")).setType(RuleType.VULNERABILITY).setStatus(Issue.STATUS_OPEN)
}
@Test
- public void getCWETop25Report_aggregation_on_portfolio() {
+ void getCWETop25Report_aggregation_on_portfolio() {
ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
package org.sonar.server.issue.index;
import org.elasticsearch.action.search.SearchResponse;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.Severity;
import org.sonar.db.component.ComponentDto;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
-public class IssueIndexSortTest extends IssueIndexTestCommon {
+class IssueIndexSortTest extends IssueIndexTestCommon {
@Test
- public void sort_by_status() {
+ void sort_by_status() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void sort_by_severity() {
+ void sort_by_severity() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void sort_by_creation_date() {
+ void sort_by_creation_date() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void sort_by_update_date() {
+ void sort_by_update_date() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void sort_by_close_date() {
+ void sort_by_close_date() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
}
@Test
- public void sort_by_file_and_line() {
+ void sort_by_file_and_line() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file1 = newFileDto(project, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo");
ComponentDto file2 = newFileDto(project, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo");
}
@Test
- public void default_sort_is_by_creation_date_then_project_then_file_then_line_then_issue_key() {
+ void default_sort_is_by_creation_date_then_project_then_file_then_line_then_issue_key() {
ComponentDto project1 = newPrivateProjectDto("P1");
ComponentDto file1 = newFileDto(project1, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo");
ComponentDto file2 = newFileDto(project1, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo");
*/
package org.sonar.server.issue.index;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.apache.lucene.search.TotalHits;
import org.apache.lucene.search.TotalHits.Relation;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
import static org.sonar.server.issue.IssueDocTesting.newDoc;
import static org.sonar.server.issue.IssueDocTesting.newDocForProject;
-public class IssueIndexTest extends IssueIndexTestCommon {
+class IssueIndexTest extends IssueIndexTestCommon {
@Test
- public void paging() {
+ void paging() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
for (int i = 0; i < 12; i++) {
}
@Test
- public void search_with_max_limit() {
+ void search_with_max_limit() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
List<IssueDoc> issues = new ArrayList<>();
// SONAR-14224
@Test
- public void search_exceeding_default_index_max_window() {
+ void search_exceeding_default_index_max_window() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
List<IssueDoc> issues = new ArrayList<>();
}
@Test
- public void search_nine_issues_with_same_creation_date_sorted_by_creation_date_order_is_sorted_also_by_key() {
+ void search_nine_issues_with_same_creation_date_sorted_by_creation_date_order_is_sorted_also_by_key() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
List<IssueDoc> issues = new ArrayList<>();
}
@Test
- public void search_nine_issues_5_times_with_same_creation_date_sorted_by_creation_date_returned_issues_same_order() {
+ void search_nine_issues_5_times_with_same_creation_date_sorted_by_creation_date_returned_issues_same_order() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project);
List<IssueDoc> issues = new ArrayList<>();
}
@Test
- public void authorized_issues_on_groups() {
+ void authorized_issues_on_groups() {
ProjectData project1 = db.components().insertPublicProject();
ProjectData project2 = db.components().insertPublicProject();
ProjectData project3 = db.components().insertPublicProject();
}
@Test
- public void authorized_issues_on_user() {
+ void authorized_issues_on_user() {
ProjectData project1 = db.components().insertPublicProject();
ProjectData project2 = db.components().insertPublicProject();
ProjectData project3 = db.components().insertPublicProject();
}
@Test
- public void list_tags() {
+ void list_tags() {
RuleDto r1 = db.rules().insert();
RuleDto r2 = db.rules().insert();
ruleIndexer.commitAndIndex(db.getSession(), asList(r1.getUuid(), r2.getUuid()));
}
@Test
- public void list_authors() {
+ void list_authors() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
newDocForProject("issue1", project).setAuthorLogin("luke.skywalker"),
}
@Test
- public void list_authors_escapes_regexp_special_characters() {
+ void prioritized_rules() {
+ ComponentDto project = newPrivateProjectDto();
+ indexIssues(
+ newDocForProject("issue1", project).setPrioritizedRule(true),
+ newDocForProject("issue2", project).setPrioritizedRule(false));
+
+ assertThatSearchReturnsOnly(IssueQuery.builder(), "issue1", "issue2");
+ assertThatSearchReturnsOnly(IssueQuery.builder().prioritizedRule(true), "issue1");
+ assertThatSearchReturnsOnly(IssueQuery.builder().prioritizedRule(false), "issue2");
+ }
+
+ @Test
+ void list_authors_escapes_regexp_special_characters() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
newDocForProject("issue1", project).setAuthorLogin("name++"));
}
@Test
- public void countTags() {
+ void countTags() {
ComponentDto project = newPrivateProjectDto();
indexIssues(
- newDocForProject("issue1", project).setTags(ImmutableSet.of("convention", "java8", "bug")),
- newDocForProject("issue2", project).setTags(ImmutableSet.of("convention", "bug")),
+ newDocForProject("issue1", project).setTags(Set.of("convention", "java8", "bug")),
+ newDocForProject("issue2", project).setTags(Set.of("convention", "bug")),
newDocForProject("issue3", project).setTags(emptyList()),
- newDocForProject("issue4", project).setTags(ImmutableSet.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED),
- newDocForProject("issue5", project).setTags(ImmutableSet.of("convention")));
+ newDocForProject("issue4", project).setTags(Set.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED),
+ newDocForProject("issue5", project).setTags(Set.of("convention")));
assertThat(underTest.countTags(projectQuery(project.uuid()), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L));
assertThat(underTest.countTags(projectQuery(project.uuid()), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L);
import java.util.Arrays;
import java.util.List;
import org.elasticsearch.search.SearchHit;
-import org.junit.Rule;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
public class IssueIndexTestCommon {
- @Rule
+ @RegisterExtension
public EsTester es = EsTester.create();
- @Rule
+ @RegisterExtension
public UserSessionRule userSessionRule = UserSessionRule.standalone();
protected final System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(getTimeZone("GMT-01:00"));
- @Rule
+ @RegisterExtension
public DbTester db = DbTester.create(system2);
private final AsyncIssueIndexing asyncIssueIndexing = mock(AsyncIssueIndexing.class);
.setRules(asList(rule1.getKey().toString(), rule2.getKey().toString()))
.setSort("CREATION_DATE")
.setAsc(true)
- .setCodeVariants(asList("variant1", "variant2"));
+ .setCodeVariants(asList("variant1", "variant2"))
+ .setPrioritizedRule(true);
IssueQuery query = underTest.create(request);
assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_CREATION_DATE);
assertThat(query.asc()).isTrue();
assertThat(query.codeVariants()).containsOnly("variant1", "variant2");
+ assertThat(query.prioritizedRule()).isTrue();
}
@Test
.setRules(asList(rule1.getKey().toString(), rule2.getKey().toString()))
.setSort("CREATION_DATE")
.setAsc(true)
- .setCodeVariants(asList("variant1", "variant2"));
+ .setCodeVariants(asList("variant1", "variant2"))
+ .setPrioritizedRule(false);
IssueQuery query = underTest.create(request);
assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_CREATION_DATE);
assertThat(query.asc()).isTrue();
assertThat(query.codeVariants()).containsOnly("variant1", "variant2");
+ assertThat(query.prioritizedRule()).isFalse();
}
@Test
import com.google.common.collect.ImmutableMap;
import java.util.Date;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.Severity;
import org.sonar.core.util.Uuids;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
-public class IssueQueryTest {
+class IssueQueryTest {
@Test
- public void build_query() {
+ void build_query() {
RuleDto rule = new RuleDto().setUuid(Uuids.createFast());
PeriodStart filterDate = new IssueQuery.PeriodStart(new Date(10_000_000_000L), false);
IssueQuery query = IssueQuery.builder()
.sort(IssueQuery.SORT_BY_CREATION_DATE)
.asc(true)
.codeVariants(List.of("codeVariant1", "codeVariant2"))
+ .prioritizedRule(true)
.build();
assertThat(query.issueKeys()).containsOnly("ABCDE");
assertThat(query.severities()).containsOnly(Severity.BLOCKER);
assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_CREATION_DATE);
assertThat(query.asc()).isTrue();
assertThat(query.codeVariants()).containsOnly("codeVariant1", "codeVariant2");
+ assertThat(query.prioritizedRule()).isTrue();
}
@Test
- public void build_pci_dss_query() {
+ void build_pci_dss_query() {
IssueQuery query = IssueQuery.builder()
.pciDss32(List.of("1.2.3", "3.2.1"))
.pciDss40(List.of("3.4.5", "5.6"))
}
@Test
- public void build_owasp_asvs_query() {
+ void build_owasp_asvs_query() {
IssueQuery query = IssueQuery.builder()
.owaspAsvs40(List.of("1.2.3", "3.2.1"))
.owaspAsvsLevel(2)
}
@Test
- public void build_owasp_query() {
+ void build_owasp_query() {
IssueQuery query = IssueQuery.builder()
.owaspTop10(List.of("a1", "a2"))
.owaspTop10For2021(List.of("a3", "a4"))
@Test
- public void build_query_without_dates() {
+ void build_query_without_dates() {
IssueQuery query = IssueQuery.builder()
.issueKeys(List.of("ABCDE"))
.createdAfter(null)
}
@Test
- public void throw_exception_if_sort_is_not_valid() {
+ void throw_exception_if_sort_is_not_valid() {
try {
IssueQuery.builder()
.sort("UNKNOWN")
}
@Test
- public void collection_params_should_not_be_null_but_empty_except_issue_keys() {
+ void collection_params_should_not_be_null_but_empty_except_issue_keys() {
IssueQuery query = IssueQuery.builder()
.issueKeys(null)
.projectUuids(null)
}
@Test
- public void test_default_query() {
+ void test_default_query() {
IssueQuery query = IssueQuery.builder().build();
assertThat(query.projectUuids()).isEmpty();
assertThat(query.componentUuids()).isEmpty();
assertThat(query.resolved()).isNull();
assertThat(query.sort()).isNull();
assertThat(query.createdAfterByProjectUuids()).isEmpty();
+ assertThat(query.prioritizedRule()).isNull();
}
@Test
- public void should_accept_null_sort() {
+ void should_accept_null_sort() {
IssueQuery query = IssueQuery.builder().sort(null).build();
assertThat(query.sort()).isNull();
}
"createdBefore", "createdInLast", "directories", "facets", "files", "issues", "scopes", "languages", "onComponentOnly",
"p", "projects", "ps", "resolutions", "resolved", "rules", "s", "severities", "statuses", "tags", "types", "pciDss-3.2", "pciDss-4.0", "owaspAsvs-4.0",
"owaspAsvsLevel", "owaspTop10", "owaspTop10-2021", "sansTop25", "cwe", "sonarsourceSecurity", "timeZone", "inNewCodePeriod", "codeVariants",
- "cleanCodeAttributeCategories", "impactSeverities", "impactSoftwareQualities", "issueStatuses", "fixedInPullRequest");
+ "cleanCodeAttributeCategories", "impactSeverities", "impactSoftwareQualities", "issueStatuses", "fixedInPullRequest",
+ "prioritizedRule");
WebService.Param branch = def.param(PARAM_BRANCH);
assertThat(branch.isInternal()).isFalse();
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_TOP_10_2021;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PCI_DSS_32;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PCI_DSS_40;
+import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PRIORITIZED_RULE;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RESOLUTIONS;
+ "<br/>When issue indexing is in progress returns 503 service unavailable HTTP code.")
.setSince("3.6")
.setChangelog(
+ new Change("10.6", format(NEW_FACET_ADDED_MESSAGE, PARAM_PRIORITIZED_RULE)),
+ new Change("10.6", format(NEW_PARAM_ADDED_MESSAGE, PARAM_PRIORITIZED_RULE)),
new Change("10.4", "Added new param '%s'".formatted(PARAM_FIXED_IN_PULL_REQUEST)),
new Change("10.4",
"Value '%s' for 'transition' response field is deprecated, use '%s' instead".formatted(DefaultTransitions.WONT_FIX,
action.createParam(PARAM_RESOLVED)
.setDescription("To match resolved or unresolved issues")
.setBooleanPossibleValues();
+ action.createParam(PARAM_PRIORITIZED_RULE)
+ .setDescription("To match issues with prioritized rule or not")
+ .setBooleanPossibleValues();
action.createParam(PARAM_RULES)
.setDescription("Comma-separated list of coding rule keys. Format is <repository>:<rule>")
.setExampleValue("java:S1144");
.setProjectKeys(request.paramAsStrings(PARAM_PROJECTS))
.setResolutions(request.paramAsStrings(PARAM_RESOLUTIONS))
.setResolved(request.paramAsBoolean(PARAM_RESOLVED))
+ .setPrioritizedRule(request.paramAsBoolean(PARAM_PRIORITIZED_RULE))
.setRules(request.paramAsStrings(PARAM_RULES))
.setSort(request.param(Param.SORT))
.setSeverities(request.paramAsStrings(PARAM_SEVERITIES))
.ifPresentOrElse(issueBuilder::setQuickFixAvailable, () -> issueBuilder.setQuickFixAvailable(false));
issueBuilder.setScope(UNIT_TEST_FILE.equals(component.qualifier()) ? IssueScope.TEST.name() : IssueScope.MAIN.name());
+ issueBuilder.setPrioritizedRule(dto.isPrioritizedRule());
}
private static void addAdditionalFieldsToIssueBuilder(Collection<SearchAdditionalField> fields, SearchResponseData data, IssueDto dto, Issue.Builder issueBuilder) {
"cleanCodeAttribute": "CLEAR",
"cleanCodeAttributeCategory": "INTENTIONAL",
"issueStatus": "ACCEPTED",
+ "prioritizedRule": false,
"impacts": [
{
"softwareQuality": "SECURITY",
import org.sonar.server.issue.AssignAction;
import org.sonar.server.issue.CommentAction;
import org.sonar.server.issue.IssueChangePostProcessorImpl;
+import org.sonar.server.issue.PrioritizedRulesFeature;
import org.sonar.server.issue.RemoveTagsAction;
import org.sonar.server.issue.SetSeverityAction;
import org.sonar.server.issue.SetTypeAction;
IssueIndexer.class,
IssueIteratorFactory.class,
PermissionIndexer.class,
+ PrioritizedRulesFeature.class,
new IssueWsModule(),
NewIssuesEmailTemplate.class,
MyNewIssuesEmailTemplate.class,
public static final String PARAM_RESOLUTIONS = "resolutions";
public static final String PARAM_ISSUE_STATUSES = "issueStatuses";
public static final String PARAM_RESOLVED = "resolved";
+ public static final String PARAM_PRIORITIZED_RULE = "prioritizedRule";
public static final String PARAM_COMPONENTS = "components";
public static final String PARAM_COMPONENT_KEYS = "componentKeys";
public static final String PARAM_COMPONENT_UUIDS = "componentUuids";
optional sonarqube.ws.commons.CleanCodeAttributeCategory cleanCodeAttributeCategory = 41;
repeated sonarqube.ws.commons.Impact impacts = 42;
optional string issueStatus = 43;
+ optional bool prioritizedRule = 44;
}
message Transitions {