package org.argeo.slc.runtime.test; import java.util.Date; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.UUID; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; import org.argeo.slc.test.TestResult; import org.argeo.slc.test.TestResultPart; import org.argeo.slc.test.TestRun; /** * Basic implementation of a test result containing only a list of result parts. */ public class SimpleTestResult implements TestResult { private static Log log = LogFactory.getLog(SimpleTestResult.class); private String uuid; private String currentTestRunUuid; private Boolean throwError = true; private Date closeDate; private List parts = new Vector(); private Map attributes = new TreeMap(); public void addResultPart(TestResultPart part) { if (throwError && part.getStatus() == ERROR) { throw new SlcException( "There was an error in the underlying test: " + part.getExceptionMessage()); } parts.add(part); if (log.isDebugEnabled()) log.debug(part); } public void close() { parts.clear(); closeDate = new Date(); } public List getParts() { return parts; } public Date getCloseDate() { return closeDate; } public void setThrowError(Boolean throwError) { this.throwError = throwError; } public void notifyTestRun(TestRun testRun) { currentTestRunUuid = testRun.getUuid(); } public String getUuid() { if (uuid == null) { uuid = UUID.randomUUID().toString(); } return uuid; } public void setUuid(String uuid) { this.uuid = uuid; } public String getCurrentTestRunUuid() { return currentTestRunUuid; } public Map getAttributes() { return attributes; } public void setAttributes(Map attributes) { this.attributes = attributes; } }