Search in sources :

Example 1 with URLValidator

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());
}
Also used : URLValidator(com.opensymphony.xwork2.validator.validators.URLValidator)

Example 2 with URLValidator

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);
}
Also used : Pattern(java.util.regex.Pattern) URLValidator(com.opensymphony.xwork2.validator.validators.URLValidator)

Example 3 with URLValidator

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());
}
Also used : URLValidator(com.opensymphony.xwork2.validator.validators.URLValidator)

Example 4 with URLValidator

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());
}
Also used : Pattern(java.util.regex.Pattern) URLValidator(com.opensymphony.xwork2.validator.validators.URLValidator)

Example 5 with URLValidator

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());
}
Also used : URLValidator(com.opensymphony.xwork2.validator.validators.URLValidator)

Aggregations

URLValidator (com.opensymphony.xwork2.validator.validators.URLValidator)14 Pattern (java.util.regex.Pattern)4 DateRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator)1 DoubleRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator)1 EmailValidator (com.opensymphony.xwork2.validator.validators.EmailValidator)1 ExpressionValidator (com.opensymphony.xwork2.validator.validators.ExpressionValidator)1 IntRangeFieldValidator (com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator)1 RequiredFieldValidator (com.opensymphony.xwork2.validator.validators.RequiredFieldValidator)1 RequiredStringValidator (com.opensymphony.xwork2.validator.validators.RequiredStringValidator)1 StringLengthFieldValidator (com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator)1 HashMap (java.util.HashMap)1 List (java.util.List)1