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.cachepolicy; |
35 |
|
|
36 |
|
import static org.hamcrest.Matchers.*; |
37 |
|
import static org.junit.Assert.assertThat; |
38 |
|
import static org.mockito.Mockito.*; |
39 |
|
|
40 |
|
import info.magnolia.cms.cache.CacheConstants; |
41 |
|
import info.magnolia.module.cache.cachekey.CacheKeyGenerator; |
42 |
|
import info.magnolia.module.cache.cachekey.DefaultCacheKeyGenerator; |
43 |
|
import info.magnolia.objectfactory.ComponentProvider; |
44 |
|
import info.magnolia.test.mock.MockWebContext; |
45 |
|
|
46 |
|
import javax.servlet.http.HttpServletRequest; |
47 |
|
|
48 |
|
import org.junit.Before; |
49 |
|
import org.junit.Test; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
51 |
|
public class XMagnoliaCacheAttributeTest { |
52 |
|
|
53 |
|
private final MockWebContext webCtx = new MockWebContext(); |
54 |
|
private final HttpServletRequest request = mock(HttpServletRequest.class); |
55 |
|
private final ComponentProvider componentProvider = mock(ComponentProvider.class); |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
1 |
@Before... |
58 |
|
public void setUp() { |
59 |
1 |
webCtx.setRequest(request); |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
62 |
1 |
@Test... |
63 |
|
public void constructor() { |
64 |
|
|
65 |
1 |
when(request.getHeader(CacheConstants.HEADER_X_MAGNOLIA_CACHE)).thenReturn(CacheKeyGenerator.class.getSimpleName() + "=" + CustomCacheKeyGenerator.class.getName() + "," + CacheConstants.HEADER_VALUE_X_MAGNOLIA_TTL + "=0,"); |
66 |
1 |
when(componentProvider.newInstance(CustomCacheKeyGenerator.class)).thenReturn(new CustomCacheKeyGenerator()); |
67 |
|
|
68 |
|
|
69 |
1 |
XMagnoliaCacheAttribute attribute = new XMagnoliaCacheAttribute(request); |
70 |
|
|
71 |
|
|
72 |
1 |
assertThat(attribute.getKeyGenerator(), instanceOf(CustomCacheKeyGenerator.class)); |
73 |
1 |
assertThat(attribute.getTtl(), is(0)); |
74 |
|
} |
75 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
76 |
|
public class CustomCacheKeyGenerator extends DefaultCacheKeyGenerator { |
77 |
|
} |
78 |
|
} |