aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xslt-test.xml
blob: d6f6d668640d728dc111c2ef98e74e6d9bce4098 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
  <import file="../antunit-base.xml" />

  <target name="setUp">
    <mkdir dir="${output}"/>
    <property name="legacy.dir"
              location="../../../etc/testcases/taskdefs/style/"/>
  </target>

  <target name="testParameterPropagation" depends="setUp">
    <xslt in="${legacy.dir}/data.xml"
          out="${output}/out.xml"
          style="${legacy.dir}/printParams.xsl">
      <param name="set" expression="myvalue"/>
    </xslt>
    <au:assertResourceContains
       resource="${output}/out.xml"
       value="set='myvalue'"/>
  </target>
  
  <target name="testParameterTypes" depends="setUp" description="parameters of various data types and XPath expressions">

    <property name="antProperty1" value="ANT_PROPERTY_1"/>
    <property name="antProperty2" value="ANT_PROPERTY_2"/>
    <property name="antProperty3" value="3"/>
    <property name="antProperty4" value="substring-before"/>
    
    <xslt in="${legacy.dir}/data.xml"
          out="${output}/out.xml">
      <param name="p1" expression="123" type="INT"/>
      <param name="p2" expression="64 * 64 div 128 + 10" type="XPATH_NUMBER"/>
      <param name="p3" expression="${antProperty4}($antProperty2, '_')" type="XPATH_STRING"/>
      
      <style>
        <string><![CDATA[<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format">

<!-- get the xsl-parameter -->
<xsl:param name="p1"/>
<xsl:param name="p2"/>
<xsl:param name="p3"/>

<!-- use the xsl-parameter -->
<xsl:template match="/">
p1_result='<xsl:value-of select="$p1 + 321"/>'
p2_result='<xsl:value-of select="$p2"/>'
p3_result='<xsl:value-of select="$p3"/>'
</xsl:template>

</xsl:stylesheet>
]]></string>
      </style>
    </xslt>
    <au:assertResourceContains resource="${output}/out.xml" value="p1_result='444'"/>
    <au:assertResourceContains resource="${output}/out.xml" value="p2_result='42'"/>
    <au:assertResourceContains resource="${output}/out.xml" value="p3_result='ANT'"/>
  </target>

  <target name="testInlineStyleSheet" depends="setUp">
    <xslt in="${legacy.dir}/data.xml"
          out="${output}/out.xml">
      <param name="set" expression="somevalue"/>
      <style>
        <string><![CDATA[<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format">

<!-- get the xsl-parameter -->
<xsl:param name="set">set default value</xsl:param>
<xsl:param name="empty">empty default value</xsl:param>
<xsl:param name="undefined">undefined default value</xsl:param>

<!-- use the xsl-parameter -->
<xsl:template match="/">
set='<xsl:value-of select="$set"/>'
empty='<xsl:value-of select="$empty"/>'
undefined='<xsl:value-of select="$undefined"/>'
</xsl:template>

</xsl:stylesheet>
]]></string>
      </style>
    </xslt>
    <au:assertResourceContains
       resource="${output}/out.xml"
       value="set='somevalue'"/>
  </target>

  <target name="testStyleDoesntExist" depends="setUp">
    <au:expectfailure expectedmessage="i-m-not-there.xslt doesn't exist.">
      <xslt in="${legacy.dir}/data.xml"
            out="${output}/out.xml"
            style="i-m-not-there.xslt"/>
    </au:expectfailure>
  </target>

  <target name="testStyleDoesntExistNoError" depends="setUp">
    <xslt in="${legacy.dir}/data.xml"
          out="${output}/out.xml"
          style="i-m-not-there.xslt"
          failOnError="false"/>
    <au:assertFileDoesntExist file="${output}/out.xml"/>
  </target>

  <target name="testStyleDoesntExistNoTransformationError" depends="setUp">
    <au:expectfailure expectedmessage="i-m-not-there.xslt doesn't exist.">
      <xslt in="${legacy.dir}/data.xml"
            out="${output}/out.xml"
            style="i-m-not-there.xslt"
            failOnTransformationError="false"/>
    </au:expectfailure>
  </target>

  <target name="testTransformationError" depends="setUp">
    <au:expectfailure expectedmessage="Fatal error during transformation">
      <xslt in="${legacy.dir}/data.xml"
            out="${output}/out.xml"
            style="xslt/printParams-invalid.xsl"
            />
    </au:expectfailure>
  </target>

  <target name="testTransformationErrorNoFail" depends="setUp">
    <xslt in="${legacy.dir}/data.xml"
          out="${output}/out.xml"
          style="xslt/printParams-invalid.xsl"
          failOnError="false"/>
    <au:assertFileDoesntExist file="${output}/out.xml"/>
  </target>

  <target name="testTransformationErrorNoFailOnTransformation" depends="setUp">
    <xslt in="${legacy.dir}/../input.stdin"
          out="${output}/out.xml"
          style="${legacy.dir}/printParams.xsl"
          failOnTransformationError="false"/>
    <au:assertFileDoesntExist file="${output}/out.xml"/>
  </target>

  <target name="testNoResources" depends="setUp">
    <au:expectfailure expectedmessage="no resources specified">
      <xslt destdir="${output}" style="${legacy.dir}/printParams.xsl"
            useImplicitFileset="false">
        <fileset dir=".">
          <include name="I don't exist"/>
        </fileset>
      </xslt>
    </au:expectfailure>
  </target>

  <target name="testNoResourcesNoFail" depends="setUp">
    <xslt destdir="${output}" style="${legacy.dir}/printParams.xsl"
          useImplicitFileset="false"
          failOnNoResources="false">
      <fileset dir=".">
        <include name="I don't exist"/>
      </fileset>
    </xslt>
  </target>

  <target name="testNoResourcesNoError" depends="setUp">
    <xslt destdir="${output}" style="${legacy.dir}/printParams.xsl"
          useImplicitFileset="false"
          failOnError="false">
      <fileset dir=".">
        <include name="I don't exist"/>
      </fileset>
    </xslt>
  </target>


  <target name="testTraceJdk14" unless="jdk1.5+" depends="setUp">
    <xslt in="${legacy.dir}/data.xml"
          out="${output}/out.xml"
          style="${legacy.dir}/printParams.xsl">
      <param name="set" expression="myvalue"/>
      <trace templates="true"/>
    </xslt>
    <au:assertLogContains text="Failed to enable tracing" level="warning"/>
  </target>

  <target name="testTraceJdk15+" if="jdk1.5+" depends="setUp">
    <xslt in="${legacy.dir}/data.xml"
          out="${output}/out.xml"
          style="${legacy.dir}/printParams.xsl">
      <param name="set" expression="myvalue"/>
      <trace templates="true" elements="true" generation="true"
             selection="true" extension="true"/>
    </xslt>
    <au:assertLogDoesntContain text="Failed to enable tracing"/>
  </target>

  <target name="setUpIfUnlessTests" depends="setUp">
    <macrodef name="xs">
      <sequential>
        <xslt in="${legacy.dir}/data.xml" out="${output}/out.xml"
              style="${legacy.dir}/printParams.xsl">
          <param name="set" expression="if-value" if="${if}"/>
          <param name="set" expression="unless-value" unless="${if}"/>
          <param name="empty" expression="if-value" if="if"/>
          <param name="empty" expression="unless-value" unless="if"/>
        </xslt>
      </sequential>
    </macrodef>
  </target>

  <target name="testPropertiesNotSet" depends="setUpIfUnlessTests">
    <xs/>
    <au:assertResourceContains resource="${output}/out.xml"
                               value="set='unless-value'"/>
    <au:assertResourceContains resource="${output}/out.xml"
                               value="empty='unless-value'"/>
  </target>

  <target name="testPropertiesSet" depends="setUpIfUnlessTests">
    <property name="if" value="whatever"/>
    <xs/>
    <au:assertResourceContains resource="${output}/out.xml"
                               value="set='unless-value'"/>
    <au:assertResourceContains resource="${output}/out.xml"
                               value="empty='if-value'"/>
  </target>

  <target name="testIfTrue" depends="setUpIfUnlessTests">
    <property name="if" value="true"/>
    <xs/>
    <au:assertResourceContains resource="${output}/out.xml"
                               value="set='if-value'"/>
    <au:assertResourceContains resource="${output}/out.xml"
                               value="empty='if-value'"/>
  </target>

  <target name="testIfFalse" depends="setUpIfUnlessTests">
    <property name="if" value="false"/>
    <xs/>
    <au:assertResourceContains resource="${output}/out.xml"
                               value="set='unless-value'"/>
    <au:assertResourceContains resource="${output}/out.xml"
                               value="empty='if-value'"/>
  </target>
</project>