use of com.opensymphony.xwork2.validator.Validator 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.Validator 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.Validator in project struts by apache.
the class ConversionErrorFieldValidatorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
ValueStack stack = ActionContext.getContext().getValueStack();
Map<String, ConversionData> conversionErrors = new HashMap<>();
conversionErrors.put("foo", new ConversionData("bar", Integer.class));
ActionContext.of(stack.getContext()).withConversionErrors(conversionErrors).bind();
validator = new ConversionErrorFieldValidator();
validationAware = new ValidationAwareSupport();
DelegatingValidatorContext validatorContext = new DelegatingValidatorContext(validationAware, container.getInstance(TextProviderFactory.class));
stack.push(validatorContext);
validator.setValidatorContext(validatorContext);
validator.setFieldName("foo");
validator.setValueStack(ActionContext.getContext().getValueStack());
assertEquals(0, validationAware.getFieldErrors().size());
}
use of com.opensymphony.xwork2.validator.Validator 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.Validator 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());
}
Aggregations