use of com.google.gerrit.util.http.testutil.FakeHttpServletRequest in project gerrit by GerritCodeReview.
the class AllRequestFilterFilterProxyTest method postponedLoading.
@Test
public void postponedLoading() throws Exception {
FilterConfig config = mock(FilterConfig.class);
HttpServletRequest req1 = new FakeHttpServletRequest();
HttpServletRequest req2 = new FakeHttpServletRequest();
HttpServletResponse res1 = new FakeHttpServletResponse();
HttpServletResponse res2 = new FakeHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
ArgumentCaptor<FilterChain> capturedChainA1 = ArgumentCaptor.forClass(FilterChain.class);
ArgumentCaptor<FilterChain> capturedChainA2 = ArgumentCaptor.forClass(FilterChain.class);
ArgumentCaptor<FilterChain> capturedChainB = ArgumentCaptor.forClass(FilterChain.class);
AllRequestFilter filterA = mock(AllRequestFilter.class);
AllRequestFilter filterB = mock(AllRequestFilter.class);
InOrder inorder = inOrder(filterA, filterB, chain);
AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
addFilter(filterA);
filterProxy.init(config);
filterProxy.doFilter(req1, res1, chain);
inorder.verify(filterA).init(config);
inorder.verify(filterA).doFilter(eq(req1), eq(res1), capturedChainA1.capture());
capturedChainA1.getValue().doFilter(req1, res1);
inorder.verify(chain).doFilter(req1, res1);
// <-- Adds filter after filterProxy's init got called.
addFilter(filterB);
filterProxy.doFilter(req2, res2, chain);
// after filterProxy's init finished. Nonetheless filterB gets initialized.
inorder.verify(filterA).doFilter(eq(req2), eq(res2), capturedChainA2.capture());
capturedChainA2.getValue().doFilter(req2, res2);
// <-- This is crucial part. filterB got loaded
inorder.verify(filterB).init(config);
inorder.verify(filterB).doFilter(eq(req2), eq(res2), capturedChainB.capture());
capturedChainB.getValue().doFilter(req2, res2);
inorder.verify(chain).doFilter(req2, res2);
filterProxy.destroy();
inorder.verify(filterA).destroy();
inorder.verify(filterB).destroy();
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletRequest in project gerrit by GerritCodeReview.
the class ResourceServletTest method smallFileWithGzip.
@Test
public void smallFileWithGzip() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true);
String content = Strings.repeat("a", 100);
writeFile("/foo", content);
FakeHttpServletRequest req = request("/foo").addHeader("Accept-Encoding", "gzip");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(req, res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getHeader("Content-Encoding")).isEqualTo("gzip");
assertThat(gunzip(res.getActualBody())).isEqualTo(content);
assertHasETag(res);
assertCacheable(res, true);
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletRequest in project gerrit by GerritCodeReview.
the class ResourceServletTest method verySmallFileDoesntBotherWithGzip.
@Test
public void verySmallFileDoesntBotherWithGzip() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true);
writeFile("/foo", "foo1");
FakeHttpServletRequest req = request("/foo").addHeader("Accept-Encoding", "gzip");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(req, res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getHeader("Content-Encoding")).isNull();
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertHasETag(res);
assertCacheable(res, true);
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletRequest in project gerrit by GerritCodeReview.
the class ParameterParserTest method parseAccessToken.
@Test
public void parseAccessToken() throws BadRequestException {
FakeHttpServletRequest req = new FakeHttpServletRequest();
req.setQueryString("query=status%3aopen&access_token=secr%65t");
QueryParams qp = ParameterParser.getQueryParams(req);
assertThat(qp.accessToken()).isEqualTo("secret");
assertThat(qp.xdMethod()).isNull();
assertThat(qp.xdContentType()).isNull();
assertThat(qp.hasXdOverride()).isFalse();
assertThat(qp.config()).isEmpty();
assertThat(qp.params()).containsKey("query");
assertThat(qp.params().get("query")).containsExactly("status:open");
req = new FakeHttpServletRequest();
req.setQueryString("access_token=secret");
qp = ParameterParser.getQueryParams(req);
assertThat(qp.accessToken()).isEqualTo("secret");
assertThat(qp.xdMethod()).isNull();
assertThat(qp.xdContentType()).isNull();
assertThat(qp.hasXdOverride()).isFalse();
assertThat(qp.config()).isEmpty();
assertThat(qp.params()).isEmpty();
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletRequest in project gerrit by GerritCodeReview.
the class ParameterParserTest method parseQuery.
@Test
public void parseQuery() throws BadRequestException {
FakeHttpServletRequest req = new FakeHttpServletRequest();
req.setQueryString("query=status%3aopen");
QueryParams qp = ParameterParser.getQueryParams(req);
assertThat(qp.accessToken()).isNull();
assertThat(qp.xdMethod()).isNull();
assertThat(qp.xdContentType()).isNull();
assertThat(qp.hasXdOverride()).isFalse();
assertThat(qp.config()).isEmpty();
assertThat(qp.params()).containsKey("query");
assertThat(qp.params().get("query")).containsExactly("status:open");
}
Aggregations