1 package org.codehaus.plexus.component.factory;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.codehaus.plexus.PlexusTestCase;
20 import org.codehaus.plexus.component.repository.ComponentDescriptor;
21
22 public class DiscoveredComponentFactoryTest extends PlexusTestCase {
23 public void testShouldFindComponentFactoriesDefinedInBothPlexusXmlAndComponentsXml() throws Exception {
24 assertNotNull(
25 "Cannot find test component factory from plexus.xml test resource.",
26 lookup(ComponentFactory.class, "testFactory1"));
27
28 assertNotNull(
29 "Cannot find test component factory from components.xml test resource.",
30 lookup(ComponentFactory.class, "testFactory2"));
31 }
32
33 public void testShouldInstantiateComponentUsingFactoryDiscoveredInPlexusXml() throws Exception {}
34
35 public void testShouldInstantiateComponentUsingFactoryDiscoveredInComponentsXml() throws Exception {
36 lookupTestComponent("testFactory2");
37 }
38
39 private void lookupTestComponent(String factoryId) throws Exception {
40 ComponentDescriptor descriptor = new ComponentDescriptor();
41
42 descriptor.setComponentFactory(factoryId);
43
44 descriptor.setRole("role");
45
46 descriptor.setRoleHint("hint");
47
48 descriptor.setImplementation("something interesting");
49
50 getContainer().addComponentDescriptor(descriptor);
51
52 Object component = lookup("role", "hint");
53
54 assertTrue(component instanceof TestFactoryResultComponent);
55
56 assertEquals(factoryId, ((TestFactoryResultComponent) component).getFactoryId());
57 }
58 }