source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.4 KB
Line 
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 */
17package org.apache.tools.ant.taskdefs;
18
19
20import org.apache.tools.ant.BuildFileTest;
21import org.apache.tools.ant.util.FileUtils;
22
23import java.io.File;
24import java.io.FileReader;
25import java.io.IOException;
26import java.io.Reader;
27import java.io.FileWriter;
28
29
30/**
31 * TestCases for <style> / <xslt> task.
32 * @version 2003-08-05
33 */
34public 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 //executeTarget("setup");
43 //commented out for performance while target is empty
44 }
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", // target
56 "out/out.xml", // file
57 "set='myvalue'"); // exptected string
58 }
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 // ************* copied from ConcatTest *************
100
101 // ------------------------------------------------------
102 // Helper methods - should be in BuildFileTest
103 // -----------------------------------------------------
104
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}
Note: See TracBrowser for help on using the repository browser.