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 junit.framework.Assert.assertEquals; |
37 |
|
import static junit.framework.Assert.assertNotNull; |
38 |
|
import static org.junit.Assert.assertFalse; |
39 |
|
import static org.junit.Assert.assertSame; |
40 |
|
import static org.junit.Assert.assertTrue; |
41 |
|
import static org.mockito.Mockito.mock; |
42 |
|
|
43 |
|
import info.magnolia.config.registry.DefinitionProvider; |
44 |
|
import info.magnolia.module.blossom.annotation.DialogFactory; |
45 |
|
import info.magnolia.module.blossom.annotation.PreRegister; |
46 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcher; |
47 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherInitializedEvent; |
48 |
|
import info.magnolia.objectfactory.Components; |
49 |
|
import info.magnolia.registry.RegistrationException; |
50 |
|
import info.magnolia.test.MgnlTestCase; |
51 |
|
import info.magnolia.ui.dialog.definition.DialogDefinition; |
52 |
|
import info.magnolia.ui.dialog.registry.DialogDefinitionRegistry; |
53 |
|
|
54 |
|
import java.util.concurrent.atomic.AtomicReference; |
55 |
|
|
56 |
|
import org.junit.Test; |
57 |
|
import org.springframework.context.support.StaticApplicationContext; |
58 |
|
|
59 |
|
|
60 |
|
@link |
61 |
|
|
62 |
|
@since |
63 |
|
|
|
|
| 97.8% |
Uncovered Elements: 1 (46) |
Complexity: 9 |
Complexity Density: 0.25 |
|
64 |
|
public class DialogExporterTest extends MgnlTestCase { |
65 |
|
|
66 |
|
@DialogFactory(value = "module:TestDialogFactory", label = "Test dialog factory") |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
67 |
|
public static class TestDialogFactory { |
68 |
|
|
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void testExportDialogFactory() throws Exception { |
73 |
1 |
String dialogId = "module:TestDialogFactory"; |
74 |
1 |
registerDialogFactory(dialogId, createApplicationContext(TestDialogFactory.class)); |
75 |
1 |
DialogDefinitionRegistry registry = Components.getComponent(DialogDefinitionRegistry.class); |
76 |
1 |
assertNotNull(registry.getDialogDefinition(dialogId)); |
77 |
|
} |
78 |
|
|
79 |
|
@DialogFactory(value = "module:TestDialogFactoryWithPreRegisterThatReturnsNull", label = "Test dialog factory") |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
|
public static class TestDialogFactoryWithPreRegisterThatReturnsNull { |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
1 |
@PreRegister... |
83 |
|
public BlossomDialogDescription register(BlossomDialogDescription description) { |
84 |
1 |
return null; |
85 |
|
} |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
88 |
1 |
@Test(expected = RegistrationException.class)... |
89 |
|
public void testExportDialogFactoryThatReturnsNull() throws Exception { |
90 |
1 |
String dialogId = "module:TestDialogFactory"; |
91 |
1 |
registerDialogFactory(dialogId, createApplicationContext(TestDialogFactoryWithPreRegisterThatReturnsNull.class)); |
92 |
1 |
DialogDefinitionRegistry registry = Components.getComponent(DialogDefinitionRegistry.class); |
93 |
1 |
registry.getDialogDefinition(dialogId); |
94 |
|
} |
95 |
|
|
96 |
|
@DialogFactory(value = "module:DialogFactoryWithPreRegisterCallback", label = "Test dialog factory") |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.5 |
|
97 |
|
public static class DialogFactoryWithPreRegisterCallback { |
98 |
|
|
99 |
|
boolean invokedWithDescription; |
100 |
|
BlossomDialogDescription description; |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
102 |
1 |
@PreRegister... |
103 |
|
public void register(BlossomDialogDescription description) { |
104 |
1 |
this.description = description; |
105 |
1 |
invokedWithDescription = true; |
106 |
|
} |
107 |
|
} |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
109 |
1 |
@Test... |
110 |
|
public void testExportDialogFactoryWithPreRegisterCallback() throws Exception { |
111 |
1 |
StaticApplicationContext ctx = createApplicationContext(DialogFactoryWithPreRegisterCallback.class); |
112 |
1 |
BlossomDialogDescription dialogDescription = registerDialogFactory("module:DialogFactoryWithPreRegisterCallback", ctx); |
113 |
1 |
DialogFactoryWithPreRegisterCallback dialog = ctx.getBean(DialogFactoryWithPreRegisterCallback.class); |
114 |
1 |
assertTrue(dialog.invokedWithDescription); |
115 |
1 |
assertSame(dialogDescription, dialog.description); |
116 |
|
} |
117 |
|
|
118 |
|
@DialogFactory(value = "module:DialogFactoryWithOverriddenPreRegisterCallback", label = "Test dialog factory") |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
119 |
|
public static class DialogFactoryWithOverriddenPreRegisterCallback extends DialogFactoryWithPreRegisterCallback { |
120 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
121 |
0 |
@Override... |
122 |
|
public void register(BlossomDialogDescription description) { |
123 |
|
} |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
126 |
1 |
@Test... |
127 |
|
public void testExportDialogFactoryWithOverriddenPreRegisterCallback() throws Exception { |
128 |
1 |
StaticApplicationContext ctx = createApplicationContext(DialogFactoryWithOverriddenPreRegisterCallback.class); |
129 |
1 |
BlossomDialogDescription dialogDescription = registerDialogFactory("module:DialogFactoryWithOverriddenPreRegisterCallback", ctx); |
130 |
1 |
DialogFactoryWithOverriddenPreRegisterCallback dialog = ctx.getBean(DialogFactoryWithOverriddenPreRegisterCallback.class); |
131 |
1 |
assertFalse(dialog.invokedWithDescription); |
132 |
|
} |
133 |
|
|
134 |
|
@DialogFactory(value="module:DialogFactoryWithPreRegisterThatAddsMessage", label="") |
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.25 |
|
135 |
|
public static class DialogFactoryWithPreRegisterThatAddsMessage { |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
137 |
1 |
@PreRegister... |
138 |
|
private BlossomDialogDescription register(BlossomDialogDescription description) { |
139 |
1 |
BlossomDialogDescriptionWithMessage descriptionWithMessage = new BlossomDialogDescriptionWithMessage(); |
140 |
1 |
descriptionWithMessage.setId(description.getId()); |
141 |
1 |
descriptionWithMessage.message = "DialogFactoryWithPreRegisterThatAddsMessage"; |
142 |
1 |
return descriptionWithMessage; |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
@DialogFactory(value="module:DialogFactoryWithPreRegisterThatAddsMessageToMessageFromSuperclass", label="") |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.5 |
|
147 |
|
public static class DialogFactoryWithPreRegisterThatAddsMessageToMessageFromSuperclass extends DialogFactoryWithPreRegisterThatAddsMessage { |
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
149 |
1 |
@PreRegister... |
150 |
|
private BlossomDialogDescription register(BlossomDialogDescription description) { |
151 |
1 |
((BlossomDialogDescriptionWithMessage)description).message += " DialogFactoryWithPreRegisterThatAddsMessageToMessageFromSuperclass"; |
152 |
1 |
return description; |
153 |
|
} |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
156 |
1 |
@Test... |
157 |
|
public void testExportDialogFactoryWithPreRegisterThatAddsMessageToMessageFromSuperclass() throws Exception { |
158 |
1 |
StaticApplicationContext ctx = createApplicationContext(DialogFactoryWithPreRegisterThatAddsMessageToMessageFromSuperclass.class); |
159 |
1 |
BlossomDialogDescriptionWithMessage descriptionWithMessage = (BlossomDialogDescriptionWithMessage) registerDialogFactory("module:DialogFactoryWithPreRegisterThatAddsMessageToMessageFromSuperclass", ctx); |
160 |
1 |
ctx.getBean(DialogFactoryWithPreRegisterThatAddsMessageToMessageFromSuperclass.class); |
161 |
1 |
assertEquals("DialogFactoryWithPreRegisterThatAddsMessage DialogFactoryWithPreRegisterThatAddsMessageToMessageFromSuperclass", descriptionWithMessage.message); |
162 |
|
} |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
164 |
5 |
private BlossomDialogDescription registerDialogFactory(final String dialogId, StaticApplicationContext ctx) throws Exception {... |
165 |
|
|
166 |
5 |
BlossomDispatcher dispatcher = mock(BlossomDispatcher.class); |
167 |
|
|
168 |
5 |
final AtomicReference<BlossomDialogDescription> reference = new AtomicReference<BlossomDialogDescription>(); |
169 |
5 |
DialogExporter dialogExporter = new DialogExporter() { |
170 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
171 |
4 |
@Override... |
172 |
|
protected DefinitionProvider<DialogDefinition> createDialogDefinitionProvider(BlossomDialogDescription dialogDescription) { |
173 |
4 |
if (dialogDescription.getId().equals(dialogId)) { |
174 |
4 |
reference.set(dialogDescription); |
175 |
|
} |
176 |
4 |
return new BlossomDialogDefinitionProvider(dialogDescription); |
177 |
|
} |
178 |
|
}; |
179 |
5 |
dialogExporter.setBlossomDispatcher(dispatcher); |
180 |
5 |
dialogExporter.setApplicationContext(ctx); |
181 |
5 |
dialogExporter.afterPropertiesSet(); |
182 |
5 |
dialogExporter.onApplicationEvent(new BlossomDispatcherInitializedEvent(dispatcher)); |
183 |
|
|
184 |
5 |
return reference.get(); |
185 |
|
} |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
187 |
5 |
private StaticApplicationContext createApplicationContext(Class<?> clazz) {... |
188 |
5 |
StaticApplicationContext applicationContext = new StaticApplicationContext(); |
189 |
5 |
applicationContext.registerSingleton(clazz.getSimpleName(), clazz); |
190 |
5 |
applicationContext.refresh(); |
191 |
5 |
return applicationContext; |
192 |
|
} |
193 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
194 |
|
public static class BlossomDialogDescriptionWithMessage extends BlossomDialogDescription { |
195 |
|
String message; |
196 |
|
} |
197 |
|
} |