KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2003-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
20 import org.apache.tools.ant.BuildFileTest;
21 import org.apache.tools.ant.util.FileUtils;
22
23 import java.io.File JavaDoc;
24 import java.io.FileReader JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.Reader JavaDoc;
27 import java.io.FileWriter JavaDoc;
28
29
30 /**
31  * TestCases for <style> / <xslt> task.
32  * @version 2003-08-05
33  */

34 public class StyleTest extends BuildFileTest {
35
36     public StyleTest(String JavaDoc s) {
37         super(s);
38     }
39
40     protected void setUp() throws Exception JavaDoc {
41         configureProject("src/etc/testcases/taskdefs/style/build.xml");
42         //executeTarget("setup");
43
//commented out for performance while target is empty
44
}
45
46     protected void tearDown() throws Exception JavaDoc {
47         executeTarget("teardown");
48     }
49
50     public void testStyleIsSet() throws Exception JavaDoc {
51         expectBuildException("testStyleIsSet", "no stylesheet specified");
52     }
53
54     public void testTransferParameterSet() throws Exception JavaDoc {
55         expectFileContains("testTransferParameterSet", // target
56
"out/out.xml", // file
57
"set='myvalue'"); // exptected string
58
}
59
60     public void testTransferParameterEmpty() throws Exception JavaDoc {
61         expectFileContains("testTransferParameterEmpty",
62                            "out/out.xml",
63                            "empty=''");
64     }
65
66     public void testTransferParameterUnset() throws Exception JavaDoc {
67         expectFileContains("testTransferParameterUnset",
68                            "out/out.xml",
69                            "undefined='${value}'");
70     }
71
72     public void testTransferParameterUnsetWithIf() throws Exception JavaDoc {
73         expectFileContains("testTransferParameterUnsetWithIf",
74                            "out/out.xml",
75                            "undefined='undefined default value'");
76     }
77
78     public void testNewerStylesheet() throws Exception JavaDoc {
79         expectFileContains("testNewerStylesheet",
80                            "out/out.xml",
81                            "new-value");
82     }
83
84
85     public void testDefaultMapper() throws Exception JavaDoc {
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 JavaDoc {
93         assertTrue(!getProject().resolveFile("out/out.xml").exists());
94         expectFileContains("testCustomMapper",
95                            "out/out.xml",
96                            "set='myvalue'");
97     }
98
99     // ************* copied from ConcatTest *************
100

101     // ------------------------------------------------------
102
// Helper methods - should be in BuildFileTest
103
// -----------------------------------------------------
104

105     private String JavaDoc getFileString(String JavaDoc filename)
106         throws IOException JavaDoc
107     {
108         Reader JavaDoc r = null;
109         try {
110             r = new FileReader JavaDoc(getProject().resolveFile(filename));
111             return FileUtils.newFileUtils().readFully(r);
112         }
113         finally {
114             try {r.close();} catch (Throwable JavaDoc ignore) {}
115         }
116
117     }
118
119     private String JavaDoc getFileString(String JavaDoc target, String JavaDoc filename)
120         throws IOException JavaDoc
121     {
122         executeTarget(target);
123         return getFileString(filename);
124     }
125
126     private void expectFileContains(
127         String JavaDoc target, String JavaDoc filename, String JavaDoc contains)
128         throws IOException JavaDoc
129     {
130         String JavaDoc 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