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