1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }