View Javadoc
1   /*
2    * Copyright (C) 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.codehaus.plexus.metadata.gleaner;
18  
19  import java.util.List;
20  
21  import org.codehaus.plexus.component.repository.ComponentDescriptor;
22  import org.codehaus.plexus.component.repository.ComponentRequirement;
23  import org.codehaus.plexus.configuration.PlexusConfiguration;
24  import org.codehaus.plexus.metadata.gleaner.ann.AnnotatedComponent;
25  import org.codehaus.plexus.metadata.gleaner.ann.AnnotatedComponentRole;
26  
27  import junit.framework.TestCase;
28  
29  /**
30   * @author Eugene Kuleshov
31   */
32  public class AnnotationComponentGleanerTest extends TestCase {
33  
34    public void testGlean() throws Exception {
35      AnnotationComponentGleaner gleaner = new AnnotationComponentGleaner();
36      Class<AnnotatedComponent> c = AnnotatedComponent.class;
37      ComponentDescriptor<?> descriptor = gleaner.glean(c.getName(), c.getClassLoader());
38      
39      assertEquals("foo", descriptor.getComponentType());
40      assertEquals(AnnotatedComponentRole.class.getName(), descriptor.getRole());
41      
42      List<ComponentRequirement> requirements = descriptor.getRequirements();
43      assertEquals(requirements.toString(), 2, requirements.size());
44  
45      ComponentRequirement requirement = requirements.get(0);
46      assertEquals("dependency", requirement.getFieldName());
47      assertEquals("default", requirement.getRoleHint());
48  
49      ComponentRequirement requirement2 = requirements.get(1);
50      assertEquals("dependency2", requirement2.getFieldName());
51      assertEquals("release,latest,snapshot", requirement2.getRoleHint());
52  
53      PlexusConfiguration configuration = descriptor.getConfiguration();
54      assertEquals(1, configuration.getChildCount());
55      PlexusConfiguration child = configuration.getChild(0);
56      assertEquals("param", child.getName());
57      assertEquals("value", child.getValue());
58    }
59  
60  }