]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/org/argeo/slc/core/test/SimpleTestResult.java
Adapt to changes in Commons
[gpl/argeo-slc.git] / org.argeo.slc.core / src / org / argeo / slc / core / test / SimpleTestResult.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
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;
17
18 import java.util.Date;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.TreeMap;
22 import java.util.UUID;
23 import java.util.Vector;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.argeo.slc.SlcException;
28 import org.argeo.slc.test.TestResult;
29 import org.argeo.slc.test.TestResultPart;
30 import org.argeo.slc.test.TestRun;
31
32 /**
33 * Basic implementation of a test result containing only a list of result parts.
34 */
35 public class SimpleTestResult implements TestResult {
36 private static Log log = LogFactory.getLog(SimpleTestResult.class);
37
38 private String uuid;
39 private String currentTestRunUuid;
40
41 private Boolean throwError = true;
42
43 private Date closeDate;
44 private List<TestResultPart> parts = new Vector<TestResultPart>();
45
46 private Map<String, String> attributes = new TreeMap<String, String>();
47
48 public void addResultPart(TestResultPart part) {
49 if (throwError && part.getStatus() == ERROR) {
50 throw new SlcException(
51 "There was an error in the underlying test: "
52 + part.getExceptionMessage());
53 }
54 parts.add(part);
55 if (log.isDebugEnabled())
56 log.debug(part);
57 }
58
59 public void close() {
60 parts.clear();
61 closeDate = new Date();
62 }
63
64 public List<TestResultPart> getParts() {
65 return parts;
66 }
67
68 public Date getCloseDate() {
69 return closeDate;
70 }
71
72 public void setThrowError(Boolean throwError) {
73 this.throwError = throwError;
74 }
75
76 public void notifyTestRun(TestRun testRun) {
77 currentTestRunUuid = testRun.getUuid();
78 }
79
80 public String getUuid() {
81 if (uuid == null) {
82 uuid = UUID.randomUUID().toString();
83 }
84 return uuid;
85 }
86
87 public void setUuid(String uuid) {
88 this.uuid = uuid;
89 }
90
91 public String getCurrentTestRunUuid() {
92 return currentTestRunUuid;
93 }
94
95 public Map<String, String> getAttributes() {
96 return attributes;
97 }
98
99 public void setAttributes(Map<String, String> attributes) {
100 this.attributes = attributes;
101 }
102
103 }