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
23      extends PlexusTestCase
24  {
25      public void testShouldFindComponentFactoriesDefinedInBothPlexusXmlAndComponentsXml()
26          throws Exception
27      {
28          assertNotNull( "Cannot find test component factory from plexus.xml test resource.",
29                         lookup( ComponentFactory.class, "testFactory1" ) );
30  
31          assertNotNull( "Cannot find test component factory from components.xml test resource.",
32                         lookup( ComponentFactory.class, "testFactory2" ) );
33      }
34  
35      public void testShouldInstantiateComponentUsingFactoryDiscoveredInPlexusXml()
36          throws Exception
37      {
38      }
39  
40      public void testShouldInstantiateComponentUsingFactoryDiscoveredInComponentsXml()
41          throws Exception
42      {
43          lookupTestComponent( "testFactory2" );
44      }
45  
46      private void lookupTestComponent( String factoryId )
47          throws Exception
48      {
49          ComponentDescriptor descriptor = new ComponentDescriptor();
50  
51          descriptor.setComponentFactory( factoryId );
52  
53          descriptor.setRole( "role" );
54  
55          descriptor.setRoleHint( "hint" );
56  
57          descriptor.setImplementation( "something interesting" );
58  
59          getContainer().addComponentDescriptor( descriptor );
60  
61          Object component = lookup( "role", "hint" );
62  
63          assertTrue( component instanceof TestFactoryResultComponent );
64  
65          assertEquals( factoryId, ( (TestFactoryResultComponent) component ).getFactoryId() );
66      }
67  }