KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2000-2002, 2004-2005 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
18 package org.apache.tools.ant.taskdefs;
19
20 import org.apache.tools.ant.BuildFileTest;
21 import org.apache.tools.ant.Project;
22 import org.apache.tools.ant.util.JavaEnvUtils;
23
24 /**
25  * JUnit test for the Available task/condition.
26  */

27 public class AvailableTest extends BuildFileTest {
28
29     public AvailableTest(String JavaDoc name) {
30         super(name);
31     }
32
33     public void setUp() {
34         configureProject("src/etc/testcases/taskdefs/available.xml");
35     }
36
37     // Nothing specified -> Fail
38
public void test1() {
39         expectBuildException("test1", "required argument not specified");
40     }
41
42     // Only property specified -> Fail
43
public void test2() {
44         expectBuildException("test2", "required argument not specified");
45     }
46
47     // Only file specified -> Fail
48
public void test3() {
49         expectBuildException("test3", "required argument not specified");
50     }
51
52     // file doesn't exist -> property 'test' == null
53
public void test4() {
54         executeTarget("test4");
55         assertTrue(project.getProperty("test") == null);
56     }
57
58     // file does exist -> property 'test' == 'true'
59
public void test5() {
60         executeTarget("test5");
61         assertEquals("true", project.getProperty("test"));
62     }
63
64     // resource doesn't exist -> property 'test' == null
65
public void test6() {
66         executeTarget("test6");
67         assertTrue(project.getProperty("test") == null);
68     }
69
70     // resource does exist -> property 'test' == 'true'
71
public void test7() {
72         executeTarget("test7");
73         assertEquals("true", project.getProperty("test"));
74     }
75
76     // class doesn't exist -> property 'test' == null
77
public void test8() {
78         executeTarget("test8");
79         assertTrue(project.getProperty("test") == null);
80     }
81
82     // class does exist -> property 'test' == 'true'
83
public void test9() {
84         executeTarget("test9");
85         assertEquals("true", project.getProperty("test"));
86     }
87
88     // All three specified and all three exist -> true
89
public void test10() {
90         executeTarget("test10");
91         assertEquals("true", project.getProperty("test"));
92     }
93
94     // All three specified but class missing -> null
95
public void test11() {
96         executeTarget("test11");
97         assertNull(project.getProperty("test"));
98     }
99
100     // Specified property-name is "" -> true
101
public void test12() {
102         executeTarget("test12");
103         assertNull(project.getProperty("test"));
104         assertEquals("true", project.getProperty(""));
105     }
106
107     // Specified file is "" -> invalid files do not exist
108
public void test13() {
109         executeTarget("test13");
110         assertNull(project.getProperty("test"));
111     }
112
113     // Specified file is "" actually a directory, so it should pass
114
public void test13b() {
115         executeTarget("test13b");
116         assertEquals("true", project.getProperty("test"));
117     }
118
119     // Specified resource is "" -> can such a thing exist?
120
/*
121      * returns non null IBM JDK 1.3 Linux
122      */

123 // public void test14() {
124
// executeTarget("test14");
125
// assertEquals(project.getProperty("test"), null);
126
// }
127

128     // Specified class is "" -> can not exist
129
public void test15() {
130         executeTarget("test15");
131         assertNull(project.getProperty("test"));
132     }
133
134     // Specified dir is "" -> this is the current directory and should
135
// always exist
136
public void test16() {
137         executeTarget("test16");
138         assertEquals("true", project.getProperty("test"));
139     }
140
141     // Specified dir is "../taskdefs" -> should exist since it's the
142
// location of the buildfile used...
143
public void test17() {
144         executeTarget("test17");
145         assertEquals("true", project.getProperty("test"));
146     }
147
148     // Specified dir is "../this_dir_should_never_exist" -> null
149
public void test18() {
150         executeTarget("test18");
151         assertNull(project.getProperty("test"));
152     }
153
154     // Invalid type specified
155
public void test19() {
156         expectBuildException("test19", "Invalid value for type attribute.");
157     }
158
159     // Core class that exists in system classpath is ignored
160
public void test20() {
161         executeTarget("test20");
162         assertNull(project.getProperty("test"));
163     }
164
165     // Core class that exists in system classpath is ignored, but found in specified classpath
166
public void test21() {
167         executeTarget("test21");
168         assertEquals("true", project.getProperty("test"));
169     }
170
171     // Core class that exists in system classpath is not ignored with ignoresystemclass="false"
172
public void test22() {
173         executeTarget("test22");
174         assertEquals("true", project.getProperty("test"));
175     }
176
177     // Core class that exists in system classpath is not ignored with default ignoresystemclasses value
178
public void test23() {
179         executeTarget("test23");
180         assertEquals("true", project.getProperty("test"));
181     }
182
183     // Class is found in specified classpath
184
public void test24() {
185         executeTarget("test24");
186         assertEquals("true", project.getProperty("test"));
187     }
188
189     // File is not found in specified filepath
190
public void testSearchInPathNotThere() {
191         executeTarget("searchInPathNotThere");
192         assertNull(project.getProperty("test"));
193     }
194
195     // File is not found in specified filepath
196
public void testSearchInPathIsThere() {
197         executeTarget("searchInPathIsThere");
198         assertEquals("true", project.getProperty("test"));
199     }
200
201     // test when file begins with basedir twice
202
public void testDoubleBasedir() {
203         executeTarget("testDoubleBasedir");
204     }
205 }
206
Popular Tags