use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class MeasureDaoTest method selectProjectMeasuresOfDeveloper.
@Test
public void selectProjectMeasuresOfDeveloper() {
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto dev = db.components().insertComponent(newDeveloper(organizationDto, "DEV"));
insertAnalysis(LAST_ANALYSIS_UUID, dev.uuid(), true);
insertAnalysis(PREVIOUS_ANALYSIS_UUID, dev.uuid(), false);
List<Integer> allMetricIds = Arrays.asList(NCLOC_METRIC_ID, COMPLEXITY_METRIC_ID, COVERAGE_METRIC_ID);
long developerId = dev.getId();
assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, allMetricIds)).isEmpty();
String projectUuid = insertComponent(Scopes.PROJECT, PROJECT, true);
String viewUuid = insertComponent(Scopes.PROJECT, VIEW, true);
String disabledProjectUuid = insertComponent(Scopes.PROJECT, PROJECT, false);
insertMeasure("M1", LAST_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
insertMeasure("M2", LAST_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
insertMeasure("M3", LAST_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
insertMeasure("M4", PREVIOUS_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
insertMeasure("M5", PREVIOUS_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
insertMeasure("M6", PREVIOUS_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
insertMeasure("M11", LAST_ANALYSIS_UUID, projectUuid, developerId, NCLOC_METRIC_ID);
insertMeasure("M12", LAST_ANALYSIS_UUID, projectUuid, developerId, COMPLEXITY_METRIC_ID);
insertMeasure("M13", LAST_ANALYSIS_UUID, projectUuid, developerId, COVERAGE_METRIC_ID);
insertMeasure("M14", PREVIOUS_ANALYSIS_UUID, projectUuid, NCLOC_METRIC_ID);
insertMeasure("M15", PREVIOUS_ANALYSIS_UUID, projectUuid, COMPLEXITY_METRIC_ID);
insertMeasure("M16", PREVIOUS_ANALYSIS_UUID, projectUuid, COVERAGE_METRIC_ID);
insertMeasure("M51", LAST_ANALYSIS_UUID, viewUuid, NCLOC_METRIC_ID);
insertMeasure("M52", LAST_ANALYSIS_UUID, viewUuid, COMPLEXITY_METRIC_ID);
insertMeasure("M53", LAST_ANALYSIS_UUID, viewUuid, COVERAGE_METRIC_ID);
insertMeasure("M54", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, NCLOC_METRIC_ID);
insertMeasure("M55", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, COMPLEXITY_METRIC_ID);
insertMeasure("M56", LAST_ANALYSIS_UUID, disabledProjectUuid, developerId, COVERAGE_METRIC_ID);
assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, allMetricIds)).extracting(MeasureDto::getData).containsOnly("M11", "M12", "M13", "M54", "M55", "M56");
assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, singletonList(NCLOC_METRIC_ID))).extracting(MeasureDto::getData).containsOnly("M11", "M54");
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method selectOrganizationUuidsOfUserWithGlobalPermission_handles_user_permissions_and_group_permissions.
@Test
public void selectOrganizationUuidsOfUserWithGlobalPermission_handles_user_permissions_and_group_permissions() {
// org: through group membership
db.users().insertPermissionOnGroup(group1, SCAN_EXECUTION);
db.users().insertMember(group1, user);
// org2 : direct user permission
OrganizationDto org2 = db.organizations().insert();
db.users().insertPermissionOnUser(org2, user, SCAN_EXECUTION);
// org3 : another permission QUALITY_GATE_ADMIN
OrganizationDto org3 = db.organizations().insert();
db.users().insertPermissionOnUser(org3, user, QUALITY_GATE_ADMIN);
// exclude project permission
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, db.components().insertProject());
Set<String> orgUuids = underTest.selectOrganizationUuidsOfUserWithGlobalPermission(dbSession, user.getId(), SCAN_EXECUTION);
assertThat(orgUuids).containsOnly(org.getUuid(), org2.getUuid());
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class GroupPermissionDaoTest method countGroupsByQuery.
@Test
public void countGroupsByQuery() {
OrganizationDto organizationDto = db.getDefaultOrganization();
GroupDto group1 = db.users().insertGroup(organizationDto, "Group-1");
db.users().insertGroup(organizationDto, "Group-2");
db.users().insertGroup(organizationDto, "Group-3");
db.users().insertPermissionOnAnyone(organizationDto, SCAN);
db.users().insertPermissionOnGroup(group1, PROVISION_PROJECTS);
assertThat(underTest.countGroupsByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().build())).isEqualTo(4);
assertThat(underTest.countGroupsByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().setPermission(PROVISION_PROJECTS.getKey()).build())).isEqualTo(1);
assertThat(underTest.countGroupsByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().withAtLeastOnePermission().build())).isEqualTo(2);
assertThat(underTest.countGroupsByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().setSearchQuery("Group-").build())).isEqualTo(3);
assertThat(underTest.countGroupsByQuery(dbSession, defaultOrganizationUuid, PermissionQuery.builder().setSearchQuery("Any").build())).isEqualTo(1);
}
use of org.sonar.db.organization.OrganizationDto 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);
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class GroupPermissionDaoTest method deleteByOrganization_does_not_fail_if_organization_has_no_group.
@Test
public void deleteByOrganization_does_not_fail_if_organization_has_no_group() {
OrganizationDto organization = db.organizations().insert();
underTest.deleteByOrganization(dbSession, organization.getUuid());
dbSession.commit();
}
Aggregations