KickJava   Java API By Example, From Geeks To Geeks.

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


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

15 public class ExpectLinkWithTextValidator implements Validator {
16   private String JavaDoc text_ ;
17   private int numberOfLink_ = -1;
18   
19   public ExpectLinkWithTextValidator(String JavaDoc text, int numberOfLink) {
20     text_ = text ;
21     numberOfLink_ = numberOfLink ;
22   }
23   
24   public ExpectLinkWithTextValidator(String JavaDoc text) {
25     text_ = text ;
26   }
27   
28   public boolean validate(WebResponse response, ExoWebClient client) throws Exception JavaDoc {
29     WebLink[] links = Util.findLinksWithText(response , null, text_) ;
30     if(numberOfLink_ == -1) {
31         return links.length > 0 ;
32     }
33     return links.length == numberOfLink_ ;
34   }
35   
36   public String JavaDoc getName() { return "ExpectLinkWithTextValidator" ; }
37    
38    public String JavaDoc getDescription() {
39      if(numberOfLink_ == -1) {
40        return "Make sure that the return xhtml has at least one link with text '..." + text_ + "...'" ;
41      }
42      return "Make sure that the return xhtml has " + numberOfLink_ + " links with text '" + text_ + "'" ;
43    }
44 }
Popular Tags