Search in sources :

Example 96 with TestRequest

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

the class ChangeStatusActionTest method fails_with_NotFoundException_if_hotspot_is_closed.

@Test
@UseDataProvider("validStatusAndResolutions")
public void fails_with_NotFoundException_if_hotspot_is_closed(String status, @Nullable String resolution) {
    ComponentDto project = dbTester.components().insertPublicProject();
    ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
    IssueDto closedHotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED));
    userSessionRule.logIn();
    TestRequest request = actionTester.newRequest().setParam("hotspot", closedHotspot.getKey()).setParam("status", status);
    if (resolution != null) {
        request.setParam("resolution", resolution);
    }
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Hotspot '%s' does not exist", closedHotspot.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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 97 with TestRequest

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

the class ChangeStatusActionTest method fails_with_NotFoundException_if_hotspot_does_not_exist.

@Test
@UseDataProvider("validStatusAndResolutions")
public void fails_with_NotFoundException_if_hotspot_does_not_exist(String status, @Nullable String resolution) {
    String key = randomAlphabetic(12);
    userSessionRule.logIn();
    TestRequest request = actionTester.newRequest().setParam("hotspot", key).setParam("status", status);
    if (resolution != null) {
        request.setParam("resolution", resolution);
    }
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Hotspot '%s' does not exist", key);
}
Also used : NotFoundException(org.sonar.server.exceptions.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 98 with TestRequest

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

the class ChangeStatusActionTest method fail_with_IAE_if_status_is_TO_REVIEW_and_resolution_is_set.

@Test
@UseDataProvider("validResolutions")
public void fail_with_IAE_if_status_is_TO_REVIEW_and_resolution_is_set(String resolution) {
    String key = randomAlphabetic(12);
    userSessionRule.logIn();
    TestRequest request = actionTester.newRequest().setParam("hotspot", key).setParam("status", STATUS_TO_REVIEW).setParam("resolution", resolution);
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("Parameter 'resolution' must not be specified when Parameter 'status' has value 'TO_REVIEW'");
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 99 with TestRequest

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

the class ChangeStatusActionTest method fails_with_UnauthorizedException_if_user_is_anonymous.

@Test
public void fails_with_UnauthorizedException_if_user_is_anonymous() {
    userSessionRule.anonymous();
    TestRequest request = actionTester.newRequest();
    assertThatThrownBy(request::execute).isInstanceOf(UnauthorizedException.class).hasMessage("Authentication is required");
}
Also used : UnauthorizedException(org.sonar.server.exceptions.UnauthorizedException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 100 with TestRequest

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

the class ChangeStatusActionTest method fails_with_IAE_if_parameter_status_is_missing.

@Test
public void fails_with_IAE_if_parameter_status_is_missing() {
    String key = randomAlphabetic(12);
    userSessionRule.logIn();
    TestRequest request = actionTester.newRequest().setParam("hotspot", key);
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("The 'status' parameter is missing");
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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