@SafeVarargs public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) { return insertComponentImpl(newPublicProjectDto(organizationDto), false, dtoPopulators); }
@SafeVarargs public final ComponentDto insertPublicProject(Consumer<ComponentDto>... dtoPopulators) { return insertComponentImpl(newPublicProjectDto(db.getDefaultOrganization()), false, dtoPopulators); }
public ComponentDto insertPublicProject(OrganizationDto organizationDto, String uuid) { return insertComponentImpl(newPublicProjectDto(organizationDto, uuid), false, noExtraConfiguration()); }
public ComponentDto insertPublicProject(OrganizationDto organizationDto) { return insertComponentImpl(newPublicProjectDto(organizationDto), false, noExtraConfiguration()); }
@Test public void commitAndIndex_indexes_project() { OrganizationDto organization = OrganizationTesting.newOrganizationDto(); ComponentDto project = ComponentTesting.newPublicProjectDto(organization); FakeIndexers underTest = new FakeIndexers(); underTest.commitAndIndex(mock(DbSession.class), singletonList(project), Cause.PROJECT_CREATION); assertThat(underTest.calls).containsExactly(project.uuid()); }
@Test public void commitAndIndex_of_module_indexes_the_project() { OrganizationDto organization = OrganizationTesting.newOrganizationDto(); ComponentDto project = ComponentTesting.newPublicProjectDto(organization); ComponentDto module = ComponentTesting.newModuleDto(project); FakeIndexers underTest = new FakeIndexers(); underTest.commitAndIndex(mock(DbSession.class), singletonList(module), Cause.PROJECT_CREATION); assertThat(underTest.calls).containsExactly(project.uuid()); }
public ComponentDto insertPublicProject() { return insertComponentImpl(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, noExtraConfiguration()); }
private ComponentDto newProjectDto(String uuid) { return ComponentTesting.newPublicProjectDto(db.getDefaultOrganization(), uuid).setName("name_" + uuid).setDbKey("key_" + uuid); }
private ComponentDto insertJdk7() { return db.components().insertComponent(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()) .setName("JDK 7") .setDbKey("net.java.openjdk:jdk7") .setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a")); } }
@Test public void apply_template_by_query_on_name_and_key_public_project() { ComponentDto publicProjectFoundByKey = ComponentTesting.newPublicProjectDto(organization).setDbKey("sonar"); db.components().insertProjectAndSnapshot(publicProjectFoundByKey); ComponentDto publicProjectFoundByName = ComponentTesting.newPublicProjectDto(organization).setName("name-sonar-name"); db.components().insertProjectAndSnapshot(publicProjectFoundByName); ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto(organization).setDbKey("new-sona").setName("project-name"); db.components().insertProjectAndSnapshot(projectUntouched); loginAsAdmin(organization); newRequest() .setParam(PARAM_TEMPLATE_ID, template1.getUuid()) .setParam(Param.TEXT_QUERY, "SONAR") .execute(); assertTemplate1AppliedToPublicProject(publicProjectFoundByKey); assertTemplate1AppliedToPublicProject(publicProjectFoundByName); assertNoPermissionOnProject(projectUntouched); }
@Test public void should_mark_favorite_items() { ComponentDto favouriteProject = db.components().insertComponent(newPrivateProjectDto(organization).setName("Project1")); ComponentDto nonFavouriteProject = db.components().insertComponent(newPublicProjectDto(organization).setName("Project2")); doReturn(singletonList(favouriteProject)).when(favoriteFinder).list(); componentIndexer.indexOnAnalysis(favouriteProject.projectUuid()); componentIndexer.indexOnAnalysis(nonFavouriteProject.projectUuid()); authorizationIndexerTester.allowOnlyAnyone(favouriteProject, nonFavouriteProject); SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") .setParam(PARAM_QUERY, "Project") .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .extracting(Suggestion::getKey, Suggestion::getIsFavorite) .containsExactly(tuple(favouriteProject.getDbKey(), true), tuple(nonFavouriteProject.getDbKey(), false)); }
@Test public void search_private_projects() { userSession.addPermission(ADMINISTER, db.getDefaultOrganization()); db.components().insertComponents( ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("private-key"), ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("public-key")); SearchWsResponse response = call(SearchRequest.builder().setVisibility("private").build()); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("private-key"); }
@Test public void search_public_projects() { userSession.addPermission(ADMINISTER, db.getDefaultOrganization()); db.components().insertComponents( ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("private-key"), ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("public-key")); SearchWsResponse response = call(SearchRequest.builder().setVisibility("public").build()); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("public-key"); }
@Test public void selectByQuery_filter_on_visibility() { db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("private-key")); db.components().insertComponent(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("public-key")); ComponentQuery privateProjectsQuery = ComponentQuery.builder().setPrivate(true).setQualifiers(PROJECT).build(); ComponentQuery publicProjectsQuery = ComponentQuery.builder().setPrivate(false).setQualifiers(PROJECT).build(); ComponentQuery allProjectsQuery = ComponentQuery.builder().setPrivate(null).setQualifiers(PROJECT).build(); assertThat(underTest.selectByQuery(dbSession, privateProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsExactly("private-key"); assertThat(underTest.selectByQuery(dbSession, publicProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsExactly("public-key"); assertThat(underTest.selectByQuery(dbSession, allProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsOnly("public-key", "private-key"); }
@Test public void components_contains_sub_projects() { OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-1")); ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("ProjectHavingModule")); indexPermissions(); ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setDbKey("ModuleHavingFile")); ComponentDto file = db.components().insertComponent(newFileDto(module, null, "BCDE").setDbKey("FileLinkedToModule")); IssueDto issue = newDto(newRule(), file, project); dbClient.issueDao().insert(session, issue); session.commit(); indexIssues(); ws.newRequest().setParam(PARAM_ADDITIONAL_FIELDS, "_all").execute() .assertJson(this.getClass(), "components_contains_sub_projects.json"); }
@Test public void apply_paging_with_one_component() { RuleDto rule = newRule(); OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-2")); ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("PROJECT_KEY")); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); for (int i = 0; i < SearchOptions.MAX_LIMIT + 1; i++) { IssueDto issue = newDto(rule, file, project).setAssigneeUuid(null); dbClient.issueDao().insert(session, issue); } session.commit(); indexIssues(); ws.newRequest().setParam(PARAM_COMPONENTS, file.getDbKey()).execute() .assertJson(this.getClass(), "apply_paging_with_one_component.json"); }
@Test public void paging_with_page_size_to_minus_one() { RuleDto rule = newRule(); OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-1")); ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("PROJECT_KEY")); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); for (int i = 0; i < 12; i++) { IssueDto issue = newDto(rule, file, project); dbClient.issueDao().insert(session, issue); } session.commit(); indexIssues(); ws.newRequest() .setParam(WebService.Param.PAGE, "1") .setParam(WebService.Param.PAGE_SIZE, "-1") .execute() .assertJson(this.getClass(), "paging_with_page_size_to_minus_one.json"); }
@Test public void deprecated_paging() { RuleDto rule = newRule(); OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-1")); ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("PROJECT_KEY")); indexPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY")); for (int i = 0; i < 12; i++) { IssueDto issue = newDto(rule, file, project).setAssigneeUuid(null); dbClient.issueDao().insert(session, issue); } session.commit(); indexIssues(); ws.newRequest() .setParam(PARAM_PAGE_INDEX, "2") .setParam(PARAM_PAGE_SIZE, "9") .execute() .assertJson(this.getClass(), "deprecated_paging.json"); }
@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 apply_template_by_query_on_name_and_key() { // partial match on key ComponentDto privateProjectFoundByKey = ComponentTesting.newPrivateProjectDto(organization).setDbKey("sonarqube"); db.components().insertProjectAndSnapshot(privateProjectFoundByKey); ComponentDto privateProjectFoundByName = ComponentTesting.newPrivateProjectDto(organization).setName("name-sonar-name"); db.components().insertProjectAndSnapshot(privateProjectFoundByName); ComponentDto projectUntouched = ComponentTesting.newPublicProjectDto(organization).setDbKey("new-sona").setName("project-name"); db.components().insertProjectAndSnapshot(projectUntouched); loginAsAdmin(organization); newRequest() .setParam(PARAM_TEMPLATE_ID, template1.getUuid()) .setParam(Param.TEXT_QUERY, "SONAR") .execute(); assertTemplate1AppliedToPrivateProject(privateProjectFoundByKey); assertTemplate1AppliedToPrivateProject(privateProjectFoundByName); assertNoPermissionOnProject(projectUntouched); }