Search in sources :

Example 56 with TestRequest

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

the class SearchProjectsActionTest method call.

private SearchProjectsWsResponse call(RequestBuilder requestBuilder) {
    SearchProjectsRequest wsRequest = requestBuilder.build();
    TestRequest httpRequest = ws.newRequest();
    ofNullable(wsRequest.getFilter()).ifPresent(filter -> httpRequest.setParam(PARAM_FILTER, filter));
    ofNullable(wsRequest.getSort()).ifPresent(sort -> httpRequest.setParam(SORT, sort));
    ofNullable(wsRequest.getAsc()).ifPresent(asc -> httpRequest.setParam(ASCENDING, Boolean.toString(asc)));
    httpRequest.setParam(PAGE, String.valueOf(wsRequest.getPage()));
    httpRequest.setParam(PAGE_SIZE, String.valueOf(wsRequest.getPageSize()));
    httpRequest.setParam(FACETS, Joiner.on(",").join(wsRequest.getFacets()));
    httpRequest.setParam(FIELDS, Joiner.on(",").join(wsRequest.getAdditionalFields()));
    return httpRequest.executeProtobuf(SearchProjectsWsResponse.class);
}
Also used : SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) TestRequest(org.sonar.server.ws.TestRequest)

Example 57 with TestRequest

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

the class AppActionTest method fail_when_branch_not_found.

@Test
public void fail_when_branch_not_found() {
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto branch = db.components().insertProjectBranch(project);
    ComponentDto file = db.components().insertComponent(newFileDto(branch));
    TestRequest request = ws.newRequest().setParam("component", file.getKey()).setParam("branch", "unknown");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 58 with TestRequest

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

the class AppActionTest method fail_when_missing_permission.

@Test
public void fail_when_missing_permission() {
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    TestRequest request = ws.newRequest().setParam("component", file.getKey());
    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 59 with TestRequest

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

the class ActivityActionTest method return_401_if_user_is_not_logged_in.

@Test
public void return_401_if_user_is_not_logged_in() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.anonymous();
    TestRequest request = ws.newRequest().setParam("componentId", project.uuid());
    assertThatThrownBy(() -> call(request)).isInstanceOf(UnauthorizedException.class).hasMessage("Authentication is required");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) UnauthorizedException(org.sonar.server.exceptions.UnauthorizedException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 60 with TestRequest

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

the class AnalysisStatusActionTest method fail_if_both_branch_and_pullRequest_are_specified.

@Test
public void fail_if_both_branch_and_pullRequest_are_specified() {
    TestRequest request = ws.newRequest().setParam(PARAM_COMPONENT, "dummy").setParam(PARAM_BRANCH, "feature1").setParam(PARAM_PULL_REQUEST, "pr1");
    assertThatThrownBy(request::execute).isInstanceOf(BadRequestException.class);
}
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