KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > tasks > junit > SuiteResult


1 package hudson.tasks.junit;
2
3 import org.dom4j.Document;
4 import org.dom4j.DocumentException;
5 import org.dom4j.Element;
6 import org.dom4j.io.SAXReader;
7
8 import java.io.File JavaDoc;
9 import java.io.Serializable JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.util.List JavaDoc;
12
13 /**
14  * Result of one test suite.
15  *
16  * <p>
17  * The notion of "test suite" is rather arbitrary in JUnit ant task.
18  * It's basically one invocation of junit.
19  *
20  * <p>
21  * This object is really only used as a part of the persisted
22  * object tree.
23  *
24  * @author Kohsuke Kawaguchi
25  */

26 public final class SuiteResult implements Serializable JavaDoc {
27     private final String JavaDoc name;
28     private final String JavaDoc stdout;
29     private final String JavaDoc stderr;
30
31     /**
32      * All test cases.
33      */

34     private final List JavaDoc<CaseResult> cases = new ArrayList JavaDoc<CaseResult>();
35     private transient TestResult parent;
36
37     SuiteResult(File JavaDoc xmlReport) throws DocumentException {
38         Document result = new SAXReader().read(xmlReport);
39         Element root = result.getRootElement();
40         name = root.attributeValue("name");
41
42         stdout = root.elementText("system-out");
43         stderr = root.elementText("system-err");
44
45         for (Element e : (List JavaDoc<Element>)root.elements("testcase")) {
46             cases.add(new CaseResult(this,e));
47         }
48     }
49
50     public String JavaDoc getName() {
51         return name;
52     }
53
54     public String JavaDoc getStdout() {
55         return stdout;
56     }
57
58     public String JavaDoc getStderr() {
59         return stderr;
60     }
61
62     public TestResult getParent() {
63         return parent;
64     }
65
66     public List JavaDoc<CaseResult> getCases() {
67         return cases;
68     }
69
70     public SuiteResult getPreviousResult() {
71         TestResult pr = parent.getPreviousResult();
72         if(pr==null) return null;
73         return pr.getSuite(name);
74     }
75
76     /**
77      * Returns the {@link CaseResult} whose {@link CaseResult#getName()}
78      * is the same as the given string.
79      *
80      * <p>
81      * Note that test name needs not be unique.
82      */

83     public CaseResult getCase(String JavaDoc name) {
84         for (CaseResult c : cases) {
85             if(c.getName().equals(name))
86                 return c;
87         }
88         return null;
89     }
90
91     /*package*/ boolean freeze(TestResult owner) {
92         if(this.parent!=null)
93             return false; // already frozen
94

95         this.parent = owner;
96         for (CaseResult c : cases)
97             c.freeze(this);
98         return true;
99     }
100 }
101
Popular Tags