1 5 package org.exoplatform.test.web.validator; 6 7 import org.exoplatform.test.web.*; 8 import com.meterware.httpunit.*; 9 15 public class ExpectLinkWithTextValidator implements Validator { 16 private String text_ ; 17 private int numberOfLink_ = -1; 18 19 public ExpectLinkWithTextValidator(String text, int numberOfLink) { 20 text_ = text ; 21 numberOfLink_ = numberOfLink ; 22 } 23 24 public ExpectLinkWithTextValidator(String text) { 25 text_ = text ; 26 } 27 28 public boolean validate(WebResponse response, ExoWebClient client) throws Exception { 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 getName() { return "ExpectLinkWithTextValidator" ; } 37 38 public String 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 |