01: package org.codehaus.groovy.ant;
02:
03: import java.io.File;
04:
05: import org.apache.tools.ant.BuildException;
06: import org.apache.tools.ant.Project;
07: import org.apache.tools.ant.ProjectHelper;
08:
09: 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(
21: "src/test/org/codehaus/groovy/ant/GroovyTest.xml");
22: private Project project;
23:
24: protected void setUp() throws Exception {
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: project.executeTarget("groovyClasspath_missing");
53: fail();
54: } catch (final Exception e) {
55: assertEquals(BuildException.class, e.getClass());
56: }
57:
58: }
59:
60: public void testClasspath_classpathAttribute() {
61: assertNull(FLAG);
62: project.executeTarget("groovyClasspath_classpathAttribute");
63: assertEquals("from groovytest3.GroovyTest3Class.doSomething()",
64: FLAG);
65: }
66:
67: public void testClasspath_classpathrefAttribute() {
68: assertNull(FLAG);
69: project.executeTarget("groovyClasspath_classpathrefAttribute");
70: assertEquals("from groovytest3.GroovyTest3Class.doSomething()",
71: FLAG);
72: }
73:
74: public void testClasspath_nestedclasspath() {
75: assertNull(FLAG);
76: project.executeTarget("groovyClasspath_nestedClasspath");
77: assertEquals("from groovytest3.GroovyTest3Class.doSomething()",
78: FLAG);
79: }
80: }
|