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 ; 9 import java.util.Collections ; 10 11 import junit.framework.TestCase; 12 13 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 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 sWriter = new StringWriter (); 43 XMLWriter writer = new CompactXMLWriter( sWriter ); 44 45 PluginUtils.writeDependencies( writer, descriptor ); 46 47 String output = sWriter.toString(); 48 49 String 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 testScript = "test.txt"; 59 60 String basedir = TestUtils.dirname( testScript ); 61 62 String includes = "**/*.txt"; 63 64 String [] files = PluginUtils.findSources( basedir, includes ); 65 assertEquals( 2, files.length ); 66 } 67 68 public void testShouldFindOneScriptsWhenAnExcludeIsGiven() 69 { 70 String testScript = "test.txt"; 71 72 String basedir = TestUtils.dirname( testScript ); 73 74 String includes = "**/*.txt"; 75 String excludes = "**/*Excludes.txt"; 76 77 String [] files = PluginUtils.findSources( basedir, includes, excludes ); 78 assertEquals( 1, files.length ); 79 } 80 81 } | Popular Tags |