You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

loadproperties-test.xml 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  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. <project name="loadproperties-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
  17. <import file="../antunit-base.xml" />
  18. <target name="setUp">
  19. <mkdir dir="${input}" />
  20. <property name="properties.tmp" location="${input}/properties.tmp" />
  21. </target>
  22. <target name="test-basic">
  23. <loadproperties>
  24. <string>basic.foo=foo
  25. basic.bar=bar
  26. basic.baz=baz</string>
  27. </loadproperties>
  28. <au:assertPropertyEquals name="basic.foo" value="foo" />
  29. <au:assertPropertyEquals name="basic.bar" value="bar" />
  30. <au:assertPropertyEquals name="basic.baz" value="baz" />
  31. </target>
  32. <target name="test-xref">
  33. <loadproperties>
  34. <string>xref.foo=foo
  35. xref.bar=$${xref.foo}
  36. xref.baz=$${xref.bar}</string>
  37. </loadproperties>
  38. <au:assertPropertyEquals name="xref.foo" value="foo" />
  39. <au:assertPropertyEquals name="xref.bar" value="foo" />
  40. <au:assertPropertyEquals name="xref.baz" value="foo" />
  41. </target>
  42. <target name="test-xref-complex">
  43. <loadproperties>
  44. <string>xref-complex.a=$$
  45. xref-complex.b={
  46. xref-complex.c=}
  47. xref-complex.d=x
  48. xref-complex.e=$${xref-complex.a}$${xref-complex.b}xref-complex.d$${xref-complex.c}
  49. xref-complex.f=$${xref-complex.e}</string>
  50. </loadproperties>
  51. <au:assertPropertyEquals name="xref-complex.a" value="$$" />
  52. <au:assertPropertyEquals name="xref-complex.b" value="{" />
  53. <au:assertPropertyEquals name="xref-complex.c" value="}" />
  54. <au:assertPropertyEquals name="xref-complex.d" value="x" />
  55. <au:assertPropertyEquals name="xref-complex.e" value="$${xref-complex.d}" />
  56. <au:assertPropertyEquals name="xref-complex.f" value="$${xref-complex.d}" />
  57. </target>
  58. <target name="testEncoding"
  59. description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47382">
  60. <mkdir dir="${input}"/>
  61. <echo file="${input}/ebcdic.properties" encoding="Cp1047">
  62. a=Hello world in EBCDIC
  63. </echo>
  64. <loadproperties srcfile="${input}/ebcdic.properties" encoding="Cp1047"/>
  65. <au:assertPropertyEquals name="a" value="Hello world in EBCDIC"/>
  66. </target>
  67. <target name="testPrefixedProperties" depends="setUp">
  68. <property name="server" value="localhost"/>
  69. <echo file="${properties.tmp}">
  70. #http.@PORT@ = 90
  71. http.@PORT@ = 80
  72. http.@SERVER@ = ${server}
  73. </echo>
  74. <loadproperties srcFile="${properties.tmp}">
  75. <filterchain>
  76. <striplinecomments>
  77. <comment value="#"/>
  78. </striplinecomments>
  79. <prefixlines prefix="server1."/>
  80. <replacetokens>
  81. <token key="PORT" value="port"/>
  82. <token key="SERVER" value="server"/>
  83. </replacetokens>
  84. <expandproperties/>
  85. </filterchain>
  86. </loadproperties>
  87. <property name="server1.http.url"
  88. value="http://${server1.http.server}:${server1.http.port}"/>
  89. </target>
  90. <target name="testLineCommentsWithoutFiltering">
  91. <loadproperties>
  92. <string value="#foo=bar" />
  93. </loadproperties>
  94. <au:assertFalse>
  95. <isset property="foo" />
  96. </au:assertFalse>
  97. </target>
  98. <target name="testPrefixAttributeProperties">
  99. <loadproperties prefix="prefixFromAttribute.">
  100. <string>foo=foo
  101. bar=bar
  102. baz=${foo} ${bar}
  103. </string>
  104. </loadproperties>
  105. <au:assertTrue>
  106. <and>
  107. <equals arg1="foo" arg2="${prefixFromAttribute.foo}" />
  108. <equals arg1="bar" arg2="${prefixFromAttribute.bar}" />
  109. <equals arg1="foo bar" arg2="${prefixFromAttribute.baz}" />
  110. </and>
  111. </au:assertTrue>
  112. </target>
  113. <target name="testSelfContainedPrefixFilterFailure"
  114. description="Show why the prefix attribute is needed">
  115. <loadproperties>
  116. <string>foo=foo
  117. bar=bar
  118. baz=${foo} ${bar}
  119. </string>
  120. <filterchain>
  121. <prefixlines prefix="prefixFromFilter." />
  122. </filterchain>
  123. </loadproperties>
  124. <au:assertTrue>
  125. <and>
  126. <equals arg1="$${foo} $${bar}" arg2="${prefixFromFilter.baz}" />
  127. <isset property="prefixFromFilter." />
  128. </and>
  129. </au:assertTrue>
  130. </target>
  131. <target name="write properties.tmp" depends="setUp">
  132. <echo file="${properties.tmp}">
  133. #tpfr.a=a
  134. tpfr.a=A
  135. tpfr.b=b\
  136. e
  137. tpfr.c=@C@
  138. </echo>
  139. </target>
  140. <presetdef name="assertPropertiesFromResourceOkay">
  141. <au:assertTrue>
  142. <equals arg1="Abesea" arg2="${tpfr.a}${tpfr.b}${tpfr.c}" />
  143. </au:assertTrue>
  144. </presetdef>
  145. <target name="testPropertiesFromResource" depends="write properties.tmp">
  146. <loadproperties resource="properties.tmp" classpath="${input}">
  147. <filterchain>
  148. <replacetokens>
  149. <token key="C" value="sea"/>
  150. </replacetokens>
  151. </filterchain>
  152. </loadproperties>
  153. </target>
  154. <target name="testPropertiesFromFileSet" depends="write properties.tmp">
  155. <loadproperties>
  156. <fileset file="${properties.tmp}" />
  157. <filterchain>
  158. <replacetokens>
  159. <token key="C" value="sea"/>
  160. </replacetokens>
  161. </filterchain>
  162. </loadproperties>
  163. <assertPropertiesFromResourceOkay />
  164. </target>
  165. <target name="testLastPropertyWins">
  166. <loadproperties>
  167. <string>foo=foo
  168. foo=bar</string>
  169. </loadproperties>
  170. <au:assertTrue>
  171. <equals arg1="bar" arg2="${foo}" />
  172. </au:assertTrue>
  173. </target>
  174. </project>