title: Struts2 unit testing annotation validator.
body: <p>Hi I have the following page model class. </p>
  
  <pre><code>public class CarModel extends PageModel {
      private static final long serialVersionUID = 4766706536002862335L;
  
      private String            name;
      private String            description;
  
  
      @RequiredStringValidator(type = ValidatorType.FIELD, key = "errors.required.name", trim = true)
      public String getName() {
          return this.name;
      }
  
      public void setName(final String name) {
          this.name = name;
      }
  
      @RequiredStringValidator(type = ValidatorType.FIELD, key = "errors.required.description", trim = true)
      public String getDescription() {
          return this.description;
      }
  
      public void setDescription(final String description) {
          this.description = description;
      }
  }
  </code></pre>
  
  <p>I have a action class. </p>
  
  <pre><code>@Component(value = "CarAction")
  @Namespace(value = "/car")
  @Action(value = "/car")
  @ExceptionMapping(exception = "com.cars.AutomobileException", result = ".page.car")
  @Result(name = "success", type = "tiles", location = ".page.car")
  public class CarAction extends BaseAction implements ParameterAware {
     private CarModel pageModel;
  
     @Action(value = "/add", results = @Result(name = "addResult", params = { "actionName",
              "addResult" }, type = "chain"))
      @InputConfig(methodName = "execute")
      @Validations(visitorFields = { @VisitorFieldValidator(shortCircuit = true, message = "Their are errors to be corrected", fieldName = "pageModel") })
      public String add() {
          this.validate();
          return SUCCESS;
      }
  }
  </code></pre>
  
  <p>here is my base action.</p>
  
  <pre><code>@InterceptorRefs({
          @InterceptorRef(value = "createSession"),
          @InterceptorRef(value = "tokenSession", params = { "includeMethods", "add,addResult" }),
          @InterceptorRef(value = "exception"),
          @InterceptorRef(value = "alias"),
          @InterceptorRef(value = "i18n"),
          @InterceptorRef(value = "chain"),
          @InterceptorRef(value = "timer"),
          @InterceptorRef(value = "logger"),
          @InterceptorRef(value = "checkbox"),
          @InterceptorRef(value = "staticParams"),
          @InterceptorRef(value = "actionMappingParams"),
          @InterceptorRef(value = "params", params = { "excludeParams", "dojo\\..*,^struts\\..*" }),
          @InterceptorRef(value = "conversionError"),
          @InterceptorRef(value = "validation", params = { "excludeMethods", "cancel,execute,reset,next,previous,updateItemPerPage,goToPage,browse", "validateAnnotatedMethodOnly", "true" }),
          @InterceptorRef(value = "annotationWorkflow", params = { "excludeMethods", "input,back,cancel,browse" }),
          @InterceptorRef(value = "execAndWait") })
  @ExceptionMappings({
          @ExceptionMapping(exception = "org.springframework.dao.DataAccessException", result = "..page.data.error"),
          @ExceptionMapping(result = ".page.servlet.error", exception = "javax.servlet.ServletException"),
          @ExceptionMapping(result = ".page.runtime.error", exception = "java.lang.NullPointerException"),
          @ExceptionMapping(result = ".page.runtime.error", exception = "java.lang.outOfMemory"),
          @ExceptionMapping(result = ".page.runtime.error", exception = "java.lang.ArrayIndexOutOfBoundsException"),
          @ExceptionMapping(result = ".page.runtime.error", exception = "java.lang.ArithmeticException") })
  @Results({
          @Result(name = "invalid.token", location = ".page.runtime.error", type = "tiles"),
          @Result(name = "wait", location = ".page.wait", type = "tiles") })
  @ParentPackage("tiles-default")
  public abstract class BaseAction extends ActionSupport {
      private static final long serialVersionUID = -5898754579799304669L;
  
  }
  </code></pre>
  
  <p>in my junit test </p>
  
  <pre><code>this.request.setParameter("name", "FD");
  final ActionProxy proxy = this.getActionProxy("/car/car");
  Assert.assertNotNull(proxy);
  
  final CarAction carAction = CarAction.class.cast(proxy.getAction());
  
  final CarModel pageModel = new CarModel(5);
  
  carAction.setPageModel(pageModel);
  Assert.assertEquals(carAction.execute(), Action.SUCCESS);
  
  -- this is where it fails. 
  final Map&lt;String, List&lt;String&gt;&gt; fieldErrors = carAction.getFieldErrors();
  Assert.assertFalse(fieldErrors.isEmpty());
  </code></pre>
  
  <p>Anybody know how to get annotation validation to fire in junit test? </p>
  
  <p>Thanks</p>