]>
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 org
.argeo
.slc
.test
.TestResultPart
;
20 import org
.argeo
.slc
.test
.TestRun
;
21 import org
.argeo
.slc
.test
.TestRunAware
;
22 import org
.argeo
.slc
.test
.TestStatus
;
26 * Basic implementation of a result part, implementing the standard three status
27 * approach for test results.
32 public class SimpleResultPart
implements TestResultPart
, TestStatus
,
37 private String testRunUuid
;
39 /** The status. Default to ERROR since it should always be explicitely set. */
40 private Integer status
= ERROR
;
41 private String message
;
42 private String exceptionMessage
;
44 public SimpleResultPart() {
47 public SimpleResultPart(Integer status
, String message
) {
48 this(status
, message
, null);
51 public SimpleResultPart(Integer status
, String message
, Exception exception
) {
53 this.message
= message
;
54 setException(exception
);
57 public String
getMessage() {
61 public void setMessage(String message
) {
62 this.message
= message
;
65 public void setStatus(Integer status
) {
69 public Integer
getStatus() {
73 public String
getExceptionMessage() {
74 return exceptionMessage
;
77 public void setException(Exception exception
) {
78 if (exception
== null)
81 StringBuffer buf
= new StringBuffer("");
82 buf
.append(exception
.toString());
84 for (StackTraceElement elem
: exception
.getStackTrace()) {
85 buf
.append('\t').append(elem
.toString()).append('\n');
88 if (exception
.getCause() != null)
89 addRootCause(buf
, exception
.getCause());
91 this.exceptionMessage
= buf
.toString();
94 protected void addRootCause(StringBuffer buf
, Throwable cause
) {
98 buf
.append("Caused by: " + cause
.getMessage());
99 for (StackTraceElement elem
: cause
.getStackTrace()) {
100 buf
.append('\t').append(elem
.toString()).append('\n');
103 if (cause
.getCause() != null) {
104 addRootCause(buf
, cause
.getCause());
109 public String
toString() {
110 StringBuffer buf
= new StringBuffer("");
111 buf
.append(SlcTestUtils
.statusToString(status
));
112 if (status
== PASSED
|| status
== FAILED
) {
114 } else if (status
== ERROR
) {
118 return buf
.toString();
127 void setTid(Long tid
) {
131 public String
getTestRunUuid() {
136 public void setTestRunUuid(String testRunUuid
) {
137 this.testRunUuid
= testRunUuid
;
140 public void notifyTestRun(TestRun testRun
) {
141 testRunUuid
= testRun
.getUuid();
144 public void setExceptionMessage(String exceptionMessage
) {
145 this.exceptionMessage
= exceptionMessage
;