001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import java.io.BufferedReader;
022: import java.io.File;
023: import java.io.FileNotFoundException;
024: import java.io.FileReader;
025: import java.io.IOException;
026: import org.apache.tools.ant.BuildFileTest;
027:
028: /**
029: */
030: public class FilterTest extends BuildFileTest {
031:
032: public FilterTest(String name) {
033: super (name);
034: }
035:
036: public void setUp() {
037: configureProject("src/etc/testcases/taskdefs/filter.xml");
038: }
039:
040: public void tearDown() {
041: executeTarget("cleanup");
042: }
043:
044: public void test1() {
045: expectBuildException("test1", "required argument missing");
046: }
047:
048: public void test2() {
049: expectBuildException("test2", "required argument missing");
050: }
051:
052: public void test3() {
053: expectBuildException("test3", "required argument missing");
054: }
055:
056: public void test4() {
057: executeTarget("test4");
058: }
059:
060: public void test5() {
061: executeTarget("test5");
062: assertEquals("2000", getFilteredFile("5", "filtered.tmp"));
063: }
064:
065: public void test6() {
066: executeTarget("test6");
067: assertEquals("2000", getFilteredFile("6",
068: "taskdefs.tmp/filter1.txt"));
069: }
070:
071: public void test7() {
072: executeTarget("test7");
073: assertEquals("<%@ include file=\"root/some/include.jsp\"%>",
074: getFilteredFile("7", "filtered.tmp"));
075: }
076:
077: public void test8() {
078: executeTarget("test8");
079: assertEquals("<%@ include file=\"root/some/include.jsp\"%>",
080: getFilteredFile("8", "taskdefs.tmp/filter2.txt"));
081: }
082:
083: public void test9() {
084: executeTarget("test9");
085: assertEquals("included", getFilteredFile("9",
086: "taskdefs.tmp/filter3.txt"));
087: }
088:
089: private String getFilteredFile(String testNumber,
090: String filteredFile) {
091:
092: String line = null;
093: File f = new File(getProjectDir(), filteredFile);
094: if (!f.exists()) {
095: fail("filter test" + testNumber + " failed");
096: } else {
097: BufferedReader in = null;
098: try {
099: in = new BufferedReader(new FileReader(f));
100: } catch (FileNotFoundException fnfe) {
101: fail("filter test" + testNumber
102: + " failed, filtered file: " + f.toString()
103: + " not found");
104: }
105: try {
106: line = in.readLine();
107: in.close();
108: } catch (IOException ioe) {
109: fail("filter test"
110: + testNumber
111: + " failed. IOException while reading filtered file: "
112: + ioe);
113: }
114: }
115: f.delete();
116: return line;
117: }
118: }
|