Commits

mrdon  committed 65d5629

Added warning for object factory missing, can be encountered when unit testing validation code
WW-1868 (Struts 2)

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/2.0@1516e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 8feaf5f
  • Branches 2.0, xwork_2_0_7

Comments (0)

Files changed (2)

File src/java/com/opensymphony/xwork2/validator/ValidatorFileParser.java

     public static void parseValidatorDefinitions(InputStream is, String resourceName) {
         parseValidatorDefinitions(is, resourceName, ObjectFactory.getObjectFactory());
     }
+
+
+	private static void verifyObjectFactory(ObjectFactory objectFactory) {
+		if (objectFactory == null) {
+    		throw new IllegalStateException("Cannot find the ObjectFactory.  "+
+    				"Please initialize it by calling 'ObjectFactory.setObjectFactory'.");
+    	}
+	}
     
     /**
      * Parses validator definitions
 
         if (doc != null) {
             NodeList nodes = doc.getElementsByTagName("validator");
+            
+            verifyObjectFactory(objectFactory);
 
             for (int i = 0; i < nodes.getLength(); i++) {
                 Element validatorElement = (Element) nodes.item(i);

File src/test/com/opensymphony/xwork2/validator/ValidatorFileParserTest.java

 package com.opensymphony.xwork2.validator;
 
 import com.opensymphony.xwork2.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.XWorkException;
 import com.opensymphony.xwork2.XWorkTestCase;
 import com.opensymphony.xwork2.config.providers.MockConfigurationProvider;
     private static final String testFileName6 = "com/opensymphony/xwork2/validator/validators-fail.xml";
 
     public void testParserActionLevelValidatorsShouldBeBeforeFieldLevelValidators() throws Exception {
+    	ObjectFactory.setObjectFactory(new ObjectFactory());
         InputStream is = ClassLoaderUtil.getResourceAsStream(testFileName2, this.getClass());
 
         List configs = ValidatorFileParser.parseActionValidatorConfigs(is, testFileName2);
 
 
     public void testParser() {
+    	ObjectFactory.setObjectFactory(new ObjectFactory());
         InputStream is = ClassLoaderUtil.getResourceAsStream(testFileName, this.getClass());
 
         List configs = ValidatorFileParser.parseActionValidatorConfigs(is, testFileName);