Search in sources :

Example 71 with TestRequest

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

the class TreeActionTest method fail_when_using_branch_db_key.

@Test
public void fail_when_using_branch_db_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)

Example 72 with TestRequest

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

the class TreeActionTest method fail_when_base_component_is_removed.

@Test
public void fail_when_base_component_is_removed() {
    ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
    db.components().insertComponent(ComponentTesting.newFileDto(project).setDbKey("file-key").setEnabled(false));
    logInWithBrowsePermission(project);
    TestRequest request = ws.newRequest().setParam(PARAM_COMPONENT, "file-key");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Component key 'file-key' not found");
}
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 73 with TestRequest

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

the class ShowActionTest method fail_if_file_does_not_exist.

@Test
public void fail_if_file_does_not_exist() {
    TestRequest request = newBaseRequest().setParam("key", "missing");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class);
}
Also used : TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 74 with TestRequest

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

the class ShowActionTest method fail_if_user_is_not_allowed_to_access_project.

@Test
public void fail_if_user_is_not_allowed_to_access_project() {
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    TestRequest request = newBaseRequest().setParam("key", file.getDbKey());
    assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 75 with TestRequest

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

the class AppActionTest method fail_if_no_parameter_provided.

@Test
public void fail_if_no_parameter_provided() {
    TestRequest request = ws.newRequest();
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("The 'component' parameter is missing");
}
Also used : 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