use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class URLValidatorTest method testValidUrlWithDefaultRegex.
public void testValidUrlWithDefaultRegex() throws Exception {
URLValidator validator = new URLValidator();
Pattern pattern = Pattern.compile(validator.getUrlRegex(), Pattern.CASE_INSENSITIVE);
assertFalse(pattern.matcher("myapp://test.com").matches());
assertFalse(pattern.matcher("myap://test.com").matches());
assertFalse(pattern.matcher("").matches());
assertFalse(pattern.matcher(" ").matches());
assertFalse(pattern.matcher("no url").matches());
assertFalse(pattern.matcher("http://example.com////////////////////////////////////////////////////////////////////////////////////??").matches());
assertTrue(pattern.matcher("http://www.opensymphony.com").matches());
assertTrue(pattern.matcher("https://www.opensymphony.com").matches());
assertTrue(pattern.matcher("https://www.opensymphony.com:443/login").matches());
assertTrue(pattern.matcher("http://localhost:8080/myapp").matches());
assertTrue(pattern.matcher("http://www.legalspace.com/__media__/js/netsoltrademark.php?d=www.a-vos-travaux.fr%2Facheter-un-aspirateur-sans-sac-pas-cher%2F").matches());
assertTrue(UrlValidator.getInstance().isValid("http://www.legalspace.com/__media__/js/netsoltrademark.php?d=www.a-vos-travaux.fr%2Facheter-un-aspirateur-sans-sac-pas-cher%2F"));
assertTrue(pattern.matcher("http://www.duadmin.isaev.Infoduadmin.Isaev.info/?a%5B%5D=%3Ca%20href%3Dhttp%3A%2F%2Fwww.aspert.fr%2Fun-seche-cheveux-lisseur-est-il-vraiment-utile%2F%3Eseche%20cheveux%20dyson%20test%3C%2Fa").matches());
assertTrue(UrlValidator.getInstance().isValid("http://www.duadmin.isaev.Infoduadmin.Isaev.info/?a%5B%5D=%3Ca%20href%3Dhttp%3A%2F%2Fwww.aspert.fr%2Fun-seche-cheveux-lisseur-est-il-vraiment-utile%2F%3Eseche%20cheveux%20dyson%20test%3C%2Fa"));
assertTrue(pattern.matcher("http://netsol-underconstruction-page-monitor-1.com/__media__/js/netsoltrademark.php?d=www.le-soutien-scolaire.fr%2Favis-et-test-comparatifs-des-robots-multifonctions%2F").matches());
assertTrue(UrlValidator.getInstance().isValid("http://netsol-underconstruction-page-monitor-1.com/__media__/js/netsoltrademark.php?d=www.le-soutien-scolaire.fr%2Favis-et-test-comparatifs-des-robots-multifonctions%2F"));
// this will cause test to hang indefinitely using JDK 1.8.0_121, Struts 2.5.10.1 and JUnit 4.5
assertTrue(pattern.matcher("http://www.javaroad.jp/news/redirect.jsp?link=http://www.forum-course-de-cote.com/que-penser-dune-trottinette-electrique/").matches());
assertTrue(UrlValidator.getInstance().isValid("http://www.javaroad.jp/news/redirect.jsp?link=http://www.forum-course-de-cote.com/que-penser-dune-trottinette-electrique/"));
// this will cause test to hang indefinitely using JDK 1.8.0_121, Struts 2.5.10.1 and JUnit 4.5
assertTrue(pattern.matcher("http://wargame.ch/wc/acw/sub/aotm/guestbook/index.php?page3D183EClearwater20Roofing20Contractors3C/a3E3Ekaldu20non20msg3C/a3E").matches());
assertTrue(UrlValidator.getInstance().isValid("http://wargame.ch/wc/acw/sub/aotm/guestbook/index.php?page3D183EClearwater20Roofing20Contractors3C/a3E3Ekaldu20non20msg3C/a3E"));
assertTrue(pattern.matcher("http://253.254.255.1").matches());
assertTrue(UrlValidator.getInstance().isValid("http://253.254.255.1"));
assertTrue(pattern.matcher("http://253.254.255.12").matches());
assertTrue(UrlValidator.getInstance().isValid("http://253.254.255.12"));
assertTrue(pattern.matcher("http://1.2.3.100").matches());
assertTrue(UrlValidator.getInstance().isValid("http://1.2.3.100"));
assertTrue(pattern.matcher("http://1.2.3.255").matches());
assertTrue(UrlValidator.getInstance().isValid("http://1.2.3.255"));
}
use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class URLValidatorTest method testValidUrl2.
public void testValidUrl2() throws Exception {
URLValidator validator = new URLValidator();
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("testingUrl5");
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.validate(new MyObject());
assertFalse(validator.getValidatorContext().hasErrors());
assertFalse(validator.getValidatorContext().hasActionErrors());
assertFalse(validator.getValidatorContext().hasActionMessages());
assertFalse(validator.getValidatorContext().hasFieldErrors());
}
use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class URLValidatorTest method testInvalidEmptyValue.
public void testInvalidEmptyValue() throws Exception {
URLValidator validator = new URLValidator();
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("testingUrl2");
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.validate(new MyObject());
assertFalse(validator.getValidatorContext().hasErrors());
assertFalse(validator.getValidatorContext().hasActionErrors());
assertFalse(validator.getValidatorContext().hasActionMessages());
assertFalse(validator.getValidatorContext().hasFieldErrors());
}
use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class AnnotationActionValidatorManagerTest method no_testGetValidatorsFromInterface.
public void no_testGetValidatorsFromInterface() {
List validatorList = annotationActionValidatorManager.getValidators(SimpleAnnotationAction3.class, alias);
// 17 in the class hierarchy + 1 in the interface + 1 in interface alias
assertEquals(19, validatorList.size());
final FieldValidator v = (FieldValidator) validatorList.get(0);
assertEquals("bar", v.getFieldName());
assertTrue(v instanceof RequiredFieldValidator);
final FieldValidator v1 = (FieldValidator) validatorList.get(1);
assertEquals("bar", v1.getFieldName());
assertTrue(v1 instanceof IntRangeFieldValidator);
final FieldValidator vdouble = (FieldValidator) validatorList.get(2);
assertEquals("percentage", vdouble.getFieldName());
assertTrue(vdouble instanceof DoubleRangeFieldValidator);
final FieldValidator v2 = (FieldValidator) validatorList.get(3);
assertEquals("baz", v2.getFieldName());
assertTrue(v2 instanceof IntRangeFieldValidator);
final FieldValidator v3 = (FieldValidator) validatorList.get(4);
assertEquals("date", v3.getFieldName());
assertTrue(v3 instanceof DateRangeFieldValidator);
// action-level validator comes first
final Validator v4 = (Validator) validatorList.get(5);
assertTrue(v4 instanceof ExpressionValidator);
// action-level validator comes first
final Validator v5 = (Validator) validatorList.get(6);
assertTrue(v5 instanceof ExpressionValidator);
// action-level validator comes first
final Validator v6 = (Validator) validatorList.get(7);
assertTrue(v6 instanceof ExpressionValidator);
// action-level validator comes first
final Validator v7 = (Validator) validatorList.get(8);
assertTrue(v7 instanceof ExpressionValidator);
// action-level validator comes first
final Validator v8 = (Validator) validatorList.get(9);
assertTrue(v8 instanceof ExpressionValidator);
final FieldValidator v9 = (FieldValidator) validatorList.get(10);
assertEquals("datefield", v9.getFieldName());
assertTrue(v9 instanceof DateRangeFieldValidator);
final FieldValidator v10 = (FieldValidator) validatorList.get(11);
assertEquals("emailaddress", v10.getFieldName());
assertTrue(v10 instanceof EmailValidator);
final FieldValidator v11 = (FieldValidator) validatorList.get(12);
assertEquals("intfield", v11.getFieldName());
assertTrue(v11 instanceof IntRangeFieldValidator);
final FieldValidator v12 = (FieldValidator) validatorList.get(13);
assertEquals("customfield", v12.getFieldName());
assertTrue(v12 instanceof RequiredFieldValidator);
final FieldValidator v13 = (FieldValidator) validatorList.get(14);
assertEquals("stringisrequired", v13.getFieldName());
assertTrue(v13 instanceof RequiredStringValidator);
final FieldValidator v14 = (FieldValidator) validatorList.get(15);
assertEquals("needstringlength", v14.getFieldName());
assertTrue(v14 instanceof StringLengthFieldValidator);
final FieldValidator v15 = (FieldValidator) validatorList.get(16);
assertEquals("hreflocation", v15.getFieldName());
assertTrue(v15 instanceof URLValidator);
final FieldValidator v16 = (FieldValidator) validatorList.get(17);
assertEquals("data", v16.getFieldName());
assertTrue(v16 instanceof RequiredFieldValidator);
final FieldValidator v17 = (FieldValidator) validatorList.get(18);
assertEquals("data", v17.getFieldName());
assertTrue(v17 instanceof RequiredStringValidator);
}
use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class URLValidatorTest method testCollectionOfUrlsSafness.
public void testCollectionOfUrlsSafness() throws Exception {
URLValidator validator = new URLValidator();
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("urlSafeness");
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.setDefaultMessage("Wrong URL provided: ${currentValue}");
validator.validate(new MyObject());
assertTrue(validator.getValidatorContext().hasErrors());
assertFalse(validator.getValidatorContext().hasActionErrors());
assertFalse(validator.getValidatorContext().hasActionMessages());
assertTrue(validator.getValidatorContext().hasFieldErrors());
assertEquals(2, validator.getValidatorContext().getFieldErrors().get("urlSafeness").size());
assertEquals("Wrong URL provided: ${1+2}", validator.getValidatorContext().getFieldErrors().get("urlSafeness").get(0));
assertEquals("Wrong URL provided: %{2+3}", validator.getValidatorContext().getFieldErrors().get("urlSafeness").get(1));
}
Aggregations