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.rendering; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.HashSet; |
25 |
|
import java.util.Map; |
26 |
|
import java.util.Set; |
27 |
|
|
28 |
|
import org.jmock.Expectations; |
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Test; |
31 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
32 |
|
import org.xwiki.model.reference.DocumentReference; |
33 |
|
import org.xwiki.observation.ObservationManager; |
34 |
|
import org.xwiki.test.internal.MockConfigurationSource; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWiki; |
37 |
|
import com.xpn.xwiki.XWikiContext; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
import com.xpn.xwiki.internal.cache.rendering.CachedItem.UsedExtension; |
40 |
|
import com.xpn.xwiki.plugin.XWikiDefaultPlugin; |
41 |
|
import com.xpn.xwiki.plugin.XWikiPluginManager; |
42 |
|
import com.xpn.xwiki.test.AbstractBridgedComponentTestCase; |
43 |
|
import com.xpn.xwiki.web.XWikiServletRequestStub; |
44 |
|
|
45 |
|
|
46 |
|
@link |
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 4 |
Complexity Density: 0.11 |
|
51 |
|
public class DefaultRenderingCacheTest extends AbstractBridgedComponentTestCase |
52 |
|
{ |
53 |
|
private XWiki mockXWiki; |
54 |
|
|
55 |
|
private XWikiDocument document; |
56 |
|
|
57 |
|
private RenderingCache renderingCache; |
58 |
|
|
59 |
|
private XWikiServletRequestStub mockRequest; |
60 |
|
|
61 |
|
private XWikiPluginManager mockPluginManager; |
62 |
|
|
63 |
|
private Map<String, String[]> parameters = new HashMap<String, String[]>(); |
64 |
|
|
65 |
|
private String refresh; |
66 |
|
|
67 |
|
private TestRenderingCacheAware testRenderingCacheAware; |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
69 |
1 |
@Override... |
70 |
|
public void setUp() throws Exception |
71 |
|
{ |
72 |
1 |
super.setUp(); |
73 |
|
|
74 |
1 |
this.mockPluginManager = getMockery().mock(XWikiPluginManager.class); |
75 |
1 |
this.testRenderingCacheAware = new TestRenderingCacheAware("Test","Test",getContext()); |
76 |
|
|
77 |
1 |
this.document = new XWikiDocument(new DocumentReference("wiki", "space", "page")); |
78 |
1 |
this.document.setOriginalDocument(this.document.clone()); |
79 |
|
|
80 |
1 |
this.mockXWiki = getMockery().mock(XWiki.class); |
81 |
1 |
getContext().setWiki(this.mockXWiki); |
82 |
|
|
83 |
1 |
this.mockRequest = getMockery().mock(XWikiServletRequestStub.class); |
84 |
1 |
getContext().setRequest(this.mockRequest); |
85 |
|
|
86 |
1 |
this.renderingCache = getComponentManager().getInstance(RenderingCache.class); |
87 |
|
|
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
89 |
1 |
getMockery().checking(new Expectations() {{... |
90 |
1 |
allowing(mockXWiki).getPluginManager(); will(returnValue(mockPluginManager)); |
91 |
1 |
allowing(mockXWiki).getDocument(document.getDocumentReference(), getContext()); will(returnValue(document)); |
92 |
1 |
allowing(mockPluginManager).getPlugin("jsx"); will(returnValue(testRenderingCacheAware)); |
93 |
1 |
allowing(mockRequest).getParameterMap(); will(returnValue(parameters)); |
94 |
1 |
allowing(mockRequest).getParameter("refresh"); will(returnValue(refresh)); |
95 |
1 |
allowing(mockPluginManager).getPlugins(); |
96 |
|
}}); |
97 |
|
|
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
100 |
1 |
@Override... |
101 |
|
protected void registerComponents() throws Exception |
102 |
|
{ |
103 |
1 |
super.registerComponents(); |
104 |
|
|
105 |
1 |
getConfigurationSource().setProperty("core.renderingcache.enabled", true); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
108 |
1 |
@Test... |
109 |
|
public void testGetSetRenderedContent() throws Exception |
110 |
|
{ |
111 |
1 |
MockConfigurationSource source = getConfigurationSource(); |
112 |
|
|
113 |
1 |
source.setProperty("core.renderingcache.documents", |
114 |
|
Collections.singletonList(this.document.getPrefixedFullName())); |
115 |
|
|
116 |
1 |
this.renderingCache.setRenderedContent(this.document.getDocumentReference(), "source", "renderedContent", |
117 |
|
getContext()); |
118 |
|
|
119 |
1 |
Assert.assertEquals("renderedContent", |
120 |
|
this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext())); |
121 |
|
|
122 |
1 |
this.parameters.put("param", new String[] {"value1", "value2"}); |
123 |
|
|
124 |
1 |
Assert.assertNull(this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", |
125 |
|
getContext())); |
126 |
|
|
127 |
1 |
this.parameters.remove("param"); |
128 |
|
|
129 |
1 |
Assert.assertEquals("renderedContent", |
130 |
|
this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext())); |
131 |
|
|
132 |
1 |
ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class); |
133 |
1 |
observationManager.notify(new DocumentUpdatedEvent(this.document.getDocumentReference()), this.document, |
134 |
|
getContext()); |
135 |
|
|
136 |
1 |
Assert.assertNull(this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", |
137 |
|
getContext())); |
138 |
|
} |
139 |
|
|
140 |
|
|
|
|
| 50% |
Uncovered Elements: 8 (16) |
Complexity: 6 |
Complexity Density: 0.6 |
|
141 |
|
private static class TestRenderingCacheAware extends XWikiDefaultPlugin implements RenderingCacheAware { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
1 |
public TestRenderingCacheAware(String name, String className, XWikiContext context) {... |
143 |
1 |
super(name, className, context); |
144 |
|
} |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
1 |
private static Map<String,Map<String,Object>> markerMap = new HashMap<String, Map<String,Object>>(){{put("Hello",new HashMap<String, Object>(){{put("a","A");}});}};... |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
1 |
private static Set<String> markerSet = new HashSet<String>(){{add("Hello");}};... |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
149 |
0 |
@Override... |
150 |
|
public UsedExtension getCacheResources(XWikiContext context) { |
151 |
0 |
Assert.assertNotNull(context); |
152 |
0 |
return new UsedExtension(markerSet,markerMap); |
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
155 |
0 |
@Override... |
156 |
|
public void restoreCacheResources(XWikiContext context, UsedExtension extension) { |
157 |
0 |
Assert.assertNotNull(extension); |
158 |
0 |
Assert.assertNotNull(context); |
159 |
0 |
Assert.assertEquals(markerMap, extension.parameters); |
160 |
0 |
Assert.assertEquals(markerSet, extension.resources); |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
|
} |