use of org.sonar.api.server.ws.Response 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();
}
use of org.sonar.api.server.ws.Response in project sonarqube by SonarSource.
the class WebServiceEngineTest method internal_error.
@Test
public void internal_error() {
ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/fail");
DumbResponse response = new DumbResponse();
underTest.execute(request, response);
assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"An error has occurred. Please contact your administrator\"}]}");
assertThat(response.stream().status()).isEqualTo(500);
assertThat(response.stream().mediaType()).isEqualTo(MediaTypes.JSON);
assertThat(logTester.logs(LoggerLevel.ERROR)).filteredOn(l -> l.contains("Fail to process request")).isNotEmpty();
}
Aggregations