use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse 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.FakeHttpServletResponse 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.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class ResourceServletTest method smallFileWithoutClientCache.
@Test
public void smallFileWithoutClientCache() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, false, false);
writeFile("/foo", "foo1");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertNotCacheable(res);
// Miss on getIfPresent, miss on get.
assertCacheHits(cache, 0, 2);
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertNotCacheable(res);
assertCacheHits(cache, 1, 2);
writeFile("/foo", "foo2");
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertNotCacheable(res);
assertCacheHits(cache, 2, 2);
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class ResourceServletTest method smallFileWithRefresh.
@Test
public void smallFileWithRefresh() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true);
writeFile("/foo", "foo1");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertCacheable(res, true);
assertHasETag(res);
// Miss on getIfPresent, miss on get.
assertCacheHits(cache, 0, 2);
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo1");
assertCacheable(res, true);
assertHasETag(res);
assertCacheHits(cache, 1, 2);
writeFile("/foo", "foo2");
res = new FakeHttpServletResponse();
servlet.doGet(request("/foo"), res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getActualBodyString()).isEqualTo("foo2");
assertCacheable(res, true);
assertHasETag(res);
// Hit, invalidate, miss.
assertCacheHits(cache, 2, 3);
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class ResourceServletTest method notFoundWithRefresh.
@Test
public void notFoundWithRefresh() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true);
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(request("/notfound"), res);
assertThat(res.getStatus()).isEqualTo(SC_NOT_FOUND);
assertNotCacheable(res);
assertCacheHits(cache, 0, 1);
res = new FakeHttpServletResponse();
servlet.doGet(request("/notfound"), res);
assertThat(res.getStatus()).isEqualTo(SC_NOT_FOUND);
assertNotCacheable(res);
assertCacheHits(cache, 1, 1);
}
Aggregations