Search in sources :

Example 6 with FacetValue

use of org.sonarqube.ws.Common.FacetValue in project sonarqube by SonarSource.

the class SearchActionFacetsTest method display_all_facets.

@Test
public void display_all_facets() {
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto file = db.components().insertComponent(newFileDto(module));
    RuleDefinitionDto rule = db.rules().insertIssueRule();
    UserDto user = db.users().insertUser();
    db.issues().insertIssue(rule, project, file, i -> i.setSeverity("MAJOR").setStatus("OPEN").setType(RuleType.CODE_SMELL).setEffort(10L).setAssigneeUuid(user.getUuid()));
    indexPermissions();
    indexIssues();
    SearchWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT_KEYS, project.getKey()).setParam(FACETS, "severities,statuses,resolutions,rules,types,languages,projects,moduleUuids,files,assignees").executeProtobuf(SearchWsResponse.class);
    Map<String, Number> expectedStatuses = ImmutableMap.<String, Number>builder().put("OPEN", 1L).put("CONFIRMED", 0L).put("REOPENED", 0L).put("RESOLVED", 0L).put("CLOSED", 0L).build();
    assertThat(response.getFacets().getFacetsList()).extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))).containsExactlyInAnyOrder(tuple("severities", of("INFO", 0L, "MINOR", 0L, "MAJOR", 1L, "CRITICAL", 0L, "BLOCKER", 0L)), tuple("statuses", expectedStatuses), tuple("resolutions", of("", 1L, "FALSE-POSITIVE", 0L, "FIXED", 0L, "REMOVED", 0L, "WONTFIX", 0L)), tuple("rules", of(rule.getKey().toString(), 1L)), tuple("types", of("CODE_SMELL", 1L, "BUG", 0L, "VULNERABILITY", 0L)), tuple("languages", of(rule.getLanguage(), 1L)), tuple("projects", of(project.getKey(), 1L)), tuple("moduleUuids", of(module.uuid(), 1L)), tuple("files", of(file.path(), 1L)), tuple("assignees", of("", 0L, user.getLogin(), 1L)));
}
Also used : IntStream(java.util.stream.IntStream) FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_PROJECTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS) Random(java.util.Random) RuleType(org.sonar.api.rules.RuleType) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Collectors.toMap(java.util.stream.Collectors.toMap) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) PARAM_FILES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES) Map(java.util.Map) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Durations(org.sonar.api.utils.Durations) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Common(org.sonarqube.ws.Common) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Issue(org.sonar.api.issue.Issue) FacetValue(org.sonarqube.ws.Common.FacetValue) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 7 with FacetValue

use of org.sonarqube.ws.Common.FacetValue in project sonarqube by SonarSource.

the class SearchActionFacetsTest method display_directory_facet_using_project.

@Test
public void display_directory_facet_using_project() {
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto directory = db.components().insertComponent(newDirectory(project, "src/main/java/dir"));
    ComponentDto file = db.components().insertComponent(newFileDto(project, directory));
    RuleDefinitionDto rule = db.rules().insertIssueRule();
    db.issues().insertIssue(rule, project, file);
    indexPermissions();
    indexIssues();
    SearchWsResponse response = ws.newRequest().setParam("resolved", "false").setParam(PARAM_COMPONENT_KEYS, project.getKey()).setParam(WebService.Param.FACETS, "directories").executeProtobuf(SearchWsResponse.class);
    assertThat(response.getFacets().getFacetsList()).extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))).containsExactlyInAnyOrder(tuple("directories", of(directory.path(), 1L)));
}
Also used : IntStream(java.util.stream.IntStream) FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_PROJECTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS) Random(java.util.Random) RuleType(org.sonar.api.rules.RuleType) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Collectors.toMap(java.util.stream.Collectors.toMap) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) PARAM_FILES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES) Map(java.util.Map) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Durations(org.sonar.api.utils.Durations) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Common(org.sonarqube.ws.Common) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Issue(org.sonar.api.issue.Issue) FacetValue(org.sonarqube.ws.Common.FacetValue) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 8 with FacetValue

use of org.sonarqube.ws.Common.FacetValue in project sonarqube by SonarSource.

the class SearchActionFacetsTest method display_files_facet_with_project.

@Test
public void display_files_facet_with_project() {
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto file1 = db.components().insertComponent(newFileDto(project));
    ComponentDto file2 = db.components().insertComponent(newFileDto(project));
    ComponentDto file3 = db.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule = db.rules().insertIssueRule();
    db.issues().insertIssue(rule, project, file1);
    db.issues().insertIssue(rule, project, file2);
    indexPermissions();
    indexIssues();
    SearchWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT_KEYS, project.getKey()).setParam(PARAM_FILES, file1.path()).setParam(WebService.Param.FACETS, "files").executeProtobuf(SearchWsResponse.class);
    assertThat(response.getFacets().getFacetsList()).extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))).containsExactlyInAnyOrder(tuple("files", of(file1.path(), 1L, file2.path(), 1L)));
}
Also used : IntStream(java.util.stream.IntStream) FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_PROJECTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS) Random(java.util.Random) RuleType(org.sonar.api.rules.RuleType) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Collectors.toMap(java.util.stream.Collectors.toMap) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) PARAM_FILES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES) Map(java.util.Map) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Durations(org.sonar.api.utils.Durations) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) Common(org.sonarqube.ws.Common) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Issue(org.sonar.api.issue.Issue) FacetValue(org.sonarqube.ws.Common.FacetValue) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)8 ImmutableMap.of (com.google.common.collect.ImmutableMap.of)8 Clock (java.time.Clock)8 Map (java.util.Map)8 Random (java.util.Random)8 Collectors.toMap (java.util.stream.Collectors.toMap)8 IntStream (java.util.stream.IntStream)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)8 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)8 Rule (org.junit.Rule)8 Test (org.junit.Test)8 Issue (org.sonar.api.issue.Issue)8 Languages (org.sonar.api.resources.Languages)8 RuleType (org.sonar.api.rules.RuleType)8 WebService (org.sonar.api.server.ws.WebService)8 FACETS (org.sonar.api.server.ws.WebService.Param.FACETS)8 Durations (org.sonar.api.utils.Durations)8 System2 (org.sonar.api.utils.System2)8 DbTester (org.sonar.db.DbTester)8