Search in sources :

Example 11 with ValidatingRequest

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

the class WebServiceEngineTest method does_not_fail_to_render_error_message_having_percent.

@Test
public void does_not_fail_to_render_error_message_having_percent() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/error_message_having_percent");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"this should not fail %s\"}]}");
    assertThat(response.stream().status()).isEqualTo(400);
    assertThat(response.stream().mediaType()).isEqualTo(MediaTypes.JSON);
}
Also used : ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Example 12 with ValidatingRequest

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

the class WebServiceEngineTest method param_value_is_not_in_possible_values.

@Test
public void param_value_is_not_in_possible_values() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/print").setParam("message", "Hello World").setParam("format", "html");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Value of parameter 'format' (html) must be one of: [json, xml]\"}]}");
}
Also used : ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Example 13 with ValidatingRequest

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

the class WebServiceEngineTest method execute_request.

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

Example 14 with ValidatingRequest

use of org.sonar.api.server.ws.internal.ValidatingRequest 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();
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test) ClientAbortException(org.apache.catalina.connector.ClientAbortException) Mockito.when(org.mockito.Mockito.when) BadRequestException(org.sonar.server.exceptions.BadRequestException) ArrayList(java.util.ArrayList) ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) WebService(org.sonar.api.server.ws.WebService) After(org.junit.After) Response(org.sonar.api.server.ws.Response) MediaTypes(org.sonarqube.ws.MediaTypes) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Mockito.mock(org.mockito.Mockito.mock) ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Example 15 with ValidatingRequest

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

the class WebServiceEngineTest method execute_request_when_path_does_not_begin_with_slash.

@Test
public void execute_request_when_path_does_not_begin_with_slash() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/health");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("good");
}
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