Commits

Anonymous committed 3fd5ce2

Refactor ActionValidatorManager
Issue number: XW-331
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@775e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 92bc9f8

Comments (0)

Files changed (8)

File src/java/com/opensymphony/xwork/validator/ActionValidatorManager.java

 /*
- * Copyright (c) 2002-2003 by OpenSymphony
+ * Copyright (c) 2002-2006 by OpenSymphony
  * All rights reserved.
  */
 package com.opensymphony.xwork.validator;
 
-import com.opensymphony.util.FileManager;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import java.util.*;
-
+import java.util.List;
 
 /**
- * This is the entry point into XWork's rule-based validation framework.  Validation rules are
- * specified in XML configuration files named "className-contextName-validation.xml" where
- * className is the name of the class the configuration is for and -contextName is optional
- * (contextName is an arbitrary key that is used to look up additional validation rules for a
- * specific context).
+ * <code>ActionValidatorManager</code>
  *
- * @author Jason Carreira
- * @author Mark Woon
- * @author James House
  * @author Rainer Hermanns
+ * @version $Id$
  */
-public class ActionValidatorManager {
-
-    /** The file suffix for any validation file. */
-    protected static final String VALIDATION_CONFIG_SUFFIX = "-validation.xml";
-
-    private static final Map validatorCache = Collections.synchronizedMap(new HashMap());
-    private static final Map validatorFileCache = Collections.synchronizedMap(new HashMap());
-    private static final Log LOG = LogFactory.getLog(ActionValidatorManager.class);
+public interface ActionValidatorManager {
 
     /**
      * Returns a list of validators for the given class and context. This is the primary
      * @param context the context of the action class - can be <tt>null</tt>.
      * @return a list of all validators for the given class and context.
      */
-    public static synchronized List getValidators(Class clazz, String context) {
-        final String validatorKey = buildValidatorKey(clazz, context);
-
-        if (validatorCache.containsKey(validatorKey)) {
-            if (FileManager.isReloadingConfigs()) {
-                validatorCache.put(validatorKey, buildValidatorConfigs(clazz, context, true, null));
-            }
-        } else {
-            validatorCache.put(validatorKey, buildValidatorConfigs(clazz, context, false, null));
-        }
-
-        // get the set of validator configs
-        List cfgs = (List) validatorCache.get(validatorKey);
-
-        // create clean instances of the validators for the caller's use
-        ArrayList validators = new ArrayList(cfgs.size());
-        for (Iterator iterator = cfgs.iterator(); iterator.hasNext(); ) {
-            ValidatorConfig cfg = (ValidatorConfig) iterator.next();
-            Validator validator = ValidatorFactory.getValidator(cfg);
-            validator.setValidatorType(cfg.getType());
-            validators.add(validator);
-        }
-
-        return validators;
-    }
+    List getValidators(Class clazz, String context);
 
     /**
      * Validates the given object using action and its context.
      * @param context the action's context.
      * @throws ValidationException if an error happens when validating the action.
      */
-    public void validate(Object object, String context) throws ValidationException {
-        ValidatorContext validatorContext = new DelegatingValidatorContext(object);
-        validate(object, context, validatorContext);
-    }
+    void validate(Object object, String context) throws ValidationException;
 
     /**
      * Validates an action give its context and a validation context.
      * @param validatorContext
      * @throws ValidationException if an error happens when validating the action.
      */
-    public static void validate(Object object, String context, ValidatorContext validatorContext) throws ValidationException {
-        List validators = getValidators(object.getClass(), context);
-        Set shortcircuitedFields = null;
-
-        for (Iterator iterator = validators.iterator(); iterator.hasNext();) {
-            Validator validator = (Validator) iterator.next();
-            validator.setValidatorContext(validatorContext);
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Running validator: " + validator + " for object " + object);
-            }
-
-            FieldValidator fValidator = null;
-            String fullFieldName = null;
-
-            if (validator instanceof FieldValidator) {
-                fValidator = (FieldValidator) validator;
-                fullFieldName = fValidator.getValidatorContext().getFullFieldName(fValidator.getFieldName());
-
-                if ((shortcircuitedFields != null) && shortcircuitedFields.contains(fullFieldName)) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Short-circuited, skipping");
-                    }
-
-                    continue;
-                }
-            }
-
-            if (validator instanceof ShortCircuitableValidator && ((ShortCircuitableValidator) validator).isShortCircuit()) {
-                // get number of existing errors
-                List errs = null;
-
-                if (fValidator != null) {
-                    if (validatorContext.hasFieldErrors()) {
-                        Collection fieldErrors = (Collection) validatorContext.getFieldErrors().get(fullFieldName);
-
-                        if (fieldErrors != null) {
-                            errs = new ArrayList(fieldErrors);
-                        }
-                    }
-                } else if (validatorContext.hasActionErrors()) {
-                    Collection actionErrors = validatorContext.getActionErrors();
-
-                    if (actionErrors != null) {
-                        errs = new ArrayList(actionErrors);
-                    }
-                }
-
-                validator.validate(object);
-
-                if (fValidator != null) {
-                    if (validatorContext.hasFieldErrors()) {
-                        Collection errCol = (Collection) validatorContext.getFieldErrors().get(fullFieldName);
-
-                        if ((errCol != null) && !errCol.equals(errs)) {
-                            if (LOG.isDebugEnabled()) {
-                                LOG.debug("Short-circuiting on field validation");
-                            }
-
-                            if (shortcircuitedFields == null) {
-                                shortcircuitedFields = new TreeSet();
-                            }
-
-                            shortcircuitedFields.add(fullFieldName);
-                        }
-                    }
-                } else if (validatorContext.hasActionErrors()) {
-                    Collection errCol = validatorContext.getActionErrors();
-
-                    if ((errCol != null) && !errCol.equals(errs)) {
-                        if (LOG.isDebugEnabled()) {
-                            LOG.debug("Short-circuiting");
-                        }
-
-                        break;
-                    }
-                }
-
-                continue;
-            }
-
-            validator.validate(object);
-        }
-    }
-
-    /**
-     * Builds a key for validators - used when caching validators.
-     *
-     * @param clazz the action.
-     * @param context the action's context.
-     * @return a validator key which is the class name plus context.
-     */
-    protected static String buildValidatorKey(Class clazz, String context) {
-        StringBuffer sb = new StringBuffer(clazz.getName());
-        sb.append("/");
-        sb.append(context);
-        return sb.toString();
-    }
-
-    private static List buildAliasValidatorConfigs(Class aClass, String context, boolean checkFile) {
-        String fileName = aClass.getName().replace('.', '/') + "-" + context + VALIDATION_CONFIG_SUFFIX;
-
-        return loadFile(fileName, aClass, checkFile);
-    }
-
-    private static List buildClassValidatorConfigs(Class aClass, boolean checkFile) {
-        String fileName = aClass.getName().replace('.', '/') + VALIDATION_CONFIG_SUFFIX;
-
-        return loadFile(fileName, aClass, checkFile);
-    }
-
-    /**
-     * <p>This method 'collects' all the validator configurations for a given
-     * action invocation.</p>
-     *
-     * <p>It will traverse up the class hierarchy looking for validators for every super class
-     * and directly implemented interface of the current action, as well as adding validators for
-     * any alias of this invocation. Nifty!</p>
-     *
-     * <p>Given the following class structure:
-     * <pre>
-     *   interface Thing;
-     *   interface Animal extends Thing;
-     *   interface Quadraped extends Animal;
-     *   class AnimalImpl implements Animal;
-     *   class QuadrapedImpl extends AnimalImpl implements Quadraped;
-     *   class Dog extends QuadrapedImpl;
-     * </pre></p>
-     *
-     * <p>This method will look for the following config files for Dog:
-     * <pre>
-     *   Animal
-     *   Animal-context
-     *   AnimalImpl
-     *   AnimalImpl-context
-     *   Quadraped
-     *   Quadraped-context
-     *   QuadrapedImpl
-     *   QuadrapedImpl-context
-     *   Dog
-     *   Dog-context
-     * </pre></p>
-     *
-     * <p>Note that the validation rules for Thing is never looked for because no class in the
-     * hierarchy directly implements Thing.</p>
-     *
-     * @param clazz the Class to look up validators for.
-     * @param context the context to use when looking up validators.
-     * @param checkFile true if the validation config file should be checked to see if it has been
-     *      updated.
-     * @param checked the set of previously checked class-contexts, null if none have been checked
-     * @return a list of validator configs for the given class and context.
-     */
-    private static List buildValidatorConfigs(Class clazz, String context, boolean checkFile, Set checked) {
-        List validatorConfigs = new ArrayList();
-
-        if (checked == null) {
-            checked = new TreeSet();
-        } else if (checked.contains(clazz.getName())) {
-            return validatorConfigs;
-        }
-
-        if (clazz.isInterface()) {
-            Class[] interfaces = clazz.getInterfaces();
-
-            for (int x = 0; x < interfaces.length; x++) {
-                validatorConfigs.addAll(buildValidatorConfigs(interfaces[x], context, checkFile, checked));
-            }
-        } else {
-            if (!clazz.equals(Object.class)) {
-                validatorConfigs.addAll(buildValidatorConfigs(clazz.getSuperclass(), context, checkFile, checked));
-            }
-        }
-
-        // look for validators for implemented interfaces
-        Class[] interfaces = clazz.getInterfaces();
-
-        for (int x = 0; x < interfaces.length; x++) {
-            if (checked.contains(interfaces[x].getName())) {
-                continue;
-            }
-
-            validatorConfigs.addAll(buildClassValidatorConfigs(interfaces[x], checkFile));
-
-            if (context != null) {
-                validatorConfigs.addAll(buildAliasValidatorConfigs(interfaces[x], context, checkFile));
-            }
-
-            checked.add(interfaces[x].getName());
-        }
-
-        validatorConfigs.addAll(buildClassValidatorConfigs(clazz, checkFile));
-
-        if (context != null) {
-            validatorConfigs.addAll(buildAliasValidatorConfigs(clazz, context, checkFile));
-        }
-
-        checked.add(clazz.getName());
-
-        return validatorConfigs;
-    }
-
-    private static List loadFile(String fileName, Class clazz, boolean checkFile) {
-        List retList = Collections.EMPTY_LIST;
-
-        if ((checkFile && FileManager.fileNeedsReloading(fileName)) || !validatorFileCache.containsKey(fileName)) {
-            InputStream is = null;
-
-            try {
-                is = FileManager.loadFile(fileName, clazz);
-
-                if (is != null) {
-                    retList = new ArrayList(ValidatorFileParser.parseActionValidatorConfigs(is, fileName));
-                }
-            } catch (Exception e) {
-                LOG.error("Caught exception while loading file " + fileName, e);
-            } finally {
-                if (is != null) {
-                    try {
-                        is.close();
-                    } catch (IOException e) {
-                        LOG.error("Unable to close input stream for " + fileName, e);
-                    }
-                }
-            }
-
-            validatorFileCache.put(fileName, retList);
-        } else {
-            retList = (List) validatorFileCache.get(fileName);
-        }
-
-        return retList;
-    }
-}
+    void validate(Object object, String context, ValidatorContext validatorContext) throws ValidationException;
+}

File src/java/com/opensymphony/xwork/validator/ActionValidatorManagerFactory.java

 
     private static final Log LOG = LogFactory.getLog(ActionValidatorManagerFactory.class);
 
-    private static ActionValidatorManager instance = new ActionValidatorManager();
+    private static ActionValidatorManager instance = new DefaultActionValidatorManager();
 
     static {
         try {

File src/java/com/opensymphony/xwork/validator/DefaultActionValidatorManager.java

+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator;
+
+import com.opensymphony.util.FileManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.util.*;
+
+
+/**
+ * This is the entry point into XWork's rule-based validation framework.  Validation rules are
+ * specified in XML configuration files named "className-contextName-validation.xml" where
+ * className is the name of the class the configuration is for and -contextName is optional
+ * (contextName is an arbitrary key that is used to look up additional validation rules for a
+ * specific context).
+ *
+ * @author Jason Carreira
+ * @author Mark Woon
+ * @author James House
+ * @author Rainer Hermanns
+ */
+public class DefaultActionValidatorManager implements ActionValidatorManager {
+
+    /** The file suffix for any validation file. */
+    protected static final String VALIDATION_CONFIG_SUFFIX = "-validation.xml";
+
+    private static final Map validatorCache = Collections.synchronizedMap(new HashMap());
+    private static final Map validatorFileCache = Collections.synchronizedMap(new HashMap());
+    private static final Log LOG = LogFactory.getLog(DefaultActionValidatorManager.class);
+
+    /**
+     * Returns a list of validators for the given class and context. This is the primary
+     * lookup method for validators.
+     *
+     * @param clazz the class to lookup.
+     * @param context the context of the action class - can be <tt>null</tt>.
+     * @return a list of all validators for the given class and context.
+     */
+    public synchronized List getValidators(Class clazz, String context) {
+        final String validatorKey = buildValidatorKey(clazz, context);
+
+        if (validatorCache.containsKey(validatorKey)) {
+            if (FileManager.isReloadingConfigs()) {
+                validatorCache.put(validatorKey, buildValidatorConfigs(clazz, context, true, null));
+            }
+        } else {
+            validatorCache.put(validatorKey, buildValidatorConfigs(clazz, context, false, null));
+        }
+
+        // get the set of validator configs
+        List cfgs = (List) validatorCache.get(validatorKey);
+
+        // create clean instances of the validators for the caller's use
+        ArrayList validators = new ArrayList(cfgs.size());
+        for (Iterator iterator = cfgs.iterator(); iterator.hasNext(); ) {
+            ValidatorConfig cfg = (ValidatorConfig) iterator.next();
+            Validator validator = ValidatorFactory.getValidator(cfg);
+            validator.setValidatorType(cfg.getType());
+            validators.add(validator);
+        }
+
+        return validators;
+    }
+
+    /**
+     * Validates the given object using action and its context.
+     *
+     * @param object the action to validate.
+     * @param context the action's context.
+     * @throws ValidationException if an error happens when validating the action.
+     */
+    public void validate(Object object, String context) throws ValidationException {
+        ValidatorContext validatorContext = new DelegatingValidatorContext(object);
+        validate(object, context, validatorContext);
+    }
+
+    /**
+     * Validates an action give its context and a validation context.
+     *
+     * @param object the action to validate.
+     * @param context the action's context.
+     * @param validatorContext
+     * @throws ValidationException if an error happens when validating the action.
+     */
+    public void validate(Object object, String context, ValidatorContext validatorContext) throws ValidationException {
+        List validators = getValidators(object.getClass(), context);
+        Set shortcircuitedFields = null;
+
+        for (Iterator iterator = validators.iterator(); iterator.hasNext();) {
+            Validator validator = (Validator) iterator.next();
+            validator.setValidatorContext(validatorContext);
+
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Running validator: " + validator + " for object " + object);
+            }
+
+            FieldValidator fValidator = null;
+            String fullFieldName = null;
+
+            if (validator instanceof FieldValidator) {
+                fValidator = (FieldValidator) validator;
+                fullFieldName = fValidator.getValidatorContext().getFullFieldName(fValidator.getFieldName());
+
+                if ((shortcircuitedFields != null) && shortcircuitedFields.contains(fullFieldName)) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Short-circuited, skipping");
+                    }
+
+                    continue;
+                }
+            }
+
+            if (validator instanceof ShortCircuitableValidator && ((ShortCircuitableValidator) validator).isShortCircuit()) {
+                // get number of existing errors
+                List errs = null;
+
+                if (fValidator != null) {
+                    if (validatorContext.hasFieldErrors()) {
+                        Collection fieldErrors = (Collection) validatorContext.getFieldErrors().get(fullFieldName);
+
+                        if (fieldErrors != null) {
+                            errs = new ArrayList(fieldErrors);
+                        }
+                    }
+                } else if (validatorContext.hasActionErrors()) {
+                    Collection actionErrors = validatorContext.getActionErrors();
+
+                    if (actionErrors != null) {
+                        errs = new ArrayList(actionErrors);
+                    }
+                }
+
+                validator.validate(object);
+
+                if (fValidator != null) {
+                    if (validatorContext.hasFieldErrors()) {
+                        Collection errCol = (Collection) validatorContext.getFieldErrors().get(fullFieldName);
+
+                        if ((errCol != null) && !errCol.equals(errs)) {
+                            if (LOG.isDebugEnabled()) {
+                                LOG.debug("Short-circuiting on field validation");
+                            }
+
+                            if (shortcircuitedFields == null) {
+                                shortcircuitedFields = new TreeSet();
+                            }
+
+                            shortcircuitedFields.add(fullFieldName);
+                        }
+                    }
+                } else if (validatorContext.hasActionErrors()) {
+                    Collection errCol = validatorContext.getActionErrors();
+
+                    if ((errCol != null) && !errCol.equals(errs)) {
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("Short-circuiting");
+                        }
+
+                        break;
+                    }
+                }
+
+                continue;
+            }
+
+            validator.validate(object);
+        }
+    }
+
+    /**
+     * Builds a key for validators - used when caching validators.
+     *
+     * @param clazz the action.
+     * @param context the action's context.
+     * @return a validator key which is the class name plus context.
+     */
+    protected static String buildValidatorKey(Class clazz, String context) {
+        StringBuffer sb = new StringBuffer(clazz.getName());
+        sb.append("/");
+        sb.append(context);
+        return sb.toString();
+    }
+
+    private List buildAliasValidatorConfigs(Class aClass, String context, boolean checkFile) {
+        String fileName = aClass.getName().replace('.', '/') + "-" + context + VALIDATION_CONFIG_SUFFIX;
+
+        return loadFile(fileName, aClass, checkFile);
+    }
+
+    private List buildClassValidatorConfigs(Class aClass, boolean checkFile) {
+        String fileName = aClass.getName().replace('.', '/') + VALIDATION_CONFIG_SUFFIX;
+
+        return loadFile(fileName, aClass, checkFile);
+    }
+
+    /**
+     * <p>This method 'collects' all the validator configurations for a given
+     * action invocation.</p>
+     *
+     * <p>It will traverse up the class hierarchy looking for validators for every super class
+     * and directly implemented interface of the current action, as well as adding validators for
+     * any alias of this invocation. Nifty!</p>
+     *
+     * <p>Given the following class structure:
+     * <pre>
+     *   interface Thing;
+     *   interface Animal extends Thing;
+     *   interface Quadraped extends Animal;
+     *   class AnimalImpl implements Animal;
+     *   class QuadrapedImpl extends AnimalImpl implements Quadraped;
+     *   class Dog extends QuadrapedImpl;
+     * </pre></p>
+     *
+     * <p>This method will look for the following config files for Dog:
+     * <pre>
+     *   Animal
+     *   Animal-context
+     *   AnimalImpl
+     *   AnimalImpl-context
+     *   Quadraped
+     *   Quadraped-context
+     *   QuadrapedImpl
+     *   QuadrapedImpl-context
+     *   Dog
+     *   Dog-context
+     * </pre></p>
+     *
+     * <p>Note that the validation rules for Thing is never looked for because no class in the
+     * hierarchy directly implements Thing.</p>
+     *
+     * @param clazz the Class to look up validators for.
+     * @param context the context to use when looking up validators.
+     * @param checkFile true if the validation config file should be checked to see if it has been
+     *      updated.
+     * @param checked the set of previously checked class-contexts, null if none have been checked
+     * @return a list of validator configs for the given class and context.
+     */
+    private List buildValidatorConfigs(Class clazz, String context, boolean checkFile, Set checked) {
+        List validatorConfigs = new ArrayList();
+
+        if (checked == null) {
+            checked = new TreeSet();
+        } else if (checked.contains(clazz.getName())) {
+            return validatorConfigs;
+        }
+
+        if (clazz.isInterface()) {
+            Class[] interfaces = clazz.getInterfaces();
+
+            for (int x = 0; x < interfaces.length; x++) {
+                validatorConfigs.addAll(buildValidatorConfigs(interfaces[x], context, checkFile, checked));
+            }
+        } else {
+            if (!clazz.equals(Object.class)) {
+                validatorConfigs.addAll(buildValidatorConfigs(clazz.getSuperclass(), context, checkFile, checked));
+            }
+        }
+
+        // look for validators for implemented interfaces
+        Class[] interfaces = clazz.getInterfaces();
+
+        for (int x = 0; x < interfaces.length; x++) {
+            if (checked.contains(interfaces[x].getName())) {
+                continue;
+            }
+
+            validatorConfigs.addAll(buildClassValidatorConfigs(interfaces[x], checkFile));
+
+            if (context != null) {
+                validatorConfigs.addAll(buildAliasValidatorConfigs(interfaces[x], context, checkFile));
+            }
+
+            checked.add(interfaces[x].getName());
+        }
+
+        validatorConfigs.addAll(buildClassValidatorConfigs(clazz, checkFile));
+
+        if (context != null) {
+            validatorConfigs.addAll(buildAliasValidatorConfigs(clazz, context, checkFile));
+        }
+
+        checked.add(clazz.getName());
+
+        return validatorConfigs;
+    }
+
+    private List loadFile(String fileName, Class clazz, boolean checkFile) {
+        List retList = Collections.EMPTY_LIST;
+
+        if ((checkFile && FileManager.fileNeedsReloading(fileName)) || !validatorFileCache.containsKey(fileName)) {
+            InputStream is = null;
+
+            try {
+                is = FileManager.loadFile(fileName, clazz);
+
+                if (is != null) {
+                    retList = new ArrayList(ValidatorFileParser.parseActionValidatorConfigs(is, fileName));
+                }
+            } catch (Exception e) {
+                LOG.error("Caught exception while loading file " + fileName, e);
+            } finally {
+                if (is != null) {
+                    try {
+                        is.close();
+                    } catch (IOException e) {
+                        LOG.error("Unable to close input stream for " + fileName, e);
+                    }
+                }
+            }
+
+            validatorFileCache.put(fileName, retList);
+        } else {
+            retList = (List) validatorFileCache.get(fileName);
+        }
+
+        return retList;
+    }
+}

File src/java/com/opensymphony/xwork/validator/ValidationInterceptor.java

     }
 
     /**
-     * Gets the current action and its context and calls {@link ActionValidatorManager#validate(Object, String)}.
+     * Gets the current action and its context and calls {@link DefaultActionValidatorManager#validate(Object, String)}.
      *
      * @param invocation the execution state of the Action.
      * @throws Exception if an error occurs validating the action.

File src/test/com/opensymphony/xwork/validator/ActionValidatorManagerTest.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.validator;
-
-import com.opensymphony.xwork.SimpleAction;
-import com.opensymphony.xwork.TestBean;
-import com.opensymphony.xwork.XWorkTestCase;
-import com.opensymphony.xwork.test.DataAware2;
-import com.opensymphony.xwork.test.SimpleAction2;
-import com.opensymphony.xwork.test.SimpleAction3;
-import com.opensymphony.xwork.test.User;
-import com.opensymphony.xwork.validator.validators.*;
-
-import java.util.List;
-
-
-/**
- * ActionValidatorManagerTest
- *
- * @author Jason Carreira
- * @author tm_jee ( tm_jee (at) yahoo.co.uk )
- *         Created Jun 9, 2003 11:03:01 AM
- */
-public class ActionValidatorManagerTest extends XWorkTestCase {
-
-    protected final String alias = "validationAlias";
-
-
-    public void testBuildValidatorKey() {
-        String validatorKey = ActionValidatorManager.buildValidatorKey(SimpleAction.class, alias);
-        assertEquals(SimpleAction.class.getName() + "/" + alias, validatorKey);
-    }
-
-    public void testBuildsValidatorsForAlias() {
-        List validatorList = ActionValidatorManager.getValidators(SimpleAction.class, alias);
-
-        // 6 in the class level + 2 in the alias
-        assertEquals(8, validatorList.size());
-    }
-
-    public void testDefaultMessageInterpolation() {
-        // get validators
-        List validatorList = ActionValidatorManager.getValidators(TestBean.class, "beanMessageBundle");
-        assertEquals(3, validatorList.size());
-
-        try {
-            TestBean bean = new TestBean();
-            bean.setName("foo");
-            bean.setCount(99);
-
-            ValidatorContext context = new GenericValidatorContext(bean);
-            ActionValidatorManager.validate(bean, "beanMessageBundle", context);
-            assertTrue(context.hasErrors());
-            assertTrue(context.hasFieldErrors());
-
-            List l = (List) context.getFieldErrors().get("count");
-            assertNotNull(l);
-            assertEquals(1, l.size());
-            assertEquals("Smaller Invalid Count: 99", l.get(0));
-        } catch (ValidationException ex) {
-            ex.printStackTrace();
-            fail("Validation error: " + ex.getMessage());
-        }
-    }
-
-    public void testGetValidatorsForInterface() {
-        List validatorList = ActionValidatorManager.getValidators(DataAware2.class, alias);
-
-        // 3 in interface hierarchy, 2 from parent interface (1 default + 1 context)
-        assertEquals(3, validatorList.size());
-
-        final FieldValidator dataValidator1 = (FieldValidator) validatorList.get(0);
-        assertEquals("data", dataValidator1.getFieldName());
-        assertTrue(dataValidator1 instanceof RequiredFieldValidator);
-
-        final FieldValidator dataValidator2 = (FieldValidator) validatorList.get(1);
-        assertEquals("data", dataValidator2.getFieldName());
-        assertTrue(dataValidator2 instanceof RequiredStringValidator);
-
-        final FieldValidator blingValidator = (FieldValidator) validatorList.get(2);
-        assertEquals("bling", blingValidator.getFieldName());
-        assertTrue(blingValidator instanceof RequiredStringValidator);
-    }
-
-    public void testGetValidatorsFromInterface() {
-        List validatorList = ActionValidatorManager.getValidators(SimpleAction3.class, alias);
-
-       
-        
-        
-        // 8 in the class hierarchy + 1 in the interface + 1 in interface alias
-        assertEquals(10, validatorList.size());
-
-        // action-level validator comes first
-        final Validator expressionValidator = (Validator) validatorList.get(0);
-        assertTrue(expressionValidator instanceof ExpressionValidator);
-        
-        final FieldValidator barValidator1 = (FieldValidator) validatorList.get(1);
-        assertEquals("bar", barValidator1.getFieldName());
-        assertTrue(barValidator1 instanceof RequiredFieldValidator);
-
-        final FieldValidator barValidator2 = (FieldValidator) validatorList.get(2);
-        assertEquals("bar", barValidator2.getFieldName());
-        assertTrue(barValidator2 instanceof IntRangeFieldValidator);
-
-        final FieldValidator dateValidator = (FieldValidator) validatorList.get(3);
-        assertEquals("date", dateValidator.getFieldName());
-        assertTrue(dateValidator instanceof DateRangeFieldValidator);
-
-        final FieldValidator fooValidator = (FieldValidator) validatorList.get(4);
-        assertEquals("foo", fooValidator.getFieldName());
-        assertTrue(fooValidator instanceof IntRangeFieldValidator);
-
-        final FieldValidator bazValidator = (FieldValidator) validatorList.get(5);
-        assertEquals("baz", bazValidator.getFieldName());
-        assertTrue(bazValidator instanceof IntRangeFieldValidator);
-
-        final FieldValidator bazValidator1 = (FieldValidator) validatorList.get(6);
-        assertEquals("baz", bazValidator1.getFieldName());
-        assertTrue(bazValidator1 instanceof RequiredFieldValidator);
-
-        final FieldValidator bazValidator2 = (FieldValidator) validatorList.get(7);
-        assertEquals("baz", bazValidator2.getFieldName());
-        assertTrue(bazValidator2 instanceof IntRangeFieldValidator);
-
-        final FieldValidator dataValidator1 = (FieldValidator) validatorList.get(8);
-        assertEquals("data", dataValidator1.getFieldName());
-        assertTrue(dataValidator1 instanceof RequiredFieldValidator);
-
-        final FieldValidator dataValidator2 = (FieldValidator) validatorList.get(9);
-        assertEquals("data", dataValidator2.getFieldName());
-        assertTrue(dataValidator2 instanceof RequiredStringValidator);
-    }
-
-    public void testMessageInterpolation() {
-        // get validators
-        List validatorList = ActionValidatorManager.getValidators(TestBean.class, "beanMessageBundle");
-        assertEquals(3, validatorList.size());
-
-        try {
-            TestBean bean = new TestBean();
-            bean.setName("foo");
-            bean.setCount(150);
-
-            ValidatorContext context = new GenericValidatorContext(bean);
-            ActionValidatorManager.validate(bean, "beanMessageBundle", context);
-            assertTrue(context.hasErrors());
-            assertTrue(context.hasFieldErrors());
-
-            List l = (List) context.getFieldErrors().get("count");
-            assertNotNull(l);
-            assertEquals(1, l.size());
-            assertEquals("Count must be between 1 and 100, current value is 150.", l.get(0));
-        } catch (ValidationException ex) {
-            ex.printStackTrace();
-            fail("Validation error: " + ex.getMessage());
-        }
-    }
-
-    public void testSameAliasWithDifferentClass() {
-        List validatorList = ActionValidatorManager.getValidators(SimpleAction.class, alias);
-        List validatorList2 = ActionValidatorManager.getValidators(SimpleAction2.class, alias);
-        assertFalse(validatorList.size() == validatorList2.size());
-    }
-
-    public void testSkipUserMarkerActionLevelShortCircuit() {
-        // get validators
-        List validatorList = ActionValidatorManager.getValidators(User.class, null);
-        assertEquals(10, validatorList.size());
-
-        try {
-            User user = new User();
-            user.setName("Mark");
-            user.setEmail("bad_email");
-            user.setEmail2("bad_email");
-
-            ValidatorContext context = new GenericValidatorContext(user);
-            ActionValidatorManager.validate(user, null, context);
-            assertTrue(context.hasFieldErrors());
-
-            // check field errors
-            List l = (List) context.getFieldErrors().get("email");
-            assertNotNull(l);
-            assertEquals(1, l.size());
-            assertEquals("Not a valid e-mail.", l.get(0));
-            l = (List) context.getFieldErrors().get("email2");
-            assertNotNull(l);
-            assertEquals(2, l.size());
-            assertEquals("Not a valid e-mail2.", l.get(0));
-            assertEquals("Email2 not from the right company.", l.get(1));
-
-            // check action errors
-            assertTrue(context.hasActionErrors());
-            l = (List) context.getActionErrors();
-            assertNotNull(l);
-            assertEquals(2, l.size()); // both expression test failed see User-validation.xml
-            assertEquals("Email does not start with mark", l.get(0));
-        } catch (ValidationException ex) {
-            ex.printStackTrace();
-            fail("Validation error: " + ex.getMessage());
-        }
-    }
-
-    public void testSkipAllActionLevelShortCircuit2() {
-        // get validators
-        List validatorList = ActionValidatorManager.getValidators(User.class, null);
-        assertEquals(10, validatorList.size());
-
-        try {
-            User user = new User();
-            user.setName("Mark");
-            // * mark both email to starts with mark to get pass the action-level validator,
-            // so we could concentrate on testing the field-level validators (User-validation.xml)
-            // * make both email the same to pass the action-level validator at 
-            // UserMarker-validation.xml
-            user.setEmail("mark_bad_email_for_field_val@foo.com");
-            user.setEmail2("mark_bad_email_for_field_val@foo.com");
-
-            ValidatorContext context = new GenericValidatorContext(user);
-            ActionValidatorManager.validate(user, null, context);
-            assertTrue(context.hasFieldErrors());
-
-            // check field errors
-            // we have an error in this field level, email does not ends with mycompany.com
-            List l = (List) context.getFieldErrors().get("email");
-            assertNotNull(l);
-            assertEquals(1, l.size()); // because email-field-val is short-circuit
-            assertEquals("Email not from the right company.", l.get(0));
-
-            
-            // check action errors
-            l = (List) context.getActionErrors();
-            assertFalse(context.hasActionErrors());
-            assertEquals(0, l.size());
-            
-            
-        } catch (ValidationException ex) {
-            ex.printStackTrace();
-            fail("Validation error: " + ex.getMessage());
-        }
-    }
-
-    
-    public void testActionLevelShortCircuit() throws Exception {
-    	
-    	List validatorList = ActionValidatorManager.getValidators(User.class, null);
-        assertEquals(10, validatorList.size());
-        
-        User user = new User();
-        // all fields will trigger error, but sc of action-level, cause it to not appear
-        user.setName(null);		
-        user.setEmail("tmjee(at)yahoo.co.uk");
-        user.setEmail("tm_jee(at)yahoo.co.uk");
-        
-        ValidatorContext context = new GenericValidatorContext(user);
-        ActionValidatorManager.validate(user, null, context);
-    	
-    	// check field level errors
-        // shouldn't have any because action error prevents validation of anything else
-        List l = (List) context.getFieldErrors().get("email2");
-        assertNull(l);
-    	
-    	
-        // check action errors
-        assertTrue(context.hasActionErrors());
-        l = (List) context.getActionErrors();
-        assertNotNull(l);
-        // we only get one, because UserMarker-validation.xml action-level validator
-        // already sc it   :-)
-        assertEquals(1, l.size()); 
-        assertEquals("Email not the same as email2", l.get(0));
-    }
-    
-    
-    public void testShortCircuitNoErrors() {
-        // get validators
-        List validatorList = ActionValidatorManager.getValidators(User.class, null);
-        assertEquals(10, validatorList.size());
-
-        try {
-            User user = new User();
-            user.setName("Mark");
-            user.setEmail("mark@mycompany.com");
-            user.setEmail2("mark@mycompany.com");
-
-            ValidatorContext context = new GenericValidatorContext(user);
-            ActionValidatorManager.validate(user, null, context);
-            assertFalse(context.hasErrors());
-        } catch (ValidationException ex) {
-            ex.printStackTrace();
-            fail("Validation error: " + ex.getMessage());
-        }
-    }
-}

File src/test/com/opensymphony/xwork/validator/DefaultActionValidatorManagerTest.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator;
+
+import com.opensymphony.xwork.SimpleAction;
+import com.opensymphony.xwork.TestBean;
+import com.opensymphony.xwork.XWorkTestCase;
+import com.opensymphony.xwork.test.DataAware2;
+import com.opensymphony.xwork.test.SimpleAction2;
+import com.opensymphony.xwork.test.SimpleAction3;
+import com.opensymphony.xwork.test.User;
+import com.opensymphony.xwork.validator.validators.*;
+
+import java.util.List;
+
+
+/**
+ * DefaultActionValidatorManagerTest
+ *
+ * @author Jason Carreira
+ * @author tm_jee ( tm_jee (at) yahoo.co.uk )
+ *         Created Jun 9, 2003 11:03:01 AM
+ */
+public class DefaultActionValidatorManagerTest extends XWorkTestCase {
+
+    protected final String alias = "validationAlias";
+
+    ActionValidatorManager actionValidatorManager;
+
+    protected void setUp() throws Exception {
+        actionValidatorManager = new DefaultActionValidatorManager();
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        actionValidatorManager = null;
+        super.tearDown();
+    }
+
+
+    public void testBuildValidatorKey() {
+        String validatorKey = DefaultActionValidatorManager.buildValidatorKey(SimpleAction.class, alias);
+        assertEquals(SimpleAction.class.getName() + "/" + alias, validatorKey);
+    }
+
+    public void testBuildsValidatorsForAlias() {
+        List validatorList = actionValidatorManager.getValidators(SimpleAction.class, alias);
+
+        // 6 in the class level + 2 in the alias
+        assertEquals(8, validatorList.size());
+    }
+
+    public void testDefaultMessageInterpolation() {
+        // get validators
+        List validatorList = actionValidatorManager.getValidators(TestBean.class, "beanMessageBundle");
+        assertEquals(3, validatorList.size());
+
+        try {
+            TestBean bean = new TestBean();
+            bean.setName("foo");
+            bean.setCount(99);
+
+            ValidatorContext context = new GenericValidatorContext(bean);
+            actionValidatorManager.validate(bean, "beanMessageBundle", context);
+            assertTrue(context.hasErrors());
+            assertTrue(context.hasFieldErrors());
+
+            List l = (List) context.getFieldErrors().get("count");
+            assertNotNull(l);
+            assertEquals(1, l.size());
+            assertEquals("Smaller Invalid Count: 99", l.get(0));
+        } catch (ValidationException ex) {
+            ex.printStackTrace();
+            fail("Validation error: " + ex.getMessage());
+        }
+    }
+
+    public void testGetValidatorsForInterface() {
+        List validatorList = actionValidatorManager.getValidators(DataAware2.class, alias);
+
+        // 3 in interface hierarchy, 2 from parent interface (1 default + 1 context)
+        assertEquals(3, validatorList.size());
+
+        final FieldValidator dataValidator1 = (FieldValidator) validatorList.get(0);
+        assertEquals("data", dataValidator1.getFieldName());
+        assertTrue(dataValidator1 instanceof RequiredFieldValidator);
+
+        final FieldValidator dataValidator2 = (FieldValidator) validatorList.get(1);
+        assertEquals("data", dataValidator2.getFieldName());
+        assertTrue(dataValidator2 instanceof RequiredStringValidator);
+
+        final FieldValidator blingValidator = (FieldValidator) validatorList.get(2);
+        assertEquals("bling", blingValidator.getFieldName());
+        assertTrue(blingValidator instanceof RequiredStringValidator);
+    }
+
+    public void testGetValidatorsFromInterface() {
+        List validatorList = actionValidatorManager.getValidators(SimpleAction3.class, alias);
+
+       
+        
+        
+        // 8 in the class hierarchy + 1 in the interface + 1 in interface alias
+        assertEquals(10, validatorList.size());
+
+        // action-level validator comes first
+        final Validator expressionValidator = (Validator) validatorList.get(0);
+        assertTrue(expressionValidator instanceof ExpressionValidator);
+        
+        final FieldValidator barValidator1 = (FieldValidator) validatorList.get(1);
+        assertEquals("bar", barValidator1.getFieldName());
+        assertTrue(barValidator1 instanceof RequiredFieldValidator);
+
+        final FieldValidator barValidator2 = (FieldValidator) validatorList.get(2);
+        assertEquals("bar", barValidator2.getFieldName());
+        assertTrue(barValidator2 instanceof IntRangeFieldValidator);
+
+        final FieldValidator dateValidator = (FieldValidator) validatorList.get(3);
+        assertEquals("date", dateValidator.getFieldName());
+        assertTrue(dateValidator instanceof DateRangeFieldValidator);
+
+        final FieldValidator fooValidator = (FieldValidator) validatorList.get(4);
+        assertEquals("foo", fooValidator.getFieldName());
+        assertTrue(fooValidator instanceof IntRangeFieldValidator);
+
+        final FieldValidator bazValidator = (FieldValidator) validatorList.get(5);
+        assertEquals("baz", bazValidator.getFieldName());
+        assertTrue(bazValidator instanceof IntRangeFieldValidator);
+
+        final FieldValidator bazValidator1 = (FieldValidator) validatorList.get(6);
+        assertEquals("baz", bazValidator1.getFieldName());
+        assertTrue(bazValidator1 instanceof RequiredFieldValidator);
+
+        final FieldValidator bazValidator2 = (FieldValidator) validatorList.get(7);
+        assertEquals("baz", bazValidator2.getFieldName());
+        assertTrue(bazValidator2 instanceof IntRangeFieldValidator);
+
+        final FieldValidator dataValidator1 = (FieldValidator) validatorList.get(8);
+        assertEquals("data", dataValidator1.getFieldName());
+        assertTrue(dataValidator1 instanceof RequiredFieldValidator);
+
+        final FieldValidator dataValidator2 = (FieldValidator) validatorList.get(9);
+        assertEquals("data", dataValidator2.getFieldName());
+        assertTrue(dataValidator2 instanceof RequiredStringValidator);
+    }
+
+    public void testMessageInterpolation() {
+        // get validators
+        List validatorList = actionValidatorManager.getValidators(TestBean.class, "beanMessageBundle");
+        assertEquals(3, validatorList.size());
+
+        try {
+            TestBean bean = new TestBean();
+            bean.setName("foo");
+            bean.setCount(150);
+
+            ValidatorContext context = new GenericValidatorContext(bean);
+            actionValidatorManager.validate(bean, "beanMessageBundle", context);
+            assertTrue(context.hasErrors());
+            assertTrue(context.hasFieldErrors());
+
+            List l = (List) context.getFieldErrors().get("count");
+            assertNotNull(l);
+            assertEquals(1, l.size());
+            assertEquals("Count must be between 1 and 100, current value is 150.", l.get(0));
+        } catch (ValidationException ex) {
+            ex.printStackTrace();
+            fail("Validation error: " + ex.getMessage());
+        }
+    }
+
+    public void testSameAliasWithDifferentClass() {
+        List validatorList = actionValidatorManager.getValidators(SimpleAction.class, alias);
+        List validatorList2 = actionValidatorManager.getValidators(SimpleAction2.class, alias);
+        assertFalse(validatorList.size() == validatorList2.size());
+    }
+
+    public void testSkipUserMarkerActionLevelShortCircuit() {
+        // get validators
+        List validatorList = actionValidatorManager.getValidators(User.class, null);
+        assertEquals(10, validatorList.size());
+
+        try {
+            User user = new User();
+            user.setName("Mark");
+            user.setEmail("bad_email");
+            user.setEmail2("bad_email");
+
+            ValidatorContext context = new GenericValidatorContext(user);
+            actionValidatorManager.validate(user, null, context);
+            assertTrue(context.hasFieldErrors());
+
+            // check field errors
+            List l = (List) context.getFieldErrors().get("email");
+            assertNotNull(l);
+            assertEquals(1, l.size());
+            assertEquals("Not a valid e-mail.", l.get(0));
+            l = (List) context.getFieldErrors().get("email2");
+            assertNotNull(l);
+            assertEquals(2, l.size());
+            assertEquals("Not a valid e-mail2.", l.get(0));
+            assertEquals("Email2 not from the right company.", l.get(1));
+
+            // check action errors
+            assertTrue(context.hasActionErrors());
+            l = (List) context.getActionErrors();
+            assertNotNull(l);
+            assertEquals(2, l.size()); // both expression test failed see User-validation.xml
+            assertEquals("Email does not start with mark", l.get(0));
+        } catch (ValidationException ex) {
+            ex.printStackTrace();
+            fail("Validation error: " + ex.getMessage());
+        }
+    }
+
+    public void testSkipAllActionLevelShortCircuit2() {
+        // get validators
+        List validatorList = actionValidatorManager.getValidators(User.class, null);
+        assertEquals(10, validatorList.size());
+
+        try {
+            User user = new User();
+            user.setName("Mark");
+            // * mark both email to starts with mark to get pass the action-level validator,
+            // so we could concentrate on testing the field-level validators (User-validation.xml)
+            // * make both email the same to pass the action-level validator at 
+            // UserMarker-validation.xml
+            user.setEmail("mark_bad_email_for_field_val@foo.com");
+            user.setEmail2("mark_bad_email_for_field_val@foo.com");
+
+            ValidatorContext context = new GenericValidatorContext(user);
+            actionValidatorManager.validate(user, null, context);
+            assertTrue(context.hasFieldErrors());
+
+            // check field errors
+            // we have an error in this field level, email does not ends with mycompany.com
+            List l = (List) context.getFieldErrors().get("email");
+            assertNotNull(l);
+            assertEquals(1, l.size()); // because email-field-val is short-circuit
+            assertEquals("Email not from the right company.", l.get(0));
+
+            
+            // check action errors
+            l = (List) context.getActionErrors();
+            assertFalse(context.hasActionErrors());
+            assertEquals(0, l.size());
+            
+            
+        } catch (ValidationException ex) {
+            ex.printStackTrace();
+            fail("Validation error: " + ex.getMessage());
+        }
+    }
+
+    
+    public void testActionLevelShortCircuit() throws Exception {
+    	
+    	List validatorList = actionValidatorManager.getValidators(User.class, null);
+        assertEquals(10, validatorList.size());
+        
+        User user = new User();
+        // all fields will trigger error, but sc of action-level, cause it to not appear
+        user.setName(null);		
+        user.setEmail("tmjee(at)yahoo.co.uk");
+        user.setEmail("tm_jee(at)yahoo.co.uk");
+        
+        ValidatorContext context = new GenericValidatorContext(user);
+        actionValidatorManager.validate(user, null, context);
+    	
+    	// check field level errors
+        // shouldn't have any because action error prevents validation of anything else
+        List l = (List) context.getFieldErrors().get("email2");
+        assertNull(l);
+    	
+    	
+        // check action errors
+        assertTrue(context.hasActionErrors());
+        l = (List) context.getActionErrors();
+        assertNotNull(l);
+        // we only get one, because UserMarker-validation.xml action-level validator
+        // already sc it   :-)
+        assertEquals(1, l.size()); 
+        assertEquals("Email not the same as email2", l.get(0));
+    }
+    
+    
+    public void testShortCircuitNoErrors() {
+        // get validators
+        List validatorList = actionValidatorManager.getValidators(User.class, null);
+        assertEquals(10, validatorList.size());
+
+        try {
+            User user = new User();
+            user.setName("Mark");
+            user.setEmail("mark@mycompany.com");
+            user.setEmail2("mark@mycompany.com");
+
+            ValidatorContext context = new GenericValidatorContext(user);
+            actionValidatorManager.validate(user, null, context);
+            assertFalse(context.hasErrors());
+        } catch (ValidationException ex) {
+            ex.printStackTrace();
+            fail("Validation error: " + ex.getMessage());
+        }
+    }
+}

File tiger/src/java/com/opensymphony/xwork/validator/AnnotationActionValidatorManager.java

  * @author jepjep
  * @version $Id$
  */
-public class AnnotationActionValidatorManager extends ActionValidatorManager {
+public class AnnotationActionValidatorManager implements ActionValidatorManager {
 
 
     /**
      * @param context the context of the action class - can be <tt>null</tt>.
      * @return a list of all validators for the given class and context.
      */
-    public static synchronized List<Validator> getValidators(Class clazz, String context) {
+    public synchronized List<Validator> getValidators(Class clazz, String context) {
         final String validatorKey = buildValidatorKey(clazz, context);
 
         if (validatorCache.containsKey(validatorKey)) {
      * @param validatorContext
      * @throws ValidationException if an error happens when validating the action.
      */
-    public static void validate(Object object, String context, ValidatorContext validatorContext) throws ValidationException {
+    public void validate(Object object, String context, ValidatorContext validatorContext) throws ValidationException {
         List<Validator> validators = getValidators(object.getClass(), context);
         Set<String> shortcircuitedFields = null;
 
         return sb.toString();
     }
 
-    private static List<ValidatorConfig> buildAliasValidatorConfigs(Class aClass, String context, boolean checkFile) {
+    private  List<ValidatorConfig> buildAliasValidatorConfigs(Class aClass, String context, boolean checkFile) {
         String fileName = aClass.getName().replace('.', '/') + "-" + context + VALIDATION_CONFIG_SUFFIX;
 
         return loadFile(fileName, aClass, checkFile);
     }
 
 
-    protected static List<ValidatorConfig> buildClassValidatorConfigs(Class aClass, boolean checkFile) {
+    protected List<ValidatorConfig> buildClassValidatorConfigs(Class aClass, boolean checkFile) {
 
         String fileName = aClass.getName().replace('.', '/') + VALIDATION_CONFIG_SUFFIX;
 
      * @param checked   the set of previously checked class-contexts, null if none have been checked
      * @return a list of validator configs for the given class and context.
      */
-    private static List<ValidatorConfig> buildValidatorConfigs(Class clazz, String context, boolean checkFile, Set checked) {
+    private List<ValidatorConfig> buildValidatorConfigs(Class clazz, String context, boolean checkFile, Set checked) {
         List<ValidatorConfig> validatorConfigs = new ArrayList<ValidatorConfig>();
 
         if (checked == null) {
         return validatorConfigs;
     }
 
-    private static List<ValidatorConfig> loadFile(String fileName, Class clazz, boolean checkFile) {
+    private List<ValidatorConfig> loadFile(String fileName, Class clazz, boolean checkFile) {
         List<ValidatorConfig> retList = Collections.emptyList();
 
         if ((checkFile && FileManager.fileNeedsReloading(fileName)) || !validatorFileCache.containsKey(fileName)) {

File tiger/src/test/com/opensymphony/xwork/validator/AnnotationActionValidatorManagerTest.java

 
     protected final String alias = "validationAlias";
 
+    AnnotationActionValidatorManager annotationActionValidatorManager;
+
+    protected void setUp() throws Exception {
+        annotationActionValidatorManager = new AnnotationActionValidatorManager();
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        annotationActionValidatorManager = null;
+        super.tearDown();
+    }
 
     public void testBuildValidatorKey() {
         String validatorKey = AnnotationActionValidatorManager.buildValidatorKey(SimpleAnnotationAction.class, alias);
     }
 
     public void testBuildsValidatorsForAlias() {
-        List validatorList = AnnotationActionValidatorManager.getValidators(SimpleAnnotationAction.class, alias);
+        List validatorList = annotationActionValidatorManager.getValidators(SimpleAnnotationAction.class, alias);
 
         // 16 in the class level + 0 in the alias
         // TODO: add alias tests
 
     public void testDefaultMessageInterpolation() {
         // get validators
-        List validatorList = AnnotationActionValidatorManager.getValidators(TestBean.class, "beanMessageBundle");
+        List validatorList = annotationActionValidatorManager.getValidators(TestBean.class, "beanMessageBundle");
         assertEquals(3, validatorList.size());
 
         try {
             bean.setCount(99);
 
             ValidatorContext context = new GenericValidatorContext(bean);
-            AnnotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
+            annotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
             assertTrue(context.hasErrors());
             assertTrue(context.hasFieldErrors());
 
     }
 
     public void testGetValidatorsForInterface() {
-        List validatorList = AnnotationActionValidatorManager.getValidators(AnnotationDataAware2.class, alias);
+        List validatorList = annotationActionValidatorManager.getValidators(AnnotationDataAware2.class, alias);
 
         // 1 in interface hierarchy, 2 from parent interface (1 default + 1 context)
         assertEquals(3, validatorList.size());
     }
 
     public void testGetValidatorsFromInterface() {
-        List validatorList = AnnotationActionValidatorManager.getValidators(SimpleAnnotationAction3.class, alias);
+        List validatorList = annotationActionValidatorManager.getValidators(SimpleAnnotationAction3.class, alias);
 
         // 16 in the class hierarchy + 1 in the interface + 1 in interface alias
         assertEquals(18, validatorList.size());
 
     public void testMessageInterpolation() {
         // get validators
-        List validatorList = AnnotationActionValidatorManager.getValidators(TestBean.class, "beanMessageBundle");
+        List validatorList = annotationActionValidatorManager.getValidators(TestBean.class, "beanMessageBundle");
         assertEquals(3, validatorList.size());
 
         try {
             bean.setCount(150);
 
             ValidatorContext context = new GenericValidatorContext(bean);
-            AnnotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
+            annotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
             assertTrue(context.hasErrors());
             assertTrue(context.hasFieldErrors());
 
     }
 
     public void testSameAliasWithDifferentClass() {
-        List validatorList = AnnotationActionValidatorManager.getValidators(SimpleAnnotationAction.class, alias);
-        List validatorList2 = AnnotationActionValidatorManager.getValidators(SimpleAnnotationAction2.class, alias);
+        List validatorList = annotationActionValidatorManager.getValidators(SimpleAnnotationAction.class, alias);
+        List validatorList2 = annotationActionValidatorManager.getValidators(SimpleAnnotationAction2.class, alias);
         assertFalse(validatorList.size() == validatorList2.size());
     }
 
     public void testSkipUserMarkerActionLevelShortCircuit() {
         // get validators
-        List validatorList = AnnotationActionValidatorManager.getValidators(AnnotationUser.class, null);
+        List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
         assertEquals(10, validatorList.size());
 
         try {
             user.setEmail2("bad_email");
 
             ValidatorContext context = new GenericValidatorContext(user);
-            AnnotationActionValidatorManager.validate(user, null, context);
+            annotationActionValidatorManager.validate(user, null, context);
             assertTrue(context.hasFieldErrors());
 
             // check field errors
 
     public void testSkipAllActionLevelShortCircuit2() {
         // get validators
-        List validatorList = AnnotationActionValidatorManager.getValidators(AnnotationUser.class, null);
+        List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
         assertEquals(10, validatorList.size());
 
         try {
             user.setEmail2("mark_bad_email_for_field_val@foo.com");
 
             ValidatorContext context = new GenericValidatorContext(user);
-            AnnotationActionValidatorManager.validate(user, null, context);
+            annotationActionValidatorManager.validate(user, null, context);
             assertTrue(context.hasFieldErrors());
 
             // check field errors
     
     public void testActionLevelShortCircuit() throws Exception {
     	
-    	List validatorList = AnnotationActionValidatorManager.getValidators(AnnotationUser.class, null);
+    	List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
         assertEquals(10, validatorList.size());
         
         AnnotationUser user = new AnnotationUser();
 
 
         ValidatorContext context = new GenericValidatorContext(user);
-        AnnotationActionValidatorManager.validate(user, null, context);
+        annotationActionValidatorManager.validate(user, null, context);
     	
     	// check field level errors
         // shouldn't have any because action error prevents validation of anything else
     
     public void testShortCircuitNoErrors() {
         // get validators
-        List validatorList = AnnotationActionValidatorManager.getValidators(AnnotationUser.class, null);
+        List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
         assertEquals(10, validatorList.size());
 
         try {
             user.setEmail2("mark@mycompany.com");
 
             ValidatorContext context = new GenericValidatorContext(user);
-            AnnotationActionValidatorManager.validate(user, null, context);
+            annotationActionValidatorManager.validate(user, null, context);
             assertFalse(context.hasErrors());
         } catch (ValidationException ex) {
             ex.printStackTrace();