Search in sources :

Example 81 with TestRequest

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

the class AddCommentActionTest method fails_with_IAE_if_parameter_comment_is_missing.

@Test
public void fails_with_IAE_if_parameter_comment_is_missing() {
    String key = randomAlphabetic(12);
    userSessionRule.logIn();
    TestRequest request = actionTester.newRequest().setParam("hotspot", key);
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("The 'comment' parameter is missing");
}
Also used : TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 82 with TestRequest

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

the class AddCommentActionTest method fails_with_NotFoundException_if_hotspot_does_not_exist.

@Test
public void fails_with_NotFoundException_if_hotspot_does_not_exist() {
    String key = randomAlphabetic(12);
    userSessionRule.logIn();
    TestRequest request = actionTester.newRequest().setParam("hotspot", key).setParam("comment", randomAlphabetic(10));
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Hotspot '%s' does not exist", key);
}
Also used : NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 83 with TestRequest

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

the class SearchActionTest method fails_with_IAE_if_status_parameter_is_neither_TO_REVIEW_or_REVIEWED.

@Test
@UseDataProvider("badStatuses")
public void fails_with_IAE_if_status_parameter_is_neither_TO_REVIEW_or_REVIEWED(String badStatus) {
    TestRequest request = actionTester.newRequest().setParam("projectKey", randomAlphabetic(13)).setParam("status", badStatus);
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("Value of parameter 'status' (" + badStatus + ") must be one of: [TO_REVIEW, REVIEWED]");
}
Also used : TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 84 with TestRequest

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

the class SearchActionTest method fail_if_hotspots_provided_with_onlyMine_param.

@Test
public void fail_if_hotspots_provided_with_onlyMine_param() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    userSessionRule.registerComponents(project);
    userSessionRule.logIn().addProjectPermission(USER, project);
    TestRequest request = actionTester.newRequest().setParam("hotspots", IntStream.range(2, 10).mapToObj(String::valueOf).collect(joining(","))).setParam("onlyMine", "true");
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("Parameter 'onlyMine' can be used with parameter 'projectKey' only");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 85 with TestRequest

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

the class EditCommentActionTest method fails_if_trying_to_delete_comment_of_another_user_in_public_project.

@Test
public void fails_if_trying_to_delete_comment_of_another_user_in_public_project() {
    UserDto userTryingToEdit = dbTester.users().insertUser();
    UserDto userWithHotspotComment = dbTester.users().insertUser();
    ComponentDto project = dbTester.components().insertPublicProject();
    IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
    IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userWithHotspotComment, "Some comment");
    userSessionRule.logIn(userTryingToEdit).registerComponents(project);
    TestRequest request = newRequest(comment.getKey(), "new comment");
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("You can only edit your own comments");
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) 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