1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.cache.executor; |
35 |
|
|
36 |
|
import static org.mockito.Matchers.anyLong; |
37 |
|
import static org.mockito.Matchers.eq; |
38 |
|
import static org.mockito.Matchers.matches; |
39 |
|
import static org.mockito.Mockito.*; |
40 |
|
|
41 |
|
import info.magnolia.cms.cache.CacheConstants; |
42 |
|
import info.magnolia.module.cache.Cache; |
43 |
|
import info.magnolia.module.cache.ContentCachingConfiguration; |
44 |
|
import info.magnolia.module.cache.browsercachepolicy.FixedDuration; |
45 |
|
import info.magnolia.module.cache.browsercachepolicy.Never; |
46 |
|
|
47 |
|
import javax.servlet.FilterChain; |
48 |
|
import javax.servlet.http.HttpServletRequest; |
49 |
|
import javax.servlet.http.HttpServletResponse; |
50 |
|
|
51 |
|
import org.junit.Test; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 2 |
Complexity Density: 0.08 |
|
56 |
|
public class SetExpirationHeadersTest { |
57 |
|
|
58 |
|
private final ContentCachingConfiguration cacheConfig = new ContentCachingConfiguration(null, null); |
59 |
|
|
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
61 |
1 |
@Test... |
62 |
|
public void testProcessCacheRequest() throws Exception { |
63 |
|
|
64 |
1 |
final HttpServletRequest request = mock(HttpServletRequest.class); |
65 |
1 |
final HttpServletResponse response = mock(HttpServletResponse.class); |
66 |
1 |
final FilterChain chain = mock(FilterChain.class); |
67 |
1 |
final Cache cache = mock(Cache.class); |
68 |
1 |
final FixedDuration fixed = new FixedDuration(); |
69 |
1 |
fixed.setExpirationMinutes(30); |
70 |
1 |
cacheConfig.setBrowserCachePolicy(fixed); |
71 |
|
|
72 |
1 |
SetExpirationHeaders executor = new SetExpirationHeaders(); |
73 |
1 |
executor.setContentCachingConfiguration(cacheConfig); |
74 |
|
|
75 |
|
|
76 |
1 |
executor.processCacheRequest(request, response, chain, cache, null); |
77 |
|
|
78 |
|
|
79 |
1 |
verify(response).setHeader(eq(CacheConstants.HEADER_CACHE_CONTROL), matches(CacheConstants.HEADER_VALUE_MAX_AGE + "=\\d{4}, " + CacheConstants.HEADER_VALUE_PUBLIC)); |
80 |
1 |
verify(response).setDateHeader(eq(CacheConstants.HEADER_EXPIRES), anyLong()); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
83 |
1 |
@Test... |
84 |
|
public void testProcessNoCacheRequest() throws Exception { |
85 |
|
|
86 |
1 |
final HttpServletRequest request = mock(HttpServletRequest.class); |
87 |
1 |
final HttpServletResponse response = mock(HttpServletResponse.class); |
88 |
1 |
final FilterChain chain = mock(FilterChain.class); |
89 |
1 |
final Cache cache = mock(Cache.class); |
90 |
1 |
final Never fixed = new Never(); |
91 |
1 |
cacheConfig.setBrowserCachePolicy(fixed); |
92 |
|
|
93 |
1 |
SetExpirationHeaders executor = new SetExpirationHeaders(); |
94 |
1 |
executor.setContentCachingConfiguration(cacheConfig); |
95 |
|
|
96 |
|
|
97 |
1 |
executor.processCacheRequest(request, response, chain, cache, null); |
98 |
|
|
99 |
|
|
100 |
1 |
verify(response).setHeader(CacheConstants.HEADER_PRAGMA, CacheConstants.HEADER_VALUE_NO_CACHE); |
101 |
1 |
verify(response).setHeader(CacheConstants.HEADER_CACHE_CONTROL, CacheConstants.HEADER_CACHE_CONTROL_VALUE_DISABLE_CACHE); |
102 |
1 |
verify(response).setDateHeader(CacheConstants.HEADER_EXPIRES, 0L); |
103 |
|
} |
104 |
|
} |