]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/SimpleResultPart.java
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.core
.test
;
19 import java
.io
.Serializable
;
21 import org
.argeo
.slc
.test
.TestResultPart
;
22 import org
.argeo
.slc
.test
.TestRun
;
23 import org
.argeo
.slc
.test
.TestRunAware
;
24 import org
.argeo
.slc
.test
.TestStatus
;
28 * Basic implementation of a result part, implementing the standard three status
29 * approach for test results.
34 public class SimpleResultPart
implements TestResultPart
, TestStatus
,
35 TestRunAware
, Serializable
{
36 private static final long serialVersionUID
= 6669675957685071901L;
40 private String testRunUuid
;
42 /** The status. Default to ERROR since it should always be explicitely set. */
43 private Integer status
= ERROR
;
44 private String message
;
45 private String exceptionMessage
;
47 public SimpleResultPart() {
50 public SimpleResultPart(Integer status
, String message
) {
51 this(status
, message
, null);
54 public SimpleResultPart(Integer status
, String message
, Exception exception
) {
56 this.message
= message
;
57 setException(exception
);
60 public String
getMessage() {
64 public void setMessage(String message
) {
65 this.message
= message
;
68 public void setStatus(Integer status
) {
72 public Integer
getStatus() {
76 public String
getExceptionMessage() {
77 return exceptionMessage
;
80 public void setException(Exception exception
) {
81 if (exception
== null)
84 StringBuffer buf
= new StringBuffer("");
85 buf
.append(exception
.toString());
87 for (StackTraceElement elem
: exception
.getStackTrace()) {
88 buf
.append('\t').append(elem
.toString()).append('\n');
91 if (exception
.getCause() != null)
92 addRootCause(buf
, exception
.getCause());
94 this.exceptionMessage
= buf
.toString();
97 protected void addRootCause(StringBuffer buf
, Throwable cause
) {
101 buf
.append("Caused by: " + cause
.getMessage());
102 for (StackTraceElement elem
: cause
.getStackTrace()) {
103 buf
.append('\t').append(elem
.toString()).append('\n');
106 if (cause
.getCause() != null) {
107 addRootCause(buf
, cause
.getCause());
112 public String
toString() {
113 StringBuffer buf
= new StringBuffer("");
114 buf
.append(SlcTestUtils
.statusToString(status
));
115 if (status
== PASSED
|| status
== FAILED
) {
117 } else if (status
== ERROR
) {
121 return buf
.toString();
130 void setTid(Long tid
) {
134 public String
getTestRunUuid() {
139 public void setTestRunUuid(String testRunUuid
) {
140 this.testRunUuid
= testRunUuid
;
143 public void notifyTestRun(TestRun testRun
) {
144 testRunUuid
= testRun
.getUuid();
147 public void setExceptionMessage(String exceptionMessage
) {
148 this.exceptionMessage
= exceptionMessage
;