Search in sources :

Example 61 with OrganizationDto

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

the class ProjectDataLoaderMediumTest method return_file_data_from_single_project.

@Test
public void return_file_data_from_single_project() {
    OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
    dbClient.organizationDao().insert(dbSession, organizationDto);
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    dbClient.componentDao().insert(dbSession, project);
    addDefaultProfile();
    ComponentDto file = ComponentTesting.newFileDto(project, null, "file");
    dbClient.componentDao().insert(dbSession, file);
    tester.get(FileSourceDao.class).insert(dbSession, newFileSourceDto(file).setSrcHash("123456"));
    dbSession.commit();
    ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
    assertThat(ref.fileDataByPath(project.key())).hasSize(1);
    FileData fileData = ref.fileData(project.key(), file.path());
    assertThat(fileData.hash()).isEqualTo("123456");
}
Also used : FileSourceDao(org.sonar.db.source.FileSourceDao) ComponentDto(org.sonar.db.component.ComponentDto) FileData(org.sonar.scanner.protocol.input.FileData) OrganizationDto(org.sonar.db.organization.OrganizationDto) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 62 with OrganizationDto

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

the class ProjectDataLoaderMediumTest method return_project_settings_with_global_scan_permission.

@Test
public void return_project_settings_with_global_scan_permission() {
    OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
    dbClient.organizationDao().insert(dbSession, organizationDto);
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    dbClient.componentDao().insert(dbSession, project);
    addDefaultProfile();
    // Project properties
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()));
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()));
    dbSession.commit();
    ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
    Map<String, String> projectSettings = ref.settings(project.key());
    assertThat(projectSettings).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR", "sonar.jira.login.secured", "john"));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) PropertyDto(org.sonar.db.property.PropertyDto) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 63 with OrganizationDto

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

the class ProjectDataLoaderMediumTest method return_project_with_module_settings.

@Test
public void return_project_with_module_settings() {
    OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
    dbClient.organizationDao().insert(dbSession, organizationDto);
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    dbClient.componentDao().insert(dbSession, project);
    addDefaultProfile();
    // Project properties
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()));
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()));
    ComponentDto module = ComponentTesting.newModuleDto(project);
    dbClient.componentDao().insert(dbSession, module);
    // Module properties
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId()));
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(module.getId()));
    dbSession.commit();
    ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
    assertThat(ref.settings(project.key())).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR", "sonar.jira.login.secured", "john"));
    assertThat(ref.settings(module.key())).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR-SERVER", "sonar.jira.login.secured", "john", "sonar.coverage.exclusions", "**/*.java"));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) PropertyDto(org.sonar.db.property.PropertyDto) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 64 with OrganizationDto

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

the class ProjectDataLoaderMediumTest method return_project_with_module_with_sub_module.

@Test
public void return_project_with_module_with_sub_module() {
    OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
    dbClient.organizationDao().insert(dbSession, organizationDto);
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    dbClient.componentDao().insert(dbSession, project);
    addDefaultProfile();
    // Project properties
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()));
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()));
    ComponentDto module = ComponentTesting.newModuleDto(project);
    dbClient.componentDao().insert(dbSession, module);
    // Module properties
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId()));
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(module.getId()));
    ComponentDto subModule = ComponentTesting.newModuleDto(module);
    dbClient.componentDao().insert(dbSession, subModule);
    // Sub module properties
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER-DAO").setResourceId(subModule.getId()));
    dbSession.commit();
    ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
    assertThat(ref.settings(project.key())).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR", "sonar.jira.login.secured", "john"));
    assertThat(ref.settings(module.key())).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR-SERVER", "sonar.jira.login.secured", "john", "sonar.coverage.exclusions", "**/*.java"));
    assertThat(ref.settings(subModule.key())).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR-SERVER-DAO", "sonar.jira.login.secured", "john", "sonar.coverage.exclusions", "**/*.java"));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) PropertyDto(org.sonar.db.property.PropertyDto) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 65 with OrganizationDto

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

the class ProjectDataLoaderMediumTest method fail_when_no_browse_permission_nor_scan_permission.

@Test
public void fail_when_no_browse_permission_nor_scan_permission() {
    userSessionRule.logIn();
    OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
    dbClient.organizationDao().insert(dbSession, organizationDto);
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
    dbClient.componentDao().insert(dbSession, project);
    dbSession.commit();
    try {
        underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
        fail();
    } catch (Exception e) {
        assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage(Messages.NO_PERMISSION);
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) ExpectedException(org.junit.rules.ExpectedException) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) 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