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