]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResultLogger.java
Make default execution ressources temp dir dependent of the JVM OS user, in order...
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / tree / TreeTestResultLogger.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
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 package org.argeo.slc.core.test.tree;
17
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;
23
24 /**
25 * Listener logging tree-based test results to the underlying logging system.
26 *
27 * @see TreeTestResult
28 *
29 */
30 public class TreeTestResultLogger implements TreeTestResultListener {
31
32 private static Log log = LogFactory.getLog(TreeTestResultLogger.class);
33
34 private Boolean logExceptionMessages = false;
35
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)) {
41 log.info(msg);
42 } else if (testResultPart.getStatus().equals(TestStatus.FAILED)) {
43 log.warn(msg);
44 } else if (testResultPart.getStatus().equals(TestStatus.ERROR)) {
45 if (logExceptionMessages)
46 msg = msg + "\n" + testResultPart.getExceptionMessage();
47
48 log.error(msg);
49
50 if (!logExceptionMessages || log.isDebugEnabled())
51 log.debug(testResultPart.getExceptionMessage());
52
53 } else {
54 log.error("Unknow test status: " + msg);
55 }
56 }
57
58 public void close(TreeTestResult testResult) {
59 log.info("Test result " + testResult.getUuid() + " closed.");
60 }
61
62 public void setLogExceptionMessages(Boolean logExceptionMessages) {
63 this.logExceptionMessages = logExceptionMessages;
64 }
65
66 public void addAttachment(TreeTestResult treeTestResult,
67 Attachment attachment) {
68 if (log.isDebugEnabled())
69 log.debug("Attachment " + attachment + " added to "
70 + treeTestResult.getUuid());
71 }
72
73 }