Search in sources :

Example 86 with TestRequest

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

the class EditCommentActionTest method fails_if_comment_with_provided_key_does_not_exist.

@Test
public void fails_if_comment_with_provided_key_does_not_exist() {
    userSessionRule.logIn();
    TestRequest request = newRequest("not-existing-comment-key", "some new comment");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Comment with key 'not-existing-comment-key' does not exist");
}
Also used : NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 87 with TestRequest

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

the class ShowActionTest method fails_with_IAE_if_parameter_hotspot_is_missing.

@Test
public void fails_with_IAE_if_parameter_hotspot_is_missing() {
    TestRequest request = actionTester.newRequest();
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("The 'hotspot' parameter is missing");
}
Also used : TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 88 with TestRequest

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

the class ShowActionTest method fails_with_ForbiddenException_if_project_is_private_and_not_allowed.

@Test
public void fails_with_ForbiddenException_if_project_is_private_and_not_allowed() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    userSessionRule.registerComponents(project);
    ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
    IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
    TestRequest request = newRequest(hotspot);
    assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Also used : ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 89 with TestRequest

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

the class ShowActionTest method fails_with_NotFoundException_if_issue_is_hotspot_is_closed.

@Test
public void fails_with_NotFoundException_if_issue_is_hotspot_is_closed() {
    ComponentDto project = dbTester.components().insertPublicProject();
    ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
    IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(Issue.STATUS_CLOSED));
    TestRequest request = newRequest(hotspot);
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Hotspot '%s' does not exist", hotspot.getKey());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 90 with TestRequest

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

the class SearchActionTest method fails_with_IAE_if_resolution_is_provided_with_status_TO_REVIEW.

@Test
@UseDataProvider("fixedOrSafeResolution")
public void fails_with_IAE_if_resolution_is_provided_with_status_TO_REVIEW(String resolution) {
    TestRequest request = actionTester.newRequest().setParam("projectKey", randomAlphabetic(13)).setParam("status", STATUS_TO_REVIEW).setParam("resolution", resolution);
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("Value '" + resolution + "' of parameter 'resolution' can only be provided if value of parameter 'status' is 'REVIEWED'");
}
Also used : TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

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