View Javadoc
1   package org.codehaus.plexus.component;
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 java.util.Map;
20  
21  import junit.framework.TestCase;
22  
23  import org.codehaus.plexus.DefaultPlexusContainer;
24  import org.codehaus.plexus.PlexusContainer;
25  import org.codehaus.plexus.component.repository.ComponentDescriptor;
26  import org.codehaus.plexus.component.repository.ComponentRequirement;
27  import org.codehaus.plexus.configuration.PlexusConfiguration;
28  import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
29  import org.codehaus.plexus.logging.LoggerManager;
30  
31  public class MapOrientedComponentProcessingTest
32      extends TestCase
33  {
34  
35      public void testShouldFindAndInitializeMapOrientedComponent()
36          throws Exception
37      {
38          PlexusContainer embedder = new DefaultPlexusContainer();
39  
40          ComponentDescriptor<TestMapOrientedComponent> descriptor =
41              new ComponentDescriptor(TestMapOrientedComponent.class, embedder.getContainerRealm());
42  
43          descriptor.setRole( TestMapOrientedComponent.ROLE );
44  
45          descriptor.setImplementation( TestMapOrientedComponent.ROLE );
46  
47          descriptor.setComponentComposer( "map-oriented" );
48  
49          descriptor.setComponentConfigurator( "map-oriented" );
50  
51          ComponentRequirement requirement = new ComponentRequirement();
52  
53          requirement.setFieldName( "testRequirement" );
54  
55          requirement.setRole( LoggerManager.ROLE );
56  
57          descriptor.addRequirement( requirement );
58  
59          PlexusConfiguration param = new XmlPlexusConfiguration( "testParameter" );
60  
61          param.setValue( "testValue" );
62  
63          PlexusConfiguration configuration = new XmlPlexusConfiguration( "configuration" );
64  
65          configuration.addChild( param );
66  
67          descriptor.setConfiguration( configuration );
68  
69  
70          embedder.addComponentDescriptor( descriptor );
71  
72          TestMapOrientedComponent component = embedder.lookup( TestMapOrientedComponent.class );
73  
74          Map context = component.getContext();
75  
76          assertTrue( "requirement (LogManager) missing from containerContext.",
77                      ( context.get( "testRequirement" ) instanceof LoggerManager ) );
78  
79          assertEquals( "parameter missing from containerContext.", "testValue", context.get( "testParameter" ) );
80      }
81  
82  }