Search in sources :

Example 16 with OrganizationDto

use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.

the class GroupWithPermissionTemplateDaoTest method select_group_names_by_query_and_template_is_paginated.

@Test
public void select_group_names_by_query_and_template_is_paginated() {
    OrganizationDto organization = db.organizations().insert();
    IntStream.rangeClosed(0, 9).forEach(i -> db.users().insertGroup(organization, i + "-name"));
    PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate(organization);
    assertThat(selectGroupNamesByQueryAndTemplate(builder().setPageIndex(1).setPageSize(1), organization, template)).containsExactly("0-name");
    assertThat(selectGroupNamesByQueryAndTemplate(builder().setPageIndex(2).setPageSize(3), organization, template)).containsExactly("3-name", "4-name", "5-name");
}
Also used : OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 17 with OrganizationDto

use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.

the class GroupWithPermissionTemplateDaoTest method select_group_names_by_query_and_template.

@Test
public void select_group_names_by_query_and_template() {
    OrganizationDto organization = db.organizations().insert();
    GroupDto group1 = db.users().insertGroup(organization, "Group-1");
    GroupDto group2 = db.users().insertGroup(organization, "Group-2");
    GroupDto group3 = db.users().insertGroup(organization, "Group-3");
    PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate(organization);
    permissionTemplateDbTester.addGroupToTemplate(template.getId(), group1.getId(), USER);
    permissionTemplateDbTester.addGroupToTemplate(template.getId(), group1.getId(), ADMIN);
    permissionTemplateDbTester.addGroupToTemplate(template.getId(), group2.getId(), PROVISIONING);
    PermissionTemplateDto anotherTemplate = permissionTemplateDbTester.insertTemplate(organization);
    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getId(), null, USER);
    permissionTemplateDbTester.addGroupToTemplate(anotherTemplate.getId(), group1.getId(), PROVISIONING);
    assertThat(selectGroupNamesByQueryAndTemplate(builder(), organization, template)).containsOnly("Group-1", "Group-2", "Group-3", "Anyone");
    assertThat(selectGroupNamesByQueryAndTemplate(builder().withAtLeastOnePermission(), organization, template)).containsOnly("Group-1", "Group-2");
    assertThat(selectGroupNamesByQueryAndTemplate(builder().setPermission(USER), organization, template)).containsOnly("Group-1");
    assertThat(selectGroupNamesByQueryAndTemplate(builder().setPermission(USER), organization, anotherTemplate)).containsOnly("Anyone");
    assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("groU"), organization, template)).containsOnly("Group-1", "Group-2", "Group-3");
    assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("nYo"), organization, template)).containsOnly("Anyone");
    assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("p-2"), organization, template)).containsOnly("Group-2");
    assertThat(selectGroupNamesByQueryAndTemplate(builder().withAtLeastOnePermission().build(), organization, 123L)).isEmpty();
    assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("unknown"), organization, template)).isEmpty();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 18 with OrganizationDto

use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.

the class IssueDaoTest method prepareTables.

private void prepareTables() {
    dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), RULE);
    OrganizationDto organizationDto = dbTester.organizations().insert();
    ComponentDto projectDto = dbTester.components().insertProject(organizationDto, (t) -> t.setUuid(PROJECT_UUID).setKey(PROJECT_KEY));
    dbTester.components().insertComponent(ComponentTesting.newFileDto(projectDto).setUuid(FILE_UUID).setKey(FILE_KEY));
    underTest.insert(dbTester.getSession(), newIssueDto(ISSUE_KEY1).setMessage("the message").setRuleId(RULE.getId()).setComponentUuid(FILE_UUID).setProjectUuid(PROJECT_UUID));
    underTest.insert(dbTester.getSession(), newIssueDto(ISSUE_KEY2).setRuleId(RULE.getId()).setComponentUuid(FILE_UUID).setProjectUuid(PROJECT_UUID));
    dbTester.getSession().commit();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 19 with OrganizationDto

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");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 20 with OrganizationDto

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());
}
Also used : OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

OrganizationDto (org.sonar.db.organization.OrganizationDto)384 Test (org.junit.Test)329 ComponentDto (org.sonar.db.component.ComponentDto)148 GroupDto (org.sonar.db.user.GroupDto)74 UserDto (org.sonar.db.user.UserDto)40 DbSession (org.sonar.db.DbSession)35 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)33 TestResponse (org.sonar.server.ws.TestResponse)19 SnapshotDto (org.sonar.db.component.SnapshotDto)17 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)16 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)15 PropertyDto (org.sonar.db.property.PropertyDto)13 SearchProjectsWsResponse (org.sonarqube.ws.WsComponents.SearchProjectsWsResponse)12 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)11 SearchOptions (org.sonar.server.es.SearchOptions)11 OrganizationTesting.newOrganizationDto (org.sonar.db.organization.OrganizationTesting.newOrganizationDto)9 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)8 Organizations (org.sonarqube.ws.Organizations)8 MetricDto (org.sonar.db.metric.MetricDto)7 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)7