1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.component.embed; |
21 |
|
|
22 |
|
import static org.mockito.Mockito.mock; |
23 |
|
import static org.mockito.Mockito.verify; |
24 |
|
|
25 |
|
import java.lang.reflect.Type; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
|
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Test; |
31 |
|
import org.slf4j.Logger; |
32 |
|
import org.xwiki.component.annotation.DisposePriority; |
33 |
|
import org.xwiki.component.descriptor.ComponentDescriptor; |
34 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
35 |
|
import org.xwiki.component.descriptor.DefaultComponentDependency; |
36 |
|
import org.xwiki.component.descriptor.DefaultComponentDescriptor; |
37 |
|
import org.xwiki.component.manager.ComponentEventManager; |
38 |
|
import org.xwiki.component.manager.ComponentLifecycleException; |
39 |
|
import org.xwiki.component.manager.ComponentLookupException; |
40 |
|
import org.xwiki.component.manager.ComponentManager; |
41 |
|
import org.xwiki.component.phase.Disposable; |
42 |
|
import org.xwiki.component.phase.Initializable; |
43 |
|
import org.xwiki.component.phase.InitializationException; |
44 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
45 |
|
|
46 |
|
|
47 |
|
@link |
48 |
|
|
49 |
|
@version |
50 |
|
@since |
51 |
|
|
|
|
| 99.6% |
Uncovered Elements: 1 (271) |
Complexity: 28 |
Complexity Density: 0.12 |
|
52 |
|
public class EmbeddableComponentManagerTest |
53 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
54 |
|
public static interface Role |
55 |
|
{ |
56 |
|
} |
57 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
58 |
|
public static class RoleImpl implements Role |
59 |
|
{ |
60 |
|
} |
61 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
62 |
|
public static class OtherRoleImpl implements Role |
63 |
|
{ |
64 |
|
} |
65 |
|
|
66 |
|
private static String lastDisposedComponent; |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
68 |
|
public static class InitializableRoleImpl implements Role, Initializable |
69 |
|
{ |
70 |
|
private boolean initialized = false; |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
1 |
@Override... |
73 |
|
public void initialize() throws InitializationException |
74 |
|
{ |
75 |
1 |
this.initialized = true; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
1 |
public boolean isInitialized()... |
79 |
|
{ |
80 |
1 |
return this.initialized; |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
84 |
|
public static class DisposableRoleImpl implements Role, Disposable |
85 |
|
{ |
86 |
|
private boolean finalized = false; |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
88 |
4 |
@Override... |
89 |
|
public void dispose() throws ComponentLifecycleException |
90 |
|
{ |
91 |
4 |
this.finalized = true; |
92 |
4 |
lastDisposedComponent = "DisposableRoleImpl"; |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
8 |
public boolean isFinalized()... |
96 |
|
{ |
97 |
8 |
return this.finalized; |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
|
@DisposePriority(2000) |
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
102 |
|
public static class DisposableWithPriorityRoleImpl implements Role, Disposable |
103 |
|
{ |
104 |
|
private boolean finalized = false; |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
106 |
1 |
@Override... |
107 |
|
public void dispose() throws ComponentLifecycleException |
108 |
|
{ |
109 |
1 |
this.finalized = true; |
110 |
1 |
lastDisposedComponent = "DisposableWithPriorityRoleImpl"; |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
2 |
public boolean isFinalized()... |
114 |
|
{ |
115 |
2 |
return this.finalized; |
116 |
|
} |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
|
public static class LoggingRoleImpl implements Role |
120 |
|
{ |
121 |
|
private Logger logger; |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
1 |
public Logger getLogger()... |
124 |
|
{ |
125 |
1 |
return this.logger; |
126 |
|
} |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
129 |
1 |
@Test... |
130 |
|
public void testLookupThisComponentManager() throws ComponentLookupException |
131 |
|
{ |
132 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
133 |
|
|
134 |
1 |
Assert.assertSame(ecm.getInstance(ComponentManager.class), ecm); |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
137 |
1 |
@Test... |
138 |
|
public void testGetComponentDescriptorList() throws Exception |
139 |
|
{ |
140 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
141 |
|
|
142 |
1 |
DefaultComponentDescriptor<Role> d1 = new DefaultComponentDescriptor<Role>(); |
143 |
1 |
d1.setRoleType(Role.class); |
144 |
1 |
d1.setRoleHint("hint1"); |
145 |
1 |
ecm.registerComponent(d1); |
146 |
|
|
147 |
1 |
DefaultComponentDescriptor<Role> d2 = new DefaultComponentDescriptor<Role>(); |
148 |
1 |
d2.setRoleType(Role.class); |
149 |
1 |
d2.setRoleHint("hint2"); |
150 |
1 |
ecm.registerComponent(d2); |
151 |
|
|
152 |
1 |
List<ComponentDescriptor<Role>> cds = ecm.getComponentDescriptorList(Role.class); |
153 |
1 |
Assert.assertEquals(2, cds.size()); |
154 |
1 |
Assert.assertTrue(cds.contains(d1)); |
155 |
1 |
Assert.assertTrue(cds.contains(d2)); |
156 |
|
} |
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
158 |
1 |
@Test... |
159 |
|
public void getComponentDescriptorListInParent() throws Exception |
160 |
|
{ |
161 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
162 |
1 |
ecm.setParent(createParentComponentManager()); |
163 |
|
|
164 |
1 |
List<ComponentDescriptor<Role>> cds = ecm.getComponentDescriptorList((Type) Role.class); |
165 |
1 |
Assert.assertEquals(1, cds.size()); |
166 |
|
} |
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
168 |
1 |
@Test... |
169 |
|
public void getComponentDescriptorInParent() throws Exception |
170 |
|
{ |
171 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
172 |
1 |
ecm.setParent(createParentComponentManager("somehint")); |
173 |
|
|
174 |
1 |
ComponentDescriptor<Role> cd = ecm.getComponentDescriptor(Role.class, "somehint"); |
175 |
1 |
Assert.assertNotNull(cd); |
176 |
1 |
Assert.assertEquals(RoleImpl.class, cd.getImplementation()); |
177 |
|
} |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
179 |
1 |
@Test... |
180 |
|
public void getComponentDescriptorWhenSomeComponentsInParent() throws Exception |
181 |
|
{ |
182 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
183 |
1 |
ecm.setParent(createParentComponentManager()); |
184 |
|
|
185 |
|
|
186 |
1 |
DefaultComponentDescriptor<Role> cd1 = new DefaultComponentDescriptor<Role>(); |
187 |
1 |
cd1.setRoleType(Role.class); |
188 |
1 |
cd1.setImplementation(RoleImpl.class); |
189 |
1 |
Role roleImpl = new RoleImpl(); |
190 |
1 |
ecm.registerComponent(cd1, roleImpl); |
191 |
|
|
192 |
|
|
193 |
1 |
DefaultComponentDescriptor<Role> cd2 = new DefaultComponentDescriptor<Role>(); |
194 |
1 |
cd2.setRoleType(Role.class); |
195 |
1 |
cd2.setRoleHint("hint"); |
196 |
1 |
cd2.setImplementation(RoleImpl.class); |
197 |
1 |
ecm.registerComponent(cd2); |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
1 |
List<ComponentDescriptor<Role>> descriptors = ecm.getComponentDescriptorList(Role.class); |
203 |
1 |
Assert.assertEquals(2, descriptors.size()); |
204 |
|
} |
205 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
206 |
1 |
@Test... |
207 |
|
public void testRegisterComponentOverExistingOne() throws Exception |
208 |
|
{ |
209 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
210 |
|
|
211 |
1 |
DefaultComponentDescriptor<Role> d1 = new DefaultComponentDescriptor<Role>(); |
212 |
1 |
d1.setRoleType(Role.class); |
213 |
1 |
d1.setImplementation(RoleImpl.class); |
214 |
1 |
ecm.registerComponent(d1); |
215 |
|
|
216 |
1 |
Object instance = ecm.getInstance(Role.class); |
217 |
1 |
Assert.assertSame(RoleImpl.class, instance.getClass()); |
218 |
|
|
219 |
1 |
DefaultComponentDescriptor<Role> d2 = new DefaultComponentDescriptor<Role>(); |
220 |
1 |
d2.setRoleType(Role.class); |
221 |
1 |
d2.setImplementation(OtherRoleImpl.class); |
222 |
1 |
ecm.registerComponent(d2); |
223 |
|
|
224 |
1 |
instance = ecm.getInstance(Role.class); |
225 |
1 |
Assert.assertSame(OtherRoleImpl.class, instance.getClass()); |
226 |
|
} |
227 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
228 |
1 |
@Test... |
229 |
|
public void testRegisterComponentInstance() throws Exception |
230 |
|
{ |
231 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
232 |
|
|
233 |
1 |
DefaultComponentDescriptor<Role> d1 = new DefaultComponentDescriptor<Role>(); |
234 |
1 |
d1.setRoleType(Role.class); |
235 |
1 |
d1.setImplementation(RoleImpl.class); |
236 |
1 |
Role instance = new RoleImpl(); |
237 |
1 |
ecm.registerComponent(d1, instance); |
238 |
|
|
239 |
1 |
Assert.assertSame(instance, ecm.getInstance(Role.class)); |
240 |
|
} |
241 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
1PASS
|
|
242 |
1 |
@Test... |
243 |
|
public void testUnregisterComponent() throws Exception |
244 |
|
{ |
245 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
246 |
|
|
247 |
1 |
DefaultComponentDescriptor<Role> d1 = new DefaultComponentDescriptor<Role>(); |
248 |
1 |
d1.setRoleType(Role.class); |
249 |
1 |
d1.setImplementation(RoleImpl.class); |
250 |
1 |
ecm.registerComponent(d1); |
251 |
|
|
252 |
|
|
253 |
1 |
Assert.assertSame(RoleImpl.class, ecm.getInstance(Role.class).getClass()); |
254 |
|
|
255 |
1 |
ecm.unregisterComponent(d1.getRoleType(), d1.getRoleHint()); |
256 |
|
|
257 |
|
|
258 |
1 |
try { |
259 |
1 |
ecm.getInstance(d1.getRoleType()); |
260 |
0 |
Assert.fail("Should have thrown a ComponentLookupException"); |
261 |
|
} catch (ComponentLookupException expected) { |
262 |
|
|
263 |
|
|
264 |
|
} |
265 |
|
} |
266 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
267 |
1 |
@Test... |
268 |
|
public void testGetInstanceWhenComponentInParent() throws Exception |
269 |
|
{ |
270 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
271 |
1 |
ecm.setParent(createParentComponentManager()); |
272 |
|
|
273 |
1 |
Role instance = ecm.getInstance(Role.class); |
274 |
1 |
Assert.assertNotNull(instance); |
275 |
|
} |
276 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
277 |
1 |
@Test... |
278 |
|
public void testGetInstanceListAndMapWhenSomeComponentsInParent() throws Exception |
279 |
|
{ |
280 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
281 |
1 |
ecm.setParent(createParentComponentManager()); |
282 |
|
|
283 |
|
|
284 |
1 |
DefaultComponentDescriptor<Role> cd1 = new DefaultComponentDescriptor<Role>(); |
285 |
1 |
cd1.setRoleType(Role.class); |
286 |
1 |
cd1.setImplementation(RoleImpl.class); |
287 |
1 |
Role roleImpl = new RoleImpl(); |
288 |
1 |
ecm.registerComponent(cd1, roleImpl); |
289 |
|
|
290 |
|
|
291 |
1 |
DefaultComponentDescriptor<Role> cd2 = new DefaultComponentDescriptor<Role>(); |
292 |
1 |
cd2.setRoleType(Role.class); |
293 |
1 |
cd2.setRoleHint("hint"); |
294 |
1 |
cd2.setImplementation(RoleImpl.class); |
295 |
1 |
ecm.registerComponent(cd2); |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
1 |
List<Role> instanceList = ecm.getInstanceList(Role.class); |
301 |
1 |
Assert.assertEquals(2, instanceList.size()); |
302 |
1 |
Assert.assertSame(roleImpl, instanceList.get(0)); |
303 |
|
|
304 |
1 |
Map<String, Role> instances = ecm.getInstanceMap(Role.class); |
305 |
1 |
Assert.assertEquals(2, instances.size()); |
306 |
1 |
Assert.assertSame(roleImpl, instances.get("default")); |
307 |
|
} |
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
309 |
1 |
@Test... |
310 |
|
public void testHasComponent() throws Exception |
311 |
|
{ |
312 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
313 |
|
|
314 |
1 |
DefaultComponentDescriptor<Role> d1 = new DefaultComponentDescriptor<Role>(); |
315 |
1 |
d1.setRoleType(Role.class); |
316 |
1 |
d1.setRoleHint("default"); |
317 |
1 |
ecm.registerComponent(d1); |
318 |
|
|
319 |
1 |
Assert.assertTrue(ecm.hasComponent(Role.class)); |
320 |
1 |
Assert.assertTrue(ecm.hasComponent(Role.class, "default")); |
321 |
|
} |
322 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
323 |
1 |
@Test... |
324 |
|
public void testHasComponentWhenComponentInParent() throws Exception |
325 |
|
{ |
326 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
327 |
1 |
ecm.setParent(createParentComponentManager()); |
328 |
|
|
329 |
1 |
Assert.assertTrue(ecm.hasComponent(Role.class)); |
330 |
1 |
Assert.assertTrue(ecm.hasComponent(Role.class, "default")); |
331 |
|
} |
332 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
333 |
1 |
@Test... |
334 |
|
public void testLoggingInjection() throws Exception |
335 |
|
{ |
336 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
337 |
|
|
338 |
1 |
DefaultComponentDescriptor<Role> d = new DefaultComponentDescriptor<Role>(); |
339 |
1 |
d.setRoleType(Role.class); |
340 |
1 |
d.setImplementation(LoggingRoleImpl.class); |
341 |
|
|
342 |
1 |
DefaultComponentDependency dependencyDescriptor = new DefaultComponentDependency(); |
343 |
1 |
dependencyDescriptor.setMappingType(Logger.class); |
344 |
1 |
dependencyDescriptor.setName("logger"); |
345 |
|
|
346 |
1 |
d.addComponentDependency(dependencyDescriptor); |
347 |
1 |
ecm.registerComponent(d); |
348 |
|
|
349 |
1 |
LoggingRoleImpl impl = (LoggingRoleImpl) ecm.getInstance(Role.class); |
350 |
1 |
Assert.assertNotNull(impl.getLogger()); |
351 |
|
} |
352 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
353 |
5 |
private ComponentManager createParentComponentManager() throws Exception... |
354 |
|
{ |
355 |
5 |
return createParentComponentManager(null); |
356 |
|
} |
357 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
358 |
6 |
private ComponentManager createParentComponentManager(String hint) throws Exception... |
359 |
|
{ |
360 |
6 |
EmbeddableComponentManager parent = new EmbeddableComponentManager(); |
361 |
6 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
362 |
6 |
cd.setRoleType(Role.class); |
363 |
6 |
cd.setImplementation(RoleImpl.class); |
364 |
6 |
if (hint != null) { |
365 |
1 |
cd.setRoleHint(hint); |
366 |
|
} |
367 |
6 |
parent.registerComponent(cd); |
368 |
6 |
return parent; |
369 |
|
} |
370 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
371 |
1 |
@Test... |
372 |
|
public void testRegisterInitializableComponent() throws Exception |
373 |
|
{ |
374 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
375 |
|
|
376 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
377 |
1 |
cd.setRoleType(Role.class); |
378 |
1 |
cd.setImplementation(InitializableRoleImpl.class); |
379 |
1 |
ecm.registerComponent(cd); |
380 |
1 |
InitializableRoleImpl instance = (InitializableRoleImpl) ecm.getInstance(Role.class); |
381 |
|
|
382 |
1 |
Assert.assertTrue(instance.isInitialized()); |
383 |
|
} |
384 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
385 |
1 |
@Test... |
386 |
|
public void testUnregisterDisposableSingletonComponent() throws Exception |
387 |
|
{ |
388 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
389 |
|
|
390 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
391 |
1 |
cd.setRoleType(Role.class); |
392 |
1 |
cd.setImplementation(DisposableRoleImpl.class); |
393 |
1 |
cd.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); |
394 |
|
|
395 |
1 |
ecm.registerComponent(cd); |
396 |
1 |
DisposableRoleImpl instance = (DisposableRoleImpl) ecm.getInstance(Role.class); |
397 |
|
|
398 |
1 |
Assert.assertFalse(instance.isFinalized()); |
399 |
|
|
400 |
1 |
ecm.unregisterComponent(cd.getRoleType(), cd.getRoleHint()); |
401 |
|
|
402 |
1 |
Assert.assertTrue(instance.isFinalized()); |
403 |
|
} |
404 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
405 |
1 |
@Test... |
406 |
|
public void testUnregisterDisposableSingletonComponentWithInstance() throws Exception |
407 |
|
{ |
408 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
409 |
|
|
410 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
411 |
1 |
cd.setRoleType(Role.class); |
412 |
1 |
cd.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); |
413 |
|
|
414 |
1 |
DisposableRoleImpl instance = new DisposableRoleImpl(); |
415 |
1 |
ecm.registerComponent(cd, instance); |
416 |
|
|
417 |
1 |
Assert.assertFalse(instance.isFinalized()); |
418 |
|
|
419 |
1 |
ecm.unregisterComponent(cd.getRoleType(), cd.getRoleHint()); |
420 |
|
|
421 |
1 |
Assert.assertTrue(instance.isFinalized()); |
422 |
|
} |
423 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
424 |
1 |
@Test... |
425 |
|
public void testRelease() throws Exception |
426 |
|
{ |
427 |
1 |
final EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
428 |
|
|
429 |
1 |
final DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
430 |
1 |
cd.setRoleType(Role.class); |
431 |
1 |
cd.setImplementation(RoleImpl.class); |
432 |
1 |
Role roleImpl = new RoleImpl(); |
433 |
1 |
ecm.registerComponent(cd, roleImpl); |
434 |
|
|
435 |
1 |
final ComponentEventManager cem = mock(ComponentEventManager.class); |
436 |
1 |
ecm.setComponentEventManager(cem); |
437 |
|
|
438 |
1 |
ecm.release(roleImpl); |
439 |
|
|
440 |
1 |
verify(cem).notifyComponentUnregistered(cd, ecm); |
441 |
1 |
verify(cem).notifyComponentRegistered(cd, ecm); |
442 |
|
|
443 |
1 |
Assert.assertNotNull(ecm.getInstance(Role.class)); |
444 |
1 |
Assert.assertNotSame(roleImpl, ecm.getInstance(Role.class)); |
445 |
|
} |
446 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
447 |
1 |
@Test... |
448 |
|
public void testReleaseDisposableComponent() throws Exception |
449 |
|
{ |
450 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
451 |
|
|
452 |
1 |
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
453 |
1 |
cd.setRoleType(Role.class); |
454 |
1 |
cd.setImplementation(DisposableRoleImpl.class); |
455 |
1 |
cd.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); |
456 |
|
|
457 |
1 |
ecm.registerComponent(cd); |
458 |
1 |
DisposableRoleImpl instance = ecm.getInstance(Role.class); |
459 |
|
|
460 |
1 |
Assert.assertFalse(instance.isFinalized()); |
461 |
|
|
462 |
1 |
ecm.release(instance); |
463 |
|
|
464 |
1 |
Assert.assertTrue(instance.isFinalized()); |
465 |
|
} |
466 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
467 |
1 |
@Test... |
468 |
|
public void testRegisterComponentNotification() throws Exception |
469 |
|
{ |
470 |
1 |
final EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
471 |
|
|
472 |
1 |
final DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
473 |
1 |
cd.setRoleType(Role.class); |
474 |
1 |
cd.setImplementation(RoleImpl.class); |
475 |
|
|
476 |
1 |
final ComponentEventManager cem = mock(ComponentEventManager.class); |
477 |
1 |
ecm.setComponentEventManager(cem); |
478 |
|
|
479 |
1 |
ecm.registerComponent(cd); |
480 |
|
|
481 |
1 |
verify(cem).notifyComponentRegistered(cd, ecm); |
482 |
|
} |
483 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
484 |
1 |
@Test... |
485 |
|
public void testUnregisterComponentNotification() throws Exception |
486 |
|
{ |
487 |
1 |
final EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
488 |
|
|
489 |
1 |
final DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>(); |
490 |
1 |
cd.setRoleType(Role.class); |
491 |
1 |
cd.setImplementation(RoleImpl.class); |
492 |
1 |
ecm.registerComponent(cd); |
493 |
|
|
494 |
1 |
final ComponentEventManager cem = mock(ComponentEventManager.class); |
495 |
1 |
ecm.setComponentEventManager(cem); |
496 |
|
|
497 |
1 |
ecm.unregisterComponent(cd.getRoleType(), cd.getRoleHint()); |
498 |
|
|
499 |
1 |
verify(cem).notifyComponentUnregistered(cd, ecm); |
500 |
|
} |
501 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
502 |
1 |
@Test... |
503 |
|
public void testRegisterComponentNotificationOnSecondRegistration() throws Exception |
504 |
|
{ |
505 |
1 |
final EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
506 |
|
|
507 |
1 |
final DefaultComponentDescriptor<Role> cd1 = new DefaultComponentDescriptor<Role>(); |
508 |
1 |
cd1.setRoleType(Role.class); |
509 |
1 |
cd1.setImplementation(RoleImpl.class); |
510 |
1 |
ecm.registerComponent(cd1); |
511 |
|
|
512 |
1 |
final DefaultComponentDescriptor<Role> cd2 = new DefaultComponentDescriptor<Role>(); |
513 |
1 |
cd2.setRoleType(Role.class); |
514 |
1 |
cd2.setImplementation(OtherRoleImpl.class); |
515 |
|
|
516 |
1 |
final ComponentEventManager cem = mock(ComponentEventManager.class); |
517 |
1 |
ecm.setComponentEventManager(cem); |
518 |
|
|
519 |
1 |
ecm.registerComponent(cd2); |
520 |
|
|
521 |
1 |
verify(cem).notifyComponentUnregistered(cd1, ecm); |
522 |
1 |
verify(cem).notifyComponentRegistered(cd2, ecm); |
523 |
|
} |
524 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
525 |
1 |
@Test... |
526 |
|
public void testDispose() throws Exception |
527 |
|
{ |
528 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
|
|
534 |
|
|
535 |
1 |
DefaultComponentDescriptor<Role> cd1 = new DefaultComponentDescriptor<>(); |
536 |
1 |
cd1.setRoleType(Role.class); |
537 |
1 |
cd1.setRoleHint("instance1"); |
538 |
1 |
cd1.setImplementation(DisposableWithPriorityRoleImpl.class); |
539 |
1 |
cd1.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); |
540 |
1 |
ecm.registerComponent(cd1); |
541 |
1 |
DisposableWithPriorityRoleImpl instance1 = ecm.getInstance(Role.class, "instance1"); |
542 |
|
|
543 |
|
|
544 |
1 |
DefaultComponentDescriptor<Role> cd2 = new DefaultComponentDescriptor<>(); |
545 |
1 |
cd2.setRoleType(Role.class); |
546 |
1 |
cd2.setRoleHint("instance2"); |
547 |
1 |
cd2.setImplementation(DisposableRoleImpl.class); |
548 |
1 |
cd2.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); |
549 |
1 |
ecm.registerComponent(cd2); |
550 |
1 |
DisposableRoleImpl instance2 = ecm.getInstance(Role.class, "instance2"); |
551 |
|
|
552 |
1 |
Assert.assertFalse(instance1.isFinalized()); |
553 |
1 |
Assert.assertFalse(instance2.isFinalized()); |
554 |
|
|
555 |
1 |
ecm.dispose(); |
556 |
|
|
557 |
1 |
Assert.assertTrue(instance1.isFinalized()); |
558 |
1 |
Assert.assertTrue(instance2.isFinalized()); |
559 |
|
|
560 |
1 |
Assert.assertNull(ecm.getComponentDescriptor(Role.class, "instance1")); |
561 |
1 |
Assert.assertNull(ecm.getComponentDescriptor(Role.class, "instance2")); |
562 |
1 |
Assert.assertNotNull(ecm.getComponentDescriptor(ComponentManager.class, "default")); |
563 |
|
|
564 |
|
|
565 |
|
|
566 |
|
|
567 |
1 |
Assert.assertEquals("DisposableWithPriorityRoleImpl", lastDisposedComponent); |
568 |
|
} |
569 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
570 |
1 |
@Test... |
571 |
|
public void diposeWhenImplementationIsECM() throws Exception |
572 |
|
{ |
573 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
574 |
|
|
575 |
1 |
DefaultComponentDescriptor<ComponentManager> cd = new DefaultComponentDescriptor<>(); |
576 |
1 |
cd.setRoleType(ComponentManager.class); |
577 |
1 |
cd.setRoleHint("hint"); |
578 |
1 |
cd.setImplementation(EmbeddableComponentManager.class); |
579 |
1 |
cd.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); |
580 |
1 |
ecm.registerComponent(cd, ecm); |
581 |
|
|
582 |
|
|
583 |
1 |
ecm.dispose(); |
584 |
|
} |
585 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
586 |
|
public static class ComponentDescriptorRoleImpl implements Role |
587 |
|
{ |
588 |
|
private ComponentDescriptor<ComponentDescriptorRoleImpl> descriptor; |
589 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
590 |
1 |
public ComponentDescriptor<ComponentDescriptorRoleImpl> getComponentDescriptor()... |
591 |
|
{ |
592 |
1 |
return this.descriptor; |
593 |
|
} |
594 |
|
} |
595 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
596 |
1 |
@Test... |
597 |
|
public void testComponentDescriptorInjection() throws Exception |
598 |
|
{ |
599 |
1 |
EmbeddableComponentManager ecm = new EmbeddableComponentManager(); |
600 |
|
|
601 |
1 |
DefaultComponentDescriptor<Role> d = new DefaultComponentDescriptor<>(); |
602 |
1 |
d.setRoleType(Role.class); |
603 |
1 |
d.setImplementation(ComponentDescriptorRoleImpl.class); |
604 |
|
|
605 |
1 |
DefaultComponentDependency dependencyDescriptor = new DefaultComponentDependency(); |
606 |
1 |
dependencyDescriptor.setRoleType( |
607 |
|
new DefaultParameterizedType(null, ComponentDescriptor.class, ComponentDescriptorRoleImpl.class)); |
608 |
1 |
dependencyDescriptor.setName("descriptor"); |
609 |
|
|
610 |
1 |
d.addComponentDependency(dependencyDescriptor); |
611 |
1 |
ecm.registerComponent(d); |
612 |
|
|
613 |
1 |
ComponentDescriptorRoleImpl impl = ecm.getInstance(Role.class); |
614 |
1 |
Assert.assertNotNull(impl.getComponentDescriptor()); |
615 |
|
} |
616 |
|
|
617 |
|
} |