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.filter; |
35 |
|
|
36 |
|
import static org.mockito.Mockito.*; |
37 |
|
|
38 |
|
import info.magnolia.cms.cache.CacheConstants; |
39 |
|
import info.magnolia.event.EventBus; |
40 |
|
import info.magnolia.module.cache.CacheModule; |
41 |
|
import info.magnolia.module.cache.ContentCompression; |
42 |
|
import info.magnolia.test.ComponentsTestUtil; |
43 |
|
import info.magnolia.voting.voters.VoterSet; |
44 |
|
|
45 |
|
import java.io.IOException; |
46 |
|
import java.util.Enumeration; |
47 |
|
|
48 |
|
import javax.servlet.FilterChain; |
49 |
|
import javax.servlet.ServletException; |
50 |
|
import javax.servlet.http.HttpServletRequest; |
51 |
|
import javax.servlet.http.HttpServletResponse; |
52 |
|
|
53 |
|
import org.apache.commons.collections4.MultiMap; |
54 |
|
import org.apache.commons.collections4.map.MultiValueMap; |
55 |
|
import org.junit.After; |
56 |
|
import org.junit.Before; |
57 |
|
import org.junit.Test; |
58 |
|
|
59 |
|
|
60 |
|
@link |
61 |
|
|
|
|
| 82.6% |
Uncovered Elements: 4 (23) |
Complexity: 7 |
Complexity Density: 0.44 |
|
62 |
|
public class ContentCachedEntryTest { |
63 |
|
|
64 |
|
private ContentCachedEntry cachedEntry; |
65 |
|
private HttpServletRequest request = mock(HttpServletRequest.class); |
66 |
|
private HttpServletResponse response = mock(HttpServletResponse.class); |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
68 |
1 |
@Before... |
69 |
|
public void setUp() throws IOException { |
70 |
1 |
CacheModule cacheModule = new CacheModule(null, mock(EventBus.class)); |
71 |
1 |
ContentCompression contentCompression = new ContentCompression(); |
72 |
1 |
contentCompression.setVoters(new VoterSet()); |
73 |
1 |
cacheModule.setCompression(contentCompression); |
74 |
1 |
ComponentsTestUtil.setInstance(CacheModule.class, cacheModule); |
75 |
|
|
76 |
1 |
when(request.getHeaders(anyString())).thenReturn(new Enumeration() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
1 |
@Override... |
78 |
|
public boolean hasMoreElements() { |
79 |
1 |
return false; |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
@Override... |
83 |
|
public Object nextElement() { |
84 |
0 |
return null; |
85 |
|
} |
86 |
|
}); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
1 |
@After... |
90 |
|
public void clear() { |
91 |
1 |
ComponentsTestUtil.clear(); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
94 |
1 |
@Test... |
95 |
|
public void replay() throws Exception { |
96 |
|
|
97 |
1 |
MultiMap headers = new MultiValueMap(); |
98 |
1 |
headers.put(CacheConstants.HEADER_CACHE_CONTROL, CacheConstants.HEADER_VALUE_NO_CACHE); |
99 |
|
|
100 |
1 |
when(response.containsHeader(CacheConstants.HEADER_CACHE_CONTROL)).thenReturn(true); |
101 |
|
|
102 |
1 |
cachedEntry = new ContentCachedEntry("contentType", "characterEncoding", 0, headers, 0l, "originalUrl", 0) { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
103 |
1 |
@Override... |
104 |
|
protected void writeContent(HttpServletRequest request, HttpServletResponse response, FilterChain chain, boolean acceptsGzipEncoding) throws IOException, ServletException { |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
0 |
@Override... |
108 |
|
protected boolean canServeGzipContent() { |
109 |
0 |
return false; |
110 |
|
} |
111 |
|
}; |
112 |
|
|
113 |
1 |
cachedEntry.replay(request, response, null); |
114 |
|
|
115 |
|
|
116 |
1 |
verify(response).setHeader(CacheConstants.HEADER_CACHE_CONTROL, CacheConstants.HEADER_VALUE_NO_CACHE); |
117 |
|
} |
118 |
|
} |