Dashboard > WebWork > ... > Testing > Testing Validation
  WebWork Log In View a printable version of the current page.  
  Testing Validation
Added by Martin Gilday, last edited by Martin Gilday on May 02, 2007
Labels: 
(None)

Test validation for an action

This is an example of how to simply test validation when using xml validation files. The following code would test the contents of the xml file "ValidateableAction-contextName-validation.xml".

public void testActionValidation() throws ValidationException {
   DefaultActionValidatorManager validator = new DefaultActionValidatorManager();
   ValidateableAction action = new ValidateableAction();
   action.setParam(new Param());
   ... // setup the parameters you want to test

   validator.validate(action, "contextName");
   assertTrue(action.hasErrors()); // If the validation should fail
   assertFalse(action.hasErrors()); // If the validation should pass
   // action.getActionErrors() will give you the errors that occurred
}

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators