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