KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > test > DefaultTestSuiteReport


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.test;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 /**
24  * Simple implementation of the <tt>TestReport</tt> interface
25  * for <tt>TestSuite</tt>
26  *
27  * @author <a HREF="mailto:vhardy@apache.lorg">Vincent Hardy</a>
28  * @version $Id: DefaultTestSuiteReport.java,v 1.5 2004/08/18 07:16:57 vhardy Exp $
29  */

30 public class DefaultTestSuiteReport implements TestSuiteReport {
31     /**
32      * Error code for a failed TestSuite
33      */

34     public static final String JavaDoc ERROR_CHILD_TEST_FAILED
35         = "DefaultTestSuiteReport.error.child.test.failed";
36
37     /**
38      * Entry for a failed child test report
39      */

40     public static final String JavaDoc ENTRY_KEY_FAILED_CHILD_TEST_REPORT
41         = "DefaultTestSuiteReport.entry.key.failed.child.test.report";
42
43     /**
44      * Entry for a passed child test report
45      */

46     public static final String JavaDoc ENTRY_KEY_PASSED_CHILD_TEST_REPORT
47         = "DefaultTestSuiteReport.entry.key.passed.child.test.report";
48
49     /**
50      * Set of <tt>TestReport</tt> coming from the <tt>TestSuite</tt>
51      */

52     protected Vector JavaDoc reports = new Vector JavaDoc();
53
54     /**
55      * TestSuite that created this report
56      */

57     protected TestSuite testSuite;
58
59     /**
60      * Descriptions in addition to that coming from children.
61      */

62     protected Entry[] description = null;
63
64     /**
65      * Parent report in case this report is part of a bigger one.
66      */

67     protected TestSuiteReport parent;
68
69     /**
70      * Status of the TestSuite
71      */

72     private boolean passed = true;
73     
74     public DefaultTestSuiteReport(TestSuite testSuite){
75         if(testSuite == null){
76             throw new IllegalArgumentException JavaDoc();
77         }
78
79         this.testSuite = testSuite;
80     }
81
82     public Test getTest(){
83         return testSuite;
84     }
85
86     public String JavaDoc getErrorCode(){
87         if(hasPassed()){
88             return null;
89         }
90         else{
91             return ERROR_CHILD_TEST_FAILED;
92         }
93     }
94
95     public TestSuiteReport getParentReport(){
96         return parent;
97     }
98
99     public void setParentReport(TestSuiteReport parent){
100         this.parent = parent;
101     }
102
103     public boolean hasPassed(){
104         Iterator JavaDoc iter = reports.iterator();
105
106         boolean passed = true;
107
108         while(iter.hasNext()){
109             TestReport childReport = (TestReport)iter.next();
110             passed = passed && childReport.hasPassed();
111         }
112         
113         return passed;
114     }
115     
116     public void addDescriptionEntry(String JavaDoc key,
117                                     Object JavaDoc value){
118         addDescriptionEntry(new Entry(key, value));
119     }
120
121     protected void addDescriptionEntry(Entry entry){
122         if(description == null){
123             description = new Entry[1];
124             description[0] = entry;
125         }
126         else{
127             Entry[] oldDescription = description;
128             description = new Entry[description.length + 1];
129             System.arraycopy(oldDescription, 0, description, 0,
130                              oldDescription.length);
131             description[oldDescription.length] = entry;
132         }
133     }
134
135     public Entry[] getDescription(){
136         Iterator JavaDoc iter = reports.iterator();
137         Vector JavaDoc descs = new Vector JavaDoc();
138
139         while(iter.hasNext()){
140             TestReport childReport = (TestReport)iter.next();
141             if(!childReport.hasPassed()){
142                 TestReport.Entry entry
143                     = new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_FAILED_CHILD_TEST_REPORT, null),
144                                            childReport);
145                 descs.addElement(entry);
146             }
147         }
148         
149         iter = reports.iterator();
150         while(iter.hasNext()){
151             TestReport childReport = (TestReport)iter.next();
152             if(childReport.hasPassed()){
153                 TestReport.Entry entry
154                     = new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_PASSED_CHILD_TEST_REPORT, null),
155                                            childReport);
156                 descs.addElement(entry);
157             }
158         }
159         
160         TestReport.Entry[] entries = null;
161         if(descs.size() > 0){
162             entries = new TestReport.Entry[descs.size()];
163             descs.copyInto(entries);
164         }
165
166         if(description != null){
167             TestReport.Entry[] e = entries;
168             entries = new TestReport.Entry[e.length + description.length];
169             System.arraycopy(e, 0, entries, 0, e.length);
170             System.arraycopy(description, 0, entries, e.length, description.length);
171         }
172
173         return entries;
174     }
175
176     public void addReport(TestReport report){
177         if(report == null){
178             throw new IllegalArgumentException JavaDoc();
179         }
180
181         report.setParentReport(this);
182         reports.addElement(report);
183     }
184     
185
186     public TestReport[] getChildrenReports(){
187         int nReports = reports.size();
188         TestReport[] r = new TestReport[nReports];
189         reports.copyInto(r);
190         return r;
191     }
192 }
193
Popular Tags