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; |
35 |
|
|
36 |
|
import static org.junit.Assert.assertFalse; |
37 |
|
import static org.mockito.Mockito.mock; |
38 |
|
import static org.mockito.Mockito.when; |
39 |
|
|
40 |
|
import info.magnolia.cms.core.Path; |
41 |
|
import info.magnolia.cms.core.SystemProperty; |
42 |
|
import info.magnolia.commands.CommandsManager; |
43 |
|
import info.magnolia.event.EventBus; |
44 |
|
import info.magnolia.module.cache.cachepolicy.Default; |
45 |
|
import info.magnolia.module.cache.inject.CacheFactoryProvider; |
46 |
|
import info.magnolia.module.cache.mbean.CacheMonitor; |
47 |
|
import info.magnolia.test.ComponentsTestUtil; |
48 |
|
|
49 |
|
import java.io.File; |
50 |
|
import java.io.IOException; |
51 |
|
import java.util.HashMap; |
52 |
|
import java.util.Map; |
53 |
|
|
54 |
|
import javax.inject.Provider; |
55 |
|
|
56 |
|
import org.apache.commons.io.FileUtils; |
57 |
|
import org.junit.After; |
58 |
|
import org.junit.Before; |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 5 |
Complexity Density: 0.24 |
|
60 |
|
public class AbstractCacheTest { |
61 |
|
|
62 |
|
protected final File cacheFolder = new File("cacheTest"); |
63 |
|
protected final File tempFolder = new File("tempTest"); |
64 |
|
protected CacheMonitor cacheMonitor; |
65 |
|
protected CacheModule cacheModule; |
66 |
|
protected CacheFactoryProvider cacheFactoryProvider; |
67 |
|
|
68 |
|
private Provider<CacheModule> cacheModuleProvider; |
69 |
|
private Map<String, ContentCachingConfiguration> contentCaching = new HashMap<String, ContentCachingConfiguration>(); |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
71 |
36 |
public void setupFolders() throws IOException {... |
72 |
36 |
assertFalse("Cache folder " + cacheFolder.getAbsolutePath() + " should not exist before test", cacheFolder.exists()); |
73 |
36 |
assertFalse("Temp folder " + tempFolder.getAbsolutePath() + " should not exist before test", tempFolder.exists()); |
74 |
|
|
75 |
36 |
SystemProperty.setProperty(SystemProperty.MAGNOLIA_CACHE_STARTDIR, cacheFolder.getAbsolutePath()); |
76 |
36 |
SystemProperty.setProperty(SystemProperty.MAGNOLIA_UPLOAD_TMPDIR, tempFolder.getAbsolutePath()); |
77 |
36 |
SystemProperty.setProperty(SystemProperty.MAGNOLIA_APP_ROOTDIR, "."); |
78 |
|
|
79 |
|
|
80 |
36 |
Path.getTempDirectory(); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
83 |
36 |
@Before... |
84 |
|
public void setUp() throws Exception { |
85 |
36 |
this.setupFolders(); |
86 |
36 |
cacheMonitor = new CacheMonitor(mock(CommandsManager.class), mock(CacheFactoryProvider.class), null); |
87 |
36 |
cacheModule = new CacheModule(cacheMonitor, mock(EventBus.class)); |
88 |
36 |
cacheModule.setContentCaching(contentCaching); |
89 |
36 |
cacheModuleProvider = mock(Provider.class); |
90 |
36 |
when(cacheModuleProvider.get()).thenReturn(cacheModule); |
91 |
36 |
cacheFactoryProvider = new CacheFactoryProvider(cacheModuleProvider); |
92 |
36 |
contentCaching.put(Default.UUID_KEY_MAP_KEY, new ContentCachingConfiguration(null, null)); |
93 |
36 |
ComponentsTestUtil.setInstance(CacheModule.class, cacheModule); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
23 |
protected void addContentCaching(String name, ContentCachingConfiguration configuration) {... |
97 |
23 |
this.contentCaching.put(name, configuration); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
100 |
36 |
public void clearFolders() throws IOException {... |
101 |
36 |
FileUtils.deleteDirectory(cacheFolder); |
102 |
36 |
FileUtils.deleteDirectory(tempFolder); |
103 |
36 |
SystemProperty.clear(); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
106 |
36 |
@After... |
107 |
|
public void tearDown() throws Exception { |
108 |
36 |
this.clearFolders(); |
109 |
36 |
ComponentsTestUtil.clear(); |
110 |
|
} |
111 |
|
} |