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 java.io.IOException; |
37 |
|
import java.lang.reflect.InvocationTargetException; |
38 |
|
import java.lang.reflect.Method; |
39 |
|
|
40 |
|
import javax.servlet.ServletException; |
41 |
|
import javax.servlet.http.HttpServletRequest; |
42 |
|
import javax.servlet.http.HttpServletResponse; |
43 |
|
|
44 |
|
import org.junit.Test; |
45 |
|
import org.springframework.util.ReflectionUtils; |
46 |
|
import org.springframework.web.servlet.HandlerExecutionChain; |
47 |
|
import org.springframework.web.servlet.ModelAndView; |
48 |
|
|
49 |
|
import static junit.framework.Assert.assertNull; |
50 |
|
import static org.junit.Assert.assertEquals; |
51 |
|
import static org.junit.Assert.assertFalse; |
52 |
|
import static org.junit.Assert.assertSame; |
53 |
|
import static org.junit.Assert.fail; |
54 |
|
|
55 |
|
import info.magnolia.module.blossom.annotation.Area; |
56 |
|
import info.magnolia.module.blossom.annotation.I18nBasename; |
57 |
|
import info.magnolia.module.blossom.annotation.Template; |
58 |
|
import info.magnolia.module.blossom.annotation.TemplateDescription; |
59 |
|
import info.magnolia.module.blossom.annotation.TernaryBoolean; |
60 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcher; |
61 |
|
|
62 |
|
|
63 |
|
@since |
64 |
|
|
|
|
| 84.3% |
Uncovered Elements: 11 (70) |
Complexity: 19 |
Complexity Density: 0.39 |
|
65 |
|
public class TemplateDefinitionBuilderTest { |
66 |
|
|
67 |
|
@I18nBasename("some-base-name") |
68 |
|
@Template(title = "Text", visible = false, id = "my-module:pages/folder/name") |
69 |
|
@TemplateDescription("Text template") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
70 |
|
public static class TestTemplate { |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void testTemplateDescription() throws Exception { |
75 |
|
|
76 |
1 |
TestTemplate template = new TestTemplate(); |
77 |
1 |
BlossomDispatcher dispatcher = new BlossomDispatcher() { |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
@Override... |
80 |
|
public ModelAndView executeChain(HandlerExecutionChain mappedHandler, HttpServletRequest request, HttpServletResponse response) throws Exception { |
81 |
0 |
return null; |
82 |
|
} |
83 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
84 |
0 |
@Override... |
85 |
|
public void forward(String path, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
86 |
|
} |
87 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
88 |
0 |
@Override... |
89 |
|
public void include(String path, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
90 |
|
} |
91 |
|
}; |
92 |
|
|
93 |
1 |
BlossomTemplateDefinition description = buildTemplateDefinition(dispatcher, template, "/test/test/"); |
94 |
|
|
95 |
1 |
assertEquals("Text", description.getTitle()); |
96 |
1 |
assertEquals("my-module:pages/folder/name", description.getId()); |
97 |
1 |
assertEquals("name", description.getName()); |
98 |
1 |
assertEquals("/test/test/", description.getHandlerPath()); |
99 |
1 |
assertFalse(description.getVisible()); |
100 |
1 |
assertEquals("Text template", description.getDescription()); |
101 |
1 |
assertSame(dispatcher, description.getDispatcher()); |
102 |
1 |
assertSame(template, description.getHandler()); |
103 |
1 |
assertEquals("some-base-name", description.getI18nBasename()); |
104 |
|
} |
105 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
106 |
|
public static class TemplateWithoutTemplateAnnotation { |
107 |
|
} |
108 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
109 |
1 |
@Test... |
110 |
|
public void testMissingTemplateAnnotation() { |
111 |
1 |
try { |
112 |
1 |
buildTemplateDefinition(new TemplateWithoutTemplateAnnotation()); |
113 |
0 |
fail(); |
114 |
|
} catch (IllegalArgumentException e) { |
115 |
1 |
assertEquals("Could not resolve template id, @Template is not present on class [info.magnolia.module.blossom.template.TemplateDefinitionBuilderTest$TemplateWithoutTemplateAnnotation]", e.getMessage()); |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
@Area(value = "Area", maxComponents = 3) |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
120 |
|
public static class AreaWithMaxComponentsSet { |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
123 |
1 |
@Test... |
124 |
|
public void testMaximumComponents() { |
125 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithMaxComponentsSet()); |
126 |
1 |
assertEquals(new Integer(3), definition.getMaxComponents()); |
127 |
|
} |
128 |
|
|
129 |
|
@Area(value = "Area") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
130 |
|
public static class AreaWithoutMaxComponentsSet { |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void testMaximumComponentsNullWhenNotSet() { |
135 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithoutMaxComponentsSet()); |
136 |
1 |
assertNull(definition.getMaxComponents()); |
137 |
|
} |
138 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
139 |
|
public static class AbstractTestTemplate { |
140 |
|
|
141 |
|
@Area("areaInSuperclass") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
142 |
|
public static class AreaInSuperclass { |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
@Template(id = "", title = "") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
147 |
|
public static class TestTemplateWithAreasFromSuperclass extends AbstractTestTemplate { |
148 |
|
|
149 |
|
@Area("areaInClass") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
150 |
|
public static class AreaInClass { |
151 |
|
} |
152 |
|
} |
153 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
154 |
1 |
@Test... |
155 |
|
public void testFindsAreasInSuperclass() { |
156 |
|
|
157 |
1 |
TestTemplateWithAreasFromSuperclass template = new TestTemplateWithAreasFromSuperclass(); |
158 |
1 |
AbstractTestTemplate.AreaInSuperclass areaInSuperclass = new AbstractTestTemplate.AreaInSuperclass(); |
159 |
1 |
TestTemplateWithAreasFromSuperclass.AreaInClass areaInClass = new TestTemplateWithAreasFromSuperclass.AreaInClass(); |
160 |
|
|
161 |
1 |
DetectedHandlersMetaData detectedHandlers = new DetectedHandlersMetaData(); |
162 |
1 |
detectedHandlers.addArea(new HandlerMetaData(areaInSuperclass, "")); |
163 |
1 |
detectedHandlers.addArea(new HandlerMetaData(areaInClass, "")); |
164 |
1 |
HandlerMetaData templateMetaData = new HandlerMetaData(template, ""); |
165 |
1 |
detectedHandlers.addTemplate(templateMetaData); |
166 |
|
|
167 |
1 |
BlossomTemplateDefinition templateDefinition = new TemplateDefinitionBuilder().buildTemplateDefinition( |
168 |
|
null, |
169 |
|
detectedHandlers, |
170 |
|
templateMetaData); |
171 |
|
|
172 |
1 |
assertEquals(2, templateDefinition.getAreas().size()); |
173 |
1 |
assertSame(areaInClass, ((BlossomAreaDefinition) templateDefinition.getAreas().get("areaInClass")).getHandler()); |
174 |
1 |
assertSame(areaInSuperclass, ((BlossomAreaDefinition) templateDefinition.getAreas().get("areaInSuperclass")).getHandler()); |
175 |
|
} |
176 |
|
|
177 |
|
@Area(value = "Area", createAreaNode = TernaryBoolean.TRUE) |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
178 |
|
public static class AreaWithoutCreateAreaNodeSetToTrue { |
179 |
|
} |
180 |
|
|
181 |
|
@Area(value = "Area", createAreaNode = TernaryBoolean.FALSE) |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
182 |
|
public static class AreaWithoutCreateAreaNodeSetToFalse { |
183 |
|
} |
184 |
|
|
185 |
|
@Area(value = "Area") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
186 |
|
public static class AreaWithoutCreateAreaNodeNotSet { |
187 |
|
} |
188 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
189 |
1 |
@Test... |
190 |
|
public void testCreateAreaNodeSetToTrue() throws InvocationTargetException, IllegalAccessException { |
191 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithoutCreateAreaNodeSetToTrue()); |
192 |
1 |
Method method = ReflectionUtils.findMethod(definition.getClass(), "setCreateAreaNode", Boolean.class); |
193 |
1 |
if (method != null) { |
194 |
0 |
assertEquals(Boolean.TRUE, ReflectionUtils.findMethod(definition.getClass(), "getCreateAreaNode").invoke(definition)); |
195 |
|
} |
196 |
|
} |
197 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
198 |
1 |
@Test... |
199 |
|
public void testCreateAreaNodeSetToFalse() throws InvocationTargetException, IllegalAccessException { |
200 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithoutCreateAreaNodeSetToFalse()); |
201 |
1 |
Method method = ReflectionUtils.findMethod(definition.getClass(), "setCreateAreaNode", Boolean.class); |
202 |
1 |
if (method != null) { |
203 |
0 |
assertEquals(Boolean.FALSE, ReflectionUtils.findMethod(definition.getClass(), "getCreateAreaNode").invoke(definition)); |
204 |
|
} |
205 |
|
} |
206 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
207 |
1 |
@Test... |
208 |
|
public void testCreateAreaNodeNotSet() throws InvocationTargetException, IllegalAccessException { |
209 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithoutCreateAreaNodeNotSet()); |
210 |
1 |
Method method = ReflectionUtils.findMethod(definition.getClass(), "setCreateAreaNode", Boolean.class); |
211 |
1 |
if (method != null) { |
212 |
0 |
assertNull(ReflectionUtils.findMethod(definition.getClass(), "getCreateAreaNode").invoke(definition)); |
213 |
|
} |
214 |
|
} |
215 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
7 |
public static BlossomTemplateDefinition buildTemplateDefinition(Object template) {... |
217 |
7 |
return buildTemplateDefinition(null, template, "/foobar"); |
218 |
|
} |
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
220 |
8 |
public static BlossomTemplateDefinition buildTemplateDefinition(BlossomDispatcher dispatcher, Object template, String handlerPath) {... |
221 |
8 |
return new TemplateDefinitionBuilder().buildTemplateDefinition( |
222 |
|
dispatcher, |
223 |
|
new DetectedHandlersMetaData(), |
224 |
|
new HandlerMetaData(template, handlerPath, template.getClass())); |
225 |
|
} |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
5 |
public static BlossomAreaDefinition buildAreaDefinition(Object template) {... |
228 |
5 |
return buildAreaDefinition(null, template, "/foobar"); |
229 |
|
} |
230 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
231 |
5 |
public static BlossomAreaDefinition buildAreaDefinition(BlossomDispatcher dispatcher, Object template, String handlerPath) {... |
232 |
5 |
return new TemplateDefinitionBuilder().buildAreaDefinition( |
233 |
|
dispatcher, |
234 |
|
new DetectedHandlersMetaData(), |
235 |
|
new HandlerMetaData(template, handlerPath, template.getClass())); |
236 |
|
} |
237 |
|
} |