@Test public void countByQuery_should_not_include_branches() { ComponentDto main = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(main); assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY)).isEqualTo(1); }
@Test public void fail_when_using_branch_db_key() throws Exception { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(format("Component key '%s' not found", branch.getDbKey())); call(request.setProject(branch.getDbKey())); }
@Test public void fail_when_using_branch_db_key() throws Exception { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(format("Component key '%s' not found", branch.getDbKey())); call(NOTIF_MY_NEW_ISSUES, null, branch.getDbKey(), null); }
@Test public void rule_id_is_not_set_on_updated_issue_when_rule_is_removed() { RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(REMOVED)); ComponentDto project = db.components().insertMainBranch(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module)); DefaultIssue issue = newIssue(rule, project, file).toDefaultIssue(); Collection<IssueDto> results = underTest.save(db.getSession(), singletonList(issue)); assertThat(results).hasSize(1); assertThat(results.iterator().next().getRuleId()).isNull(); }
@Test public void fail_to_delete_project_when_branch() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(IllegalArgumentException.class); underTest.delete(dbSession, branch); }
@Test public void fail_to_getByUuidOrKey_when_using_branch_key() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(format("Component key '%s' not found", branch.getDbKey())); underTest.getByUuidOrKey(dbSession, null, branch.getDbKey(), ID_AND_KEY); }
@Test public void legacy_branch() { ComponentDto project = db.components().insertMainBranch(); db.properties().insertProperties(newComponentPropertyDto(project).setKey("sonar.leak.period").setValue("1")); Branch branch = createBranch("legacy", true); when(branch.isLegacyFeature()).thenReturn(true); Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getName(), true)); assertThat(config.get("sonar.leak.period")).hasValue("1"); }
@Test public void does_not_return_branches() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, project); SearchMyProjectsWsResponse result = callWs(); assertThat(result.getProjectsList()) .extracting(Project::getKey) .containsExactlyInAnyOrder(project.getDbKey()); }
@Before public void prepare() { rule = dbTester.rules().insert(); ruleRepositoryRule.add(rule.getKey()); rootProjectDto = dbTester.components().insertMainBranch(); ReportComponent rootProject = ReportComponent.builder(Component.Type.FILE, 1) .setKey(rootProjectDto.getDbKey()) .setUuid(rootProjectDto.uuid()).build(); reportModulesPath = mock(ReportModulesPath.class); underTest = new ProjectTrackerBaseLazyInput(analysisMetadataHolder, mock(ComponentsWithUnprocessedIssues.class), dbClient, new IssueFieldsSetter(), issuesLoader, reportModulesPath, rootProject); }
@Test public void fail_when_using_branch_db_key() { ComponentDto project = db.components().insertMainBranch(); userSession.addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(String.format("Component key '%s' not found", branch.getDbKey())); ws.newRequest() .setParam(PARAM_COMPONENT, branch.getDbKey()) .executeProtobuf(ShowWsResponse.class); }
@Test public void fail_when_using_branch_uuid() { ComponentDto project = db.components().insertMainBranch(); userSession.addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(String.format("Component id '%s' not found", branch.uuid())); ws.newRequest() .setParam(PARAM_COMPONENT_ID, branch.uuid()) .executeProtobuf(ShowWsResponse.class); }
@Test public void fail_when_using_branch_db_key() { ComponentDto project = db.components().insertMainBranch(); userSession.addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(String.format("Component key '%s' not found", branch.getDbKey())); ws.newRequest() .setParam(PARAM_COMPONENT, branch.getDbKey()) .executeProtobuf(Components.ShowWsResponse.class); }
@Test public void does_not_return_branches_when_searching_by_key() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); userSession.addPermission(ADMINISTER, db.getDefaultOrganization()); SearchWsResponse response = call(SearchRequest.builder().build()); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getDbKey()); }
@Test public void does_not_return_branches_when_searching_all_components() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); userSession.setRoot(); String result = call(null, null, null); assertJson(result).isSimilarTo("[" + " {" + " \"id\":" + project.getId() + "," + " }" + "]"); }
@Test public void fail_when_using_branch_uuid() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertMainBranch(organization); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(format("Component id '%s' not found", branch.uuid())); ws.newRequest() .setParam("uuid", branch.uuid()) .execute(); }
@Test public void fail_if_no_administer_permission() { userSession.logIn(); ComponentDto project = db.components().insertMainBranch(); expectedException.expect(ForbiddenException.class); expectedException.expectMessage("Insufficient privileges"); tester.newRequest() .setParam("project", project.getKey()) .setParam("name", "branch1") .execute(); }
@Test public void branch_settings_contains_project_settings() { ComponentDto project = db.components().insertMainBranch(); db.properties().insertProperties(newComponentPropertyDto(project).setKey("key").setValue("value")); ComponentDto branch = db.components().insertProjectBranch(project); db.properties().insertProperties(newComponentPropertyDto(branch).setKey("sonar.leak.period").setValue("1")); Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getBranch(), false)); assertThat(config.get("key")).hasValue("value"); assertThat(config.get("sonar.leak.period")).hasValue("1"); }
@Test public void fail_if_both_componentId_and_pull_request_parameters_provided() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); ComponentDto file = db.components().insertComponent(newFileDto(branch)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'"); ws.newRequest() .setParam("uuid", file.uuid()) .setParam("pullRequest", file.getPullRequest()) .execute(); }
@Before public void setUp() { underTest = new MergeBranchComponentUuids(analysisMetadataHolder, db.getDbClient()); analysisMetadataHolder.setBranch(branch); ComponentDto project = db.components().insertMainBranch(); mergeBranch = db.components().insertProjectBranch(project, b -> b.setKey("mergeBranch")); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1")); mergeBranchFile = ComponentTesting.newFileDto(mergeBranch, null, "file").setUuid("mergeFile"); branchFile = ComponentTesting.newFileDto(branch, null, "file").setUuid("file1"); db.components().insertComponents(mergeBranchFile, branchFile); }
private ComponentDto insertProjectWithBranchAndRelatedData() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto module = db.components().insertComponent(newModuleDto(branch)); ComponentDto subModule = db.components().insertComponent(newModuleDto(module)); ComponentDto file = db.components().insertComponent(newFileDto(subModule)); db.issues().insert(rule, branch, file); db.issues().insert(rule, branch, subModule); db.issues().insert(rule, branch, module); return project; }