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.dialog; |
35 |
|
|
36 |
|
import static org.junit.Assert.assertEquals; |
37 |
|
import static org.junit.Assert.assertFalse; |
38 |
|
import static org.junit.Assert.assertNotNull; |
39 |
|
import static org.junit.Assert.assertNull; |
40 |
|
import static org.junit.Assert.assertTrue; |
41 |
|
import static org.junit.Assert.fail; |
42 |
|
import static org.mockito.Mockito.mock; |
43 |
|
import static org.mockito.Mockito.when; |
44 |
|
|
45 |
|
import info.magnolia.init.MagnoliaConfigurationProperties; |
46 |
|
import info.magnolia.module.blossom.annotation.DialogFactory; |
47 |
|
import info.magnolia.module.blossom.annotation.PostCreate; |
48 |
|
import info.magnolia.module.blossom.annotation.TabFactory; |
49 |
|
import info.magnolia.module.blossom.annotation.TabOrder; |
50 |
|
import info.magnolia.test.ComponentsTestUtil; |
51 |
|
import info.magnolia.ui.dialog.config.DialogBuilder; |
52 |
|
import info.magnolia.ui.dialog.definition.ConfiguredFormDialogDefinition; |
53 |
|
import info.magnolia.ui.dialog.definition.DialogDefinition; |
54 |
|
import info.magnolia.ui.form.config.TabBuilder; |
55 |
|
import info.magnolia.ui.form.config.TextFieldBuilder; |
56 |
|
import info.magnolia.ui.form.definition.TabDefinition; |
57 |
|
import info.magnolia.ui.framework.config.UiConfig; |
58 |
|
|
59 |
|
import java.util.ArrayList; |
60 |
|
import java.util.List; |
61 |
|
|
62 |
|
import javax.jcr.Node; |
63 |
|
|
64 |
|
import org.junit.Test; |
65 |
|
|
66 |
|
import com.vaadin.data.Item; |
67 |
|
|
68 |
|
|
69 |
|
@link |
70 |
|
|
71 |
|
@since |
72 |
|
|
|
|
| 97% |
Uncovered Elements: 4 (134) |
Complexity: 19 |
Complexity Density: 0.17 |
|
73 |
|
public class DefaultDialogCreatorTest extends DialogTestSupport { |
74 |
|
|
75 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
76 |
|
public interface AnnotatedInterface { |
77 |
|
|
78 |
|
@TabFactory("FromInterface") |
79 |
|
void foo(); |
80 |
|
} |
81 |
|
|
82 |
|
@DialogFactory(value = "some-dialog", label = "TestDialog") |
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 3 |
Complexity Density: - |
|
83 |
|
public static class SimpleFactory implements AnnotatedInterface { |
84 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
85 |
4 |
@TabFactory("Properties")... |
86 |
|
public void properties() { |
87 |
|
} |
88 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
89 |
3 |
@TabFactory("Settings")... |
90 |
|
public void settings() { |
91 |
|
} |
92 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
93 |
0 |
@Override... |
94 |
|
public void foo() { |
95 |
|
} |
96 |
|
} |
97 |
|
|
98 |
|
@DialogFactory("some-dialog") |
99 |
|
@TabOrder({"Margins", "Sizes", "Properties"}) |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 2 |
Complexity Density: - |
|
100 |
|
public static class InheritingFactory extends SimpleFactory { |
101 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
102 |
1 |
@TabFactory("Margins")... |
103 |
|
public void margins(TabBuilder builder, DialogCreationContext context, DialogDefinition dialog, UiConfig cfg) { |
104 |
|
} |
105 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
106 |
1 |
@TabFactory("Sizes")... |
107 |
|
@Override |
108 |
|
public void settings() { |
109 |
|
} |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void testSimpleFactory() throws Exception { |
114 |
|
|
115 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription(new SimpleFactory(), null); |
116 |
|
|
117 |
1 |
assertEquals("some-dialog", description.getId()); |
118 |
1 |
assertEquals("TestDialog", description.getFactoryMetaData().getLabel()); |
119 |
|
|
120 |
1 |
final DialogCreationContext context = new DialogCreationContext(); |
121 |
1 |
DefaultDialogCreator creator = creator(); |
122 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
123 |
|
|
124 |
1 |
assertHasTabsWithLabels(context.getDialog(), new String[]{"Settings", "Properties"}); |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
127 |
1 |
@Test... |
128 |
|
public void testInheritingFactory() throws Exception { |
129 |
|
|
130 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription(new InheritingFactory(), null); |
131 |
|
|
132 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
133 |
1 |
DefaultDialogCreator creator = creator(); |
134 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
135 |
|
|
136 |
1 |
assertHasTabsInLabelOrder(context.getDialog(), new String[]{"Margins", "Sizes", "Properties"}); |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
|
public static class BogusTemplate { |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
1 |
@DialogFactory("some-dialog")... |
142 |
|
public void someDialog(DialogBuilder builder, DialogDefinition dialog, DialogCreationContext context) { |
143 |
1 |
builder.form().tab("settings").label("Settings"); |
144 |
|
} |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
147 |
1 |
@Test... |
148 |
|
public void testDialogFactoryOnMethod() throws Exception { |
149 |
|
|
150 |
1 |
List<BlossomDialogDescription> descriptions = new DialogDescriptionBuilder().buildDescriptions(new BogusTemplate()); |
151 |
|
|
152 |
1 |
assertEquals(1, descriptions.size()); |
153 |
|
|
154 |
1 |
BlossomDialogDescription description = descriptions.get(0); |
155 |
|
|
156 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
157 |
1 |
DefaultDialogCreator creator = creator(); |
158 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
159 |
|
|
160 |
1 |
assertHasTabsWithLabels(context.getDialog(), new String[]{"Settings"}); |
161 |
|
} |
162 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 1 |
|
163 |
|
public static class TemplateWithDialogFactoryThatNeedsItem { |
164 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
165 |
1 |
@DialogFactory("some-dialog")... |
166 |
|
public void someDialog(DialogBuilder builder, Item item) { |
167 |
1 |
if (item != null) { |
168 |
1 |
builder.form().tab("gotItem").label("gotItem"); |
169 |
|
} |
170 |
|
} |
171 |
|
} |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
173 |
1 |
@Test... |
174 |
|
public void testDialogFactoryThatNeedsItem() throws Exception { |
175 |
|
|
176 |
1 |
List<BlossomDialogDescription> descriptions = new DialogDescriptionBuilder().buildDescriptions(new TemplateWithDialogFactoryThatNeedsItem()); |
177 |
|
|
178 |
1 |
assertEquals(1, descriptions.size()); |
179 |
|
|
180 |
1 |
BlossomDialogDescription description = descriptions.get(0); |
181 |
|
|
182 |
1 |
Item mockItem = mock(Item.class); |
183 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
184 |
1 |
context.setItem(mockItem); |
185 |
1 |
DefaultDialogCreator creator = creator(); |
186 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
187 |
|
|
188 |
1 |
assertHasTabsWithLabels(context.getDialog(), new String[]{"gotItem"}); |
189 |
|
} |
190 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 1 |
|
191 |
|
public static class DialogFactoryWithTabFactoryThatNeedsItem { |
192 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
193 |
1 |
@TabFactory("Content")... |
194 |
|
public void someDialog(TabBuilder builder, Item item) { |
195 |
1 |
if (item != null) { |
196 |
1 |
builder.fields(new TextFieldBuilder("gotItem")); |
197 |
|
} |
198 |
|
} |
199 |
|
} |
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
201 |
1 |
@Test... |
202 |
|
public void testDialogFactoryWithTabFactoryThatNeedsItem() throws Exception { |
203 |
|
|
204 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription("id", "label", new DialogFactoryWithTabFactoryThatNeedsItem()); |
205 |
|
|
206 |
1 |
Item mockItem = mock(Item.class); |
207 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
208 |
1 |
context.setItem(mockItem); |
209 |
1 |
DefaultDialogCreator creator = creator(); |
210 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
211 |
|
|
212 |
1 |
assertEquals("gotItem", context.getDialog().getForm().getTabs().get(0).getFields().get(0).getName()); |
213 |
|
} |
214 |
|
|
215 |
|
private static List<String> events = new ArrayList<String>(); |
216 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
217 |
|
public static class DialogFactoryWithPostCreateMethod { |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
1 |
@PostCreate... |
220 |
|
public void postCreate() { |
221 |
1 |
events.add("DialogFactoryWithPostCreateMethod"); |
222 |
|
} |
223 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
224 |
3 |
@TabFactory("a")... |
225 |
|
public void a() { |
226 |
|
} |
227 |
|
} |
228 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
229 |
|
public static class DialogFactoryWithPostCreateMethodExtendingSuperclass extends DialogFactoryWithPostCreateMethod { |
230 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
231 |
1 |
@PostCreate... |
232 |
|
public void postCreate2() { |
233 |
1 |
events.add("DialogFactoryWithPostCreateMethodExtendingSuperclass"); |
234 |
|
} |
235 |
|
} |
236 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
237 |
1 |
@Test... |
238 |
|
public void testPostCreateIsInvokedOnSuperclassesFirst() throws Exception { |
239 |
|
|
240 |
|
|
241 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription("id", "label", new DialogFactoryWithPostCreateMethodExtendingSuperclass()); |
242 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
243 |
1 |
DefaultDialogCreator creator = creator(); |
244 |
|
|
245 |
|
|
246 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
247 |
|
|
248 |
|
|
249 |
1 |
assertEquals("DialogFactoryWithPostCreateMethod", events.remove(0)); |
250 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodExtendingSuperclass", events.remove(0)); |
251 |
1 |
assertTrue(events.isEmpty()); |
252 |
|
} |
253 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1.5 |
|
254 |
|
public static class DialogFactoryWithPostCreateMethodOverridingMethodInSuperclass extends DialogFactoryWithPostCreateMethod { |
255 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
256 |
1 |
@PostCreate... |
257 |
|
public void postCreate2() { |
258 |
1 |
events.add("DialogFactoryWithPostCreateMethodOverridingMethodInSuperclass#postCreate2"); |
259 |
|
} |
260 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
261 |
1 |
@Override... |
262 |
|
@PostCreate |
263 |
|
public void postCreate() { |
264 |
1 |
events.add("DialogFactoryWithPostCreateMethodOverridingMethodInSuperclass#postCreate"); |
265 |
|
} |
266 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
267 |
1 |
@TabFactory("b")... |
268 |
|
public void b() { |
269 |
|
} |
270 |
|
} |
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
272 |
1 |
@Test... |
273 |
|
public void testPostCreateOnMethodInSuperclassThatIsOverriddenIsInvokedFirst() throws Exception { |
274 |
|
|
275 |
|
|
276 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription("id", "label", new DialogFactoryWithPostCreateMethodOverridingMethodInSuperclass()); |
277 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
278 |
1 |
DefaultDialogCreator creator = creator(); |
279 |
|
|
280 |
|
|
281 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
282 |
|
|
283 |
|
|
284 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodOverridingMethodInSuperclass#postCreate", events.remove(0)); |
285 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodOverridingMethodInSuperclass#postCreate2", events.remove(0)); |
286 |
1 |
assertTrue(events.isEmpty()); |
287 |
|
} |
288 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
289 |
|
public static class DialogFactoryWithPostCreateMethodOverridingMethodInSuperclassWithoutRepeatingAnnotation extends DialogFactoryWithPostCreateMethod { |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
291 |
0 |
@Override... |
292 |
|
public void postCreate() { |
293 |
0 |
events.add("DialogFactoryWithPostCreateMethodOverridingMethodInSuperclassWithoutRepeatingAnnotation#postCreate"); |
294 |
|
} |
295 |
|
} |
296 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
297 |
1 |
@Test... |
298 |
|
public void testPostCreateIsNotInvokedIfMethodIsOverriddenWithoutRepeatingAnnotation() throws Exception { |
299 |
|
|
300 |
|
|
301 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription("id", "label", new DialogFactoryWithPostCreateMethodOverridingMethodInSuperclassWithoutRepeatingAnnotation()); |
302 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
303 |
1 |
DefaultDialogCreator creator = creator(); |
304 |
|
|
305 |
|
|
306 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
307 |
|
|
308 |
|
|
309 |
1 |
assertFalse(events.contains("DialogFactoryWithPostCreateMethodOverridingMethodInSuperclassWithoutRepeatingAnnotation#postCreate")); |
310 |
1 |
assertTrue(events.isEmpty()); |
311 |
|
} |
312 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.17 |
|
313 |
|
public static class DialogFactoryWithPostCreateMethodTakingArguments { |
314 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
315 |
1 |
@PostCreate... |
316 |
|
public void postCreate(DialogBuilder dialogBuilder, DialogCreationContext context, ConfiguredFormDialogDefinition definition, Node node, Item item, UiConfig cfg) { |
317 |
1 |
assertNotNull(dialogBuilder); |
318 |
1 |
assertNotNull(context); |
319 |
1 |
assertNotNull(definition); |
320 |
1 |
assertNotNull(node); |
321 |
1 |
assertNotNull(item); |
322 |
1 |
assertNotNull(cfg); |
323 |
|
} |
324 |
|
} |
325 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
326 |
1 |
@Test... |
327 |
|
public void testPostCreateIsInvokedWithArguments() throws Exception { |
328 |
|
|
329 |
|
|
330 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription("id", "label", new DialogFactoryWithPostCreateMethodTakingArguments()); |
331 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
332 |
1 |
context.setItem(mock(Item.class)); |
333 |
1 |
context.setContentNode(mock(Node.class)); |
334 |
1 |
DefaultDialogCreator creator = creator(); |
335 |
|
|
336 |
|
|
337 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
} |
342 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 1 |
|
343 |
|
public static class DialogFactoryWithPostCreateMethodAfterSubclasses { |
344 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
345 |
1 |
@TabFactory("tab")... |
346 |
|
public void tabFactory() { |
347 |
1 |
events.add("DialogFactoryWithPostCreateMethodAfterSubclasses#tabFactory"); |
348 |
|
} |
349 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
350 |
1 |
@PostCreate... |
351 |
|
public void postCreate() { |
352 |
1 |
events.add("DialogFactoryWithPostCreateMethodAfterSubclasses#postCreate"); |
353 |
|
} |
354 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
355 |
1 |
@PostCreate(PostCreate.Phase.AFTER_SUB_CLASSES)... |
356 |
|
public void postCreateAfterSubclasses() { |
357 |
1 |
events.add("DialogFactoryWithPostCreateMethodAfterSubclasses#postCreateAfterSubclasses"); |
358 |
|
} |
359 |
|
} |
360 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
361 |
|
public static class DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass extends DialogFactoryWithPostCreateMethodAfterSubclasses { |
362 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
363 |
1 |
@TabFactory("tabInSubClass")... |
364 |
|
public void tabFactory2() { |
365 |
1 |
events.add("DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass#tabInSubClass"); |
366 |
|
} |
367 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
368 |
1 |
@PostCreate... |
369 |
|
public void postCreate2() { |
370 |
1 |
events.add("DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass#postCreate2"); |
371 |
|
} |
372 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
373 |
1 |
@PostCreate(PostCreate.Phase.AFTER_SUB_CLASSES)... |
374 |
|
public void postCreateAfterSubclasses() { |
375 |
1 |
events.add("DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass#postCreateAfterSubclasses"); |
376 |
1 |
super.postCreateAfterSubclasses(); |
377 |
|
} |
378 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
379 |
1 |
@PostCreate(PostCreate.Phase.AFTER_SUB_CLASSES)... |
380 |
|
public void postCreateAfterSubclasses2() { |
381 |
1 |
events.add("DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass#postCreateAfterSubclasses2"); |
382 |
|
} |
383 |
|
} |
384 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
385 |
1 |
@Test... |
386 |
|
public void testPostCreateForAfterSubclassesPhaseIsInvokedLast() throws Exception { |
387 |
|
|
388 |
|
|
389 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription("id", "label", new DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass()); |
390 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
391 |
1 |
DefaultDialogCreator creator = creator(); |
392 |
|
|
393 |
|
|
394 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
395 |
|
|
396 |
|
|
397 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodAfterSubclasses#tabFactory", events.remove(0)); |
398 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodAfterSubclasses#postCreate", events.remove(0)); |
399 |
|
|
400 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass#tabInSubClass", events.remove(0)); |
401 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass#postCreate2", events.remove(0)); |
402 |
|
|
403 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass#postCreateAfterSubclasses", events.remove(0)); |
404 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodAfterSubclasses#postCreateAfterSubclasses", events.remove(0)); |
405 |
|
|
406 |
1 |
assertEquals("DialogFactoryWithPostCreateMethodAfterSubclassesExtendingSuperclass#postCreateAfterSubclasses2", events.remove(0)); |
407 |
|
|
408 |
1 |
assertTrue(events.isEmpty()); |
409 |
|
} |
410 |
|
|
411 |
|
@DialogFactory("dialog") |
412 |
|
@TabOrder({"tab3", "tab2", "tab1"}) |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 1 |
|
413 |
|
public static class DialogWithTabsOrderedByName { |
414 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
415 |
1 |
@TabFactory("tab1")... |
416 |
|
public void tab1(TabBuilder tab) { |
417 |
1 |
tab.label("this is tab 1"); |
418 |
|
} |
419 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
420 |
1 |
@TabFactory("tab2")... |
421 |
|
public void tab2(TabBuilder tab) { |
422 |
1 |
tab.label("this is tab 2"); |
423 |
|
} |
424 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
425 |
1 |
@TabFactory("tab3")... |
426 |
|
public void tab3(TabBuilder tab) { |
427 |
1 |
tab.label("this is tab 3"); |
428 |
|
} |
429 |
|
} |
430 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
431 |
1 |
@Test... |
432 |
|
public void testSortTabsByName() throws Exception { |
433 |
|
|
434 |
|
|
435 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription(new DialogWithTabsOrderedByName(), null); |
436 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
437 |
1 |
mockProperty(DefaultDialogCreator.SORT_TABS_BY_LABEL_PROPERTY_NAME, "false"); |
438 |
1 |
DefaultDialogCreator creator = creator(); |
439 |
1 |
assertFalse(creator.getSortTabsByLabel()); |
440 |
|
|
441 |
|
|
442 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
443 |
|
|
444 |
|
|
445 |
1 |
assertHasTabsInNameOrder(context.getDialog(), new String[]{"tab3", "tab2", "tab1"}); |
446 |
|
} |
447 |
|
|
448 |
|
@DialogFactory("dialog") |
449 |
|
@TabOrder({"this is tab 3", "this is tab 2", "this is tab 1"}) |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 1 |
|
450 |
|
public static class DialogWithTabsOrderedByLabel { |
451 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
452 |
1 |
@TabFactory("tab1")... |
453 |
|
public void tab1(TabBuilder tab) { |
454 |
1 |
tab.label("this is tab 1"); |
455 |
|
} |
456 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
457 |
1 |
@TabFactory("tab2")... |
458 |
|
public void tab2(TabBuilder tab) { |
459 |
1 |
tab.label("this is tab 2"); |
460 |
|
} |
461 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
462 |
1 |
@TabFactory("tab3")... |
463 |
|
public void tab3(TabBuilder tab) { |
464 |
1 |
tab.label("this is tab 3"); |
465 |
|
} |
466 |
|
} |
467 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
468 |
1 |
@Test... |
469 |
|
public void testSortTabsByLabel() throws Exception { |
470 |
|
|
471 |
|
|
472 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription(new DialogWithTabsOrderedByLabel(), null); |
473 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
474 |
1 |
mockProperty(DefaultDialogCreator.SORT_TABS_BY_LABEL_PROPERTY_NAME, "true"); |
475 |
1 |
DefaultDialogCreator creator = creator(); |
476 |
1 |
assertTrue(creator.getSortTabsByLabel()); |
477 |
|
|
478 |
|
|
479 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
480 |
|
|
481 |
|
|
482 |
1 |
assertHasTabsInLabelOrder(context.getDialog(), new String[]{"this is tab 3", "this is tab 2", "this is tab 1"}); |
483 |
|
} |
484 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
485 |
1 |
@Test... |
486 |
|
public void testSetsBothLabelAndNameByDefault() throws Exception { |
487 |
|
|
488 |
|
|
489 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription(new SimpleFactory(), null); |
490 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
491 |
1 |
DefaultDialogCreator creator = creator(); |
492 |
1 |
assertTrue(creator.getSetTabLabels()); |
493 |
|
|
494 |
|
|
495 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
496 |
|
|
497 |
|
|
498 |
1 |
for (TabDefinition tab : context.getDialog().getForm().getTabs()) { |
499 |
2 |
assertNotNullOrEmpty(tab.getLabel()); |
500 |
2 |
assertNotNullOrEmpty(tab.getName()); |
501 |
|
} |
502 |
|
} |
503 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
504 |
1 |
@Test... |
505 |
|
public void testSetsNoLabelIfAskedNotTo() throws Exception { |
506 |
|
|
507 |
|
|
508 |
1 |
BlossomDialogDescription description = new DialogDescriptionBuilder().buildDescription(new SimpleFactory(), null); |
509 |
1 |
DialogCreationContext context = new DialogCreationContext(); |
510 |
1 |
mockProperty(DefaultDialogCreator.SET_TAB_LABELS_PROPERTY_NAME, "false"); |
511 |
1 |
DefaultDialogCreator creator = creator(); |
512 |
1 |
assertFalse(creator.getSetTabLabels()); |
513 |
|
|
514 |
|
|
515 |
1 |
creator.createDialog(description.getFactoryMetaData(), context); |
516 |
|
|
517 |
|
|
518 |
1 |
for (TabDefinition tab : context.getDialog().getForm().getTabs()) { |
519 |
2 |
assertNull(tab.getLabel()); |
520 |
|
} |
521 |
|
} |
522 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
523 |
14 |
private DefaultDialogCreator creator() throws Exception {... |
524 |
14 |
DefaultDialogCreator creator = new DefaultDialogCreator(); |
525 |
14 |
creator.afterPropertiesSet(); |
526 |
14 |
return creator; |
527 |
|
} |
528 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
529 |
3 |
private void mockProperty(String key, String value) {... |
530 |
3 |
MagnoliaConfigurationProperties configurationProperties = mock(MagnoliaConfigurationProperties.class); |
531 |
3 |
when(configurationProperties.getProperty(key)).thenReturn(value); |
532 |
3 |
ComponentsTestUtil.setInstance(MagnoliaConfigurationProperties.class, configurationProperties); |
533 |
|
} |
534 |
|
|
|
|
| 50% |
Uncovered Elements: 4 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
535 |
4 |
private void assertNotNullOrEmpty(String s) {... |
536 |
4 |
if (s == null) { |
537 |
0 |
fail("Expected string to not be null, was: " + s); |
538 |
4 |
} else if (s.length() == 0) { |
539 |
0 |
fail("Expected string to not be empty, was: " + s); |
540 |
|
} |
541 |
|
} |
542 |
|
} |