Search in sources :

Example 16 with FakeHttpServletRequest

use of com.google.gerrit.util.http.testutil.FakeHttpServletRequest in project gerrit by GerritCodeReview.

the class ParameterParserTest method rejectDuplicateContentType.

@Test
public void rejectDuplicateContentType() {
    FakeHttpServletRequest req = new FakeHttpServletRequest();
    req.setQueryString("$ct=json&$ct=string");
    BadRequestException bad = assertThrows(BadRequestException.class, () -> ParameterParser.getQueryParams(req));
    assertThat(bad).hasMessageThat().isEqualTo("duplicate $ct");
}
Also used : FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) Test(org.junit.Test)

Example 17 with FakeHttpServletRequest

use of com.google.gerrit.util.http.testutil.FakeHttpServletRequest in project gerrit by GerritCodeReview.

the class ParameterParserTest method rejectInvalidMethod.

@Test
public void rejectInvalidMethod() {
    FakeHttpServletRequest req = new FakeHttpServletRequest();
    req.setQueryString("$m=CONNECT");
    BadRequestException bad = assertThrows(BadRequestException.class, () -> ParameterParser.getQueryParams(req));
    assertThat(bad).hasMessageThat().isEqualTo("invalid $m");
}
Also used : FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) Test(org.junit.Test)

Example 18 with FakeHttpServletRequest

use of com.google.gerrit.util.http.testutil.FakeHttpServletRequest in project gerrit by GerritCodeReview.

the class ParameterParserTest method parseXdOverride.

@Test
public void parseXdOverride() throws BadRequestException {
    FakeHttpServletRequest req = new FakeHttpServletRequest();
    req.setQueryString("$m=PUT&$ct=json&access_token=secret");
    QueryParams qp = ParameterParser.getQueryParams(req);
    assertThat(qp.accessToken()).isEqualTo("secret");
    assertThat(qp.xdMethod()).isEqualTo("PUT");
    assertThat(qp.xdContentType()).isEqualTo("json");
    assertThat(qp.hasXdOverride()).isTrue();
    assertThat(qp.config()).isEmpty();
    assertThat(qp.params()).isEmpty();
}
Also used : FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) QueryParams(com.google.gerrit.httpd.restapi.ParameterParser.QueryParams) Test(org.junit.Test)

Aggregations

FakeHttpServletRequest (com.google.gerrit.util.http.testutil.FakeHttpServletRequest)18 Test (org.junit.Test)17 FakeHttpServletResponse (com.google.gerrit.util.http.testutil.FakeHttpServletResponse)12 FilterChain (javax.servlet.FilterChain)7 FilterConfig (javax.servlet.FilterConfig)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 InOrder (org.mockito.InOrder)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 Resource (com.google.gerrit.httpd.raw.ResourceServlet.Resource)3 QueryParams (com.google.gerrit.httpd.restapi.ParameterParser.QueryParams)3 Path (java.nio.file.Path)3 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 GerritApi (com.google.gerrit.extensions.api.GerritApi)1 Accounts (com.google.gerrit.extensions.api.accounts.Accounts)1 Config (com.google.gerrit.extensions.api.config.Config)1 Server (com.google.gerrit.extensions.api.config.Server)1 ServerInfo (com.google.gerrit.extensions.common.ServerInfo)1