@Test public void assignedToMe_facet_must_escape_login_of_authenticated_user() { // login looks like an invalid regexp UserDto user = db.users().insertUser(u -> u.setLogin("foo[")); userSession.logIn(user); // should not fail SearchWsResponse response = ws.newRequest() .setParam(FACETS, "assigned_to_me") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder( tuple("assigned_to_me", of("foo[", 0L))); }
@Test public void check_projects_facet_max_size() { RuleDefinitionDto rule = db.rules().insert(); IntStream.rangeClosed(1, 110) .forEach(i -> { ComponentDto project = db.components().insertPublicProject(); db.issues().insert(rule, project, project); }); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam(FACETS, "projects") .executeProtobuf(SearchWsResponse.class); assertThat(response.getPaging().getTotal()).isEqualTo(110); assertThat(response.getFacets().getFacets(0).getValuesCount()).isEqualTo(100); }
.executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(
.executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(
.executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, Common.Facet::getValuesCount) .containsExactlyInAnyOrder(
.executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(
@Test public void projects_facet_is_sticky() { OrganizationDto organization1 = db.organizations().insert(); OrganizationDto organization2 = db.organizations().insert(); OrganizationDto organization3 = db.organizations().insert(); ComponentDto project1 = db.components().insertPublicProject(organization1); ComponentDto project2 = db.components().insertPublicProject(organization2); ComponentDto project3 = db.components().insertPublicProject(organization3); ComponentDto file1 = db.components().insertComponent(newFileDto(project1)); ComponentDto file2 = db.components().insertComponent(newFileDto(project2)); ComponentDto file3 = db.components().insertComponent(newFileDto(project3)); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project1, file1); db.issues().insert(rule, project2, file2); db.issues().insert(rule, project3, file3); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam(PARAM_PROJECTS, project1.getKey()) .setParam(WebService.Param.FACETS, "projects") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(tuple("projects", of(project1.getKey(), 1L, project2.getKey(), 1L, project3.getKey(), 1L))); }
@Test public void display_moduleUuids_facet_using_project() { ComponentDto project = db.components().insertPublicProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto subModule1 = db.components().insertComponent(newModuleDto(module)); ComponentDto subModule2 = db.components().insertComponent(newModuleDto(module)); ComponentDto subModule3 = db.components().insertComponent(newModuleDto(module)); ComponentDto file1 = db.components().insertComponent(newFileDto(subModule1)); ComponentDto file2 = db.components().insertComponent(newFileDto(subModule2)); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, file1); db.issues().insert(rule, project, file2); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam(PARAM_PROJECTS, project.getKey()) .setParam(PARAM_COMPONENT_UUIDS, module.uuid()) .setParam(PARAM_MODULE_UUIDS, subModule1.uuid()) .setParam(WebService.Param.FACETS, "moduleUuids") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(tuple("moduleUuids", of(subModule1.uuid(), 1L, subModule2.uuid(), 1L))); }
@Test public void display_module_facet_using_organization() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto subModule1 = db.components().insertComponent(newModuleDto(module)); ComponentDto subModule2 = db.components().insertComponent(newModuleDto(module)); ComponentDto subModule3 = db.components().insertComponent(newModuleDto(module)); ComponentDto file1 = db.components().insertComponent(newFileDto(subModule1)); ComponentDto file2 = db.components().insertComponent(newFileDto(subModule2)); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, file1); db.issues().insert(rule, project, file2); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_COMPONENT_UUIDS, module.uuid()) .setParam(PARAM_MODULE_UUIDS, subModule1.uuid() + "," + subModule2.uuid()) .setParam(WebService.Param.FACETS, "moduleUuids") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(tuple("moduleUuids", of(subModule1.uuid(), 1L, subModule2.uuid(), 1L))); }
@Test public void display_fileUuids_facet_with_project() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); 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().insert(); db.issues().insert(rule, project, file1); db.issues().insert(rule, project, file2); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, project.getKey()) .setParam(PARAM_FILE_UUIDS, file1.uuid()) .setParam(WebService.Param.FACETS, "fileUuids") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(tuple("fileUuids", of(file1.uuid(), 1L, file2.uuid(), 1L))); }
@Test public void assigned_to_me_facet_is_sticky_relative_to_assignees() { ComponentDto project = db.components().insertPublicProject(); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(); UserDto john = db.users().insertUser(); UserDto alice = db.users().insertUser(); db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(john.getUuid())); db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(alice.getUuid())); db.issues().insert(rule, project, file, i -> i.setAssigneeUuid(null)); indexIssues(); userSession.logIn(john); SearchWsResponse response = ws.newRequest() .setParam("resolved", "false") .setParam("assignees", alice.getLogin()) .setParam(FACETS, "assignees,assigned_to_me") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder( tuple("assignees", of(john.getLogin(), 1L, alice.getLogin(), 1L, "", 1L)), tuple("assigned_to_me", of(john.getLogin(), 1L))); }
@Test public void display_fileUuids_facet_with_organization() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); 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().insert(); db.issues().insert(rule, project, file1); db.issues().insert(rule, project, file2); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_FILE_UUIDS, file1.uuid()) .setParam(WebService.Param.FACETS, "fileUuids") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(tuple("fileUuids", of(file1.uuid(), 1L, file2.uuid(), 1L))); }
@Test public void display_directory_facet_using_organization() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); ComponentDto directory = db.components().insertComponent(newDirectory(project, "src/main/java/dir")); ComponentDto file = db.components().insertComponent(newFileDto(project, directory)); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, file); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam("resolved", "false") .setParam(PARAM_ORGANIZATION, organization.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))); }
@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().insert(); db.issues().insert(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))); }
@Test public void display_projects_facet() { ComponentDto project = db.components().insertPublicProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, file); indexPermissions(); indexIssues(); SearchWsResponse response = ws.newRequest() .setParam(PARAM_PROJECTS, project.getKey()) .setParam(WebService.Param.FACETS, "projects") .executeProtobuf(SearchWsResponse.class); assertThat(response.getFacets().getFacetsList()) .extracting(Common.Facet::getProperty, facet -> facet.getValuesList().stream().collect(toMap(FacetValue::getVal, FacetValue::getCount))) .containsExactlyInAnyOrder(tuple("projects", of(project.getKey(), 1L))); }