]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/SimpleResultPart.java
Start working on serialized JMS
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / SimpleResultPart.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.slc.core.test;
18
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;
23
24 /**
25 * <p>
26 * Basic implementation of a result part, implementing the standard three status
27 * approach for test results.
28 * </p>
29 *
30 * @see TestStatus
31 */
32 public class SimpleResultPart implements TestResultPart, TestStatus,
33 TestRunAware {
34
35 private Long tid;
36
37 private String testRunUuid;
38
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;
43
44 public SimpleResultPart() {
45 }
46
47 public SimpleResultPart(Integer status, String message) {
48 this(status, message, null);
49 }
50
51 public SimpleResultPart(Integer status, String message, Exception exception) {
52 this.status = status;
53 this.message = message;
54 setException(exception);
55 }
56
57 public String getMessage() {
58 return message;
59 }
60
61 public void setMessage(String message) {
62 this.message = message;
63 }
64
65 public void setStatus(Integer status) {
66 this.status = status;
67 }
68
69 public Integer getStatus() {
70 return status;
71 }
72
73 public String getExceptionMessage() {
74 return exceptionMessage;
75 }
76
77 public void setException(Exception exception) {
78 if (exception == null)
79 return;
80
81 StringBuffer buf = new StringBuffer("");
82 buf.append(exception.toString());
83 buf.append('\n');
84 for (StackTraceElement elem : exception.getStackTrace()) {
85 buf.append('\t').append(elem.toString()).append('\n');
86 }
87
88 if (exception.getCause() != null)
89 addRootCause(buf, exception.getCause());
90
91 this.exceptionMessage = buf.toString();
92 }
93
94 protected void addRootCause(StringBuffer buf, Throwable cause) {
95 if (cause == null)
96 return;
97
98 buf.append("Caused by: " + cause.getMessage());
99 for (StackTraceElement elem : cause.getStackTrace()) {
100 buf.append('\t').append(elem.toString()).append('\n');
101 }
102
103 if (cause.getCause() != null) {
104 addRootCause(buf, cause.getCause());
105 }
106 }
107
108 @Override
109 public String toString() {
110 StringBuffer buf = new StringBuffer("");
111 buf.append(SlcTestUtils.statusToString(status));
112 if (status == PASSED || status == FAILED) {
113 buf.append(' ');
114 } else if (status == ERROR) {
115 buf.append(" ");
116 }
117 buf.append(message);
118 return buf.toString();
119 }
120
121 /** @deprecated */
122 Long getTid() {
123 return tid;
124 }
125
126 /** @deprecated */
127 void setTid(Long tid) {
128 this.tid = tid;
129 }
130
131 public String getTestRunUuid() {
132 return testRunUuid;
133 }
134
135 /** For ORM */
136 public void setTestRunUuid(String testRunUuid) {
137 this.testRunUuid = testRunUuid;
138 }
139
140 public void notifyTestRun(TestRun testRun) {
141 testRunUuid = testRun.getUuid();
142 }
143
144 public void setExceptionMessage(String exceptionMessage) {
145 this.exceptionMessage = exceptionMessage;
146 }
147
148 }