KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > web > TestSuites


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.test.web;
6
7 import java.util.* ;
8 import org.exoplatform.test.web.unit.WebUnit;
9
10 /**
11  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
12  * @since Oct 2, 2004
13  * @version $Id: TestSuites.java,v 1.1 2004/10/11 23:36:03 tuan08 Exp $
14  */

15 public class TestSuites {
16   private List suites_ ;
17   private int suiteIdx_ ;
18   private int unitIdx_ ;
19   private WebUnit currentUnit_ ;
20   private WebUnitSuite currentSuite_ ;
21   
22   public TestSuites() {
23     suites_ = new ArrayList() ;
24   }
25   
26   public void addSuite(WebUnitSuite suite) { suites_.add(suite) ; }
27   public List getSuites() { return suites_ ; }
28   public void setSuites(List suites) { suites_ = suites ; }
29
30   public void reset() {
31     suiteIdx_ = 0 ;
32     unitIdx_ = 0 ;
33     for(int i = 0; i < suites_.size(); i++) {
34       WebUnitSuite suite = (WebUnitSuite)suites_.get(i) ;
35       if(suite.getStatus() != WebUnitSuite.IGNORE_STATUS) {
36         suite.setStatus(WebUnitSuite.NOT_RUN_STATUS) ;
37       }
38       List units = suite.getWebUnits() ;
39       for(int j = 0; j < units.size(); j++) {
40         WebUnit unit = (WebUnit) units.get(j) ;
41         unit.getMonitor().reset() ;
42       }
43     }
44   }
45   
46   public WebUnit getCurrentWebUnit() { return currentUnit_ ; }
47   public WebUnitSuite getCurrentWebUnitSuite() { return currentSuite_ ; }
48   
49   public boolean nextUnit() {
50     currentUnit_ = null ;
51     if(suiteIdx_ == suites_.size()) {
52       currentSuite_ = null ;
53       return false ;
54     }
55     WebUnitSuite currentSuite = (WebUnitSuite)suites_.get(suiteIdx_) ;
56     if(currentSuite.getStatus() == WebUnitSuite.IGNORE_STATUS) {
57       suiteIdx_++ ;
58       unitIdx_ = 0 ;
59       return nextUnit() ;
60     }
61     if(unitIdx_ == currentSuite.getWebUnits().size()) {
62       suiteIdx_++ ;
63       unitIdx_ = 0 ;
64       return nextUnit() ;
65     }
66     currentUnit_ = (WebUnit) currentSuite.getWebUnits().get(unitIdx_) ;
67     currentSuite_ = currentSuite ;
68     if(currentSuite_.getStatus() == WebUnitSuite.NOT_RUN_STATUS) {
69       currentSuite_.setStatus(WebUnitSuite.OK_STATUS) ;
70     }
71     unitIdx_++ ;
72     return true ;
73   }
74   
75   public TestSuites softClone() {
76     TestSuites ts = new TestSuites() ;
77     ts.setSuites(suites_) ;
78     return ts ;
79   }
80   
81   public String JavaDoc getHtmlSummary() throws Exception JavaDoc {
82     StringBuffer JavaDoc b = new StringBuffer JavaDoc(10000) ;
83     b.append("<html>").
84         append("<body>") ;
85     for(int i = 0 ; i < suites_.size(); i++) {
86       WebUnitSuite suite = (WebUnitSuite) suites_.get(i) ;
87       suite.appendHtmlTextSummary(b) ;
88     }
89     b. append("</body>").
90       append("</html>") ;
91     return b.toString() ;
92   }
93   
94   public String JavaDoc getTextSummary() {
95     StringBuffer JavaDoc b = new StringBuffer JavaDoc(10000) ;
96     for(int i = 0 ; i < suites_.size(); i++) {
97       WebUnitSuite suite = (WebUnitSuite) suites_.get(i) ;
98       b.append(suite.getTextSummary()).append("\n") ;
99     }
100     return b.toString() ;
101   }
102 }
Popular Tags