KickJava   Java API By Example, From Geeks To Geeks.

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


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: ExpectLinkWithURLValidator.java,v 1.1 2004/10/11 23:36:06 tuan08 Exp $
14  **/

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