1 17 18 package org.apache.tools.ant.taskdefs; 19 20 import java.io.BufferedReader ; 21 import java.io.File ; 22 import java.io.FileNotFoundException ; 23 import java.io.FileReader ; 24 import java.io.IOException ; 25 import org.apache.tools.ant.BuildFileTest; 26 27 29 public class FilterTest extends BuildFileTest { 30 31 public FilterTest(String 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 getFilteredFile(String testNumber, String filteredFile) { 91 92 String line = null; 93 File f = new File (getProjectDir(), filteredFile); 94 if (!f.exists()) { 95 fail("filter test"+testNumber+" failed"); 96 } else { 97 BufferedReader in = null; 98 try { 99 in = new BufferedReader (new FileReader (f)); 100 } catch (FileNotFoundException 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 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 |