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:
Stefan Bodewig 2008-04-08 13:13:20 +00:00
parent 5481b97906
commit 81a6051f78
4 changed files with 66 additions and 0 deletions

View File

@ -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>

View File

@ -301,4 +301,45 @@ under the License.
<echo>bad characters: ]]&gt;</echo>
</target>
<property name="propertiesstart" value="&lt;properties&gt;" />
<property name="propertiesend" value="&lt;/properties&gt;" />
<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}.*&lt;property name="@{name}" value="@{value}" /&gt;.*${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="&amp;&lt;&gt;&quot;&apos;" />
<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="&lt;testsuite.*${propertiesstart}.*${propertiesend}.*&lt;/testsuite" singleline="true"
message="Properties element should be child of testsuite" />
<au:assertMatches string="${reportxml}" pattern="${propertiesend}.*&lt;testcase" singleline="true"
message="Properties element should be before testcases" />
<assertDoesntMatch string="${reportxml}" pattern="&lt;/testcase&gt;.*${propertiesstart}" singleline="true"
message="Properties element should not be after testcases" />
<assertDoesntMatch string="${reportxml}" pattern="&lt;property.*${propertiesstart}" singleline="true"
message="Property element should only be inside properties" />
<assertDoesntMatch string="${reportxml}" pattern="${propertiesend}.*&lt;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;amp;&amp;lt;&amp;gt;&amp;quot;&amp;apos;" />
<clean/>
</target>
</project>

View File

@ -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);
}

View File

@ -74,4 +74,7 @@ public class XMLListenerTest extends BuildFileTest {
executeTarget("badcharacters");
}
public void testProperties() {
executeTarget("properties");
}
}