1 package org.codehaus.groovy.ant;
2
3 import java.io.File;
4
5 import org.apache.tools.ant.BuildException;
6 import org.apache.tools.ant.Project;
7 import org.apache.tools.ant.ProjectHelper;
8
9 import groovy.util.GroovyTestCase;
10
11 /***
12 * Unit tests for the {@link Groovy} ant task.
13 * Caution: the *.groovy files used by this test should not get compiled with the rest of the
14 * test classes compilation process otherwiser they would be available in the classpath
15 * and the tests here would be meaningless (tested by testClasspath_missing).
16 * @author Marc Guillemot
17 */
18 public class GroovyTest extends GroovyTestCase {
19 public static String FLAG = null;
20 private final File antFile = new File("src/test/org/codehaus/groovy/ant/GroovyTest.xml");
21 private Project project;
22
23 protected void setUp() throws Exception
24 {
25 super.setUp();
26 project = new Project();
27 project.init();
28 ProjectHelper.getProjectHelper().parse(project, antFile);
29 FLAG = null;
30 }
31
32 public void testGroovyCodeWithinTag() {
33 assertNull(FLAG);
34 project.executeTarget("groovyCodeWithinTask");
35 assertEquals("from groovy inlined in ant", FLAG);
36 }
37
38 public void testGroovyCodeExternalFile() {
39 assertNull(FLAG);
40 project.executeTarget("groovyCodeInExternalFile");
41 assertEquals("from groovy file called from ant", FLAG);
42 }
43
44 public void testGroovyCodeInExternalFileWithOtherClass() {
45 assertNull(FLAG);
46 project.executeTarget("groovyCodeInExternalFileWithOtherClass");
47 assertEquals("from GroovyTest2Class.doSomething()", FLAG);
48 }
49
50 public void testClasspath_missing() {
51 try
52 {
53 project.executeTarget("groovyClasspath_missing");
54 fail();
55 }
56 catch (final Exception e)
57 {
58 assertEquals(BuildException.class, e.getClass());
59 }
60
61 }
62
63 public void testClasspath_classpathAttribute() {
64 assertNull(FLAG);
65 project.executeTarget("groovyClasspath_classpathAttribute");
66 assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG);
67 }
68
69 public void testClasspath_classpathrefAttribute() {
70 assertNull(FLAG);
71 project.executeTarget("groovyClasspath_classpathrefAttribute");
72 assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG);
73 }
74
75 public void testClasspath_nestedclasspath() {
76 assertNull(FLAG);
77 project.executeTarget("groovyClasspath_nestedClasspath");
78 assertEquals("from groovytest3.GroovyTest3Class.doSomething()", FLAG);
79 }
80 }