View Javadoc
1   package org.codehaus.plexus.component.factory;
2   
3   /*
4    * Copyright 2001-2006 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  }