1 package org.apache.maven.plugin.tools.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.descriptor.MojoDescriptor;
23 import org.codehaus.plexus.util.StringUtils;
24
25 import java.io.File;
26 import java.net.URL;
27 import java.util.Set;
28
29 import junit.framework.TestCase;
30
31 public class PluginMetadataParserTest
32 extends TestCase
33 {
34
35 public void testBasicDeclarationWithoutCall()
36 throws PluginMetadataParseException
37 {
38 File metadataFile = getMetadataFile( "test.mojos.xml" );
39 Set descriptors = new PluginMetadataParser().parseMojoDescriptors( metadataFile );
40
41 assertEquals( 1, descriptors.size() );
42
43 MojoDescriptor desc = (MojoDescriptor) descriptors.iterator().next();
44 assertTrue( desc.getImplementation().indexOf( ":" ) < 0 );
45 assertEquals( "test", desc.getGoal() );
46 }
47
48 public void testBasicDeclarationWithCall()
49 throws PluginMetadataParseException
50 {
51 File metadataFile = getMetadataFile( "test2.mojos.xml" );
52 Set descriptors = new PluginMetadataParser().parseMojoDescriptors( metadataFile );
53
54 assertEquals( 1, descriptors.size() );
55
56 MojoDescriptor desc = (MojoDescriptor) descriptors.iterator().next();
57 assertTrue( desc.getImplementation().endsWith( ":test2" ) );
58 assertEquals( "test2", desc.getGoal() );
59 }
60
61 private File getMetadataFile( String name )
62 {
63 URL resource = Thread.currentThread().getContextClassLoader().getResource( name );
64 if ( resource == null )
65 {
66 fail( "Cannot find classpath resource: '" + name + "'." );
67 }
68
69 return new File( StringUtils.replace( resource.getPath(), "%20", " " ) );
70 }
71
72 }