Search in sources :

Example 26 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class QualityProfileDaoTest method select_selected_projects.

@Test
public void select_selected_projects() throws Exception {
    ComponentDto project1 = dbTester.components().insertProject((t) -> t.setName("Project1 name"));
    ComponentDto project2 = dbTester.components().insertProject((t) -> t.setName("Project2 name"));
    ComponentDto project3 = dbTester.components().insertProject((t) -> t.setName("Project3 name"));
    QualityProfileDto profile1 = newQualityProfileDto();
    qualityProfileDb.insertQualityProfiles(profile1);
    qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
    qualityProfileDb.associateProjectWithQualityProfile(project2, profile1);
    QualityProfileDto profile2 = newQualityProfileDto();
    qualityProfileDb.insertQualityProfiles(profile2);
    qualityProfileDb.associateProjectWithQualityProfile(project3, profile2);
    assertThat(underTest.selectSelectedProjects(profile1.getKey(), null, dbSession)).extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey").containsOnly(tuple(project1.getId(), project1.uuid(), project1.key(), project1.name(), profile1.getKey()), tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), profile1.getKey()));
    assertThat(underTest.selectSelectedProjects(profile1.getKey(), "ect1", dbSession)).hasSize(1);
    assertThat(underTest.selectSelectedProjects("unknown", null, dbSession)).isEmpty();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) QualityProfileTesting.newQualityProfileDto(org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto) Test(org.junit.Test)

Example 27 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class QualityProfileDaoTest method select_deselected_projects.

@Test
public void select_deselected_projects() throws Exception {
    ComponentDto project1 = dbTester.components().insertProject((t) -> t.setName("Project1 name"));
    ComponentDto project2 = dbTester.components().insertProject((t) -> t.setName("Project2 name"));
    ComponentDto project3 = dbTester.components().insertProject((t) -> t.setName("Project3 name"));
    QualityProfileDto profile1 = newQualityProfileDto();
    qualityProfileDb.insertQualityProfiles(profile1);
    qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
    QualityProfileDto profile2 = newQualityProfileDto();
    qualityProfileDb.insertQualityProfiles(profile2);
    qualityProfileDb.associateProjectWithQualityProfile(project2, profile2);
    assertThat(underTest.selectDeselectedProjects(profile1.getKey(), null, dbSession)).extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey").containsOnly(tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), null), tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null));
    assertThat(underTest.selectDeselectedProjects(profile1.getKey(), "ect2", dbSession)).hasSize(1);
    assertThat(underTest.selectDeselectedProjects("unknown", null, dbSession)).hasSize(3);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) QualityProfileTesting.newQualityProfileDto(org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto) Test(org.junit.Test)

Example 28 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class AuthorizationDaoTest method selectProjectPermissionsOfAnonymous_returns_permissions_of_anonymous_user_on_specified_project.

@Test
public void selectProjectPermissionsOfAnonymous_returns_permissions_of_anonymous_user_on_specified_project() {
    ComponentDto project = db.components().insertProject(org);
    db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
    db.users().insertProjectPermissionOnUser(db.users().insertUser(), UserRole.USER, project);
    ComponentDto otherProject = db.components().insertProject();
    db.users().insertProjectPermissionOnAnyone(UserRole.ISSUE_ADMIN, otherProject);
    assertThat(underTest.selectProjectPermissionsOfAnonymous(dbSession, project.uuid())).containsOnly(UserRole.CODEVIEWER);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 29 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class AuthorizationDaoTest method selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_project.

@Test
public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_project() {
    ComponentDto project = db.components().insertProject(org);
    db.users().insertProjectPermissionOnUser(user, UserRole.CODEVIEWER, project);
    db.users().insertProjectPermissionOnUser(db.users().insertUser(), UserRole.ISSUE_ADMIN, project);
    assertThat(underTest.selectProjectPermissions(dbSession, project.uuid(), user.getId())).containsOnly(UserRole.CODEVIEWER);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 30 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class GroupPermissionDaoTest method delete_global_permission_from_group.

@Test
public void delete_global_permission_from_group() {
    OrganizationDto org = db.organizations().insert();
    GroupDto group1 = db.users().insertGroup(org);
    ComponentDto project1 = db.components().insertProject(org);
    db.users().insertPermissionOnAnyone(org, "perm1");
    db.users().insertPermissionOnGroup(group1, "perm2");
    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
    db.users().insertProjectPermissionOnAnyone("perm4", project1);
    underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
    dbSession.commit();
    assertThatNoPermission("perm2");
    assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
}
Also used : GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)836 Test (org.junit.Test)661 OrganizationDto (org.sonar.db.organization.OrganizationDto)151 SnapshotDto (org.sonar.db.component.SnapshotDto)94 DbSession (org.sonar.db.DbSession)70 SearchOptions (org.sonar.server.es.SearchOptions)62 MetricDto (org.sonar.db.metric.MetricDto)49 IssueDto (org.sonar.db.issue.IssueDto)48 RuleDto (org.sonar.db.rule.RuleDto)47 GroupDto (org.sonar.db.user.GroupDto)39 UserDto (org.sonar.db.user.UserDto)38 WsTester (org.sonar.server.ws.WsTester)33 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)25 PropertyDto (org.sonar.db.property.PropertyDto)23 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)21 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)18 Date (java.util.Date)16 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)14 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)13