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