git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@916043 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,95 +0,0 @@ | |||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||
<!-- | |||
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 name="loadproperties-test" | |||
basedir="." | |||
default="testPrefixedProperties"> | |||
<target name="init"> | |||
</target> | |||
<target name="testPrefixedProperties" depends="init"> | |||
<property name="server" value="localhost"/> | |||
<echo file="properties.tmp"> | |||
#http.@PORT@ = 90 | |||
http.@PORT@ = 80 | |||
http.@SERVER@ = ${server} | |||
</echo> | |||
<loadproperties srcFile="properties.tmp"> | |||
<filterchain> | |||
<striplinecomments> | |||
<comment value="#"/> | |||
</striplinecomments> | |||
<prefixlines prefix="server1."/> | |||
<replacetokens> | |||
<token key="PORT" value="port"/> | |||
<token key="SERVER" value="server"/> | |||
</replacetokens> | |||
<expandproperties/> | |||
</filterchain> | |||
</loadproperties> | |||
<property name="server1.http.url" | |||
value="http://${server1.http.server}:${server1.http.port}"/> | |||
</target> | |||
<target name="write properties.tmp" depends="init"> | |||
<echo file="properties.tmp"> | |||
#tpfr.a=a | |||
tpfr.a=A | |||
tpfr.b=b\ | |||
e | |||
tpfr.c=@C@ | |||
</echo> | |||
</target> | |||
<target name="testPropertiesFromResource" depends="write properties.tmp"> | |||
<loadproperties resource="properties.tmp" classpath="${basedir}"> | |||
<filterchain> | |||
<replacetokens> | |||
<token key="C" value="sea"/> | |||
</replacetokens> | |||
</filterchain> | |||
</loadproperties> | |||
</target> | |||
<target name="testPropertiesFromFileSet" depends="write properties.tmp"> | |||
<loadproperties> | |||
<fileset dir="${basedir}"> | |||
<include name="properties.tmp"/> | |||
</fileset> | |||
<filterchain> | |||
<replacetokens> | |||
<token key="C" value="sea"/> | |||
</replacetokens> | |||
</filterchain> | |||
</loadproperties> | |||
</target> | |||
<target name="loadPropertiesCheck"> | |||
<condition property="testPropertiesFromResource.ok"> | |||
<equals arg1="Abesea" arg2="${tpfr.a}${tpfr.b}${tpfr.c}" /> | |||
</condition> | |||
<fail unless="testPropertiesFromResource.ok"> | |||
$${tpfr.a}$${tpfr.b}$${tpfr.c}="${tpfr.a}${tpfr.b}${tpfr.c}" | |||
</fail> | |||
</target> | |||
<target name="cleanup"> | |||
<delete file="properties.tmp"/> | |||
</target> | |||
</project> |
@@ -15,10 +15,15 @@ | |||
See the License for the specific language governing permissions and | |||
limitations under the License. | |||
--> | |||
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> | |||
<project name="loadproperties-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> | |||
<import file="../antunit-base.xml" /> | |||
<target name="setUp"> | |||
<mkdir dir="${input}" /> | |||
<property name="properties.tmp" location="${input}/properties.tmp" /> | |||
</target> | |||
<target name="test-basic"> | |||
<loadproperties> | |||
<string>basic.foo=foo | |||
@@ -68,4 +73,66 @@ a=Hello world in EBCDIC | |||
<au:assertPropertyEquals name="a" value="Hello world in EBCDIC"/> | |||
</target> | |||
<target name="testPrefixedProperties" depends="setUp"> | |||
<property name="server" value="localhost"/> | |||
<echo file="${properties.tmp}"> | |||
#http.@PORT@ = 90 | |||
http.@PORT@ = 80 | |||
http.@SERVER@ = ${server} | |||
</echo> | |||
<loadproperties srcFile="${properties.tmp}"> | |||
<filterchain> | |||
<striplinecomments> | |||
<comment value="#"/> | |||
</striplinecomments> | |||
<prefixlines prefix="server1."/> | |||
<replacetokens> | |||
<token key="PORT" value="port"/> | |||
<token key="SERVER" value="server"/> | |||
</replacetokens> | |||
<expandproperties/> | |||
</filterchain> | |||
</loadproperties> | |||
<property name="server1.http.url" | |||
value="http://${server1.http.server}:${server1.http.port}"/> | |||
</target> | |||
<target name="write properties.tmp" depends="setUp"> | |||
<echo file="${properties.tmp}"> | |||
#tpfr.a=a | |||
tpfr.a=A | |||
tpfr.b=b\ | |||
e | |||
tpfr.c=@C@ | |||
</echo> | |||
</target> | |||
<presetdef name="assertPropertiesFromResourceOkay"> | |||
<au:assertTrue> | |||
<equals arg1="Abesea" arg2="${tpfr.a}${tpfr.b}${tpfr.c}" /> | |||
</au:assertTrue> | |||
</presetdef> | |||
<target name="testPropertiesFromResource" depends="write properties.tmp"> | |||
<loadproperties resource="properties.tmp" classpath="${input}"> | |||
<filterchain> | |||
<replacetokens> | |||
<token key="C" value="sea"/> | |||
</replacetokens> | |||
</filterchain> | |||
</loadproperties> | |||
</target> | |||
<target name="testPropertiesFromFileSet" depends="write properties.tmp"> | |||
<loadproperties> | |||
<fileset file="${properties.tmp}" /> | |||
<filterchain> | |||
<replacetokens> | |||
<token key="C" value="sea"/> | |||
</replacetokens> | |||
</filterchain> | |||
</loadproperties> | |||
<assertPropertiesFromResourceOkay /> | |||
</target> | |||
</project> |
@@ -1,60 +0,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. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
/** | |||
*/ | |||
public class LoadPropertiesTest extends BuildFileTest { | |||
public LoadPropertiesTest(String name) { | |||
super(name); | |||
} | |||
/** | |||
* The JUnit setup method | |||
*/ | |||
public void setUp() { | |||
configureProject("src/etc/testcases/taskdefs/loadproperties.xml"); | |||
} | |||
/** | |||
* The teardown method for JUnit | |||
*/ | |||
public void tearDown() { | |||
executeTarget("cleanup"); | |||
} | |||
public void testPrefixedProperties() { | |||
executeTarget("testPrefixedProperties"); | |||
String url = project.getProperty("server1.http.url"); | |||
assertEquals("http://localhost:80", url); | |||
} | |||
public void testPropertiesFromResource() { | |||
executeTarget("testPropertiesFromResource"); | |||
executeTarget("loadPropertiesCheck"); | |||
} | |||
public void testPropertiesFromFileSet() { | |||
executeTarget("testPropertiesFromFileSet"); | |||
executeTarget("loadPropertiesCheck"); | |||
} | |||
} |