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.blossom.template; |
35 |
|
|
36 |
|
import static org.junit.Assert.assertEquals; |
37 |
|
import static org.junit.Assert.assertTrue; |
38 |
|
import static org.mockito.Mockito.mock; |
39 |
|
|
40 |
|
import info.magnolia.module.blossom.annotation.Area; |
41 |
|
import info.magnolia.module.blossom.annotation.PreRegister; |
42 |
|
import info.magnolia.module.blossom.annotation.TabFactory; |
43 |
|
import info.magnolia.module.blossom.annotation.Template; |
44 |
|
import info.magnolia.module.blossom.dialog.BlossomDialogDescription; |
45 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcher; |
46 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherInitializedEvent; |
47 |
|
import info.magnolia.objectfactory.Components; |
48 |
|
import info.magnolia.registry.RegistrationException; |
49 |
|
import info.magnolia.rendering.template.AreaDefinition; |
50 |
|
import info.magnolia.rendering.template.TemplateAvailability; |
51 |
|
import info.magnolia.rendering.template.TemplateDefinition; |
52 |
|
import info.magnolia.rendering.template.configured.DefaultTemplateAvailability; |
53 |
|
import info.magnolia.rendering.template.registry.TemplateDefinitionRegistry; |
54 |
|
import info.magnolia.test.ComponentsTestUtil; |
55 |
|
import info.magnolia.test.MgnlTestCase; |
56 |
|
|
57 |
|
import java.util.ArrayList; |
58 |
|
import java.util.HashMap; |
59 |
|
import java.util.List; |
60 |
|
|
61 |
|
import org.junit.Before; |
62 |
|
import org.junit.Test; |
63 |
|
import org.springframework.context.ApplicationContext; |
64 |
|
import org.springframework.context.support.StaticApplicationContext; |
65 |
|
import org.springframework.web.bind.annotation.RequestMapping; |
66 |
|
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; |
67 |
|
|
68 |
|
|
69 |
|
@link |
70 |
|
|
71 |
|
@since |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (66) |
Complexity: 6 |
Complexity Density: 0.1 |
|
73 |
|
public class TemplateExporterTest extends MgnlTestCase { |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
75 |
4 |
@Before... |
76 |
|
public void setUp() throws Exception { |
77 |
4 |
super.setUp(); |
78 |
4 |
ComponentsTestUtil.setImplementation(TemplateAvailability.class, DefaultTemplateAvailability.class); |
79 |
|
} |
80 |
|
|
81 |
|
@Template(id = "module:TestTemplate", title = "") |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
82 |
|
public static class TestTemplate { |
83 |
|
|
84 |
|
@Area("testArea") |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
85 |
|
public static class TestArea { |
86 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
87 |
0 |
@RequestMapping("/testTemplate/testArea")... |
88 |
|
public void render() { |
89 |
|
|
90 |
|
} |
91 |
|
} |
92 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
93 |
0 |
@RequestMapping("/testTemplate")... |
94 |
|
public void render() { |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void testExportTemplate() throws Exception { |
100 |
|
|
101 |
1 |
String templateId = "module:TestTemplate"; |
102 |
|
|
103 |
1 |
StaticApplicationContext ctx = new StaticApplicationContext(); |
104 |
1 |
ctx.registerSingleton(TestTemplate.class.getSimpleName(), TestTemplate.class); |
105 |
1 |
ctx.registerSingleton(TestTemplate.TestArea.class.getSimpleName(), TestTemplate.TestArea.class); |
106 |
1 |
ctx.refresh(); |
107 |
|
|
108 |
1 |
HashMap<String, Object> handlerMap = new HashMap<String, Object>(); |
109 |
1 |
handlerMap.put("/testTemplate", ctx.getBean(TestTemplate.class)); |
110 |
1 |
handlerMap.put("/testTemplate/testArea", ctx.getBean(TestTemplate.TestArea.class)); |
111 |
|
|
112 |
1 |
exportTemplate(ctx, handlerMap); |
113 |
|
|
114 |
1 |
TemplateDefinition templateDefinition = Components.getComponent(TemplateDefinitionRegistry.class).getTemplateDefinition(templateId); |
115 |
1 |
assertEquals(templateId, templateDefinition.getId()); |
116 |
1 |
assertEquals(1, templateDefinition.getAreas().size()); |
117 |
1 |
assertEquals("testArea", templateDefinition.getAreas().values().iterator().next().getName()); |
118 |
|
} |
119 |
|
|
120 |
|
@Template(id = "module:TemplateWithPreRegisterCallbackThatReturnsNull", title = "") |
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
121 |
|
public static class TemplateWithPreRegisterCallbackThatReturnsNull { |
122 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
123 |
0 |
@RequestMapping("/testTemplate")... |
124 |
|
public void render() { |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
1 |
@PreRegister... |
128 |
|
public BlossomTemplateDefinition register(BlossomTemplateDefinition templateDefinition) { |
129 |
1 |
return null; |
130 |
|
} |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
133 |
1 |
@Test(expected = RegistrationException.class)... |
134 |
|
public void testExportTemplateWithPreRegisterCallbackThatReturnsNull() throws Exception { |
135 |
|
|
136 |
1 |
String templateId = "module:TemplateWithPreRegisterCallbackThatReturnsNull"; |
137 |
|
|
138 |
1 |
StaticApplicationContext ctx = new StaticApplicationContext(); |
139 |
1 |
ctx.registerSingleton(TemplateWithPreRegisterCallbackThatReturnsNull.class.getSimpleName(), TemplateWithPreRegisterCallbackThatReturnsNull.class); |
140 |
1 |
ctx.refresh(); |
141 |
|
|
142 |
1 |
HashMap<String, Object> handlerMap = new HashMap<String, Object>(); |
143 |
1 |
handlerMap.put("/testTemplate", ctx.getBean(TemplateWithPreRegisterCallbackThatReturnsNull.class)); |
144 |
|
|
145 |
1 |
exportTemplate(ctx, handlerMap); |
146 |
|
|
147 |
1 |
Components.getComponent(TemplateDefinitionRegistry.class).getTemplateDefinition(templateId); |
148 |
|
} |
149 |
|
|
150 |
|
@Template(id = "module:TemplateWithAreaWithPreRegisterCallbackThatReturnsNull", title = "") |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
151 |
|
public static class TemplateWithAreaWithPreRegisterCallbackThatReturnsNull { |
152 |
|
|
153 |
|
@Area("testArea") |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
154 |
|
public static class TestArea { |
155 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
156 |
0 |
@RequestMapping("/testTemplate/testArea")... |
157 |
|
public void render() { |
158 |
|
|
159 |
|
} |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
0 |
@PreRegister... |
162 |
|
public BlossomAreaDefinition register(BlossomAreaDefinition areaDefinition) { |
163 |
0 |
return null; |
164 |
|
} |
165 |
|
} |
166 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
167 |
0 |
@RequestMapping("/testTemplate")... |
168 |
|
public void render() { |
169 |
|
} |
170 |
|
} |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
172 |
1 |
@Test... |
173 |
|
public void testExportTemplateWithAreaWithPreRegisterCallbackThatReturnsNull() throws Exception { |
174 |
|
|
175 |
1 |
String templateId = "module:TemplateWithAreaWithPreRegisterCallbackThatReturnsNull"; |
176 |
|
|
177 |
1 |
StaticApplicationContext ctx = new StaticApplicationContext(); |
178 |
1 |
ctx.registerSingleton(TemplateWithAreaWithPreRegisterCallbackThatReturnsNull.class.getSimpleName(), TemplateWithAreaWithPreRegisterCallbackThatReturnsNull.class); |
179 |
1 |
ctx.refresh(); |
180 |
|
|
181 |
1 |
HashMap<String, Object> handlerMap = new HashMap<String, Object>(); |
182 |
1 |
handlerMap.put("/testTemplate", ctx.getBean(TemplateWithAreaWithPreRegisterCallbackThatReturnsNull.class)); |
183 |
|
|
184 |
1 |
exportTemplate(ctx, handlerMap); |
185 |
|
|
186 |
1 |
TemplateDefinition templateDefinition = Components.getComponent(TemplateDefinitionRegistry.class).getTemplateDefinition(templateId); |
187 |
1 |
assertEquals(0, templateDefinition.getAreas().size()); |
188 |
|
} |
189 |
|
|
190 |
|
private static List<String> events = new ArrayList<String>(); |
191 |
|
|
192 |
|
@Template(id = "module:TemplateWithPreRegisterCallbacks", title = "") |
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 4 |
Complexity Density: 2 |
|
193 |
|
public static class TemplateWithPreRegisterCallbacks { |
194 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
195 |
|
public static class AbstractArea { |
196 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
197 |
1 |
@PreRegister... |
198 |
|
public void registerInAbstract(AreaDefinition areaDefinition) { |
199 |
1 |
events.add("AbstractArea.register-area"); |
200 |
|
} |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
202 |
1 |
@PreRegister... |
203 |
|
public void registerInAbstract(BlossomDialogDescription dialogDescription) { |
204 |
1 |
events.add("AbstractArea.register-dialog"); |
205 |
|
} |
206 |
|
} |
207 |
|
|
208 |
|
@Area("testArea") |
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 4 |
Complexity Density: 2 |
|
209 |
|
public static class TestArea extends AbstractArea { |
210 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
211 |
0 |
@RequestMapping("/testTemplate/testArea")... |
212 |
|
public void render() { |
213 |
|
} |
214 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
215 |
0 |
@TabFactory("")... |
216 |
|
public void tab() { |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
1 |
@PreRegister... |
220 |
|
public void register(AreaDefinition areaDefinition) { |
221 |
1 |
events.add("TestArea.register-area"); |
222 |
|
} |
223 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
224 |
1 |
@PreRegister... |
225 |
|
public void register(BlossomDialogDescription dialogDescription) { |
226 |
1 |
events.add("TestArea.register-dialog"); |
227 |
|
} |
228 |
|
} |
229 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
230 |
0 |
@RequestMapping("/testTemplate")... |
231 |
|
public void render() { |
232 |
|
} |
233 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
234 |
0 |
@TabFactory("")... |
235 |
|
public void tab() { |
236 |
|
} |
237 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
238 |
1 |
@PreRegister... |
239 |
|
public void register(TemplateDefinition templateDefinition) { |
240 |
1 |
events.add("TemplateWithPreRegisterCallbacks.register-template"); |
241 |
|
} |
242 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
243 |
1 |
@PreRegister... |
244 |
|
public void register(BlossomDialogDescription dialogDescription) { |
245 |
1 |
events.add("TemplateWithPreRegisterCallbacks.register-dialog"); |
246 |
|
} |
247 |
|
} |
248 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
249 |
1 |
@Test... |
250 |
|
public void testTemplateAreaAndDialogRegistrationCallbacks() throws Exception { |
251 |
1 |
String templateId = "module:TemplateWithPreRegisterCallbacks"; |
252 |
|
|
253 |
1 |
StaticApplicationContext ctx = new StaticApplicationContext(); |
254 |
1 |
ctx.registerSingleton(TemplateWithPreRegisterCallbacks.class.getSimpleName(), TemplateWithPreRegisterCallbacks.class); |
255 |
1 |
ctx.registerSingleton(TemplateWithPreRegisterCallbacks.TestArea.class.getSimpleName(), TemplateWithPreRegisterCallbacks.TestArea.class); |
256 |
1 |
ctx.refresh(); |
257 |
|
|
258 |
1 |
HashMap<String, Object> handlerMap = new HashMap<String, Object>(); |
259 |
1 |
handlerMap.put("/testTemplate", ctx.getBean(TemplateWithPreRegisterCallbacks.class)); |
260 |
1 |
handlerMap.put("/testTemplate/testArea", ctx.getBean(TemplateWithPreRegisterCallbacks.TestArea.class)); |
261 |
|
|
262 |
1 |
exportTemplate(ctx, handlerMap); |
263 |
|
|
264 |
1 |
TemplateDefinition templateDefinition = Components.getComponent(TemplateDefinitionRegistry.class).getTemplateDefinition(templateId); |
265 |
1 |
assertEquals(templateId, templateDefinition.getId()); |
266 |
1 |
assertEquals(1, templateDefinition.getAreas().size()); |
267 |
1 |
assertEquals("testArea", templateDefinition.getAreas().values().iterator().next().getName()); |
268 |
|
|
269 |
1 |
assertTrue(events.contains("AbstractArea.register-area")); |
270 |
1 |
assertTrue(events.contains("AbstractArea.register-dialog")); |
271 |
1 |
assertTrue(events.contains("TestArea.register-area")); |
272 |
1 |
assertTrue(events.contains("TestArea.register-dialog")); |
273 |
1 |
assertTrue(events.contains("TemplateWithPreRegisterCallbacks.register-template")); |
274 |
1 |
assertTrue(events.contains("TemplateWithPreRegisterCallbacks.register-dialog")); |
275 |
|
} |
276 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
277 |
4 |
private void exportTemplate(ApplicationContext ctx, HashMap<String, Object> handlerMap) throws Exception {... |
278 |
|
|
279 |
4 |
SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); |
280 |
4 |
handlerMapping.setUrlMap(handlerMap); |
281 |
4 |
handlerMapping.setApplicationContext(ctx); |
282 |
|
|
283 |
4 |
BlossomDispatcher dispatcher = mock(BlossomDispatcher.class); |
284 |
|
|
285 |
4 |
TemplateExporter templateExporter = new TemplateExporter(); |
286 |
4 |
templateExporter.setBlossomDispatcher(dispatcher); |
287 |
4 |
templateExporter.afterPropertiesSet(); |
288 |
|
|
289 |
4 |
templateExporter.postProcessAfterInitialization(handlerMapping, "handlerMapping"); |
290 |
4 |
templateExporter.onApplicationEvent(new BlossomDispatcherInitializedEvent(dispatcher)); |
291 |
|
} |
292 |
|
} |