1 package org.apache.maven.plugin.ant;
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.testing.AbstractMojoTestCase;
23 import org.apache.maven.project.MavenProject;
24
25 import java.io.File;
26 import java.io.FileInputStream;
27 import java.util.Properties;
28
29
30
31
32
33
34
35 public class AntMojoTest
36 extends AbstractMojoTestCase
37 {
38
39
40
41 protected void setUp()
42 throws Exception
43 {
44
45 super.setUp();
46 }
47
48
49
50
51 protected void tearDown()
52 throws Exception
53 {
54
55 }
56
57
58
59
60
61
62 public void testDefaultProject()
63 throws Exception
64 {
65 invokeAntMojo( "ant-test" );
66 }
67
68
69
70
71
72
73 public void testProjectWithNoDep()
74 throws Exception
75 {
76 invokeAntMojo( "ant-nodep-test" );
77 }
78
79
80
81
82
83
84 public void testProjectWithJavadoc()
85 throws Exception
86 {
87 invokeAntMojo( "ant-javadoc-test" );
88 }
89
90
91
92
93
94
95
96
97
98
99
100 private void invokeAntMojo( String testProject )
101 throws Exception
102 {
103 File testPom = new File( getBasedir(), "src/test/resources/unit/" + testProject + "/pom.xml" );
104 AntMojo mojo = (AntMojo) lookupMojo( "ant", testPom );
105 mojo.execute();
106
107 MavenProject currentProject = (MavenProject) getVariableValueFromObject( mojo, "project" );
108
109 File antBasedir = new File( getBasedir(), "target/test/unit/" + testProject + "/" );
110 File antBuild = new File( antBasedir, AntBuildWriter.DEFAULT_BUILD_FILENAME );
111 assertTrue( antBuild.exists() );
112 if ( !currentProject.getPackaging().toLowerCase().equals( "pom" ) )
113 {
114 File antProperties = new File( antBasedir, AntBuildWriter.DEFAULT_MAVEN_PROPERTIES_FILENAME );
115 assertTrue( antProperties.exists() );
116 }
117
118 AntWrapper.invoke( antBuild );
119
120 if ( !currentProject.getPackaging().toLowerCase().equals( "pom" ) )
121 {
122 assertTrue( new File( antBasedir, "target" ).exists() );
123 assertTrue( new File( antBasedir, "target/classes" ).exists() );
124 assertTrue(
125 new File( antBasedir, "target/" + currentProject.getBuild().getFinalName() + ".jar" ).exists() );
126
127 Properties properties = new Properties();
128 properties.load(
129 new FileInputStream( new File( antBasedir, AntBuildWriter.DEFAULT_MAVEN_PROPERTIES_FILENAME ) ) );
130 String repo = properties.getProperty( "maven.repo.local" );
131 assertTrue( repo.equals( new File( getBasedir(), "target/local-repo" ).getAbsolutePath() ) );
132 }
133 }
134 }