1 package com.atlassian.core.filters.cache;
2
3 import junit.framework.TestCase;
4 import com.atlassian.core.filters.ServletStubs;
5
6 public class TestJspCachingStrategy extends TestCase
7 {
8 private JspCachingStrategy strategy;
9 private ServletStubs.Request request;
10
11 protected void setUp() throws Exception
12 {
13 super.setUp();
14 strategy = new JspCachingStrategy();
15 request = ServletStubs.getRequestInstance();
16 }
17
18 public void testMatchesJspUrls() throws Exception
19 {
20 request.setRequestURI("super.jsp");
21 assertTrue(strategy.matches(request));
22
23 request.setRequestURI("super.jsp?param=value");
24 assertTrue(strategy.matches(request));
25
26 }
27
28 public void testMatchesJspaUrls() throws Exception
29 {
30 request.setRequestURI("super.jspa");
31 assertTrue(strategy.matches(request));
32
33 request.setRequestURI("super.jspa?param=value");
34 assertTrue(strategy.matches(request));
35 }
36
37 public void testDoesNotMatchOtherUrls() throws Exception
38 {
39 request.setRequestURI(".jsp");
40 assertFalse(strategy.matches(request));
41
42 request.setRequestURI(".jspa");
43 assertFalse(strategy.matches(request));
44
45 request.setRequestURI("super.action?param=value");
46 assertFalse(strategy.matches(request));
47
48 request.setRequestURI("this-is-not-a-jsp.gif");
49 assertFalse(strategy.matches(request));
50 }
51
52 public void testCachingHeaders() throws Exception
53 {
54 ServletStubs.Response response = ServletStubs.getResponseInstance();
55 strategy.setCachingHeaders(response);
56
57 assertEquals("no-cache, no-store, must-revalidate", response.getHeader("Cache-Control"));
58 assertEquals("no-cache", response.getHeader("Pragma"));
59 assertEquals(0L, response.getDateHeader("Expires"));
60 }
61 }