new class to manage icons. Showing failures,etc on a test suite.
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / testpool / TestSuite.java
1 /*
2  * Created on Jul 31, 2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */
7 package net.sourceforge.phpeclipse.phpunit.testpool;
8
9 import java.util.Vector;
10
11 /**
12  * @author Ali Echihabi
13  *
14  * To change the template for this generated type comment go to
15  * Window>Preferences>Java>Code Generation>Code and Comments
16  */
17 public class TestSuite {
18
19
20
21         private boolean hasFailure;
22         private boolean isAllPass;
23         private boolean hasError;
24         private Vector testCases; // current or actual.
25         private Vector testSuites; // current or actual.
26         private String name;
27         private String id;
28         private int numTestCasesExpected; //expected
29         private int numTestCasesRunSoFar;
30         TestSuite parent;
31
32
33
34         /**
35          * @param name
36          * @param testID
37          * @param testCount
38          */
39         public TestSuite(TestSuite parent, String name, String testID, int testCount) {
40                 
41                 this.parent = parent;
42                 this.id = testID;
43                 this.name = name;
44                 this.numTestCasesExpected = testCount;
45         
46                 testCases = new Vector();
47                 testSuites = new Vector();
48                 
49                 hasError = false;
50                 isAllPass = true;
51                 hasFailure = false;
52         }
53                         
54         public void addTestCase(TestCase test) {
55                 testCases.addElement(test);
56                 test.setParentSuite(this);
57                 numTestCasesRunSoFar++;
58         }
59         
60         public void removeTestCase(TestCase test) {}
61         
62         public boolean contains(TestCase test) {
63                 
64                 return false;
65                 
66         }
67         
68         public String toString() {
69                 
70                 String string = "";
71                 
72                 //print test cases.
73                 TestCase tc = null;
74                 for(int i = 0; i < testCases.size(); i++) {
75                         
76                         tc = (TestCase) testCases.elementAt(i);
77                         string += "  - " + tc.getTestID() + ", " + tc.getTestName() + "\n";
78                         
79                         
80                 }
81                 
82                 for(int i = 0; i < testSuites.size(); i++) 
83                         string += ((TestSuite) testSuites.elementAt(i)).toString();
84                 
85                 //print its own test suites.            
86                 return string;
87         }
88
89         /**
90          * @return
91          */
92         public String getId() {
93                 return id;
94         }
95
96         /**
97          * @return
98          */
99         public String getName() {
100                 return name;
101         }
102
103         /**
104          * @return
105          */
106         public int getNumTestCasesExpected() {
107                 return numTestCasesExpected;
108         }
109
110         /**
111          * @param string
112          */
113         public void setId(String string) {
114                 id = string;
115         }
116
117         /**
118          * @param string
119          */
120         public void setName(String string) {
121                 name = string;
122         }
123
124         /**
125          * @param i
126          */
127         public void setNumTestCasesExpected(int i) {
128                 numTestCasesExpected = i;
129         }
130
131         /**
132          * @param suite
133          */
134         public void addTestSuite(TestSuite suite) {
135                 testSuites.addElement(suite);
136                 
137         }
138
139         /**
140          * @return
141          */
142         public boolean isFinished() {
143                 
144                 return numTestCasesRunSoFar >= numTestCasesExpected;
145                 
146         }
147
148         /**
149          * @return
150          */
151         public TestSuite getParent() {
152                 return parent;
153         }
154
155         /**
156          * @param suite
157          */
158         public void setParent(TestSuite suite) {
159                 parent = suite;
160         }
161
162         /**
163          * @return
164          */
165         public int getNumTestCases() {
166                 
167                 return testCases.size();
168         }
169
170         /**
171          * @return
172          */
173         public Vector getTestCases() {
174                 return testCases;
175         }
176
177         /**
178          * @return
179          */
180         public Vector getTestSuites() {
181                 return testSuites;
182         }
183
184         /**
185          * @param vector
186          */
187         public void setTestCases(Vector vector) {
188                 testCases = vector;
189         }
190
191         /**
192          * @param vector
193          */
194         public void setTestSuites(Vector vector) {
195                 testSuites = vector;
196         }
197
198         /**
199          * @return
200          */
201         public boolean hasError() {
202
203                 return hasError;                
204
205         }
206         
207         public void setHasError() {
208                 
209                 if(hasError)
210                         return;
211                         
212                 hasError = true;
213                 
214                 if(parent != null)
215                         parent.setHasError();
216         }
217
218
219         /**
220          * @return
221          */
222         public boolean hasFailure() {
223
224                 return hasFailure;              
225
226         }
227         
228         public void setHasFailure() {
229                 
230                 if(hasFailure)
231                         return;
232                         
233                 hasFailure = true;
234                 
235                 if(parent != null)
236                         parent.setHasFailure();
237         }
238         
239
240         public boolean isAllPass() {
241                 
242                 return !hasError() && !hasFailure();
243                 
244         }       
245 }