Search in sources :

Example 1 with ValidatingRequest

use of org.sonar.api.server.ws.internal.ValidatingRequest in project sonarqube by SonarSource.

the class WebServiceEngineTest method unknown_parameter_is_set.

@Test
public void unknown_parameter_is_set() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/fail_with_undeclared_parameter").setParam("unknown", "Unknown");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"BUG - parameter 'unknown' is undefined for action 'fail_with_undeclared_parameter'\"}]}");
}
Also used : ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Example 2 with ValidatingRequest

use of org.sonar.api.server.ws.internal.ValidatingRequest in project sonarqube by SonarSource.

the class WebServiceEngineTest method no_content.

@Test
public void no_content() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/alive");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEmpty();
}
Also used : ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Example 3 with ValidatingRequest

use of org.sonar.api.server.ws.internal.ValidatingRequest in project sonarqube by SonarSource.

the class WebServiceEngineTest method does_not_fail_when_request_is_aborted_and_response_is_committed.

@Test
public void does_not_fail_when_request_is_aborted_and_response_is_committed() throws Exception {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/fail_with_client_abort_exception");
    Response response = mock(Response.class);
    ServletResponse.ServletStream servletStream = mock(ServletResponse.ServletStream.class);
    when(response.stream()).thenReturn(servletStream);
    HttpServletResponse httpServletResponse = mock(HttpServletResponse.class);
    when(httpServletResponse.isCommitted()).thenReturn(true);
    when(servletStream.response()).thenReturn(httpServletResponse);
    underTest.execute(request, response);
    assertThat(logTester.logs(LoggerLevel.DEBUG)).isNotEmpty();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.sonar.api.server.ws.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 4 with ValidatingRequest

use of org.sonar.api.server.ws.internal.ValidatingRequest in project sonarqube by SonarSource.

the class WebServiceEngineTest method method_post_required.

@Test
public void method_post_required() {
    ValidatingRequest request = new TestRequest().setMethod("POST").setPath("/api/system/ping");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("pong");
}
Also used : ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Example 5 with ValidatingRequest

use of org.sonar.api.server.ws.internal.ValidatingRequest in project sonarqube by SonarSource.

the class WebServiceEngineTest method required_parameter_is_not_set.

@Test
public void required_parameter_is_not_set() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/print");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"The 'message' parameter is missing\"}]}");
}
Also used : ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 ValidatingRequest (org.sonar.api.server.ws.internal.ValidatingRequest)23 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Response (org.sonar.api.server.ws.Response)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClientAbortException (org.apache.catalina.connector.ClientAbortException)1 IOUtils (org.apache.commons.io.IOUtils)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 After (org.junit.After)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 WebService (org.sonar.api.server.ws.WebService)1 LogTester (org.sonar.api.utils.log.LogTester)1 LoggerLevel (org.sonar.api.utils.log.LoggerLevel)1 BadRequestException (org.sonar.server.exceptions.BadRequestException)1