@Test public void does_not_return_branches() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); setBrowsePermissionOnUserAndIndex(project, branch); SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT, MODULE, FILE))); assertThat(response.getComponentsList()).extracting(Component::getKey) .containsOnly(project.getDbKey()); }
private void setBrowsePermissionOnUserAndIndex(ComponentDto... projects) { index(); Arrays.stream(projects).forEach(project -> authorizationIndexerTester.allowOnlyUser(project, user)); }
@Test public void search_with_pagination() { OrganizationDto organizationDto = db.organizations().insert(); List<ComponentDto> componentDtoList = new ArrayList<>(); for (int i = 1; i <= 9; i++) { componentDtoList.add(newPrivateProjectDto(organizationDto, "project-uuid-" + i).setDbKey("project-key-" + i).setName("Project Name " + i)); } insertProjectsAuthorizedForUser(componentDtoList.toArray(new ComponentDto[] {})); SearchWsResponse response = call(new SearchRequest().setOrganization(organizationDto.getKey()).setPage(2).setPageSize(3).setQualifiers(singletonList(PROJECT))); assertThat(response.getComponentsList()).extracting(Component::getKey).containsExactly("project-key-4", "project-key-5", "project-key-6"); }
@Test public void fail_if_unknown_qualifier_provided() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Value of parameter 'qualifiers' (Unknown-Qualifier) must be one of: [BRC, DIR, FIL, TRK]"); call(new SearchRequest().setQualifiers(singletonList("Unknown-Qualifier"))); }
private void insertProjectsAuthorizedForUser(ComponentDto... projects) { db.components().insertComponents(projects); setBrowsePermissionOnUserAndIndex(projects); db.commit(); }
@Before public void setUp() { resourceTypes.setAllQualifiers(PROJECT, MODULE, DIRECTORY, FILE); when(languages.all()).thenReturn(javaLanguage()); ws = new WsActionTester(new SearchAction(index, db.getDbClient(), resourceTypes, i18n, languages, defaultOrganizationProvider)); user = db.users().insertUser("john"); userSession.logIn(user); }
@Test public void fail_when_no_qualifier_provided() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The 'qualifiers' parameter is missing"); call(new SearchRequest()); }
@Test public void test_json_example() { OrganizationDto organizationDto = db.organizations().insertForKey("my-org-1"); db.components().insertComponent(newView(organizationDto)); ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid").setName("Project Name").setDbKey("project-key"); ComponentDto module = newModuleDto("module-uuid", project).setName("Module Name").setDbKey("module-key"); ComponentDto directory = newDirectory(module, "path/to/directoy").setUuid("directory-uuid").setDbKey("directory-key").setName("Directory Name"); db.components().insertComponents(project, module, directory, newFileDto(module, directory, "file-uuid").setDbKey("file-key").setLanguage("java").setName("File Name")); setBrowsePermissionOnUserAndIndex(project); String response = ws.newRequest() .setMediaType(MediaTypes.JSON) .setParam(PARAM_ORGANIZATION, organizationDto.getKey()) .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(PROJECT, DIRECTORY, FILE)) .execute().getInput(); assertJson(response).isSimilarTo(ws.getDef().responseExampleAsString()); }
@Test public void search_for_files() { ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); ComponentDto file1 = newFileDto(project).setDbKey("file1"); ComponentDto file2 = newFileDto(project).setDbKey("file2"); db.components().insertComponents(project, file1, file2); setBrowsePermissionOnUserAndIndex(project); SearchWsResponse response = call(new SearchRequest().setQuery(file1.getDbKey()).setQualifiers(singletonList(FILE))); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(file1.getDbKey()); }
@Test public void search_by_key_query() { insertProjectsAuthorizedForUser( ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("project-_%-key"), ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("project-key-without-escaped-characters")); SearchWsResponse response = call(new SearchRequest().setQuery("project-_%-key").setQualifiers(singletonList(PROJECT))); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("project-_%-key"); }
@Test public void return_only_components_from_projects_on_which_user_has_browse_permission() { ComponentDto project1 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); ComponentDto file1 = newFileDto(project1).setDbKey("file1"); ComponentDto file2 = newFileDto(project1).setDbKey("file2"); ComponentDto project2 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); ComponentDto file3 = newFileDto(project2).setDbKey("file3"); db.components().insertComponents(project1, file1, file2, project2, file3); setBrowsePermissionOnUserAndIndex(project1); SearchWsResponse response = call(new SearchRequest().setQualifiers(singletonList(FILE))); assertThat(response.getComponentsList()).extracting(Component::getKey) .containsExactlyInAnyOrder(file1.getDbKey(), file2.getDbKey()); assertThat(response.getPaging().getTotal()).isEqualTo(2); }
@Test public void search_with_language() { OrganizationDto organizationDto = db.organizations().insert(); insertProjectsAuthorizedForUser( ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("java-project").setLanguage("java"), ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("cpp-project").setLanguage("cpp")); SearchWsResponse response = call(new SearchRequest().setOrganization(organizationDto.getKey()).setLanguage("java").setQualifiers(singletonList(PROJECT))); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("java-project"); }
@Test public void return_project_key() { ComponentDto project = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()); ComponentDto module = ComponentTesting.newModuleDto(project); ComponentDto file1 = newFileDto(module).setDbKey("file1"); ComponentDto file2 = newFileDto(module).setDbKey("file2"); ComponentDto file3 = newFileDto(project).setDbKey("file3"); db.components().insertComponents(project, module, file1, file2, file3); setBrowsePermissionOnUserAndIndex(project); SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT, MODULE, FILE))); assertThat(response.getComponentsList()).extracting(Component::getKey, Component::getProject) .containsOnly(tuple(project.getDbKey(), project.getDbKey()), tuple(module.getDbKey(), project.getDbKey()), tuple(file1.getDbKey(), project.getDbKey()), tuple(file2.getDbKey(), project.getDbKey()), tuple(file3.getDbKey(), project.getDbKey())); }