X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.runtime%2Fsrc%2Forg%2Fargeo%2Fslc%2Fruntime%2Ftest%2FSimpleResultPart.java;h=7ba74646331283d97667807794473197e549b1d9;hb=f27e8fc8c485b839950728871671605b8666770e;hp=2c7726fcdd51d138e8535af84eca9c32aff41954;hpb=dfac3414a612edd63eaaf8568ddc80271707af22;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.runtime/src/org/argeo/slc/runtime/test/SimpleResultPart.java b/org.argeo.slc.runtime/src/org/argeo/slc/runtime/test/SimpleResultPart.java index 2c7726fcd..7ba746463 100644 --- a/org.argeo.slc.runtime/src/org/argeo/slc/runtime/test/SimpleResultPart.java +++ b/org.argeo.slc.runtime/src/org/argeo/slc/runtime/test/SimpleResultPart.java @@ -1,150 +1,135 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.slc.runtime.test; - -import java.io.Serializable; - -import org.argeo.slc.test.TestResultPart; -import org.argeo.slc.test.TestRun; -import org.argeo.slc.test.TestRunAware; -import org.argeo.slc.test.TestStatus; - -/** - *

- * Basic implementation of a result part, implementing the standard three status - * approach for test results. - *

- * - * @see TestStatus - */ -public class SimpleResultPart implements TestResultPart, TestStatus, - TestRunAware, Serializable { - private static final long serialVersionUID = 6669675957685071901L; - - private Long tid; - - private String testRunUuid; - - /** The status. Default to ERROR since it should always be explicitely set. */ - private Integer status = ERROR; - private String message; - private String exceptionMessage; - - public SimpleResultPart() { - } - - public SimpleResultPart(Integer status, String message) { - this(status, message, null); - } - - public SimpleResultPart(Integer status, String message, Exception exception) { - this.status = status; - this.message = message; - setException(exception); - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public Integer getStatus() { - return status; - } - - public String getExceptionMessage() { - return exceptionMessage; - } - - public void setException(Exception exception) { - if (exception == null) - return; - - StringBuffer buf = new StringBuffer(""); - buf.append(exception.toString()); - buf.append('\n'); - for (StackTraceElement elem : exception.getStackTrace()) { - buf.append('\t').append(elem.toString()).append('\n'); - } - - if (exception.getCause() != null) - addRootCause(buf, exception.getCause()); - - this.exceptionMessage = buf.toString(); - } - - protected void addRootCause(StringBuffer buf, Throwable cause) { - if (cause == null) - return; - - buf.append("Caused by: " + cause.getMessage()); - for (StackTraceElement elem : cause.getStackTrace()) { - buf.append('\t').append(elem.toString()).append('\n'); - } - - if (cause.getCause() != null) { - addRootCause(buf, cause.getCause()); - } - } - - @Override - public String toString() { - StringBuffer buf = new StringBuffer(""); - buf.append(SlcTestUtils.statusToString(status)); - if (status == PASSED || status == FAILED) { - buf.append(' '); - } else if (status == ERROR) { - buf.append(" "); - } - buf.append(message); - return buf.toString(); - } - - /** @deprecated */ - Long getTid() { - return tid; - } - - /** @deprecated */ - void setTid(Long tid) { - this.tid = tid; - } - - public String getTestRunUuid() { - return testRunUuid; - } - - /** For ORM */ - public void setTestRunUuid(String testRunUuid) { - this.testRunUuid = testRunUuid; - } - - public void notifyTestRun(TestRun testRun) { - testRunUuid = testRun.getUuid(); - } - - public void setExceptionMessage(String exceptionMessage) { - this.exceptionMessage = exceptionMessage; - } - -} +package org.argeo.slc.runtime.test; + +import java.io.Serializable; + +import org.argeo.slc.test.TestResultPart; +import org.argeo.slc.test.TestRun; +import org.argeo.slc.test.TestRunAware; +import org.argeo.slc.test.TestStatus; + +/** + *

+ * Basic implementation of a result part, implementing the standard three status + * approach for test results. + *

+ * + * @see TestStatus + */ +public class SimpleResultPart implements TestResultPart, TestStatus, + TestRunAware, Serializable { + private static final long serialVersionUID = 6669675957685071901L; + + private Long tid; + + private String testRunUuid; + + /** The status. Default to ERROR since it should always be explicitely set. */ + private Integer status = ERROR; + private String message; + private String exceptionMessage; + + public SimpleResultPart() { + } + + public SimpleResultPart(Integer status, String message) { + this(status, message, null); + } + + public SimpleResultPart(Integer status, String message, Exception exception) { + this.status = status; + this.message = message; + setException(exception); + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Integer getStatus() { + return status; + } + + public String getExceptionMessage() { + return exceptionMessage; + } + + public void setException(Exception exception) { + if (exception == null) + return; + + StringBuffer buf = new StringBuffer(""); + buf.append(exception.toString()); + buf.append('\n'); + for (StackTraceElement elem : exception.getStackTrace()) { + buf.append('\t').append(elem.toString()).append('\n'); + } + + if (exception.getCause() != null) + addRootCause(buf, exception.getCause()); + + this.exceptionMessage = buf.toString(); + } + + protected void addRootCause(StringBuffer buf, Throwable cause) { + if (cause == null) + return; + + buf.append("Caused by: " + cause.getMessage()); + for (StackTraceElement elem : cause.getStackTrace()) { + buf.append('\t').append(elem.toString()).append('\n'); + } + + if (cause.getCause() != null) { + addRootCause(buf, cause.getCause()); + } + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(""); + buf.append(SlcTestUtils.statusToString(status)); + if (status == PASSED || status == FAILED) { + buf.append(' '); + } else if (status == ERROR) { + buf.append(" "); + } + buf.append(message); + return buf.toString(); + } + + /** @deprecated */ + Long getTid() { + return tid; + } + + /** @deprecated */ + void setTid(Long tid) { + this.tid = tid; + } + + public String getTestRunUuid() { + return testRunUuid; + } + + /** For ORM */ + public void setTestRunUuid(String testRunUuid) { + this.testRunUuid = testRunUuid; + } + + public void notifyTestRun(TestRun testRun) { + testRunUuid = testRun.getUuid(); + } + + public void setExceptionMessage(String exceptionMessage) { + this.exceptionMessage = exceptionMessage; + } + +}