1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ehcache.constructs.web.filter;
18
19 import com.meterware.httpunit.WebResponse;
20 import net.sf.ehcache.constructs.web.AbstractWebTest;
21 import net.sf.ehcache.constructs.web.PageInfo;
22 import org.apache.commons.httpclient.Header;
23 import org.apache.commons.httpclient.HttpClient;
24 import org.apache.commons.httpclient.HttpMethod;
25 import org.apache.commons.httpclient.methods.GetMethod;
26
27
28
29
30
31 public class PageFragmentCachingFilterTest extends AbstractWebTest {
32
33
34
35
36 public void testBasic() throws Exception {
37 WebResponse response = getResponseFromAcceptGzipRequest("/include/Footer.jsp");
38 assertResponseOk(response);
39 assertIncludeHeadersSane(response);
40 assertPageNotBlank(response);
41 }
42
43
44
45
46 public void testCachedPageFragmentIsCached() throws Exception {
47 WebResponse response = getResponseFromAcceptGzipRequest("/fragment/CachedFragment.jsp");
48 assertResponseOk(response);
49 assertIncludeHeadersSane(response);
50 assertPageNotBlank(response);
51 String firstResponse = response.getText();
52
53 response = getResponseFromAcceptGzipRequest("/fragment/CachedFragment.jsp");
54 assertResponseOk(response);
55 assertIncludeHeadersSane(response);
56 assertPageNotBlank(response);
57 String secondResponse = response.getText();
58
59 assertEquals(firstResponse, secondResponse);
60 }
61
62
63
64
65 public void testNotGzippedWhenAcceptEncodingPageFragment() throws Exception {
66 HttpClient httpClient = new HttpClient();
67 HttpMethod httpMethod = new GetMethod(buildUrl("/include/Footer.jsp"));
68
69 httpClient.executeMethod(httpMethod);
70 byte[] responseBody = httpMethod.getResponseBody();
71 assertFalse(PageInfo.isGzipped(responseBody));
72 assertNotSame("gzip", httpMethod.getResponseHeader("Accept-encoding"));
73 }
74
75
76
77
78 public void testNotGzippedWhenNotAcceptEncodingPageFragment() throws Exception {
79 HttpClient httpClient = new HttpClient();
80 HttpMethod httpMethod = new GetMethod(buildUrl("/include/Footer.jsp"));
81 httpMethod.setRequestHeader(new Header("Accept-encoding", "gzip"));
82 httpClient.executeMethod(httpMethod);
83 byte[] responseBody = httpMethod.getResponseBody();
84 assertFalse(PageInfo.isGzipped(responseBody));
85 assertNotSame("gzip", httpMethod.getResponseHeader("Accept-encoding"));
86 }
87
88
89
90
91
92
93 public void testFromJSPInclude() throws Exception {
94 WebResponse response = getResponseFromAcceptGzipRequest("/fragment/NonCachedPageIncludingCachedFragment.jsp");
95 assertResponseOk(response);
96 assertHeadersSane(response);
97 assertPageNotBlank(response);
98 assertTrue(response.getText().indexOf("</html>") != -1);
99
100 }
101
102
103 }