Search in sources :

Example 51 with TestRequest

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

the class ActivityActionTest method throws_IAE_if_page_is_higher_than_available.

@Test
public void throws_IAE_if_page_is_higher_than_available() {
    logInAsSystemAdministrator();
    ComponentDto project1 = db.components().insertPrivateProject();
    insertActivity("T1", project1, SUCCESS);
    insertActivity("T2", project1, SUCCESS);
    insertActivity("T3", project1, SUCCESS);
    TestRequest request = ws.newRequest().setParam(Param.PAGE, Integer.toString(2)).setParam(Param.PAGE_SIZE, Integer.toString(3)).setParam(PARAM_STATUS, "SUCCESS,FAILED,CANCELED,IN_PROGRESS,PENDING");
    assertThatThrownBy(() -> call(request)).isInstanceOf(IllegalArgumentException.class).hasMessage("Can return only the first 3 results. 4th result asked.");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 52 with TestRequest

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

the class ActivityActionTest method search_by_task_id_returns_403_if_project_admin_but_not_root.

@Test
public void search_by_task_id_returns_403_if_project_admin_but_not_root() {
    // WS api/ce/task must be used in order to search by task id.
    // Here it's a convenient feature of search by text query, which
    // is reserved to roots
    ComponentDto view = db.components().insertPrivatePortfolio();
    insertActivity("T1", view, SUCCESS);
    userSession.logIn().addProjectPermission(UserRole.ADMIN, view);
    TestRequest request = ws.newRequest().setParam(TEXT_QUERY, "T1");
    assertThatThrownBy(() -> call(request)).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Also used : ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 53 with TestRequest

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

the class TokenRenewActionTest method missing_project_admin_permission_should_fail.

@Test
public void missing_project_admin_permission_should_fail() {
    ComponentDto project = db.components().insertPrivateProject();
    TestRequest request = ws.newRequest().setParam("project", project.getKey());
    Assertions.assertThatThrownBy(request::execute).hasMessage("Insufficient privileges").isInstanceOf(ForbiddenException.class);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 54 with TestRequest

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

the class TokenActionTest method missing_project_parameter_should_fail.

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

Example 55 with TestRequest

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

the class TokenActionTest method missing_project_permission_should_fail.

@Test
public void missing_project_permission_should_fail() {
    ComponentDto project = db.components().insertPrivateProject();
    TestRequest request = ws.newRequest().setParam("project", project.getKey());
    Assertions.assertThatThrownBy(request::execute).hasMessage("Insufficient privileges").isInstanceOf(ForbiddenException.class);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) 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