use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class URLValidatorTest method testAcceptNullValueForMutualExclusionOfValidators.
public void testAcceptNullValueForMutualExclusionOfValidators() throws Exception {
URLValidator validator = new URLValidator();
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("testingUrl1");
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 testLongRunningValidations.
public void testLongRunningValidations() throws Exception {
URLValidator validator = new URLValidator();
Pattern pattern = Pattern.compile(validator.getUrlRegex(), Pattern.CASE_INSENSITIVE);
long time = System.currentTimeMillis();
assertFalse(pattern.matcher("ftp://aaaaaaaaaaaaaaaaaaaaaaaa|").matches());
assertTrue("Validation did not complete in half a second", System.currentTimeMillis() - time < 500);
time = System.currentTimeMillis();
assertFalse(pattern.matcher("ftp://bbbbbbbbbbbbbbbbbbbbbbbb}").matches());
assertTrue("Validation did not complete in half a second", System.currentTimeMillis() - time < 500);
time = System.currentTimeMillis();
assertFalse(pattern.matcher("ftp://cccccccccccccccccccccccc{").matches());
assertTrue("Validation did not complete in half a second", System.currentTimeMillis() - time < 500);
}
use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class URLValidatorTest method testArrayOfUrls.
public void testArrayOfUrls() throws Exception {
URLValidator validator = new URLValidator();
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("urls");
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.validate(new MyObject());
assertTrue(validator.getValidatorContext().hasErrors());
assertFalse(validator.getValidatorContext().hasActionErrors());
assertFalse(validator.getValidatorContext().hasActionMessages());
assertTrue(validator.getValidatorContext().hasFieldErrors());
assertEquals(1, validator.getValidatorContext().getFieldErrors().get("urls").size());
}
use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class URLValidatorTest method testValidUrlWithRegex.
public void testValidUrlWithRegex() throws Exception {
URLValidator validator = new URLValidator();
validator.setUrlRegex("^myapp:\\/\\/[a-z]*\\.com$");
Pattern pattern = Pattern.compile(validator.getUrlRegex());
assertTrue(pattern.matcher("myapp://test.com").matches());
assertFalse(pattern.matcher("myap://test.com").matches());
}
use of com.opensymphony.xwork2.validator.validators.URLValidator in project struts by apache.
the class URLValidatorTest method testValidUrl1.
public void testValidUrl1() throws Exception {
URLValidator validator = new URLValidator();
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("testingUrl4");
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());
}
Aggregations