Commits

Anonymous committed eac7eca

XW-154: unit test fixes so they work outside the US :)

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

  • Participants
  • Parent commits 3a6fd2d

Comments (0)

Files changed (5)

File src/test/com/opensymphony/xwork/config/providers/MockConfigurationProvider.java

     //~ Methods ////////////////////////////////////////////////////////////////
 
     /**
-    * Allows the configuration to clean up any resources used
-    */
+     * Allows the configuration to clean up any resources used
+     */
     public void destroy() {
     }
 
     /**
-    * Initializes the configuration object.
-    */
+     * Initializes the configuration object.
+     */
     public void init(Configuration configurationManager) {
         PackageConfig defaultPackageContext = new PackageConfig();
         HashMap params = new HashMap();
         interceptors.add(new ParametersInterceptor());
         interceptors.add(new ValidationInterceptor());
 
-        ActionConfig validationActionConfig = new ActionConfig(null, SimpleAction.class, null, results, interceptors);
+        //Explicitly set an out-of-range date for DateRangeValidatorTest
+        params = new HashMap();
+        params.put("date", new java.util.Date(2002 - 1900, 11, 20));
+
+        ActionConfig validationActionConfig = new ActionConfig(null, SimpleAction.class, params, results, interceptors);
         defaultPackageContext.addActionConfig(VALIDATION_ACTION_NAME, validationActionConfig);
         defaultPackageContext.addActionConfig(VALIDATION_ALIAS_NAME, validationActionConfig);
         defaultPackageContext.addActionConfig(VALIDATION_SUBPROPERTY_NAME, validationActionConfig);
 
     /**
      * Tells whether the ConfigurationProvider should reload its configuration
+     *
      * @return
      */
     public boolean needsReload() {

File src/test/com/opensymphony/xwork/util/OgnlUtilTest.java

     }
 
     public void testSetPropertiesDate() {
+        Locale orig = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+
         Foo foo = new Foo();
 
         Map context = Ognl.createDefaultContext(foo);
         cal.set(Calendar.YEAR, 1982);
 
         assertEquals(cal.getTime(), foo.getBirthday());
+        Locale.setDefault(orig);
     }
 
     public void testSetPropertiesInt() {

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

 
 import java.util.List;
 import java.util.Map;
+import java.util.Iterator;
+import java.util.Locale;
 
 
 /**
  * DateRangeValidatorTest
+ *
  * @author Jason Carreira
- * Created Feb 9, 2003 1:25:42 AM
+ *         Created Feb 9, 2003 1:25:42 AM
  */
 public class DateRangeValidatorTest extends TestCase {
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void testRangeValidation() {
-        try {
-            ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null);
-            proxy.execute();
-            assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
-
-            Map errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
-            List errorMessages = (List) errors.get("date");
-            assertEquals(1, errorMessages.size());
-
-            String errorMessage = (String) errorMessages.get(0);
-            assertNotNull(errorMessage);
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail();
-        }
+    private Locale origLocale;
+
+    /**
+     * Tests whether the date range validation is working. Should produce an validation error,
+     * because the action config sets date to 12/20/2002 while expected range is Dec 22-25.
+     */
+    public void testRangeValidation() throws Exception {
+        ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null);
+        proxy.execute();
+        assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
+
+        Map errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
+        Iterator it = errors.entrySet().iterator();
+
+        List errorMessages = (List) errors.get("date");
+        assertNotNull("Expected date range validation error message.", errorMessages);
+        assertEquals(1, errorMessages.size());
+
+        String errorMessage = (String) errorMessages.get(0);
+        assertNotNull(errorMessage);
+
     }
 
     protected void setUp() throws Exception {
+        origLocale = Locale.getDefault();
+        Locale.setDefault(Locale.US);
         ConfigurationManager.clearConfigurationProviders();
         ConfigurationManager.addConfigurationProvider(new MockConfigurationProvider());
         ConfigurationManager.getConfiguration().reload();
     }
+
+    protected void tearDown() throws Exception {
+        Locale.setDefault(origLocale);
+    }
+
 }

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

 
 /**
  * SimpleActionValidationTest
- *
+ * <p/>
  * Created : Jan 20, 2003 11:04:25 PM
  *
  * @author Jason Carreira
 public class SimpleActionValidationTest extends TestCase {
     //~ Methods ////////////////////////////////////////////////////////////////
 
+    private Locale origLocale;
+
     public void testAliasValidation() {
         HashMap params = new HashMap();
         params.put("baz", "10");
     }
 
     protected void setUp() throws Exception {
+        origLocale = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+
         ConfigurationManager.destroyConfiguration();
         ConfigurationManager.addConfigurationProvider(new MockConfigurationProvider());
         ConfigurationManager.getConfiguration().reload();
     }
+
+    protected void tearDown() throws Exception {
+        Locale.setDefault(origLocale);
+    }
+
 }

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

 
 import junit.framework.TestCase;
 
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 /**
     //~ Instance fields ////////////////////////////////////////////////////////
 
     protected VisitorValidatorTestAction action;
+    private Locale origLocale;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void setUp() {
+        origLocale = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+
         action = new VisitorValidatorTestAction();
 
         TestBean bean = action.getBean();
     protected void tearDown() throws Exception {
         super.tearDown();
         ActionContext.setContext(null);
+        Locale.setDefault(origLocale);
     }
 
     private void validate(String context) throws ValidationException {