Search in sources :

Example 66 with OrganizationDto

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

the class ProjectDataLoaderMediumTest method return_sub_module_settings.

@Test
public void return_sub_module_settings() {
    OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
    dbClient.organizationDao().insert(dbSession, organizationDto);
    ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
    dbClient.componentDao().insert(dbSession, project);
    addDefaultProfile();
    // No project properties
    ComponentDto module = ComponentTesting.newModuleDto(project);
    dbClient.componentDao().insert(dbSession, module);
    // No module properties
    ComponentDto subModule = ComponentTesting.newModuleDto(module);
    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    dbClient.componentDao().insert(dbSession, subModule);
    // Sub module properties
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(subModule.getId()));
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(subModule.getId()));
    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(subModule.getId()));
    dbSession.commit();
    ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(subModule.key()));
    assertThat(ref.settings(project.key())).isEmpty();
    assertThat(ref.settings(module.key())).isEmpty();
    assertThat(ref.settings(subModule.key())).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR", "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 67 with OrganizationDto

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

the class ComponentDaoTest method select_ghost_projects.

@Test
public void select_ghost_projects() {
    OrganizationDto organization = db.organizations().insert();
    // ghosts because has at least one snapshot with status U but none with status P
    ComponentDto ghostProject = db.components().insertProject(organization);
    db.components().insertSnapshot(ghostProject, dto -> dto.setStatus("U"));
    db.components().insertSnapshot(ghostProject, dto -> dto.setStatus("U"));
    ComponentDto ghostProject2 = db.components().insertProject(organization);
    db.components().insertSnapshot(ghostProject2, dto -> dto.setStatus("U"));
    ComponentDto disabledGhostProject = db.components().insertProject(dto -> dto.setEnabled(false));
    db.components().insertSnapshot(disabledGhostProject, dto -> dto.setStatus("U"));
    ComponentDto project1 = db.components().insertProject(organization);
    db.components().insertSnapshot(project1, dto -> dto.setStatus("P"));
    db.components().insertSnapshot(project1, dto -> dto.setStatus("U"));
    ComponentDto module = db.components().insertComponent(newModuleDto(project1));
    ComponentDto dir = db.components().insertComponent(newDirectory(module, "foo"));
    db.components().insertComponent(newFileDto(module, dir, "bar"));
    ComponentDto provisionedProject = db.components().insertProject(organization);
    // not a ghost because has at least one snapshot with status P
    ComponentDto project2 = db.components().insertProject(organization);
    db.components().insertSnapshot(project2, dto -> dto.setStatus("P"));
    // not a ghost because it's not a project
    ComponentDto view = db.components().insertView(organization);
    db.components().insertSnapshot(view, dto -> dto.setStatus("U"));
    db.components().insertComponent(newProjectCopy("do", project1, view));
    assertThat(underTest.selectGhostProjects(dbSession, organization.getUuid(), null, 0, 10)).extracting(ComponentDto::uuid).containsOnly(ghostProject.uuid(), ghostProject2.uuid(), disabledGhostProject.uuid());
    assertThat(underTest.countGhostProjects(dbSession, organization.getUuid(), null)).isEqualTo(3);
}
Also used : OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 68 with OrganizationDto

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

the class ComponentDaoTest method select_projects.

@Test
public void select_projects() {
    OrganizationDto organization = db.organizations().insert();
    ComponentDto provisionedProject = db.components().insertProject();
    ComponentDto provisionedView = db.components().insertView(organization, (dto) -> {
    });
    String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid();
    String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid();
    String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
    assertThat(underTest.selectProjects(dbSession)).extracting(ComponentDto::uuid).containsOnly(provisionedProject.uuid(), projectUuid);
}
Also used : OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 69 with OrganizationDto

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

the class ComponentDaoTest method select_provisioned.

@Test
public void select_provisioned() {
    OrganizationDto organization = db.organizations().insert();
    ComponentDto provisionedProject = db.components().insertComponent(newProjectDto(organization).setKey("provisioned.project").setName("Provisioned Project"));
    ComponentDto provisionedView = db.components().insertView(organization);
    String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid();
    String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid();
    String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
    Set<String> projectQualifiers = newHashSet(Qualifiers.PROJECT);
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsOnly(provisionedProject.uuid());
    // pagination
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(2, 10))).isEmpty();
    // filter on qualifiers
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet("XXX"), new RowBounds(0, 10))).isEmpty();
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT, "XXX"), new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsOnly(provisionedProject.uuid());
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT, Qualifiers.VIEW), new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsOnly(provisionedProject.uuid(), provisionedView.uuid());
    // match key
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), provisionedProject.getKey(), projectQualifiers, new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsExactly(provisionedProject.uuid());
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "pROvisiONed.proJEcT", projectQualifiers, new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsExactly(provisionedProject.uuid());
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "missing", projectQualifiers, new RowBounds(0, 10))).isEmpty();
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "to be escaped '\"\\%", projectQualifiers, new RowBounds(0, 10))).isEmpty();
    // match name
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "ned proj", projectQualifiers, new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsExactly(provisionedProject.uuid());
}
Also used : RowBounds(org.apache.ibatis.session.RowBounds) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 70 with OrganizationDto

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

the class ComponentDaoTest method selectAncestors.

@Test
public void selectAncestors() {
    // organization
    OrganizationDto organization = db.organizations().insert();
    // project -> module -> file
    ComponentDto project = newProjectDto(organization, PROJECT_UUID);
    db.components().insertProjectAndSnapshot(project);
    ComponentDto module = newModuleDto(MODULE_UUID, project);
    db.components().insertComponent(module);
    ComponentDto file = newFileDto(module, null, FILE_1_UUID);
    db.components().insertComponent(file);
    db.commit();
    // ancestors of root
    List<ComponentDto> ancestors = underTest.selectAncestors(dbSession, project);
    assertThat(ancestors).isEmpty();
    // ancestors of module
    ancestors = underTest.selectAncestors(dbSession, module);
    assertThat(ancestors).extracting("uuid").containsExactly(PROJECT_UUID);
    // ancestors of file
    ancestors = underTest.selectAncestors(dbSession, file);
    assertThat(ancestors).extracting("uuid").containsExactly(PROJECT_UUID, MODULE_UUID);
}
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