1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.cache; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
|
24 |
|
import org.jmock.Expectations; |
25 |
|
import org.junit.Test; |
26 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
27 |
|
import org.xwiki.cache.config.CacheConfiguration; |
28 |
|
import org.xwiki.cache.eviction.LRUEvictionConfiguration; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
import org.xwiki.observation.ObservationManager; |
31 |
|
|
32 |
|
import com.xpn.xwiki.XWiki; |
33 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
34 |
|
import com.xpn.xwiki.test.AbstractBridgedComponentTestCase; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 5 |
Complexity Density: 0.19 |
|
42 |
|
public class DefaultDocumentCacheTest extends AbstractBridgedComponentTestCase |
43 |
|
{ |
44 |
|
private XWiki mockXWiki; |
45 |
|
|
46 |
|
private XWikiDocument document; |
47 |
|
|
48 |
|
private DefaultDocumentCache<String> cache; |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
50 |
2 |
@Override... |
51 |
|
public void setUp() throws Exception |
52 |
|
{ |
53 |
2 |
super.setUp(); |
54 |
|
|
55 |
2 |
this.cache = (DefaultDocumentCache<String>) getComponentManager().getInstance(DocumentCache.class); |
56 |
|
|
57 |
2 |
CacheConfiguration cacheConfiguration = new CacheConfiguration(); |
58 |
2 |
cacheConfiguration.setConfigurationId("documentcachetest"); |
59 |
2 |
LRUEvictionConfiguration lru = new LRUEvictionConfiguration(); |
60 |
2 |
cacheConfiguration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru); |
61 |
2 |
this.cache.create(cacheConfiguration); |
62 |
|
|
63 |
2 |
this.document = new XWikiDocument(new DocumentReference("wiki", "space", "page")); |
64 |
2 |
this.document.setOriginalDocument(this.document.clone()); |
65 |
|
|
66 |
2 |
this.mockXWiki = getMockery().mock(XWiki.class); |
67 |
2 |
getContext().setWiki(this.mockXWiki); |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
69 |
2 |
getMockery().checking(new Expectations() {{... |
70 |
2 |
allowing(mockXWiki).getDocument(document.getDocumentReference(), getContext()); will(returnValue(document)); |
71 |
|
}}); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
74 |
2 |
@Override... |
75 |
|
public void tearDown() throws Exception |
76 |
|
{ |
77 |
2 |
this.cache.dispose(); |
78 |
|
|
79 |
2 |
super.tearDown(); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
82 |
1 |
@Test... |
83 |
|
public void testGetSet() |
84 |
|
{ |
85 |
1 |
this.cache.set("data", this.document.getDocumentReference()); |
86 |
1 |
this.cache.set("data2", this.document.getDocumentReference(), "ext1", "ext2"); |
87 |
|
|
88 |
1 |
Assert.assertEquals("data", this.cache.get(this.document.getDocumentReference())); |
89 |
1 |
Assert.assertEquals("data2", this.cache.get(this.document.getDocumentReference(), "ext1", "ext2")); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
92 |
1 |
@Test... |
93 |
|
public void testEventBasedCleanup() throws Exception |
94 |
|
{ |
95 |
1 |
this.cache.set("data", this.document.getDocumentReference()); |
96 |
1 |
this.cache.set("data", this.document.getDocumentReference(), "ext1", "ext2"); |
97 |
|
|
98 |
1 |
ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class); |
99 |
1 |
observationManager.notify( |
100 |
|
new DocumentUpdatedEvent(this.document.getDocumentReference()), this.document, getContext()); |
101 |
|
|
102 |
1 |
Assert.assertNull(this.cache.get(this.document.getDocumentReference())); |
103 |
1 |
Assert.assertNull(this.cache.get(this.document.getDocumentReference(), "ext1", "ext2")); |
104 |
|
} |
105 |
|
} |