Search in sources :

Example 46 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class QualityGateFinderTest method fail_when_project_qgate_defined_does_not_exist.

@Test
public void fail_when_project_qgate_defined_does_not_exist() {
    ProjectDto project = db.components().insertPrivateProjectDto();
    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My team QG"));
    db.qualityGates().setDefaultQualityGate(dbQualityGate);
    db.qualityGates().associateProjectToQualityGate(project, dbQualityGate);
    db.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
    assertThatThrownBy(() -> underTest.getQualityGate(dbSession, project)).isInstanceOf(IllegalStateException.class).hasMessage("Default quality gate is missing");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 47 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class QualityGateFinderTest method return_project_quality_gate_over_default.

@Test
public void return_project_quality_gate_over_default() {
    ProjectDto project = db.components().insertPrivateProjectDto();
    db.qualityGates().createDefaultQualityGate(qg -> qg.setName("Sonar way"));
    QualityGateDto dbQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("My team QG"));
    db.qualityGates().associateProjectToQualityGate(project, dbQualityGate);
    QualityGateFinder.QualityGateData result = underTest.getQualityGate(dbSession, project);
    assertThat(result.getQualityGate().getUuid()).isEqualTo(dbQualityGate.getUuid());
    assertThat(result.isDefault()).isFalse();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 48 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class QualityGateFinderTest method fail_when_default_qgate_defined_does_not_exist.

@Test
public void fail_when_default_qgate_defined_does_not_exist() {
    ProjectDto project = db.components().insertPrivateProjectDto();
    QualityGateDto dbQualityGate = db.qualityGates().createDefaultQualityGate(qg -> qg.setName("Sonar way"));
    db.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
    db.commit();
    assertThatThrownBy(() -> underTest.getQualityGate(dbSession, project)).isInstanceOf(IllegalStateException.class).hasMessage("Default quality gate is missing");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 49 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class ThreadLocalUserSessionTest method throw_ForbiddenException_when_no_access_to_applications_projects.

@Test
public void throw_ForbiddenException_when_no_access_to_applications_projects() {
    GroupDto group = GroupTesting.newGroupDto();
    MockUserSession expected = new MockUserSession("karadoc").setUuid("karadoc-uuid").setResetPassword(true).setLastSonarlintConnectionDate(1000L).setGroups(group);
    threadLocalUserSession.set(expected);
    ComponentDto componentDto = new ComponentDto().setQualifier(Qualifiers.APP).setMainBranchProjectUuid("component-uuid");
    ProjectDto projectDto = new ProjectDto().setQualifier(Qualifiers.APP).setUuid("project-uuid");
    assertThatThrownBy(() -> threadLocalUserSession.checkChildProjectsPermission(USER, componentDto)).isInstanceOf(ForbiddenException.class);
    assertThatThrownBy(() -> threadLocalUserSession.checkChildProjectsPermission(USER, projectDto)).isInstanceOf(ForbiddenException.class);
}
Also used : MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) ProjectDto(org.sonar.db.project.ProjectDto) GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 50 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class ThreadLocalUserSessionTest method checkChildProjectsPermission_gets_session_when_user_has_access_to_applications_projects.

@Test
public void checkChildProjectsPermission_gets_session_when_user_has_access_to_applications_projects() {
    GroupDto group = GroupTesting.newGroupDto();
    MockUserSession expected = new MockUserSession("karadoc").setUuid("karadoc-uuid").setResetPassword(true).setLastSonarlintConnectionDate(1000L).setGroups(group);
    ProjectDto subProjectDto = new ProjectDto().setQualifier(Qualifiers.PROJECT).setUuid("subproject-uuid");
    ComponentDto applicationAsComponentDto = new ComponentDto().setQualifier(Qualifiers.APP).setUuid("application-component-uuid").setProjectUuid("application-project-uuid");
    ProjectDto applicationAsProjectDto = new ProjectDto().setQualifier(Qualifiers.APP).setUuid("application-project-uuid");
    expected.registerProjects(subProjectDto);
    expected.registerApplication(applicationAsProjectDto, subProjectDto);
    expected.registerComponents(applicationAsComponentDto);
    threadLocalUserSession.set(expected);
    assertThat(threadLocalUserSession.checkChildProjectsPermission(USER, applicationAsComponentDto)).isEqualTo(threadLocalUserSession);
    assertThat(threadLocalUserSession.checkChildProjectsPermission(USER, applicationAsProjectDto)).isEqualTo(threadLocalUserSession);
}
Also used : MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) ProjectDto(org.sonar.db.project.ProjectDto) GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

ProjectDto (org.sonar.db.project.ProjectDto)283 Test (org.junit.Test)215 DbSession (org.sonar.db.DbSession)49 BranchDto (org.sonar.db.component.BranchDto)42 UserDto (org.sonar.db.user.UserDto)39 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)38 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 SnapshotDto (org.sonar.db.component.SnapshotDto)27 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)26 ComponentDto (org.sonar.db.component.ComponentDto)23 ComponentTesting.newPrivateProjectDto (org.sonar.db.component.ComponentTesting.newPrivateProjectDto)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)17 WebhookDto (org.sonar.db.webhook.WebhookDto)15 ApplicationProjectDto (org.sonar.db.project.ApplicationProjectDto)14 WebService (org.sonar.api.server.ws.WebService)13 DbClient (org.sonar.db.DbClient)12 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)12 TestRequest (org.sonar.server.ws.TestRequest)11 TestResponse (org.sonar.server.ws.TestResponse)10 Projects (org.sonarqube.ws.Projects)10