1 17 18 package org.apache.tools.ant.taskdefs; 19 20 import java.net.URL ; 21 import java.io.File ; 22 23 import org.apache.tools.ant.BuildFileTest; 24 import org.apache.tools.ant.BuildException; 25 import org.apache.tools.ant.util.FileUtils; 26 27 29 public class PropertyTest extends BuildFileTest { 30 31 public PropertyTest(String name) { 32 super(name); 33 } 34 35 public void setUp() { 36 configureProject("src/etc/testcases/taskdefs/property.xml"); 37 } 38 39 public void test1() { 40 expectOutputAndError("test1", "", ""); 42 } 43 44 public void test2() { 45 expectLog("test2", "testprop1=aa, testprop3=xxyy, testprop4=aazz"); 46 } 47 48 public void test3() { 49 try { 50 executeTarget("test3"); 51 } 52 catch (BuildException e) { 53 assertEquals("Circular definition not detected - ", true, 54 e.getMessage().indexOf("was circularly defined") != -1); 55 return; 56 } 57 fail("Did not throw exception on circular exception"); 58 } 59 60 public void test4() { 61 expectLog("test4", "http.url is http://localhost:999"); 62 } 63 64 public void test5() { 65 String baseDir = getProject().getProperty("basedir"); 66 try { 67 String uri = FileUtils.newFileUtils().toURI( 68 baseDir + "/property3.properties"); 69 getProject().setNewProperty( 70 "test5.url", uri); 71 } catch (Exception ex) { 72 throw new BuildException(ex); 73 } 74 expectLog("test5", "http.url is http://localhost:999"); 75 } 76 77 public void testPrefixSuccess() { 78 executeTarget("prefix.success"); 79 assertEquals("80", project.getProperty("server1.http.port")); 80 } 81 82 public void testPrefixFailure() { 83 try { 84 executeTarget("prefix.fail"); 85 } 86 catch (BuildException e) { 87 assertEquals("Prefix allowed on non-resource/file load - ", true, 88 e.getMessage().indexOf("Prefix is only valid") != -1); 89 return; 90 } 91 fail("Did not throw exception on invalid use of prefix"); 92 } 93 94 public void testCircularReference() { 95 try { 96 executeTarget("testCircularReference"); 97 } catch (BuildException e) { 98 assertEquals("Circular definition not detected - ", true, 99 e.getMessage().indexOf("was circularly defined") 100 != -1); 101 return; 102 } 103 fail("Did not throw exception on circular exception"); 104 } 105 106 public void testThisIsNotACircularReference() { 107 expectLog("thisIsNotACircularReference", "b is A/A/A"); 108 } 109 110 } 111 | Popular Tags |