/** * Tests that a normal request goes through to the chain. * * @throws IOException Never. * @throws ServletException Never. */ @Test public void testNormal() throws IOException, ServletException { Configuration configuration = makeConfiguration(); HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class); EasyMock.expect(req.getRequestURI()).andReturn("/foo/bar"); EasyMock.replay(req); HttpServletResponse res = EasyMock.createStrictMock(HttpServletResponse.class); EasyMock.replay(res); WorkflowChain wc = EasyMock.createStrictMock(WorkflowChain.class); wc.continueWorkflow(); EasyMock.replay(wc); StaticResourceWorkflow srw = new StaticResourceWorkflow(req, res, configuration); srw.perform(wc); EasyMock.verify(configuration, req, res, wc); }
/** * Tests that a bad request returns 404. * * @throws IOException Never. * @throws ServletException Never. */ @Test public void testBadRequest() throws IOException, ServletException { Configuration configuration = makeConfiguration(); HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class); EasyMock.expect(req.getRequestURI()).andReturn("/component/2.1.1/bad.jpg"); EasyMock.expect(req.getDateHeader("If-Modified-Since")).andReturn(0l); EasyMock.replay(req); HttpServletResponse res = EasyMock.createStrictMock(HttpServletResponse.class); EasyMock.replay(res); WorkflowChain wc = EasyMock.createStrictMock(WorkflowChain.class); wc.continueWorkflow(); EasyMock.replay(wc); StaticResourceWorkflow srw = new StaticResourceWorkflow(req, res, configuration); srw.perform(wc); EasyMock.verify(configuration, req, res, wc); }
/** * Tests that a cache request returns never expire. * * @throws IOException Never. * @throws ServletException Never. */ @Test public void testCacheRequest() throws IOException, ServletException { Configuration configuration = makeConfiguration(); HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class); EasyMock.expect(req.getRequestURI()).andReturn("/component/2.1.1/test.jpg"); EasyMock.expect(req.getDateHeader("If-Modified-Since")).andReturn(1l); EasyMock.replay(req); HttpServletResponse res = EasyMock.createStrictMock(HttpServletResponse.class); res.setDateHeader("Expires", Long.MAX_VALUE); res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); EasyMock.replay(res); WorkflowChain wc = EasyMock.createStrictMock(WorkflowChain.class); EasyMock.replay(wc); StaticResourceWorkflow srw = new StaticResourceWorkflow(req, res, configuration); srw.perform(wc); EasyMock.verify(configuration, req, res, wc); }
/** * Tests that a new request returns the byte stream. * * @throws IOException Never. * @throws ServletException Never. */ @Test public void testNewRequest() throws IOException, ServletException { Configuration configuration = makeConfiguration(); HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class); EasyMock.expect(req.getRequestURI()).andReturn("/component/2.1.1/test.jpg"); EasyMock.expect(req.getDateHeader("If-Modified-Since")).andReturn(0l); EasyMock.replay(req); final StringBuilder build = new StringBuilder(); ServletOutputStream sos = new ServletOutputStream() { public void write(int b) throws IOException { build.appendCodePoint(b); } }; HttpServletResponse res = EasyMock.createStrictMock(HttpServletResponse.class); res.setContentType("image/jpeg"); res.setDateHeader(EasyMock.eq("Date"), EasyMock.gt(System.currentTimeMillis())); res.setDateHeader("Expires", Long.MAX_VALUE); res.setDateHeader("Retry-After", Long.MAX_VALUE); res.setHeader("Cache-Control", "public"); res.setDateHeader("Last-Modified", 0); EasyMock.expect(res.getOutputStream()).andReturn(sos); EasyMock.replay(res); WorkflowChain wc = EasyMock.createStrictMock(WorkflowChain.class); EasyMock.replay(wc); StaticResourceWorkflow srw = new StaticResourceWorkflow(req, res, configuration); srw.perform(wc); EasyMock.verify(configuration, req, res, wc); assertEquals("Test\n", build.toString()); }