Search in sources :

Example 61 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class DismissAnalysisWarningActionTest method return_403_if_user_has_no_browse_permission_on_private_project.

@Test
public void return_403_if_user_has_no_browse_permission_on_private_project() {
    ProjectDto project = db.components().insertPrivateProjectDto();
    UserDto user = db.users().insertUser();
    userSession.logIn(user);
    TestRequest request = underTest.newRequest().setParam("component", project.getKee()).setParam("warning", "55c40b35-4145-4b78-bdf2-dfb242c25f15");
    assertThrows("Insufficient privileges", ForbiddenException.class, request::execute);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 62 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class DismissAnalysisWarningActionTest method returns_400_if_warning_is_not_dismissable.

@Test
public void returns_400_if_warning_is_not_dismissable() {
    UserDto user = db.users().insertUser();
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn(user).addProjectPermission(UserRole.USER, project);
    SnapshotDto analysis = db.components().insertSnapshot(project);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
    CeTaskMessageDto taskMessage = createTaskMessage(activity, "generic warning");
    TestRequest request = underTest.newRequest().setParam("component", project.getKey()).setParam("warning", taskMessage.getUuid());
    assertThrows(format("Message '%s' cannot be dismissed.", taskMessage.getUuid()), IllegalArgumentException.class, request::execute);
    assertThat(db.countRowsOfTable("USER_DISMISSED_MESSAGES")).isZero();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) UserDto(org.sonar.db.user.UserDto) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 63 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class DismissAnalysisWarningActionTest method return_401_if_user_is_not_logged_in.

@Test
public void return_401_if_user_is_not_logged_in() {
    userSession.anonymous();
    TestRequest request = underTest.newRequest().setParam("component", "6653f062-7c03-4b55-bcd2-0dac67640c4d").setParam("warning", "55c40b35-4145-4b78-bdf2-dfb242c25f15");
    assertThrows("Authentication is required", UnauthorizedException.class, request::execute);
}
Also used : TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 64 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class TreeActionTest method fail_if_branch_does_not_exist.

@Test
public void fail_if_branch_does_not_exist() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
    TestRequest request = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_BRANCH, "another_branch");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage(format("Component '%s' on branch '%s' not found", project.getKey(), "another_branch"));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 65 with TestRequest

use of org.sonar.server.ws.TestRequest in project sonarqube by SonarSource.

the class TreeActionTest method fail_when_using_branch_key.

@Test
public void fail_when_using_branch_key() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    ComponentDto branch = db.components().insertProjectBranch(project);
    TestRequest request = ws.newRequest().setParam(PARAM_COMPONENT, branch.getDbKey());
    assertThatThrownBy(() -> request.executeProtobuf(Components.ShowWsResponse.class)).isInstanceOf(NotFoundException.class).hasMessage(format("Component key '%s' not found", branch.getDbKey()));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Aggregations

TestRequest (org.sonar.server.ws.TestRequest)375 Test (org.junit.Test)309 UserDto (org.sonar.db.user.UserDto)82 ComponentDto (org.sonar.db.component.ComponentDto)61 NotFoundException (org.sonar.server.exceptions.NotFoundException)59 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)41 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)29 IssueDto (org.sonar.db.issue.IssueDto)21 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)21 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)20 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)15 IOException (java.io.IOException)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 BadRequestException (org.sonar.server.exceptions.BadRequestException)11 ProjectDto (org.sonar.db.project.ProjectDto)10 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)9 TestResponse (org.sonar.server.ws.TestResponse)9 WsActionTester (org.sonar.server.ws.WsActionTester)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Mockito.mock (org.mockito.Mockito.mock)8