Search in sources :

Example 21 with Validator

use of com.opensymphony.xwork2.validator.Validator 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)

Example 22 with Validator

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

Example 23 with Validator

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

Example 24 with Validator

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

Example 25 with Validator

use of com.opensymphony.xwork2.validator.Validator in project struts by apache.

the class CreditCardAction method setUp.

protected void setUp() throws Exception {
    super.setUp();
    validator = new CreditCardValidator();
    action = new CreditCardAction();
    TextProviderFactory tpf = container.getInstance(TextProviderFactory.class);
    context = new DummyValidatorContext(action, tpf);
    validator.setValidatorContext(context);
    ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
    valueStack.push(action);
    validator.setValueStack(valueStack);
}
Also used : TextProviderFactory(com.opensymphony.xwork2.TextProviderFactory) ValueStack(com.opensymphony.xwork2.util.ValueStack) DummyValidatorContext(com.opensymphony.xwork2.validator.DummyValidatorContext) ValueStackFactory(com.opensymphony.xwork2.util.ValueStackFactory)

Aggregations

ValueStack (com.opensymphony.xwork2.util.ValueStack)19 DummyValidatorContext (com.opensymphony.xwork2.validator.DummyValidatorContext)18 ValidatorContext (com.opensymphony.xwork2.validator.ValidatorContext)18 URLValidator (com.opensymphony.xwork2.validator.validators.URLValidator)16 RegexFieldValidator (com.opensymphony.xwork2.validator.validators.RegexFieldValidator)12 EmailValidator (com.opensymphony.xwork2.validator.validators.EmailValidator)9 ValueStackFactory (com.opensymphony.xwork2.util.ValueStackFactory)7 RequiredStringValidator (com.opensymphony.xwork2.validator.validators.RequiredStringValidator)6 HashMap (java.util.HashMap)6 ActionSupport (com.opensymphony.xwork2.ActionSupport)5 Validator (com.opensymphony.xwork2.validator.Validator)5 ExpressionValidator (com.opensymphony.xwork2.validator.validators.ExpressionValidator)5 VisitorFieldValidator (com.opensymphony.xwork2.validator.validators.VisitorFieldValidator)5 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)4 RequiredFieldValidator (com.opensymphony.xwork2.validator.validators.RequiredFieldValidator)4 StringLengthFieldValidator (com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator)4 TextProviderFactory (com.opensymphony.xwork2.TextProviderFactory)3 ConversionErrorFieldValidator (com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator)3 DateRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator)3 DoubleRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator)3