1 17 package org.apache.tools.ant.taskdefs; 18 19 20 import org.apache.tools.ant.BuildFileTest; 21 import org.apache.tools.ant.util.FileUtils; 22 23 import java.io.File ; 24 import java.io.FileReader ; 25 import java.io.IOException ; 26 import java.io.Reader ; 27 import java.io.FileWriter ; 28 29 30 34 public class StyleTest extends BuildFileTest { 35 36 public StyleTest(String s) { 37 super(s); 38 } 39 40 protected void setUp() throws Exception { 41 configureProject("src/etc/testcases/taskdefs/style/build.xml"); 42 } 45 46 protected void tearDown() throws Exception { 47 executeTarget("teardown"); 48 } 49 50 public void testStyleIsSet() throws Exception { 51 expectBuildException("testStyleIsSet", "no stylesheet specified"); 52 } 53 54 public void testTransferParameterSet() throws Exception { 55 expectFileContains("testTransferParameterSet", "out/out.xml", "set='myvalue'"); } 59 60 public void testTransferParameterEmpty() throws Exception { 61 expectFileContains("testTransferParameterEmpty", 62 "out/out.xml", 63 "empty=''"); 64 } 65 66 public void testTransferParameterUnset() throws Exception { 67 expectFileContains("testTransferParameterUnset", 68 "out/out.xml", 69 "undefined='${value}'"); 70 } 71 72 public void testTransferParameterUnsetWithIf() throws Exception { 73 expectFileContains("testTransferParameterUnsetWithIf", 74 "out/out.xml", 75 "undefined='undefined default value'"); 76 } 77 78 public void testNewerStylesheet() throws Exception { 79 expectFileContains("testNewerStylesheet", 80 "out/out.xml", 81 "new-value"); 82 } 83 84 85 public void testDefaultMapper() throws Exception { 86 assertTrue(!getProject().resolveFile("out/data.html").exists()); 87 expectFileContains("testDefaultMapper", 88 "out/data.html", 89 "set='myvalue'"); 90 } 91 92 public void testCustomMapper() throws Exception { 93 assertTrue(!getProject().resolveFile("out/out.xml").exists()); 94 expectFileContains("testCustomMapper", 95 "out/out.xml", 96 "set='myvalue'"); 97 } 98 99 101 105 private String getFileString(String filename) 106 throws IOException 107 { 108 Reader r = null; 109 try { 110 r = new FileReader (getProject().resolveFile(filename)); 111 return FileUtils.newFileUtils().readFully(r); 112 } 113 finally { 114 try {r.close();} catch (Throwable ignore) {} 115 } 116 117 } 118 119 private String getFileString(String target, String filename) 120 throws IOException 121 { 122 executeTarget(target); 123 return getFileString(filename); 124 } 125 126 private void expectFileContains( 127 String target, String filename, String contains) 128 throws IOException 129 { 130 String content = getFileString(target, filename); 131 assertTrue( 132 "expecting file " + filename + " to contain " + 133 contains + 134 " but got " + content, content.indexOf(contains) > -1); 135 } 136 137 } 138 | Popular Tags |