Log properties in xmllistener, Submitted by David Jackman, PR 43614
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/antunit/trunk@645897 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5481b97906
commit
81a6051f78
|
|
@ -58,6 +58,10 @@
|
|||
plainlistener and xmllistener can now optionally contain the
|
||||
test's log output in their reports
|
||||
</action>
|
||||
<action type="add" issue="43614">
|
||||
xmllistener will now log the properties of the project under
|
||||
test
|
||||
</action>
|
||||
</release>
|
||||
|
||||
</document>
|
||||
|
|
|
|||
|
|
@ -301,4 +301,45 @@ under the License.
|
|||
<echo>bad characters: ]]></echo>
|
||||
</target>
|
||||
|
||||
<property name="propertiesstart" value="<properties>" />
|
||||
<property name="propertiesend" value="</properties>" />
|
||||
<macrodef name="assertPropertyElement">
|
||||
<attribute name="name" description="Name of the property to look for" />
|
||||
<attribute name="value" description="Expected property value (as a regular expression)" />
|
||||
<sequential>
|
||||
<au:assertMatches string="${reportxml}" pattern='${propertiesstart}.*<property name="@{name}" value="@{value}" />.*${propertiesend}' singleline="true"
|
||||
message="Element for property @{name} not present." />
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<target name="properties">
|
||||
<clean/>
|
||||
<property name="thisIsTheProperty" value="thisIsTheValue" />
|
||||
<property name="badCharacters" value="&<>"'" />
|
||||
<au:antunit failOnError="false">
|
||||
<file file="${ant.file}" />
|
||||
<au:xmllistener />
|
||||
<propertyset>
|
||||
<propertyref name="thisIsTheProperty" />
|
||||
<propertyref name="badCharacters" />
|
||||
</propertyset>
|
||||
</au:antunit>
|
||||
<loadfile property="reportxml" srcFile="${reportfile}" />
|
||||
<au:assertMatches string="${reportxml}" pattern="${propertiesstart}.*${propertiesend}" singleline="true"
|
||||
message="Properties element not present" />
|
||||
<au:assertMatches string="${reportxml}" pattern="<testsuite.*${propertiesstart}.*${propertiesend}.*</testsuite" singleline="true"
|
||||
message="Properties element should be child of testsuite" />
|
||||
<au:assertMatches string="${reportxml}" pattern="${propertiesend}.*<testcase" singleline="true"
|
||||
message="Properties element should be before testcases" />
|
||||
<assertDoesntMatch string="${reportxml}" pattern="</testcase>.*${propertiesstart}" singleline="true"
|
||||
message="Properties element should not be after testcases" />
|
||||
<assertDoesntMatch string="${reportxml}" pattern="<property.*${propertiesstart}" singleline="true"
|
||||
message="Property element should only be inside properties" />
|
||||
<assertDoesntMatch string="${reportxml}" pattern="${propertiesend}.*<property.*" singleline="true"
|
||||
message="Property element should only be inside properties" />
|
||||
<assertPropertyElement name="thisIsTheProperty" value="${thisIsTheProperty}" />
|
||||
<assertPropertyElement name="java.version" value="${java.version}" />
|
||||
<assertPropertyElement name="badCharacters" value="&amp;&lt;&gt;&quot;&apos;" />
|
||||
<clean/>
|
||||
</target>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ import java.io.Writer;
|
|||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ant.antunit.AssertionFailedException;
|
||||
|
||||
|
|
@ -90,6 +93,21 @@ public class XMLAntUnitListener extends BaseAntUnitListener {
|
|||
domWri.writeXMLDeclaration(wri);
|
||||
domWri.openElement(root, wri, 0, INDENT, true);
|
||||
wri.write(StringUtils.LINE_SEP);
|
||||
|
||||
Element propertiesElement =
|
||||
DOMUtils.createChildElement(root, XMLConstants.PROPERTIES);
|
||||
Hashtable propertiesMap = testProject.getProperties();
|
||||
for (final Iterator iterator = propertiesMap.entrySet().iterator();
|
||||
iterator.hasNext();) {
|
||||
final Map.Entry property = (Map.Entry) iterator.next();
|
||||
Element e = DOMUtils.createChildElement(propertiesElement,
|
||||
XMLConstants.PROPERTY);
|
||||
e.setAttribute(XMLConstants.ATTR_NAME,
|
||||
property.getKey().toString());
|
||||
e.setAttribute(XMLConstants.ATTR_VALUE,
|
||||
property.getValue().toString());
|
||||
}
|
||||
domWri.write(propertiesElement, wri, 1, INDENT);
|
||||
} catch (IOException ex) {
|
||||
throw new BuildException(ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,4 +74,7 @@ public class XMLListenerTest extends BuildFileTest {
|
|||
executeTarget("badcharacters");
|
||||
}
|
||||
|
||||
public void testProperties() {
|
||||
executeTarget("properties");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue