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.1% |
Uncovered Elements: 11 (69) |
Complexity: 19 |
Complexity Density: 0.4 |
|
65 |
|
public class TemplateDefinitionBuilderTest { |
66 |
|
|
67 |
|
@I18nBasename("some-base-name") |
68 |
|
@Template(title = "Text", visible = false, id = "base") |
69 |
|
@TemplateDescription("Text template") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
70 |
|
public static class TestTemplate { |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
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("base", description.getId()); |
97 |
1 |
assertEquals("/test/test/", description.getHandlerPath()); |
98 |
1 |
assertFalse(description.getVisible()); |
99 |
1 |
assertEquals("Text template", description.getDescription()); |
100 |
1 |
assertSame(dispatcher, description.getDispatcher()); |
101 |
1 |
assertSame(template, description.getHandler()); |
102 |
1 |
assertEquals("some-base-name", description.getI18nBasename()); |
103 |
|
} |
104 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
105 |
|
public static class TemplateWithoutTemplateAnnotation { |
106 |
|
} |
107 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
108 |
1 |
@Test... |
109 |
|
public void testMissingTemplateAnnotation() { |
110 |
1 |
try { |
111 |
1 |
buildTemplateDefinition(new TemplateWithoutTemplateAnnotation()); |
112 |
0 |
fail(); |
113 |
|
} catch (IllegalArgumentException e) { |
114 |
1 |
assertEquals("Could not resolve template id, @Template is not present on class [info.magnolia.module.blossom.template.TemplateDefinitionBuilderTest$TemplateWithoutTemplateAnnotation]", e.getMessage()); |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
@Area(value = "Area", maxComponents = 3) |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
119 |
|
public static class AreaWithMaxComponentsSet { |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
122 |
1 |
@Test... |
123 |
|
public void testMaximumComponents() { |
124 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithMaxComponentsSet()); |
125 |
1 |
assertEquals(new Integer(3), definition.getMaxComponents()); |
126 |
|
} |
127 |
|
|
128 |
|
@Area(value = "Area") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
129 |
|
public static class AreaWithoutMaxComponentsSet { |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
132 |
1 |
@Test... |
133 |
|
public void testMaximumComponentsNullWhenNotSet() { |
134 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithoutMaxComponentsSet()); |
135 |
1 |
assertNull(definition.getMaxComponents()); |
136 |
|
} |
137 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
138 |
|
public static class AbstractTestTemplate { |
139 |
|
|
140 |
|
@Area("areaInSuperclass") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
141 |
|
public static class AreaInSuperclass { |
142 |
|
} |
143 |
|
} |
144 |
|
|
145 |
|
@Template(id = "", title = "") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
146 |
|
public static class TestTemplateWithAreasFromSuperclass extends AbstractTestTemplate { |
147 |
|
|
148 |
|
@Area("areaInClass") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
149 |
|
public static class AreaInClass { |
150 |
|
} |
151 |
|
} |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
153 |
1 |
@Test... |
154 |
|
public void testFindsAreasInSuperclass() { |
155 |
|
|
156 |
1 |
TestTemplateWithAreasFromSuperclass template = new TestTemplateWithAreasFromSuperclass(); |
157 |
1 |
AbstractTestTemplate.AreaInSuperclass areaInSuperclass = new AbstractTestTemplate.AreaInSuperclass(); |
158 |
1 |
TestTemplateWithAreasFromSuperclass.AreaInClass areaInClass = new TestTemplateWithAreasFromSuperclass.AreaInClass(); |
159 |
|
|
160 |
1 |
DetectedHandlersMetaData detectedHandlers = new DetectedHandlersMetaData(); |
161 |
1 |
detectedHandlers.addArea(new HandlerMetaData(areaInSuperclass, "")); |
162 |
1 |
detectedHandlers.addArea(new HandlerMetaData(areaInClass, "")); |
163 |
1 |
HandlerMetaData templateMetaData = new HandlerMetaData(template, ""); |
164 |
1 |
detectedHandlers.addTemplate(templateMetaData); |
165 |
|
|
166 |
1 |
BlossomTemplateDefinition templateDefinition = new TemplateDefinitionBuilder().buildTemplateDefinition( |
167 |
|
null, |
168 |
|
detectedHandlers, |
169 |
|
templateMetaData); |
170 |
|
|
171 |
1 |
assertEquals(2, templateDefinition.getAreas().size()); |
172 |
1 |
assertSame(areaInClass, ((BlossomAreaDefinition) templateDefinition.getAreas().get("areaInClass")).getHandler()); |
173 |
1 |
assertSame(areaInSuperclass, ((BlossomAreaDefinition) templateDefinition.getAreas().get("areaInSuperclass")).getHandler()); |
174 |
|
} |
175 |
|
|
176 |
|
@Area(value = "Area", createAreaNode = TernaryBoolean.TRUE) |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
177 |
|
public static class AreaWithoutCreateAreaNodeSetToTrue { |
178 |
|
} |
179 |
|
|
180 |
|
@Area(value = "Area", createAreaNode = TernaryBoolean.FALSE) |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
181 |
|
public static class AreaWithoutCreateAreaNodeSetToFalse { |
182 |
|
} |
183 |
|
|
184 |
|
@Area(value = "Area") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
185 |
|
public static class AreaWithoutCreateAreaNodeNotSet { |
186 |
|
} |
187 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
188 |
1 |
@Test... |
189 |
|
public void testCreateAreaNodeSetToTrue() throws InvocationTargetException, IllegalAccessException { |
190 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithoutCreateAreaNodeSetToTrue()); |
191 |
1 |
Method method = ReflectionUtils.findMethod(definition.getClass(), "setCreateAreaNode", Boolean.class); |
192 |
1 |
if (method != null) { |
193 |
0 |
assertEquals(Boolean.TRUE, ReflectionUtils.findMethod(definition.getClass(), "getCreateAreaNode").invoke(definition)); |
194 |
|
} |
195 |
|
} |
196 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
197 |
1 |
@Test... |
198 |
|
public void testCreateAreaNodeSetToFalse() throws InvocationTargetException, IllegalAccessException { |
199 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithoutCreateAreaNodeSetToFalse()); |
200 |
1 |
Method method = ReflectionUtils.findMethod(definition.getClass(), "setCreateAreaNode", Boolean.class); |
201 |
1 |
if (method != null) { |
202 |
0 |
assertEquals(Boolean.FALSE, ReflectionUtils.findMethod(definition.getClass(), "getCreateAreaNode").invoke(definition)); |
203 |
|
} |
204 |
|
} |
205 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
206 |
1 |
@Test... |
207 |
|
public void testCreateAreaNodeNotSet() throws InvocationTargetException, IllegalAccessException { |
208 |
1 |
BlossomAreaDefinition definition = buildAreaDefinition(new AreaWithoutCreateAreaNodeNotSet()); |
209 |
1 |
Method method = ReflectionUtils.findMethod(definition.getClass(), "setCreateAreaNode", Boolean.class); |
210 |
1 |
if (method != null) { |
211 |
0 |
assertNull(ReflectionUtils.findMethod(definition.getClass(), "getCreateAreaNode").invoke(definition)); |
212 |
|
} |
213 |
|
} |
214 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
215 |
7 |
public static BlossomTemplateDefinition buildTemplateDefinition(Object template) {... |
216 |
7 |
return buildTemplateDefinition(null, template, "/foobar"); |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
8 |
public static BlossomTemplateDefinition buildTemplateDefinition(BlossomDispatcher dispatcher, Object template, String handlerPath) {... |
220 |
8 |
return new TemplateDefinitionBuilder().buildTemplateDefinition( |
221 |
|
dispatcher, |
222 |
|
new DetectedHandlersMetaData(), |
223 |
|
new HandlerMetaData(template, handlerPath, template.getClass())); |
224 |
|
} |
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
5 |
public static BlossomAreaDefinition buildAreaDefinition(Object template) {... |
227 |
5 |
return buildAreaDefinition(null, template, "/foobar"); |
228 |
|
} |
229 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
230 |
5 |
public static BlossomAreaDefinition buildAreaDefinition(BlossomDispatcher dispatcher, Object template, String handlerPath) {... |
231 |
5 |
return new TemplateDefinitionBuilder().buildAreaDefinition( |
232 |
|
dispatcher, |
233 |
|
new DetectedHandlersMetaData(), |
234 |
|
new HandlerMetaData(template, handlerPath, template.getClass())); |
235 |
|
} |
236 |
|
} |