private Vector<PartStruct> partStructs = new Vector<PartStruct>();\r
private Thread thread;\r
\r
+ private Boolean synchronous = false;\r
+ \r
+ protected AsynchronousTreeTestResultListener(){\r
+ this(false);\r
+ }\r
+\r
+ protected AsynchronousTreeTestResultListener(Boolean synchronousByDefault){\r
+ synchronous = synchronousByDefault;\r
+ }\r
+\r
/** Starts the underlying thread. */\r
public void init() {\r
- thread = new Thread(this);\r
- thread.start();\r
+ if (!synchronous) {\r
+ thread = new Thread(this);\r
+ thread.start();\r
+ }\r
}\r
\r
/** Finish the remaining and destroy */\r
public final void resultPartAdded(TestResult testResult,\r
TestResultPart testResultPart) {\r
TreeTestResult result = (TreeTestResult) testResult;\r
- synchronized (partStructs) {\r
- partStructs.add(new PartStruct(result.getCurrentPath(),\r
- (NumericTRId) result.getTestResultId(), testResultPart,\r
- result));\r
- partStructs.notifyAll();\r
+ PartStruct partStruct = new PartStruct(result.getCurrentPath(),\r
+ (NumericTRId) result.getTestResultId(), testResultPart, result);\r
+\r
+ if (!synchronous) {\r
+ synchronized (partStructs) {\r
+ partStructs.add(partStruct);\r
+ partStructs.notifyAll();\r
+ }\r
+ } else {\r
+ resultPartAdded(partStruct);\r
}\r
}\r
\r
\r
}\r
\r
+ public Boolean getSynchronous() {\r
+ return synchronous;\r
+ }\r
+\r
+ public void setSynchronous(Boolean synchronous) {\r
+ this.synchronous = synchronous;\r
+ }\r
+\r
}\r
import org.apache.commons.logging.Log;\r
import org.apache.commons.logging.LogFactory;\r
\r
+import org.argeo.slc.core.test.SimpleResultPart;\r
+import org.argeo.slc.core.test.TestResultPart;\r
+import org.argeo.slc.core.test.TestStatus;\r
+\r
/**\r
* Listener logging tree-based test results to the underlying logging system.\r
* \r
public class TreeTestResultLogger extends AsynchronousTreeTestResultListener {\r
\r
private static Log log = LogFactory.getLog(TreeTestResultLogger.class);\r
+ \r
+ public TreeTestResultLogger() {\r
+ super(true);\r
+ }\r
\r
@Override\r
protected void resultPartAdded(PartStruct partStruct) {\r
- log.info(partStruct.part + " - " + partStruct.resultId + ":"\r
- + partStruct.path);\r
+ TestResultPart part = partStruct.part;\r
+ String msg = partStruct.part + " - " + partStruct.resultId + ":"\r
+ + partStruct.path;\r
+ if (part.getStatus().equals(TestStatus.PASSED)) {\r
+ log.info(msg);\r
+ } else if (part.getStatus().equals(TestStatus.FAILED)) {\r
+ log.warn(msg);\r
+ } else if (part.getStatus().equals(TestStatus.ERROR)) {\r
+ log.error(msg, ((SimpleResultPart) part).getException());\r
+ } else {\r
+ log.error("Unknow test status: " + msg);\r
+ }\r
}\r
\r
}\r
package org.argeo.slc.core.test.tree.htmlreport;\r
\r
import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.io.StringWriter;\r
import java.util.Date;\r
import java.util.SortedMap;\r
import java.util.TreeMap;\r
\r
import org.apache.commons.io.FileUtils;\r
+import org.apache.commons.io.IOUtils;\r
import org.apache.commons.logging.Log;\r
import org.apache.commons.logging.LogFactory;\r
\r
for (TestResultPart part : subList.getParts()) {\r
SimpleResultPart sPart = (SimpleResultPart) part;\r
String clss = "";\r
- if (sPart.getStatus().equals(SimpleResultPart.PASSED)) {\r
+ if (sPart.getStatus().equals(TestStatus.PASSED)) {\r
clss = "passed";\r
} else {\r
clss = "failed";\r
buf.append("<td class=\"").append(clss).append("\">");\r
\r
buf.append(sPart.getMessage());\r
+ if (sPart.getStatus().equals(TestStatus.ERROR)) {\r
+ buf\r
+ .append("<p><b>An unexpected error prevented the test to run properly.</b>");\r
+ Throwable exception = sPart.getException();\r
+ if (exception != null) {\r
+ StringWriter writer = new StringWriter();\r
+ exception.printStackTrace(new PrintWriter(writer));\r
+ buf.append("<br/><pre>");\r
+ buf.append(writer.toString());\r
+ buf.append("</pre>");\r
+ IOUtils.closeQuietly(writer);\r
+ }\r
+ buf.append("</p>");\r
+ }\r
buf.append("</td>");\r
buf.append("</tr>\n");\r
\r
td {\r
font-size: 12px;\r
padding: 1px;\r
- vertical-align: middle;\r
+ vertical-align: top;\r
text-align: left;\r
}\r
\r
</id>\r
<property name="status" column="STATUS" not-null="true" />\r
<property name="message" column="MESSAGE" not-null="true" />\r
+ <property name="exception" column="EXCEPTION" not-null="false" />\r
</class>\r
</hibernate-mapping>
\ No newline at end of file
"/root/Category1/SubCategory2/testSimple/slc.test0", 1,\r
TestStatus.FAILED,\r
"Compare nato-expected.txt with nato-reached.txt");\r
+ assertPart(testResult1,\r
+ "/root/Category1/SubCategory2/testError/slc.test0", 0,\r
+ TestStatus.ERROR, "Execute example appli");\r
\r
numericTRId.setValue(2l);\r
TreeTestResult testResult2 = (TreeTestResult) testResultDao\r
value="${slc.workDir}/data/expected/un-expected.txt" />\r
</bean>\r
\r
+ <bean id="testData.un.bad"\r
+ class="org.argeo.slc.example.ExampleTestData" scope="prototype">\r
+ <property name="inputFile"\r
+ value="${slc.workDir}/data/input/un-inXXX.txt" />\r
+ <property name="reachedFile"\r
+ value="${slc.workDir}/data/reached/un-reachedXXX.txt" />\r
+ <property name="expectedFile"\r
+ value="${slc.workDir}/data/expected/un-expectedXXX.txt" />\r
+ </bean>\r
+ \r
<bean id="testData.eu-reform"\r
class="org.argeo.slc.example.ExampleTestData" scope="prototype">\r
<property name="inputFile"\r
<project default="test" name="testProject">\r
<description>A Test project</description>\r
\r
- <target name="test" depends="testSimple,testComplex">\r
+ <target name="test" depends="testSimple,testComplex,testError">\r
<slc.closeResult result="testResult" />\r
<slc.closeResult result="testResult2" />\r
<slc.report report="report" />\r
</slc.test>\r
</target>\r
\r
+ <target name="testError" description="A crashing test">\r
+ <slc.test description="UN crashing">\r
+ <testDefinition bean="simpleExampleTestDef" />\r
+ <testData bean="testData.un.bad" />\r
+ </slc.test>\r
+ </target>\r
+\r
</project>
\ No newline at end of file