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: import org.apache.tools.ant.BuildException;
023: import org.apache.tools.ant.util.FileUtils;
024:
025: /**
026: */
027: public class PropertyTest extends BuildFileTest {
028:
029: /** Utilities used for file operations */
030: private static final FileUtils FILE_UTILS = FileUtils
031: .getFileUtils();
032:
033: public PropertyTest(String name) {
034: super (name);
035: }
036:
037: public void setUp() {
038: configureProject("src/etc/testcases/taskdefs/property.xml");
039: }
040:
041: public void test1() {
042: // should get no output at all
043: expectOutputAndError("test1", "", "");
044: }
045:
046: public void test2() {
047: expectLog("test2",
048: "testprop1=aa, testprop3=xxyy, testprop4=aazz");
049: }
050:
051: public void test3() {
052: try {
053: executeTarget("test3");
054: } catch (BuildException e) {
055: assertTrue(
056: "Circular definition not detected - ",
057: e.getMessage().indexOf("was circularly defined") != -1);
058: return;
059: }
060: fail("Did not throw exception on circular exception");
061: }
062:
063: public void test4() {
064: expectLog("test4", "http.url is http://localhost:999");
065: }
066:
067: public void test5() {
068: String baseDir = getProject().getProperty("basedir");
069: try {
070: String uri = FILE_UTILS.toURI(baseDir
071: + "/property3.properties");
072: getProject().setNewProperty("test5.url", uri);
073: } catch (Exception ex) {
074: throw new BuildException(ex);
075: }
076: expectLog("test5", "http.url is http://localhost:999");
077: }
078:
079: public void testPrefixSuccess() {
080: executeTarget("prefix.success");
081: assertEquals("80", project.getProperty("server1.http.port"));
082: }
083:
084: public void testPrefixFailure() {
085: try {
086: executeTarget("prefix.fail");
087: } catch (BuildException e) {
088: assertTrue("Prefix allowed on non-resource/file load - ", e
089: .getMessage().indexOf("Prefix is only valid") != -1);
090: return;
091: }
092: fail("Did not throw exception on invalid use of prefix");
093: }
094:
095: public void testCircularReference() {
096: try {
097: executeTarget("testCircularReference");
098: } catch (BuildException e) {
099: assertTrue(
100: "Circular definition not detected - ",
101: e.getMessage().indexOf("was circularly defined") != -1);
102: return;
103: }
104: fail("Did not throw exception on circular exception");
105: }
106:
107: public void testThisIsNotACircularReference() {
108: expectLog("thisIsNotACircularReference", "b is A/A/A");
109: }
110:
111: }
|