Search in sources :

Example 6 with ValidatingRequest

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

the class WebServiceEngineTest method bad_request_with_multiple_messages.

@Test
public void bad_request_with_multiple_messages() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/fail_with_multiple_messages").setParam("count", "3");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[" + "{\"msg\":\"Bad request reason #0\"}," + "{\"msg\":\"Bad request reason #1\"}," + "{\"msg\":\"Bad request reason #2\"}" + "]}");
    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 7 with ValidatingRequest

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

the class WebServiceEngineTest method bad_request_if_action_suffix_is_not_supported.

@Test
public void bad_request_if_action_suffix_is_not_supported() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/health.bat");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().status()).isEqualTo(400);
    assertThat(response.stream().mediaType()).isEqualTo(MediaTypes.JSON);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Unknown action extension: bat\"}]}");
}
Also used : ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Example 8 with ValidatingRequest

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

the class WebServiceEngineTest method bad_controller.

@Test
public void bad_controller() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/xxx/health");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Unknown url : /api/xxx/health\"}]}");
    assertThat(response.stream().status()).isEqualTo(404);
}
Also used : ValidatingRequest(org.sonar.api.server.ws.internal.ValidatingRequest) Test(org.junit.Test)

Example 9 with ValidatingRequest

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

the class WebServiceEngineTest method bad_request.

@Test
public void bad_request() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/fail_bad_request").setParam("count", "3");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Bad request !\"}]}");
    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 10 with ValidatingRequest

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

the class WebServiceEngineTest method bad_action.

@Test
public void bad_action() {
    ValidatingRequest request = new TestRequest().setMethod("GET").setPath("/api/system/xxx");
    DumbResponse response = new DumbResponse();
    underTest.execute(request, response);
    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Unknown url : /api/system/xxx\"}]}");
    assertThat(response.stream().status()).isEqualTo(404);
}
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