Author: emuckenhuber
Date: 2007-10-11 05:26:00 -0400 (Thu, 11 Oct 2007)
New Revision: 8598
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/JUnitReporterTests.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/MyTestInfo.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/MyTestReport.java
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java
Log:
- junit reporter test case
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java 2007-10-11 05:44:45
UTC (rev 8597)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/AllTests.java 2007-10-11 09:26:00
UTC (rev 8598)
@@ -23,9 +23,11 @@
package org.jboss.test.unit;
import org.jboss.test.unit.api.AssertTests;
+import org.jboss.test.unit.blah.BlahTestTwo;
import org.jboss.test.unit.blah.BlahTests;
import org.jboss.test.unit.pojo.AbstractPOJOTests;
import org.jboss.test.unit.pojo.junit.JUnitPOJOTests;
+import org.jboss.test.unit.report.junit.JUnitReporterTests;
import org.jboss.test.unit.runner.CompositeTestRunnerTests;
import org.jboss.test.unit.runner.ParametrizationTests;
import org.jboss.test.unit.runner.TestDriverRunnerTests;
@@ -62,5 +64,11 @@
//
BlahTests.main(args);
+
+ //
+ BlahTestTwo.main(args);
+
+ //
+ JUnitReporterTests.main(args);
}
}
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/JUnitReporterTests.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/JUnitReporterTests.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/JUnitReporterTests.java 2007-10-11
09:26:00 UTC (rev 8598)
@@ -0,0 +1,154 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.test.unit.report.junit;
+
+import org.jboss.unit.Failure;
+import org.jboss.unit.FailureType;
+import org.jboss.unit.TestId;
+import org.jboss.unit.api.Assert;
+import org.jboss.unit.runner.TestResult;
+import org.jboss.unit.runner.event.EndRunnerEvent;
+import org.jboss.unit.runner.event.EndTestEvent;
+import org.jboss.unit.runner.event.RunnerFailureEvent;
+import org.jboss.unit.runner.event.StartRunnerEvent;
+import org.jboss.unit.runner.event.StartTestEvent;
+import org.jboss.unit.runner.results.TestFailure;
+import org.jboss.unit.runner.results.TestSuccess;
+import org.w3c.dom.Element;
+
+import static org.jboss.unit.util.XMLTools.*;
+import static org.jboss.unit.report.impl.junit.XMLConstants.*;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel
Muckenhuber</a>
+ * @version $Revision$
+ */
+public class JUnitReporterTests
+{
+ /** The testSuiteName */
+ private final static String testSuiteName = JUnitReporterTests.class.getName();
+
+ public static void main(String[] args) throws Exception
+ {
+ testTestSuite();
+ testTestCase();
+ testTestCaseFailure();
+ }
+
+ private static void testTestSuite()
+ {
+ MyTestReport report = new MyTestReport(testSuiteName);
+ // add StartRunnerEvent
+ report.startTestSuite(new StartRunnerEvent());
+ // add RunnerFailureEvent
+ Failure f = new Failure("fehler", FailureType.ERROR);
+ RunnerFailureEvent rfe = new RunnerFailureEvent(f);
+ report.runnerFailed(rfe);
+ // add EndRunnerEvent
+ EndRunnerEvent endRunnerEvent = new EndRunnerEvent();
+ report.endTestSuite(endRunnerEvent);
+ // get Root Element
+ Element e = report.getRootElement();
+
+ // Testing root element
+ Assert.assertEquals(TESTSUITE, e.getNodeName());
+ Assert.assertEquals(testSuiteName, e.getAttribute(ATTR_NAME));
+ Assert.assertNotNull(e.getAttribute(HOSTNAME));
+ Assert.assertNotNull(e.getAttribute(TIMESTAMP));
+ Assert.assertEquals("1", e.getAttribute(ATTR_TESTS));
+ Assert.assertEquals("1", e.getAttribute(ATTR_ERRORS));
+ Assert.assertEquals("0", e.getAttribute(ATTR_FAILURES));
+
+ // Testing properties
+ Assert.assertNotNull(child(e, PROPERTIES));
+
+ // TODO - property
+
+ e = report.getRootElement();
+ Element error = child(e, ERROR);
+ Assert.assertEquals("fehler", error.getAttribute(ATTR_MESSAGE));
+ }
+
+
+ private static void testTestCase()
+ {
+ MyTestReport report = new MyTestReport(testSuiteName);
+ report.startTestSuite(new StartRunnerEvent());
+
+ TestId testId = new TestId("foo");
+ StartTestEvent startTestEvent = new StartTestEvent(testId, new MyTestInfo());
+ report.startTest(startTestEvent);
+
+ TestResult testResult = new TestSuccess(20);
+ EndTestEvent endTestEvent = new EndTestEvent(testId, testResult);
+ report.endTest(endTestEvent);
+ // end report
+ report.endTestSuite(new EndRunnerEvent());
+ Element e = report.getRootElement();
+
+ Assert.assertEquals(TESTSUITE, e.getNodeName());
+ Assert.assertEquals("1", e.getAttribute(ATTR_TESTS));
+ Assert.assertEquals("0", e.getAttribute(ATTR_ERRORS));
+ Assert.assertEquals("0", e.getAttribute(ATTR_FAILURES));
+
+ Element testCase = child(e, TESTCASE);
+ Assert.assertEquals(TESTCASE, testCase.getNodeName());
+ Assert.assertEquals("foo", testCase.getAttribute(ATTR_NAME));
+ Assert.assertEquals("20", testCase.getAttribute(ATTR_TIME));
+
+ Assert.assertNull(child(e, ERROR));
+ }
+
+ private static void testTestCaseFailure()
+ {
+ MyTestReport report = new MyTestReport(testSuiteName);
+ report.startTestSuite(new StartRunnerEvent());
+
+ TestId testId = new TestId("foo");
+ StartTestEvent startTestEvent = new StartTestEvent(testId, new MyTestInfo());
+ report.startTest(startTestEvent);
+
+ Failure f = new Failure("foo", new AssertionError("expecting
something different."), FailureType.ASSERTION);
+ TestResult testResult = new TestFailure(f, 20);
+ EndTestEvent endTestEvent = new EndTestEvent(testId, testResult);
+ report.endTest(endTestEvent);
+ // end report
+ report.endTestSuite(new EndRunnerEvent());
+ Element e = report.getRootElement();
+
+ Assert.assertEquals(TESTSUITE, e.getNodeName());
+ Assert.assertEquals("1", e.getAttribute(ATTR_TESTS));
+ Assert.assertEquals("0", e.getAttribute(ATTR_ERRORS));
+ Assert.assertEquals("1", e.getAttribute(ATTR_FAILURES));
+
+ Element testCase = child(e, TESTCASE);
+ Assert.assertEquals(TESTCASE, testCase.getNodeName());
+ Assert.assertEquals("foo", testCase.getAttribute(ATTR_NAME));
+ Assert.assertEquals("20", testCase.getAttribute(ATTR_TIME));
+
+ Element error = child(testCase, FAILURE);
+ Assert.assertEquals("expecting something different.",
error.getAttribute(ATTR_MESSAGE));
+ Assert.assertEquals("java.lang.AssertionError",
error.getAttribute(ATTR_TYPE));
+ Assert.assertNotNull(error.getTextContent());
+ }
+}
Added: modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/MyTestInfo.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/MyTestInfo.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/MyTestInfo.java 2007-10-11
09:26:00 UTC (rev 8598)
@@ -0,0 +1,59 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.test.unit.report.junit;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.unit.info.ParameterInfo;
+import org.jboss.unit.info.TestInfo;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel
Muckenhuber</a>
+ * @version $Revision$
+ */
+public class MyTestInfo implements TestInfo
+{
+
+ public String getDescription()
+ {
+ return null;
+ }
+
+ public Set<String> getKeywords()
+ {
+ return null;
+ }
+
+ public String getName()
+ {
+ return null;
+ }
+
+ public Map<String, ? extends ParameterInfo> getParameters()
+ {
+ return null;
+ }
+
+}
+
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/MyTestReport.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/MyTestReport.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/MyTestReport.java 2007-10-11
09:26:00 UTC (rev 8598)
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.test.unit.report.junit;
+
+import org.jboss.unit.report.impl.junit.JUnitTestReport;
+import org.w3c.dom.Element;
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel
Muckenhuber</a>
+ * @version $Revision$
+ */
+public class MyTestReport extends JUnitTestReport
+{
+ public MyTestReport(String testSuiteName)
+ {
+ super(testSuiteName);
+ }
+
+ public Element getRootElement()
+ {
+ return this.rootElement;
+ }
+
+}
+
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java 2007-10-11
05:44:45 UTC (rev 8597)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java 2007-10-11
09:26:00 UTC (rev 8598)
@@ -80,7 +80,7 @@
private Document document;
/** The root element */
- private Element rootElement;
+ protected Element rootElement;
/** The started Tests */
private Map<TestId, TestInfo> startedTests = new HashMap<TestId,
TestInfo>();
@@ -265,7 +265,7 @@
{
try
{
-
+ toDir = checkDir(toDir);
StringBuffer filePath = new StringBuffer();
// If no test suite name is specified use default and add timestamp
@@ -299,6 +299,16 @@
}
}
+ private String checkDir(String toDir)
+ {
+ File dir = new File(toDir);
+ if (! dir.exists())
+ {
+ dir.mkdir();
+ }
+ return dir.toString();
+ }
+
private Element addError(String type, Throwable t)
{
Element error = document.createElement(type);