]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/SimpleResultPart.java
Various changes
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / SimpleResultPart.java
index da0ddcbebfcde8db0954104ba40bef26a40d8bba..543cc98bb89849cefbbe5b626205fdd169daefdf 100644 (file)
@@ -1,5 +1,14 @@
 package org.argeo.slc.core.test;\r
 \r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.io.StringReader;\r
+import java.io.StringWriter;\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
+import org.apache.commons.io.IOUtils;\r
+\r
 /**\r
  * <p>\r
  * Basic implementation of a result part, implementing the standard three status\r
@@ -8,15 +17,19 @@ package org.argeo.slc.core.test;
  * \r
  * @see TestStatus\r
  */\r
-public class SimpleResultPart implements TestResultPart, TestStatus {\r
+public class SimpleResultPart implements TestResultPart, TestStatus,\r
+               TestRunAware {\r
 \r
-       /** For ORM */\r
+       /** @deprecated */\r
        private Long tid;\r
 \r
+       private String testRunUuid;\r
+\r
        /** The status. Default to ERROR since it should always be explicitely set. */\r
        private Integer status = ERROR;\r
        private String message;\r
-       private Exception exception;\r
+       private String exceptionMessage;\r
+       private List<String> exceptionStackLines = new Vector<String>();\r
 \r
        public SimpleResultPart() {\r
        }\r
@@ -28,7 +41,7 @@ public class SimpleResultPart implements TestResultPart, TestStatus {
        public SimpleResultPart(Integer status, String message, Exception exception) {\r
                this.status = status;\r
                this.message = message;\r
-               this.exception = exception;\r
+               setException(exception);\r
        }\r
 \r
        public String getMessage() {\r
@@ -47,12 +60,29 @@ public class SimpleResultPart implements TestResultPart, TestStatus {
                return status;\r
        }\r
 \r
-       public Exception getException() {\r
-               return exception;\r
+       public String getExceptionMessage() {\r
+               return exceptionMessage;\r
        }\r
 \r
        public void setException(Exception exception) {\r
-               this.exception = exception;\r
+               if (exception == null)\r
+                       return;\r
+\r
+               this.exceptionMessage = exception.getMessage();\r
+\r
+               StringWriter writer = null;\r
+               StringReader reader = null;\r
+               try {\r
+                       writer = new StringWriter();\r
+                       exception.printStackTrace(new PrintWriter(writer));\r
+                       reader = new StringReader(writer.toString());\r
+                       exceptionStackLines = new Vector<String>(IOUtils.readLines(reader));\r
+               } catch (IOException e) {\r
+                       // silent\r
+               } finally {\r
+                       IOUtils.closeQuietly(writer);\r
+                       IOUtils.closeQuietly(reader);\r
+               }\r
        }\r
 \r
        @Override\r
@@ -65,18 +95,42 @@ public class SimpleResultPart implements TestResultPart, TestStatus {
                        buf.append("  ");\r
                }\r
                buf.append(message);\r
-               if (exception != null) {\r
-                       buf.append("(").append(exception.getMessage()).append(")");\r
-               }\r
                return buf.toString();\r
        }\r
 \r
+       /** @deprecated */\r
        Long getTid() {\r
                return tid;\r
        }\r
 \r
+       /** @deprecated */\r
        void setTid(Long tid) {\r
                this.tid = tid;\r
        }\r
 \r
+       public String getTestRunUuid() {\r
+               return testRunUuid;\r
+       }\r
+\r
+       /** For ORM */\r
+       public void setTestRunUuid(String testRunUuid) {\r
+               this.testRunUuid = testRunUuid;\r
+       }\r
+\r
+       public void notifyTestRun(TestRun testRun) {\r
+               testRunUuid = testRun.getUuid();\r
+       }\r
+\r
+       public List<String> getExceptionStackLines() {\r
+               return exceptionStackLines;\r
+       }\r
+\r
+       public void setExceptionStackLines(List<String> exceptionStackLines) {\r
+               this.exceptionStackLines = exceptionStackLines;\r
+       }\r
+\r
+       public void setExceptionMessage(String exceptionMessage) {\r
+               this.exceptionMessage = exceptionMessage;\r
+       }\r
+\r
 }\r