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
.tree
;
18 import org
.apache
.commons
.logging
.Log
;
19 import org
.apache
.commons
.logging
.LogFactory
;
20 import org
.argeo
.slc
.core
.attachment
.Attachment
;
21 import org
.argeo
.slc
.test
.TestResultPart
;
22 import org
.argeo
.slc
.test
.TestStatus
;
25 * Listener logging tree-based test results to the underlying logging system.
30 public class TreeTestResultLogger
implements TreeTestResultListener
{
32 private static Log log
= LogFactory
.getLog(TreeTestResultLogger
.class);
34 private Boolean logExceptionMessages
= false;
36 public void resultPartAdded(TreeTestResult testResult
,
37 TestResultPart testResultPart
) {
38 String msg
= testResultPart
+ " - " + testResult
.getUuid() + ":"
39 + testResult
.getCurrentPath();
40 if (testResultPart
.getStatus().equals(TestStatus
.PASSED
)) {
42 } else if (testResultPart
.getStatus().equals(TestStatus
.FAILED
)) {
44 } else if (testResultPart
.getStatus().equals(TestStatus
.ERROR
)) {
45 if (logExceptionMessages
)
46 msg
= msg
+ "\n" + testResultPart
.getExceptionMessage();
50 if (!logExceptionMessages
|| log
.isDebugEnabled())
51 log
.debug(testResultPart
.getExceptionMessage());
54 log
.error("Unknow test status: " + msg
);
58 public void close(TreeTestResult testResult
) {
59 log
.info("Test result " + testResult
.getUuid() + " closed.");
62 public void setLogExceptionMessages(Boolean logExceptionMessages
) {
63 this.logExceptionMessages
= logExceptionMessages
;
66 public void addAttachment(TreeTestResult treeTestResult
,
67 Attachment attachment
) {
68 if (log
.isDebugEnabled())
69 log
.debug("Attachment " + attachment
+ " added to "
70 + treeTestResult
.getUuid());