aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/propertyhelper-test.xml
blob: f86342e1604c05261418f6c44c3823e0a28011d7 (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
<?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">
  <!-- each test verifies that the PropertyEvaluator delegate works -->
  <import file="../antunit-base.xml" />

  <condition property="prereqs-ok">
    <and>
      <available classname="org.apache.bsf.BSFManager"/>
      <available classname="bsh.util.BeanShellBSFEngine"/>
    </and>
  </condition>

  <target name="setUp" unless="setup.complete" if="prereqs-ok">
    <script language="beanshell" manager="bsf">
      import org.apache.tools.ant.PropertyHelper;
      public class MapEvaluator implements PropertyHelper.PropertyEvaluator {
        HashMap map = new HashMap();
        public MapEvaluator() {
          map.put("string", "string");
          map.put("object", new Object());
          map.put("int", new Integer(1));
          map.put("null", null);
        }
        public Object evaluate(String property, PropertyHelper propertyHelper) {
          return map.get(property.toLowerCase());
        }
      }
      project.addReference("mapEvaluator", new MapEvaluator());
    </script>
    <propertyhelper>
      <delegate refid="mapEvaluator" />
    </propertyhelper>
    <property name="setup.complete" value="true" />
  </target>

  <target name="testValueTypes" depends="setUp" if="prereqs-ok">
    <!-- verify BC, strings -->
    <au:assertPropertyEquals name="string" value="${STRING}" />

    <!-- verify non-string properties -->
    <au:assertPropertyEquals name="object" value="${OBJECT}" />
    <au:assertPropertyEquals name="int" value="${INT}" />

    <!-- verify that a string containing nothing but a property reference is a valid value -->
    <property name="string2" value="${string}" />
    <au:assertPropertyEquals name="string2" value="${string}" />

    <property name="object2" value="${object}" />
    <!-- demonstrate that equals args can be non-string -->
    <au:assertPropertyEquals name="object2" value="${object}" />

    <property name="int2" value="${int}" />
    <au:assertPropertyEquals name="int2" value="${int}" />
  </target>

  <target name="testNull" depends="setUp" if="prereqs-ok">
    <!-- demonstrate that a null value always implies a nonexistent property -->
    <au:assertFalse>
      <isset property="null" />
    </au:assertFalse>
  </target>

  <target name="testAvailable" depends="setUp" if="prereqs-ok">
    <!-- verify the available task can set a non-string property -->
    <available file="${ant.file}" type="file" property="available.string" value="bc" />
    <au:assertPropertyEquals name="available.string" value="bc" />
    <available file="${ant.file}" type="file" property="available.object" value="${object}" />
    <au:assertPropertyEquals name="available.object" value="${OBJECT}" />
  </target>

  <target name="testCondition" depends="setUp" if="prereqs-ok">
    <!-- verify the condition task can set a non-string property -->
    <echo>$${ant.file}=${ant.file}</echo>
    <condition property="condition.true.string">
      <available file="${ant.file}" type="file" />
    </condition>
    <au:assertPropertyEquals name="condition.true.string" value="true" />
    <condition property="condition.else.string" value="true" else="false">
      <not><available file="${ant.file}" type="file" /></not>
    </condition>
    <au:assertPropertyEquals name="condition.else.string" value="false" />
    <condition property="condition.true.object" value="${object}">
      <available file="${ant.file}" type="file" />
    </condition>
    <au:assertPropertyEquals name="condition.true.object" value="${OBJECT}" />
    <condition property="condition.else.int" value="${object}" else="${int}">
      <not><available file="${ant.file}" type="file" /></not>
    </condition>
    <au:assertPropertyEquals name="condition.else.int" value="${INT}" />
  </target>

  <target name="testEmbeddedNonString" if="prereqs-ok">
    <!-- verify that a property embedded in a string is a substring -->
    <au:assertTrue>
      <equals arg1="@${int}@" arg2="@1@" />
    </au:assertTrue>
  </target>

  <target name="XtestLoadPropertiesWithObjects" if="prereqs-ok" depends="setUp">
    <au:assertFalse>
      <isset property="object2" />
    </au:assertFalse>
    <string id="props" value="object2=$${object}" />
    <!-- verify the property is not yet expanded -->
    <au:assertTrue>
      <length length="17">
        <resource refid="props" />
      </length>
    </au:assertTrue>
    <loadproperties>
      <resource refid="props" />
    </loadproperties>
    <au:assertPropertyEquals name="object2" value="${object}" />
    <au:assertPropertyEquals name="object2" value="${OBJECT}" />
  </target>

  <target name="testLoadPropertiesWithStrings" if="prereqs-ok" depends="setUp">
    <au:assertFalse>
      <isset property="string2" />
    </au:assertFalse>
    <string id="props" value="string2=$${string}" />
    <!-- verify the property is not yet expanded -->
    <au:assertTrue>
      <length length="17">
        <resource refid="props" />
      </length>
    </au:assertTrue>
    <loadproperties>
      <resource refid="props" />
    </loadproperties>
    <au:assertPropertyEquals name="string2" value="${string}" />
    <au:assertPropertyEquals name="string2" value="${STRING}" />
  </target>

</project>