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