KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > LoadFileTest


1 /*
2  * Copyright 2001-2002,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.tools.ant.taskdefs;
18
19 import org.apache.tools.ant.BuildFileTest;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.BuildException;
22 import java.io.File JavaDoc;
23
24 /**
25  * Test the load file task
26  *
27  * @created 10 December 2001
28  */

29 public class LoadFileTest extends BuildFileTest {
30
31     /**
32      * Constructor for the LoadFileTest object
33      *
34      * @param name Description of Parameter
35      */

36     public LoadFileTest(String JavaDoc name) {
37         super(name);
38     }
39
40
41     /**
42      * The JUnit setup method
43      */

44     public void setUp() {
45         configureProject("src/etc/testcases/taskdefs/loadfile.xml");
46     }
47
48
49     /**
50      * The teardown method for JUnit
51      */

52     public void tearDown() {
53         executeTarget("cleanup");
54     }
55
56
57     /**
58      * A unit test for JUnit
59      */

60     public void testNoSourcefileDefined() {
61         expectBuildException("testNoSourcefileDefined",
62                 "source file not defined");
63     }
64
65
66     /**
67      * A unit test for JUnit
68      */

69     public void testNoPropertyDefined() {
70         expectBuildException("testNoPropertyDefined",
71                 "output property not defined");
72     }
73
74
75     /**
76      * A unit test for JUnit
77      */

78     public void testNoSourcefilefound() {
79         expectBuildExceptionContaining("testNoSourcefilefound",
80                 "File not found",
81                 "Unable to load file");
82     }
83
84     /**
85      * A unit test for JUnit
86      */

87     public void testFailOnError()
88             throws BuildException {
89         expectPropertyUnset("testFailOnError","testFailOnError");
90     }
91
92
93     /**
94      * A unit test for JUnit
95      */

96     public void testLoadAFile()
97             throws BuildException {
98         executeTarget("testLoadAFile");
99         if(project.getProperty("testLoadAFile").indexOf("eh?")<0) {
100             fail("property is not all in the file");
101         }
102     }
103
104
105     /**
106      * A unit test for JUnit
107      */

108     public void testLoadAFileEnc()
109             throws BuildException {
110         executeTarget("testLoadAFileEnc");
111         if(project.getProperty("testLoadAFileEnc")==null) {
112             fail("file load failed");
113         }
114     }
115
116     /**
117      * A unit test for JUnit
118      */

119     public void testEvalProps()
120             throws BuildException {
121         executeTarget("testEvalProps");
122         if(project.getProperty("testEvalProps").indexOf("rain")<0) {
123             fail("property eval broken");
124         }
125     }
126
127     /**
128      * Test FilterChain and FilterReaders
129      */

130     public void testFilterChain()
131             throws BuildException {
132         executeTarget("testFilterChain");
133         if(project.getProperty("testFilterChain").indexOf("World!")<0) {
134             fail("Filter Chain broken");
135         }
136     }
137
138     /**
139      * Test StripJavaComments filterreader functionality.
140      */

141     public final void testStripJavaComments()
142             throws BuildException {
143         executeTarget("testStripJavaComments");
144         final String JavaDoc expected = project.getProperty("expected");
145         final String JavaDoc generated = project.getProperty("testStripJavaComments");
146         assertEquals(expected, generated);
147     }
148
149     /**
150      * A unit test for JUnit
151      */

152     public void testOneLine()
153             throws BuildException {
154             expectPropertySet("testOneLine","testOneLine","1,2,3,4");
155
156     }
157 }
158
Popular Tags