]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/test/SimpleTestResult.java
update
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / test / SimpleTestResult.java
1 package org.argeo.slc.core.test;
2
3 import java.util.Date;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.TreeMap;
7 import java.util.UUID;
8 import java.util.Vector;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 import org.argeo.slc.SlcException;
14 import org.argeo.slc.test.TestResult;
15 import org.argeo.slc.test.TestResultPart;
16 import org.argeo.slc.test.TestRun;
17
18 /**
19 * Basic implementation of a test result containing only a list of result parts.
20 */
21 public class SimpleTestResult implements TestResult {
22 private static Log log = LogFactory.getLog(SimpleTestResult.class);
23
24 private String uuid;
25 private String currentTestRunUuid;
26
27 private Boolean throwError = true;
28
29 private Date closeDate;
30 private List<TestResultPart> parts = new Vector<TestResultPart>();
31
32 private Map<String, String> attributes = new TreeMap<String, String>();
33
34 public void addResultPart(TestResultPart part) {
35 if (throwError && part.getStatus() == ERROR) {
36 throw new SlcException(
37 "There was an error in the underlying test: "
38 + part.getExceptionMessage());
39 }
40 parts.add(part);
41 if (log.isDebugEnabled())
42 log.debug(part);
43 }
44
45 public void close() {
46 parts.clear();
47 closeDate = new Date();
48 }
49
50 public List<TestResultPart> getParts() {
51 return parts;
52 }
53
54 public Date getCloseDate() {
55 return closeDate;
56 }
57
58 public void setThrowError(Boolean throwError) {
59 this.throwError = throwError;
60 }
61
62 public void notifyTestRun(TestRun testRun) {
63 currentTestRunUuid = testRun.getUuid();
64 }
65
66 public String getUuid() {
67 if (uuid == null) {
68 uuid = UUID.randomUUID().toString();
69 }
70 return uuid;
71 }
72
73 public void setUuid(String uuid) {
74 this.uuid = uuid;
75 }
76
77 public String getCurrentTestRunUuid() {
78 return currentTestRunUuid;
79 }
80
81 public Map<String, String> getAttributes() {
82 return attributes;
83 }
84
85 }