KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > tools > plugin > util > PluginUtilsTest


1 package org.apache.maven.tools.plugin.util;
2
3 import org.apache.maven.plugin.descriptor.PluginDescriptor;
4 import org.codehaus.plexus.component.repository.ComponentDependency;
5 import org.codehaus.plexus.util.xml.CompactXMLWriter;
6 import org.codehaus.plexus.util.xml.XMLWriter;
7
8 import java.io.StringWriter JavaDoc;
9 import java.util.Collections JavaDoc;
10
11 import junit.framework.TestCase;
12
13 /**
14  * @author jdcasey
15  */

16 public class PluginUtilsTest
17     extends TestCase
18 {
19
20     public void testShouldTrimArtifactIdToFindPluginId()
21     {
22         assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-artifactId-plugin" ) );
23         assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-plugin-artifactId" ) );
24         assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId-maven-plugin" ) );
25         assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId" ) );
26         assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId-plugin" ) );
27         assertEquals( "plugin", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-plugin-plugin" ) );
28     }
29
30     public void testShouldWriteDependencies()
31         throws Exception JavaDoc
32     {
33         ComponentDependency dependency = new ComponentDependency();
34         dependency.setArtifactId( "testArtifactId" );
35         dependency.setGroupId( "testGroupId" );
36         dependency.setType( "pom" );
37         dependency.setVersion( "0.0.0" );
38         
39         PluginDescriptor descriptor = new PluginDescriptor();
40         descriptor.setDependencies( Collections.singletonList( dependency ) );
41
42         StringWriter JavaDoc sWriter = new StringWriter JavaDoc();
43         XMLWriter writer = new CompactXMLWriter( sWriter );
44
45         PluginUtils.writeDependencies( writer, descriptor );
46
47         String JavaDoc output = sWriter.toString();
48
49         String JavaDoc pattern = "<dependencies>" + "<dependency>" + "<groupId>testGroupId</groupId>" +
50             "<artifactId>testArtifactId</artifactId>" + "<type>pom</type>" + "<version>0.0.0</version>" +
51             "</dependency>" + "</dependencies>";
52
53         assertEquals( pattern, output );
54     }
55
56     public void testShouldFindTwoScriptsWhenNoExcludesAreGiven()
57     {
58         String JavaDoc testScript = "test.txt";
59
60         String JavaDoc basedir = TestUtils.dirname( testScript );
61
62         String JavaDoc includes = "**/*.txt";
63
64         String JavaDoc[] files = PluginUtils.findSources( basedir, includes );
65         assertEquals( 2, files.length );
66     }
67
68     public void testShouldFindOneScriptsWhenAnExcludeIsGiven()
69     {
70         String JavaDoc testScript = "test.txt";
71
72         String JavaDoc basedir = TestUtils.dirname( testScript );
73
74         String JavaDoc includes = "**/*.txt";
75         String JavaDoc excludes = "**/*Excludes.txt";
76
77         String JavaDoc[] files = PluginUtils.findSources( basedir, includes, excludes );
78         assertEquals( 1, files.length );
79     }
80
81 }
Popular Tags