Search in sources :

Example 86 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class AddProjectActionTest method throw_NotFoundException_if_project_does_not_exist.

@Test
public void throw_NotFoundException_if_project_does_not_exist() {
    logInAsProfileAdmin();
    QProfileDto profile = db.qualityProfiles().insert();
    assertThatThrownBy(() -> {
        tester.newRequest().setParam("project", "unknown").setParam("profileKey", profile.getKee()).execute();
    }).isInstanceOf(NotFoundException.class).hasMessage("Project 'unknown' not found");
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) Test(org.junit.Test)

Example 87 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class AddProjectActionTest method project_administrator_can_change_profile.

@Test
public void project_administrator_can_change_profile() {
    ProjectDto project = db.components().insertPrivateProjectDto();
    QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
    userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project);
    call(project, profile);
    assertProjectIsAssociatedToProfile(project, profile);
    verify(qualityProfileChangeEventService).publishRuleActivationToSonarLintClients(project, profile, null);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Test(org.junit.Test)

Example 88 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class AddProjectActionTest method throw_ForbiddenException_if_not_project_nor_global_administrator.

@Test
public void throw_ForbiddenException_if_not_project_nor_global_administrator() {
    userSession.logIn(db.users().insertUser());
    ProjectDto project = db.components().insertPrivateProjectDto();
    QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
    assertThatThrownBy(() -> call(project, profile)).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Test(org.junit.Test)

Example 89 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class AddProjectActionTest method throw_UnauthorizedException_if_not_logged_in.

@Test
public void throw_UnauthorizedException_if_not_logged_in() {
    userSession.anonymous();
    ProjectDto project = db.components().insertPrivateProjectDto();
    QProfileDto profile = db.qualityProfiles().insert();
    assertThatThrownBy(() -> call(project, profile)).isInstanceOf(UnauthorizedException.class).hasMessage("Authentication is required");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UnauthorizedException(org.sonar.server.exceptions.UnauthorizedException) Test(org.junit.Test)

Example 90 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class AddProjectActionTest method add_project_on_profile.

@Test
public void add_project_on_profile() {
    logInAsProfileAdmin();
    ProjectDto project = db.components().insertPrivateProjectDto();
    QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
    TestResponse response = call(project, profile);
    assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
    assertProjectIsAssociatedToProfile(project, profile);
    verify(qualityProfileChangeEventService).publishRuleActivationToSonarLintClients(project, profile, null);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Aggregations

QProfileDto (org.sonar.db.qualityprofile.QProfileDto)389 Test (org.junit.Test)329 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)139 UserDto (org.sonar.db.user.UserDto)72 DbSession (org.sonar.db.DbSession)38 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)38 ProjectDto (org.sonar.db.project.ProjectDto)36 RuleParamDto (org.sonar.db.rule.RuleParamDto)36 GroupDto (org.sonar.db.user.GroupDto)35 NotFoundException (org.sonar.server.exceptions.NotFoundException)31 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)23 TestRequest (org.sonar.server.ws.TestRequest)23 System2 (org.sonar.api.utils.System2)22 RuleQuery (org.sonar.server.rule.index.RuleQuery)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)21 DbTester (org.sonar.db.DbTester)21 BadRequestException (org.sonar.server.exceptions.BadRequestException)20 UserSessionRule (org.sonar.server.tester.UserSessionRule)20 List (java.util.List)19 Rule (org.junit.Rule)19