Search in sources :

Example 91 with TestRequest

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

the class SearchActionTest method fails_with_NotFoundException_if_project_does_not_exist.

@Test
public void fails_with_NotFoundException_if_project_does_not_exist() {
    String key = randomAlphabetic(12);
    TestRequest request = actionTester.newRequest().setParam("projectKey", key);
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Project '%s' not found", key);
}
Also used : NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 92 with TestRequest

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

the class SearchActionTest method fails_with_IAE_if_parameters_projectKey_and_hotspots_are_missing.

@Test
public void fails_with_IAE_if_parameters_projectKey_and_hotspots_are_missing() {
    TestRequest request = actionTester.newRequest();
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("A value must be provided for either parameter 'projectKey' or parameter 'hotspots'");
}
Also used : TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 93 with TestRequest

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

the class SearchActionTest method fails_with_NotFoundException_if_project_is_neither_a_project_nor_an_application.

@Test
public void fails_with_NotFoundException_if_project_is_neither_a_project_nor_an_application() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    ComponentDto directory = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "foo"));
    ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project));
    ComponentDto portfolio = dbTester.components().insertPrivatePortfolio();
    TestRequest request = actionTester.newRequest();
    for (ComponentDto component : Arrays.asList(directory, file, portfolio)) {
        request.setParam("projectKey", component.getKey());
        assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Project '%s' not found", component.getKey());
    }
}
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 94 with TestRequest

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

the class ChangeStatusActionTest method fails_with_ForbiddenException_if_project_is_public_and_user_has_no_HotspotAdmin_permission_on_it.

@Test
@UseDataProvider("anyPublicProjectPermissionButHotspotAdmin")
public void fails_with_ForbiddenException_if_project_is_public_and_user_has_no_HotspotAdmin_permission_on_it(String permission) {
    ComponentDto project = dbTester.components().insertPublicProject();
    userSessionRule.logIn().registerComponents(project).addProjectPermission(permission, project);
    ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
    IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
    Arrays.stream(validStatusAndResolutions()).forEach(o -> {
        String status = (String) o[0];
        String resolution = (String) o[1];
        TestRequest request = newRequest(hotspot, status, resolution, NO_COMMENT);
        assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
    });
}
Also used : ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 95 with TestRequest

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

the class ChangeStatusActionTest method fail_with_IAE_if_status_value_is_neither_REVIEWED_nor_TO_REVIEW.

@Test
@UseDataProvider("badStatuses")
public void fail_with_IAE_if_status_value_is_neither_REVIEWED_nor_TO_REVIEW(String badStatus) {
    String key = randomAlphabetic(12);
    userSessionRule.logIn();
    TestRequest request = actionTester.newRequest().setParam("hotspot", key).setParam("status", badStatus);
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("Value of parameter 'status' (" + badStatus + ") must be one of: [TO_REVIEW, REVIEWED]");
}
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)

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