001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.BuildFileTest;
022:
023: /**
024: * JUnit test for the Available task/condition.
025: */
026: public class AvailableTest extends BuildFileTest {
027:
028: public AvailableTest(String name) {
029: super (name);
030: }
031:
032: public void setUp() {
033: configureProject("src/etc/testcases/taskdefs/available.xml");
034: }
035:
036: // Nothing specified -> Fail
037: public void test1() {
038: expectBuildException("test1", "required argument not specified");
039: }
040:
041: // Only property specified -> Fail
042: public void test2() {
043: expectBuildException("test2", "required argument not specified");
044: }
045:
046: // Only file specified -> Fail
047: public void test3() {
048: expectBuildException("test3", "required argument not specified");
049: }
050:
051: // file doesn't exist -> property 'test' == null
052: public void test4() {
053: executeTarget("test4");
054: assertTrue(project.getProperty("test") == null);
055: }
056:
057: // file does exist -> property 'test' == 'true'
058: public void test5() {
059: executeTarget("test5");
060: assertEquals("true", project.getProperty("test"));
061: }
062:
063: // resource doesn't exist -> property 'test' == null
064: public void test6() {
065: executeTarget("test6");
066: assertTrue(project.getProperty("test") == null);
067: }
068:
069: // resource does exist -> property 'test' == 'true'
070: public void test7() {
071: executeTarget("test7");
072: assertEquals("true", project.getProperty("test"));
073: }
074:
075: // class doesn't exist -> property 'test' == null
076: public void test8() {
077: executeTarget("test8");
078: assertTrue(project.getProperty("test") == null);
079: }
080:
081: // class does exist -> property 'test' == 'true'
082: public void test9() {
083: executeTarget("test9");
084: assertEquals("true", project.getProperty("test"));
085: }
086:
087: // All three specified and all three exist -> true
088: public void test10() {
089: executeTarget("test10");
090: assertEquals("true", project.getProperty("test"));
091: }
092:
093: // All three specified but class missing -> null
094: public void test11() {
095: executeTarget("test11");
096: assertNull(project.getProperty("test"));
097: }
098:
099: // Specified property-name is "" -> true
100: public void test12() {
101: executeTarget("test12");
102: assertNull(project.getProperty("test"));
103: assertEquals("true", project.getProperty(""));
104: }
105:
106: // Specified file is "" -> invalid files do not exist
107: public void test13() {
108: executeTarget("test13");
109: assertNull(project.getProperty("test"));
110: }
111:
112: // Specified file is "" actually a directory, so it should pass
113: public void test13b() {
114: executeTarget("test13b");
115: assertEquals("true", project.getProperty("test"));
116: }
117:
118: // Specified resource is "" -> can such a thing exist?
119: /*
120: * returns non null IBM JDK 1.3 Linux
121: */
122: // public void test14() {
123: // executeTarget("test14");
124: // assertEquals(project.getProperty("test"), null);
125: // }
126: // Specified class is "" -> can not exist
127: public void test15() {
128: executeTarget("test15");
129: assertNull(project.getProperty("test"));
130: }
131:
132: // Specified dir is "" -> this is the current directory and should
133: // always exist
134: public void test16() {
135: executeTarget("test16");
136: assertEquals("true", project.getProperty("test"));
137: }
138:
139: // Specified dir is "../taskdefs" -> should exist since it's the
140: // location of the buildfile used...
141: public void test17() {
142: executeTarget("test17");
143: assertEquals("true", project.getProperty("test"));
144: }
145:
146: // Specified dir is "../this_dir_should_never_exist" -> null
147: public void test18() {
148: executeTarget("test18");
149: assertNull(project.getProperty("test"));
150: }
151:
152: // Invalid type specified
153: public void test19() {
154: expectBuildException("test19",
155: "Invalid value for type attribute.");
156: }
157:
158: // Core class that exists in system classpath is ignored
159: public void test20() {
160: executeTarget("test20");
161: assertNull(project.getProperty("test"));
162: }
163:
164: // Core class that exists in system classpath is ignored, but found in specified classpath
165: public void test21() {
166: executeTarget("test21");
167: assertEquals("true", project.getProperty("test"));
168: }
169:
170: // Core class that exists in system classpath is not ignored with ignoresystemclass="false"
171: public void test22() {
172: executeTarget("test22");
173: assertEquals("true", project.getProperty("test"));
174: }
175:
176: // Core class that exists in system classpath is not ignored with default ignoresystemclasses value
177: public void test23() {
178: executeTarget("test23");
179: assertEquals("true", project.getProperty("test"));
180: }
181:
182: // Class is found in specified classpath
183: public void test24() {
184: executeTarget("test24");
185: assertEquals("true", project.getProperty("test"));
186: }
187:
188: // File is not found in specified filepath
189: public void testSearchInPathNotThere() {
190: executeTarget("searchInPathNotThere");
191: assertNull(project.getProperty("test"));
192: }
193:
194: // File is not found in specified filepath
195: public void testSearchInPathIsThere() {
196: executeTarget("searchInPathIsThere");
197: assertEquals("true", project.getProperty("test"));
198: }
199:
200: // test when file begins with basedir twice
201: public void testDoubleBasedir() {
202: executeTarget("testDoubleBasedir");
203: }
204:
205: // test for searching parents
206: public void testSearchParents() {
207: executeTarget("search-parents");
208: }
209:
210: // test for not searching parents
211: public void testSearchParentsNot() {
212: executeTarget("search-parents-not");
213: }
214: }
|