diff --git a/src/etc/testcases/listener/xmllistener.xml b/src/etc/testcases/listener/xmllistener.xml new file mode 100755 index 0000000..89e65d7 --- /dev/null +++ b/src/etc/testcases/listener/xmllistener.xml @@ -0,0 +1,304 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + suiteSetUp + + + + suiteTearDown + + + + setUp + + + + tearDown + + + + debugmessage + verbosemessage + infomessage + warningmessage + errormessage + + + + test2 + bad characters: ]]> + + + diff --git a/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java b/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java index 66cc376..07e4657 100644 --- a/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java +++ b/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java @@ -30,6 +30,7 @@ import java.util.Date; import org.apache.ant.antunit.AssertionFailedException; +import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Location; import org.apache.tools.ant.Project; @@ -53,6 +54,10 @@ public class XMLAntUnitListener extends BaseAntUnitListener { private Document doc; private Element root; private Element currentTest; + /** + * Collects log messages. + */ + private StringBuffer log = new StringBuffer(); public XMLAntUnitListener() { super(new BaseAntUnitListener.SendLogTo(SendLogTo.FILE), "xml"); @@ -92,8 +97,14 @@ public class XMLAntUnitListener extends BaseAntUnitListener { public void endTestSuite(Project testProject, String buildFile) { try { - Element e = DOMUtils.createChildElement(root, - XMLConstants.ATTR_TESTS); + Element e; + if (log.length() > 0) { + e = DOMUtils.createChildElement(root, XMLConstants.SYSTEM_OUT); + DOMUtils.appendCDATA(e, log.toString()); + log.setLength(0); + domWri.write(e, wri, 1, INDENT); + } + e = DOMUtils.createChildElement(root, XMLConstants.ATTR_TESTS); DOMUtils.appendText(e, String.valueOf(runCount)); domWri.write(e, wri, 1, INDENT); e = DOMUtils.createChildElement(root, XMLConstants.ATTR_FAILURES); @@ -180,6 +191,11 @@ public class XMLAntUnitListener extends BaseAntUnitListener { } } + protected void messageLogged(BuildEvent event) { + log.append(event.getMessage()); + log.append(System.getProperty("line.separator")); + } + /** * get the local hostname - stolen from junit.XMLJUnitResultFormatter * @return the name of the local host, or "localhost" if we cannot diff --git a/src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java b/src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java new file mode 100755 index 0000000..34a236e --- /dev/null +++ b/src/tests/junit/org/apache/ant/antunit/listener/XMLListenerTest.java @@ -0,0 +1,79 @@ +/* + * 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.ant.antunit.listener; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Tests the plain listener. + */ +public class XMLListenerTest extends BuildFileTest { + protected void setUp() throws Exception { + configureProject("src/etc/testcases/listener/xmllistener.xml"); + } + + public void testStdoutPlacement() { + executeTarget("stdoutplacement"); + } + + public void testShowDefault() { + executeTarget("showdefault"); + } + + public void testShowError() { + executeTarget("showerror"); + } + + public void testShowWarning() { + executeTarget("showwarning"); + } + + public void testShowInfo() { + executeTarget("showinfo"); + } + + public void testShowVerbose() { + executeTarget("showverbose"); + } + + public void testShowDebug() { + executeTarget("showdebug"); + } + + public void testShowNone() { + executeTarget("shownone"); + } + + public void testSetUpTearDown() { + executeTarget("setupteardown"); + } + + /* + public void testSuiteSetUpTearDown() { + executeTarget("suitesetupteardown"); + } + */ + + public void testBadCharacters() { + executeTarget("badcharacters"); + } + +} \ No newline at end of file