]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/SimpleResultPart.java
56ea3a9904e286bb6e969cb813b381ab1736d2a8
2 * Copyright (C) 2007-2012 Mathieu Baudier
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.
16 package org
.argeo
.slc
.core
.test
;
18 import java
.io
.Serializable
;
20 import org
.argeo
.slc
.test
.TestResultPart
;
21 import org
.argeo
.slc
.test
.TestRun
;
22 import org
.argeo
.slc
.test
.TestRunAware
;
23 import org
.argeo
.slc
.test
.TestStatus
;
27 * Basic implementation of a result part, implementing the standard three status
28 * approach for test results.
33 public class SimpleResultPart
implements TestResultPart
, TestStatus
,
34 TestRunAware
, Serializable
{
35 private static final long serialVersionUID
= 6669675957685071901L;
39 private String testRunUuid
;
41 /** The status. Default to ERROR since it should always be explicitely set. */
42 private Integer status
= ERROR
;
43 private String message
;
44 private String exceptionMessage
;
46 public SimpleResultPart() {
49 public SimpleResultPart(Integer status
, String message
) {
50 this(status
, message
, null);
53 public SimpleResultPart(Integer status
, String message
, Exception exception
) {
55 this.message
= message
;
56 setException(exception
);
59 public String
getMessage() {
63 public void setMessage(String message
) {
64 this.message
= message
;
67 public void setStatus(Integer status
) {
71 public Integer
getStatus() {
75 public String
getExceptionMessage() {
76 return exceptionMessage
;
79 public void setException(Exception exception
) {
80 if (exception
== null)
83 StringBuffer buf
= new StringBuffer("");
84 buf
.append(exception
.toString());
86 for (StackTraceElement elem
: exception
.getStackTrace()) {
87 buf
.append('\t').append(elem
.toString()).append('\n');
90 if (exception
.getCause() != null)
91 addRootCause(buf
, exception
.getCause());
93 this.exceptionMessage
= buf
.toString();
96 protected void addRootCause(StringBuffer buf
, Throwable cause
) {
100 buf
.append("Caused by: " + cause
.getMessage());
101 for (StackTraceElement elem
: cause
.getStackTrace()) {
102 buf
.append('\t').append(elem
.toString()).append('\n');
105 if (cause
.getCause() != null) {
106 addRootCause(buf
, cause
.getCause());
111 public String
toString() {
112 StringBuffer buf
= new StringBuffer("");
113 buf
.append(SlcTestUtils
.statusToString(status
));
114 if (status
== PASSED
|| status
== FAILED
) {
116 } else if (status
== ERROR
) {
120 return buf
.toString();
129 void setTid(Long tid
) {
133 public String
getTestRunUuid() {
138 public void setTestRunUuid(String testRunUuid
) {
139 this.testRunUuid
= testRunUuid
;
142 public void notifyTestRun(TestRun testRun
) {
143 testRunUuid
= testRun
.getUuid();
146 public void setExceptionMessage(String exceptionMessage
) {
147 this.exceptionMessage
= exceptionMessage
;