public void test_ETag_Header_Response()
throws Exception
{
WebRequest request = newMock(WebRequest.class);
checkOrder(request, false);
WebResponse response = newMock(WebResponse.class);
WebContext context = newMock(WebContext.class);
IRequestCycle cycle = newMock(IRequestCycle.class);
ResourceMatcher matcher = newMock(ResourceMatcher.class);
ClassResolver resolver = new DefaultClassResolver();
URLConnection url = resolver.getResource("/org/apache/tapestry/asset/tapestry-in-action.png").openConnection();
AssetService service = new AssetService();
service.setRequest(request);
service.setResponse(response);
service.setLog(LogFactory.getLog("test"));
service.setUnprotectedMatcher(matcher);
service.setClassResolver(resolver);
service.setContext(context);
expect(cycle.getParameter("path")).andReturn("/org/apache/tapestry/asset/tapestry-in-action.png");
expect(cycle.getParameter("digest")).andReturn(null);
expect(matcher.containsResource("/org/apache/tapestry/asset/tapestry-in-action.png")).andReturn(true);
expect(request.getDateHeader("If-Modified-Since")).andReturn(-1L);
expect(context.getMimeType("/org/apache/tapestry/asset/tapestry-in-action.png")).andReturn("image/png");
response.setDateHeader("Last-Modified", url.getLastModified());
response.setDateHeader("Expires", service._expireTime);
response.setHeader("Cache-Control", "public, max-age=" + (AssetService.MONTH_SECONDS * 3));
expect(request.getHeader("User-Agent")).andReturn("Mozilla").anyTimes();
response.setHeader("ETag", "W/\"" + url.getContentLength() + "-" + url.getLastModified() + "\"");
response.setContentLength(url.getContentLength());
expect(response.getOutputStream(new ContentType("image/png"))).andReturn(new ByteArrayOutputStream());
replay();
service.service(cycle);