Search in sources :

Example 66 with TestRequest

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

the class TreeActionTest method fail_when_search_query_has_less_than_3_characters.

@Test
public void fail_when_search_query_has_less_than_3_characters() {
    ComponentDto project = db.components().insertComponent(newPrivateProjectDto("project-uuid"));
    db.commit();
    TestRequest request = ws.newRequest().setParam(PARAM_COMPONENT, project.getDbKey()).setParam(Param.TEXT_QUERY, "fi");
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("'q' length (2) is shorter than the minimum authorized (3)");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 67 with TestRequest

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

the class SearchActionTest method call.

private SearchWsResponse call(SearchRequest wsRequest) {
    TestRequest request = underTest.newRequest();
    ofNullable(wsRequest.getQualifiers()).ifPresent(p1 -> request.setParam(PARAM_QUALIFIERS, Joiner.on(",").join(p1)));
    ofNullable(wsRequest.getQuery()).ifPresent(p -> request.setParam(TEXT_QUERY, p));
    ofNullable(wsRequest.getPage()).ifPresent(page -> request.setParam(PAGE, String.valueOf(page)));
    ofNullable(wsRequest.getPageSize()).ifPresent(pageSize -> request.setParam(PAGE_SIZE, String.valueOf(pageSize)));
    return request.executeProtobuf(SearchWsResponse.class);
}
Also used : TestRequest(org.sonar.server.ws.TestRequest)

Example 68 with TestRequest

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

the class ShowActionTest method fail_if_branch_does_not_exist.

@Test
public void fail_if_branch_does_not_exist() {
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    userSession.addProjectPermission(UserRole.USER, project);
    db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
    TestRequest request = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_BRANCH, "another_branch");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch"));
}
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 69 with TestRequest

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

the class ShowActionTest 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(ShowWsResponse.class)).isInstanceOf(NotFoundException.class).hasMessage(String.format("Component key '%s' not found", branch.getDbKey()));
}
Also used : ShowWsResponse(org.sonarqube.ws.Components.ShowWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 70 with TestRequest

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

the class TreeActionTest method fail_when_base_component_not_found.

@Test
public void fail_when_base_component_not_found() {
    TestRequest request = ws.newRequest().setParam(PARAM_COMPONENT, "project-key");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.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