KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2000-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
18 package org.apache.tools.ant.taskdefs;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.File JavaDoc;
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.FileReader JavaDoc;
24 import java.io.IOException JavaDoc;
25 import org.apache.tools.ant.BuildFileTest;
26
27 /**
28  */

29 public class FilterTest extends BuildFileTest {
30
31     public FilterTest(String JavaDoc name) {
32         super(name);
33     }
34
35     public void setUp() {
36         configureProject("src/etc/testcases/taskdefs/filter.xml");
37     }
38
39     public void tearDown() {
40         executeTarget("cleanup");
41     }
42
43     public void test1() {
44         expectBuildException("test1", "required argument missing");
45     }
46
47     public void test2() {
48         expectBuildException("test2", "required argument missing");
49     }
50
51     public void test3() {
52         expectBuildException("test3", "required argument missing");
53     }
54
55     public void test4() {
56         executeTarget("test4");
57     }
58
59     public void test5() {
60         executeTarget("test5");
61         assertEquals("2000",
62                      getFilteredFile("5", "filtered.tmp"));
63     }
64
65
66     public void test6() {
67         executeTarget("test6");
68         assertEquals("2000",
69                      getFilteredFile("6", "taskdefs.tmp/filter1.txt"));
70     }
71
72     public void test7() {
73         executeTarget("test7");
74         assertEquals("<%@ include file=\"root/some/include.jsp\"%>",
75                      getFilteredFile("7", "filtered.tmp"));
76     }
77
78     public void test8() {
79         executeTarget("test8");
80         assertEquals("<%@ include file=\"root/some/include.jsp\"%>",
81                      getFilteredFile("8", "taskdefs.tmp/filter2.txt"));
82     }
83
84     public void test9() {
85         executeTarget("test9");
86         assertEquals("included",
87                     getFilteredFile("9", "taskdefs.tmp/filter3.txt"));
88     }
89
90     private String JavaDoc getFilteredFile(String JavaDoc testNumber, String JavaDoc filteredFile) {
91
92         String JavaDoc line = null;
93         File JavaDoc f = new File JavaDoc(getProjectDir(), filteredFile);
94         if (!f.exists()) {
95             fail("filter test"+testNumber+" failed");
96         } else {
97             BufferedReader JavaDoc in = null;
98             try {
99                 in = new BufferedReader JavaDoc(new FileReader JavaDoc(f));
100             } catch (FileNotFoundException JavaDoc fnfe) {
101                 fail("filter test"+testNumber+" failed, filtered file: " + f.toString() + " not found");
102             }
103             try {
104                 line = in.readLine();
105                 in.close();
106             } catch (IOException JavaDoc ioe) {
107                 fail("filter test"+testNumber+" failed. IOException while reading filtered file: " + ioe);
108             }
109         }
110         f.delete();
111         return line;
112     }
113 }
114
Popular Tags