KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > web > validator > ExpectBlockValidator


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.validator;
6
7 import org.exoplatform.test.web.ExoWebClient;
8 import com.meterware.httpunit.*;
9 /**
10  * May 21, 2004
11  * @author: Tuan Nguyen
12  * @email: tuan08@users.sourceforge.net
13  * @version: $Id: ExpectBlockValidator.java,v 1.1 2004/10/11 23:36:06 tuan08 Exp $
14  **/

15 public class ExpectBlockValidator implements Validator {
16     static private WebTable[] EMPTY = new WebTable[0] ;
17   private String JavaDoc blockId_ ;
18   private int numberOfBlock_ = -1 ;
19   
20   public ExpectBlockValidator(String JavaDoc text) {
21     blockId_ = text ;
22   }
23   
24   public ExpectBlockValidator(String JavaDoc text, int num) {
25     blockId_ = text ;
26     numberOfBlock_ = num ;
27   }
28   
29   
30   public boolean validate(WebResponse response, ExoWebClient client) throws Exception JavaDoc {
31     WebTable[] tables = response.getMatchingTables(WebTable.MATCH_ID, blockId_) ;
32     if(tables == null) tables = EMPTY ;
33     if(numberOfBlock_ == -1) {
34         return tables.length > 0 ;
35     }
36     return tables.length == numberOfBlock_ ;
37   }
38   
39   public String JavaDoc getName() { return "ExpectBlockValidator" ; }
40   
41   public String JavaDoc getDescription() {
42     return "Make sure that the return xhtml has a block(it can be a div, table.. block) with the id '" + blockId_ + "'" ;
43   }
44 }
Popular Tags