You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/04/08 15:13:22 UTC

svn commit: r645897 - in /ant/antlibs/antunit/trunk: changes.xml src/etc/testcases/listener/xmllistener.xml src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java

Author: bodewig
Date: Tue Apr  8 06:13:20 2008
New Revision: 645897

URL: http://svn.apache.org/viewvc?rev=645897&view=rev
Log:
Log properties in xmllistener, Submitted by David Jackman, PR 43614

Modified:
    ant/antlibs/antunit/trunk/changes.xml
    ant/antlibs/antunit/trunk/src/etc/testcases/listener/xmllistener.xml
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java
    ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java

Modified: ant/antlibs/antunit/trunk/changes.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/changes.xml?rev=645897&r1=645896&r2=645897&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/changes.xml (original)
+++ ant/antlibs/antunit/trunk/changes.xml Tue Apr  8 06:13:20 2008
@@ -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>

Modified: ant/antlibs/antunit/trunk/src/etc/testcases/listener/xmllistener.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/listener/xmllistener.xml?rev=645897&r1=645896&r2=645897&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/listener/xmllistener.xml (original)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/listener/xmllistener.xml Tue Apr  8 06:13:20 2008
@@ -301,4 +301,45 @@
     <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>

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java?rev=645897&r1=645896&r2=645897&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java Tue Apr  8 06:13:20 2008
@@ -27,6 +27,9 @@
 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 @@
             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);
         }

Modified: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java?rev=645897&r1=645896&r2=645897&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java (original)
+++ ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java Tue Apr  8 06:13:20 2008
@@ -74,4 +74,7 @@
         executeTarget("badcharacters");
     }
     
+    public void testProperties() {
+        executeTarget("properties");
+    }
 }