View Javadoc
1   package org.codehaus.plexus.component.repository;
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 junit.framework.TestCase;
20  import org.codehaus.plexus.component.repository.io.PlexusTools;
21  import org.codehaus.plexus.classworlds.ClassWorld;
22  import org.codehaus.plexus.classworlds.realm.ClassRealm;
23  
24  import java.util.List;
25  
26  /**
27   *
28   *
29   * @author Jason van Zyl
30   *
31   * @version $Id$
32   */
33  public class ComponentSetTest
34      extends TestCase
35  {
36      public void testSimpleComponentResolution()
37          throws Exception
38      {
39          String xml =
40              "<component-set>" +
41              "  <components>" +
42              "    <component>" +
43              "      <implementation>java.lang.String</implementation>" +
44              "      <role>c1</role>" +
45              "      <role-hint>role-hint</role-hint>" +
46              "      <component-profile>component-profile</component-profile>" +
47              "      <requirements>" +
48              "        <requirement>" +
49              "          <role>c2</role>" +
50              "        </requirement>" +
51              "        <requirement>" +
52              "          <role>c3</role>" +
53              "        </requirement>" +
54              "      </requirements>" +
55              "    </component>" +
56              "  </components>" +
57              "  <dependencies>" +
58              "    <dependency>" +
59              "      <group-id>plexus</group-id>" +
60              "      <artifact-id>wedgy</artifact-id>" +
61              "      <version>1.0</version>" +
62              "    </dependency>" +
63              "  </dependencies>" +
64              "</component-set>";
65  
66          ClassWorld classWorld = new ClassWorld( "test", Thread.currentThread().getContextClassLoader() );
67          ClassRealm realm = classWorld.getRealm( "test" );
68  
69          ComponentSetDescriptor cs = PlexusTools.buildComponentSet( PlexusTools.buildConfiguration( xml ), realm );
70  
71          ComponentDescriptor<?> c1 = cs.getComponents().get( 0 );
72  
73          assertEquals( "c1", c1.getRole() );
74  
75          assertEquals( "role-hint", c1.getRoleHint() );
76  
77          assertEquals( "component-profile", c1.getComponentProfile() );
78  
79          List<ComponentRequirement> requirements = c1.getRequirements();
80  
81          assertEquals( 2, requirements.size() );
82  
83          boolean containsC2 = false;
84  
85          boolean containsC3 = false;
86  
87          for ( ComponentRequirement requirement : requirements )
88          {
89              if ( requirement.getRole().equals( "c2" ) )
90              {
91                  containsC2 = true;
92              }
93              else if ( requirement.getRole().equals( "c3" ) )
94              {
95                  containsC3 = true;
96              }
97  
98          }
99  
100         assertTrue( containsC2 );
101 
102         assertTrue( containsC3 );
103 
104         ComponentDependency d1 = cs.getDependencies().get( 0 );
105 
106         assertEquals( "plexus", d1.getGroupId() );
107 
108         assertEquals( "wedgy", d1.getArtifactId() );
109 
110         assertEquals( "1.0", d1.getVersion() );
111     }
112 }