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