private void insertProjectsAuthorizedForUser(ComponentDto... projects) { db.components().insertComponents(projects); setBrowsePermissionOnUserAndIndex(projects); db.commit(); }
@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()); }
@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_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 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())); }
@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()); }