Author: niallp
Date: Sat Nov  4 19:34:09 2006
New Revision: 471352

URL: http://svn.apache.org/viewvc?view=rev&rev=471352
Log:
BEANUTILS-255 - Add new generic DateTimeConverter implementation which support 
java.util.Date and java.util.Calendar and switch exisiting java.sql.Date, 
java.sql.Time and java.sql.Timestamp to use the new implementation. There was 
some disagreement about whether we should have support for this in BeanUtils 
(sse comments on JIRA/mailing list) - however, thought I would commit it for 
review - easily reverted in SVN if there are objections.

Added:
    
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/CalendarConverterTestCase.java
   (with props)
    
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestCase.java
   (with props)
Modified:
    
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlDateConverter.java
    
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java
    
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java
    
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestBase.java
    
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlDateConverterTestCase.java
    
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java
    
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java

Modified: 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlDateConverter.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlDateConverter.java?view=diff&rev=471352&r1=471351&r2=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlDateConverter.java
 (original)
+++ 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlDateConverter.java
 Sat Nov  4 19:34:09 2006
@@ -14,122 +14,46 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.commons.beanutils.converters;
 
-
 import java.sql.Date;
-import java.util.Calendar;
-
-import org.apache.commons.beanutils.ConversionException;
-import org.apache.commons.beanutils.Converter;
-
 
 /**
- * <p>Standard [EMAIL PROTECTED] Converter} implementation that converts an 
incoming
- * String into a <code>java.sql.Date</code> object, optionally using a
- * default value or throwing a [EMAIL PROTECTED] ConversionException} if a 
conversion
- * error occurs.</p>
+ * [EMAIL PROTECTED] DateTimeConverter} implementation that handles conversion 
to
+ * and from <b>java.sql.Date</b> objects.
+ * <p>
+ * This implementation can be configured to handle conversion either
+ * by using java.sql.Date's default String conversion, or by using a
+ * Locale's default format or by specifying a set of format patterns.
+ * See the [EMAIL PROTECTED] DateTimeConverter} documentation for further 
details.
+ * <p>
+ * Can be configured to either return a <i>default value</i> or throw a
+ * <code>ConversionException</code> if a conversion error occurs.
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  * @since 1.3
  */
-
-public final class SqlDateConverter implements Converter {
-
-
-    // ----------------------------------------------------------- Constructors
-
+public final class SqlDateConverter extends DateTimeConverter {
 
     /**
-     * Create a [EMAIL PROTECTED] Converter} that will throw a [EMAIL 
PROTECTED] ConversionException}
-     * if a conversion error occurs.
+     * Construct a <b>java.sql.Date</b> <i>Converter</i> that throws
+     * a <code>ConversionException</code> if an error occurs.
      */
     public SqlDateConverter() {
-
-        this.defaultValue = null;
-        this.useDefault = false;
-
+        super(Date.class);
     }
 
-
     /**
-     * Create a [EMAIL PROTECTED] Converter} that will return the specified 
default value
-     * if a conversion error occurs.
+     * Construct a <b>java.sql.Date</b> <i>Converter</i> that returns
+     * a default value if an error occurs.
      *
      * @param defaultValue The default value to be returned
+     * if the value to be converted is missing or an error
+     * occurs converting the value.
      */
     public SqlDateConverter(Object defaultValue) {
-
-        this.defaultValue = defaultValue;
-        this.useDefault = true;
-
-    }
-
-
-    // ----------------------------------------------------- Instance Variables
-
-
-    /**
-     * The default value specified to our Constructor, if any.
-     */
-    private Object defaultValue = null;
-
-
-    /**
-     * Should we return the default value on conversion errors?
-     */
-    private boolean useDefault = true;
-
-
-    // --------------------------------------------------------- Public Methods
-
-
-    /**
-     * Convert the specified input object into an output object of the
-     * specified type.
-     *
-     * @param type Data type to which this value should be converted
-     * @param value The input value to be converted
-     *
-     * @exception ConversionException if conversion cannot be performed
-     *  successfully
-     */
-    public Object convert(Class type, Object value) {
-
-        if (value == null) {
-            if (useDefault) {
-                return (defaultValue);
-            } else {
-                throw new ConversionException("No value specified");
-            }
-        }
-
-        if (value instanceof Date) {
-            return (value);
-        }
-
-        if (value instanceof java.util.Date) {
-            return new Date(((java.util.Date)value).getTime());
-        }
-
-        if (value instanceof Calendar) {
-            return new Date(((Calendar)value).getTime().getTime());
-        }
-
-        try {
-            return (Date.valueOf(value.toString()));
-        } catch (Exception e) {
-            if (useDefault) {
-                return (defaultValue);
-            } else {
-                throw new ConversionException(e);
-            }
-        }
-
+        super(Date.class, defaultValue);
     }
-
 
 }

Modified: 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java?view=diff&rev=471352&r1=471351&r2=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java
 (original)
+++ 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimeConverter.java
 Sat Nov  4 19:34:09 2006
@@ -14,123 +14,69 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.commons.beanutils.converters;
 
-
 import java.sql.Time;
-import java.util.Calendar;
-import java.util.Date;
-
-import org.apache.commons.beanutils.ConversionException;
-import org.apache.commons.beanutils.Converter;
-
+import java.text.DateFormat;
+import java.util.Locale;
+import java.util.TimeZone;
 
 /**
- * <p>Standard [EMAIL PROTECTED] Converter} implementation that converts an 
incoming
- * String into a <code>java.sql.Time</code> object, optionally using a
- * default value or throwing a [EMAIL PROTECTED] ConversionException} if a 
conversion
- * error occurs.</p>
+ * [EMAIL PROTECTED] DateTimeConverter} implementation that handles conversion 
to
+ * and from <b>java.sql.Time</b> objects.
+ * <p>
+ * This implementation can be configured to handle conversion either
+ * by using java.sql.Time's default String conversion, or by using a
+ * Locale's default format or by specifying a set of format patterns.
+ * See the [EMAIL PROTECTED] DateTimeConverter} documentation for further 
details.
+ * <p>
+ * Can be configured to either return a <i>default value</i> or throw a
+ * <code>ConversionException</code> if a conversion error occurs.
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  * @since 1.3
  */
-
-public final class SqlTimeConverter implements Converter {
-
-
-    // ----------------------------------------------------------- Constructors
-
+public final class SqlTimeConverter extends DateTimeConverter {
 
     /**
-     * Create a [EMAIL PROTECTED] Converter} that will throw a [EMAIL 
PROTECTED] ConversionException}
-     * if a conversion error occurs.
+     * Construct a <b>java.sql.Time</b> <i>Converter</i> that throws
+     * a <code>ConversionException</code> if an error occurs.
      */
     public SqlTimeConverter() {
-
-        this.defaultValue = null;
-        this.useDefault = false;
-
+        super(Time.class);
     }
 
-
     /**
-     * Create a [EMAIL PROTECTED] Converter} that will return the specified 
default value
-     * if a conversion error occurs.
+     * Construct a <b>java.sql.Time</b> <i>Converter</i> that returns
+     * a default value if an error occurs.
      *
      * @param defaultValue The default value to be returned
+     * if the value to be converted is missing or an error
+     * occurs converting the value.
      */
     public SqlTimeConverter(Object defaultValue) {
-
-        this.defaultValue = defaultValue;
-        this.useDefault = true;
-
+        super(Time.class, defaultValue);
     }
 
-
-    // ----------------------------------------------------- Instance Variables
-
-
-    /**
-     * The default value specified to our Constructor, if any.
-     */
-    private Object defaultValue = null;
-
-
-    /**
-     * Should we return the default value on conversion errors?
-     */
-    private boolean useDefault = true;
-
-
-    // --------------------------------------------------------- Public Methods
-
-
     /**
-     * Convert the specified input object into an output object of the
-     * specified type.
+     * Return a <code>DateFormat<code> for the Locale.
+     * @param locale TODO
+     * @param timeZone TODO
      *
-     * @param type Data type to which this value should be converted
-     * @param value The input value to be converted
-     *
-     * @exception ConversionException if conversion cannot be performed
-     *  successfully
+     * @return The DateFormat.
      */
-    public Object convert(Class type, Object value) {
-
-        if (value == null) {
-            if (useDefault) {
-                return (defaultValue);
-            } else {
-                throw new ConversionException("No value specified");
-            }
+    protected DateFormat getFormat(Locale locale, TimeZone timeZone) {
+        DateFormat format = null;
+        if (locale == null) {
+            format = DateFormat.getTimeInstance(DateFormat.SHORT);
+        } else {
+            format = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
         }
-
-        if (value instanceof Time) {
-            return (value);
-        }
-
-        if (value instanceof Date) {
-            return new Time(((Date)value).getTime());
-        }
-
-        if (value instanceof Calendar) {
-            return new Time(((Calendar)value).getTime().getTime());
+        if (timeZone != null) {
+            format.setTimeZone(timeZone);
         }
-
-        try {
-            return (Time.valueOf(value.toString()));
-        } catch (Exception e) {
-            if (useDefault) {
-                return (defaultValue);
-            } else {
-                throw new ConversionException(e);
-            }
-        }
-
+        return format;
     }
-
 
 }

Modified: 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java?view=diff&rev=471352&r1=471351&r2=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java
 (original)
+++ 
jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/SqlTimestampConverter.java
 Sat Nov  4 19:34:09 2006
@@ -14,123 +14,68 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.commons.beanutils.converters;
 
-
 import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Date;
-
-import org.apache.commons.beanutils.ConversionException;
-import org.apache.commons.beanutils.Converter;
-
+import java.text.DateFormat;
+import java.util.Locale;
+import java.util.TimeZone;
 
 /**
- * <p>Standard [EMAIL PROTECTED] Converter} implementation that converts an 
incoming
- * String into a <code>java.sql.Timestamp</code> object, optionally using a
- * default value or throwing a [EMAIL PROTECTED] ConversionException} if a 
conversion
- * error occurs.</p>
+ * [EMAIL PROTECTED] DateTimeConverter} implementation that handles conversion 
to
+ * and from <b>java.sql.Timestamp</b> objects.
+ * <p>
+ * This implementation can be configured to handle conversion either
+ * by using java.sql.Timestamp's default String conversion, or by using a
+ * Locale's default format or by specifying a set of format patterns.
+ * See the [EMAIL PROTECTED] DateTimeConverter} documentation for further 
details.
+ * <p>
+ * Can be configured to either return a <i>default value</i> or throw a
+ * <code>ConversionException</code> if a conversion error occurs.
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  * @since 1.3
  */
-
-public final class SqlTimestampConverter implements Converter {
-
-
-    // ----------------------------------------------------------- Constructors
-
+public final class SqlTimestampConverter extends DateTimeConverter {
 
     /**
-     * Create a [EMAIL PROTECTED] Converter} that will throw a [EMAIL 
PROTECTED] ConversionException}
-     * if a conversion error occurs.
+     * Construct a <b>java.sql.Timestamp</b> <i>Converter</i> that throws
+     * a <code>ConversionException</code> if an error occurs.
      */
     public SqlTimestampConverter() {
-
-        this.defaultValue = null;
-        this.useDefault = false;
-
+        super(Timestamp.class);
     }
 
-
     /**
-     * Create a [EMAIL PROTECTED] Converter} that will return the specified 
default value
-     * if a conversion error occurs.
+     * Construct a <b>java.sql.Timestamp</b> <i>Converter</i> that returns
+     * a default value if an error occurs.
      *
      * @param defaultValue The default value to be returned
+     * if the value to be converted is missing or an error
+     * occurs converting the value.
      */
     public SqlTimestampConverter(Object defaultValue) {
-
-        this.defaultValue = defaultValue;
-        this.useDefault = true;
-
+        super(Timestamp.class, defaultValue);
     }
 
-
-    // ----------------------------------------------------- Instance Variables
-
-
     /**
-     * The default value specified to our Constructor, if any.
-     */
-    private Object defaultValue = null;
-
-
-    /**
-     * Should we return the default value on conversion errors?
-     */
-    private boolean useDefault = true;
-
-
-    // --------------------------------------------------------- Public Methods
-
-
-    /**
-     * Convert the specified input object into an output object of the
-     * specified type.
-     *
-     * @param type Data type to which this value should be converted
-     * @param value The input value to be converted
+     * Return a <code>DateFormat<code> for the Locale.
+     * @param locale TODO
+     * @param timeZone TODO
      *
-     * @exception ConversionException if conversion cannot be performed
-     *  successfully
+     * @return The DateFormat.
      */
-    public Object convert(Class type, Object value) {
-
-        if (value == null) {
-            if (useDefault) {
-                return (defaultValue);
-            } else {
-                throw new ConversionException("No value specified");
-            }
+    protected DateFormat getFormat(Locale locale, TimeZone timeZone) {
+        DateFormat format = null;
+        if (locale == null) {
+            format = DateFormat.getDateTimeInstance(DateFormat.SHORT, 
DateFormat.SHORT);
+        } else {
+            format = DateFormat.getDateTimeInstance(DateFormat.SHORT, 
DateFormat.SHORT, locale);
         }
-
-        if (value instanceof Timestamp) {
-            return (value);
+        if (timeZone != null) {
+            format.setTimeZone(timeZone);
         }
-
-        if (value instanceof Date) {
-            return new Timestamp(((Date)value).getTime());
-        }
-
-        if (value instanceof Calendar) {
-            return new Timestamp(((Calendar)value).getTime().getTime());
-        }
-
-        try {
-            return (Timestamp.valueOf(value.toString()));
-        } catch (Exception e) {
-            if (useDefault) {
-                return (defaultValue);
-            } else {
-                throw new ConversionException(e);
-            }
-        }
-
+        return format;
     }
-
-
 }

Added: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/CalendarConverterTestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/CalendarConverterTestCase.java?view=auto&rev=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/CalendarConverterTestCase.java
 (added)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/CalendarConverterTestCase.java
 Sat Nov  4 19:34:09 2006
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.beanutils.converters;
+
+import java.util.Calendar;
+import junit.framework.TestSuite;
+
+/**
+ * Test Case for the CalendarConverter class.
+ *
+ * @version $Revision$
+ */
+public class CalendarConverterTestCase extends DateConverterTestBase {
+
+    /**
+     * Construct a new Calendar test case.
+     * @param name Test Name
+     */
+    public CalendarConverterTestCase(String name) {
+        super(name);
+    }
+
+    // ------------------------------------------------------------------------
+
+    /**
+     * Create Test Suite
+     * @return test suite
+     */
+    public static TestSuite suite() {
+        return new TestSuite(CalendarConverterTestCase.class);        
+    }
+
+    // ------------------------------------------------------------------------
+    /**
+     * Create the Converter with no default value.
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter() {
+        return new CalendarConverter();
+    }
+    
+    /**
+     * Create the Converter with a default value.
+     * @param defaultValue The default value
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter(Object defaultValue) {
+        return new CalendarConverter(defaultValue);
+    }
+
+    /**
+     * Return the expected type
+     * @return The expected type
+     */
+    protected Class getExpectedType() {
+        return Calendar.class;
+    }
+
+    /**
+     * Convert from a java.util.Date to the Converter's type.
+     * 
+     * @param value The Date value to convert
+     * @return The converted value
+     */
+    protected Object toType(Calendar value) {
+        return value;
+   }
+
+}
\ No newline at end of file

Propchange: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/CalendarConverterTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/CalendarConverterTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestBase.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestBase.java?view=diff&rev=471352&r1=471351&r2=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestBase.java
 (original)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestBase.java
 Sat Nov  4 19:34:09 2006
@@ -17,8 +17,12 @@
 
 package org.apache.commons.beanutils.converters;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.Locale;
 
 import junit.framework.TestCase;
 import org.apache.commons.beanutils.Converter;
@@ -34,21 +38,49 @@
 
     // ------------------------------------------------------------------------
 
+    /**
+     * Construtc a new test case.
+     * @param name Name of the test
+     */
     public DateConverterTestBase(String name) {
         super(name);
     }
 
     // ------------------------------------------------------------------------
 
-    protected abstract Converter makeConverter();
+    /**
+     * Create the Converter with no default value.
+     * @return A new Converter
+     */
+    protected abstract DateTimeConverter makeConverter();
+    
+    /**
+     * Create the Converter with a default value.
+     * @param defaultValue The default value
+     * @return A new Converter
+     */
+    protected abstract DateTimeConverter makeConverter(Object defaultValue);
+
+    /**
+     * Return the expected type
+     * @return The expected type
+     */
     protected abstract Class getExpectedType();
 
+    /**
+     * Convert from a Calendar to the appropriate Date type
+     * 
+     * @param value The Calendar value to convert
+     * @return The converted value
+     */
+    protected abstract Object toType(Calendar value);
+
     // ------------------------------------------------------------------------
 
     /**
      * Assumes ConversionException in response to covert(getExpectedType(), 
null).
      */
-    public void testConvertNull() throws Exception {
+    public void testConvertNull() {
         try {
             makeConverter().convert(getExpectedType(), null);
             fail("Expected ConversionException");
@@ -61,7 +93,7 @@
      * Assumes convert() returns some non-null
      * instance of getExpectedType().
      */
-    public void testConvertDate() throws Exception {
+    public void testConvertDate() {
         String[] message= {
             "from Date",
             "from Calendar",
@@ -89,7 +121,392 @@
             assertTrue("Convert " + message[i] + " should return a " + 
getExpectedType().getName(),
                        getExpectedType().isInstance(val));
             assertEquals("Convert " + message[i] + " should return a " + 
date[0],
-                         now, ((Date) val).getTime());
+                         now, (Calendar.class.isInstance(val) ? 
((Calendar)val).getTimeInMillis() : ((Date)val).getTime()));
+        }
+    }
+
+    /**
+     * Test Default Type conversion (i.e. don't specify target type)
+     */
+    public void testDefaultType() {
+        String pattern = "yyyy-MM-dd";
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setPattern(pattern);
+
+        // Valid String --> Type Conversion
+        String testString = "2006-10-29";
+        Calendar calendar = toCalendar(testString, pattern, null);
+        Object expected   = toType(calendar);
+        
+        Object result = converter.convert(null, testString);
+        if (getExpectedType().equals(Calendar.class)) {
+            assertTrue("TYPE ", 
getExpectedType().isAssignableFrom(result.getClass()));
+        } else {
+            assertEquals("TYPE ", getExpectedType(), result.getClass());
+        }
+        assertEquals("VALUE ", expected, result);
+    }
+
+    /**
+     * Test default String to type conversion
+     *
+     * N.B. This method is overriden by test case
+     * implementations for java.sql.Date/Time/Timestamp
+     */
+    public void testDefaultStringToTypeConvert() {
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setUseLocaleFormat(false);
+        try {
+            converter.convert(getExpectedType(), "2006-10-23");
+            fail("Expected Conversion exception");
+        } catch (ConversionException e) {
+            // expected result
         }
+
+    }
+
+    /**
+     * Test Conversion to String
+     */
+    public void testStringConversion() {
+
+        String pattern = "yyyy-MM-dd";
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setPattern(pattern);
+
+        // Create Values
+        String expected = "2006-10-29";
+        Calendar calendar = toCalendar(expected, pattern, null);
+
+        // Type --> String Conversion
+        stringConversion(converter, expected, toType(calendar));
+
+        // Calendar --> String Conversion
+        stringConversion(converter, expected, calendar);
+
+        // java.util.Date --> String Conversion
+        stringConversion(converter, expected, toDate(calendar));
+
+        // java.sql.Date --> String Conversion
+        stringConversion(converter, expected, toSqlDate(calendar));
+
+        // java.sql.Timestamp --> String Conversion
+        stringConversion(converter, expected, toSqlTimestamp(calendar));
+
+        // java.sql.Time --> String Conversion
+        stringConversion(converter, expected, toSqlTime(calendar));
+
+        stringConversion(converter, null, null);
+        stringConversion(converter, "", "");
+
+    }
+
+    /**
+     * Test Converter with no default value
+     */
+    public void testPatternNoDefault() {
+
+        String pattern = "yyyy-MM-dd";
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setPattern(pattern);
+
+        // Valid String --> Type Conversion
+        String testString = "2006-10-29";
+        Calendar calendar = toCalendar(testString, pattern, null);
+        Object expected   = toType(calendar);
+        validConversion(converter, expected, testString);
+
+        // Valid java.util.Date --> Type Conversion
+        validConversion(converter, expected, calendar);
+
+        // Valid Calendar --> Type Conversion
+        validConversion(converter, expected, toDate(calendar));
+
+        // Test java.sql.Date --> Type Conversion
+        validConversion(converter, expected, toSqlDate(calendar));
+
+        // java.sql.Timestamp --> String Conversion
+        validConversion(converter, expected, toSqlTimestamp(calendar));
+
+        // java.sql.Time --> String Conversion
+        validConversion(converter, expected, toSqlTime(calendar));
+
+        // Invalid Conversions
+        invalidConversion(converter, null);
+        invalidConversion(converter, "");
+        invalidConversion(converter, "2006-10-2X");
+        invalidConversion(converter, "2006/10/01");
+        invalidConversion(converter, "02/10/2006");
+        invalidConversion(converter, "02/10/06");
+        invalidConversion(converter, new Integer(2));
+
+    }
+
+    /**
+     * Test Converter with no default value
+     */
+    public void testPatternDefault() {
+
+        String pattern = "yyyy-MM-dd";
+
+        // Create & Configure the Converter
+        Object defaultValue = toType("2000-01-01", pattern, null);
+        assertNotNull("Check default date", defaultValue);
+        DateTimeConverter converter = makeConverter(defaultValue);
+        converter.setPattern(pattern);
+
+        // Valid String --> Type Conversion
+        String testString = "2006-10-29";
+        Object expected = toType(testString, pattern, null);
+        validConversion(converter, expected, testString);
+
+        // Invalid Values, expect default value
+        validConversion(converter, defaultValue, null);
+        validConversion(converter, defaultValue, "");
+        validConversion(converter, defaultValue, "2006-10-2X");
+        validConversion(converter, defaultValue, "2006/10/01");
+        validConversion(converter, defaultValue, "02/10/06");
+        validConversion(converter, defaultValue, new Integer(2));
+
+    }
+
+    /**
+     * Test Converter with no default value
+     */
+    public void testPatternNullDefault() {
+
+        String pattern = "yyyy-MM-dd";
+
+        // Create & Configure the Converter
+        Object defaultValue = null;
+        DateTimeConverter converter = makeConverter(defaultValue);
+        converter.setPattern(pattern);
+
+        // Valid String --> Type Conversion
+        String testString = "2006-10-29";
+        Object expected = toType(testString, pattern, null);
+        validConversion(converter, expected, testString);
+
+        // Invalid Values, expect default --> null
+        validConversion(converter, defaultValue, null);
+        validConversion(converter, defaultValue, "");
+        validConversion(converter, defaultValue, "2006-10-2X");
+        validConversion(converter, defaultValue, "2006/10/01");
+        validConversion(converter, defaultValue, "02/10/06");
+        validConversion(converter, defaultValue, new Integer(2));
+
+    }
+
+    /**
+     * Test Converter with multiple patterns
+     */
+    public void testMultiplePatterns() {
+        String testString = null;
+        Object expected = null;
+
+        // Create & Configure the Converter
+        String[] patterns = new String[] {"yyyy-MM-dd", "yyyy/MM/dd"};
+        DateTimeConverter converter = makeConverter();
+        converter.setPatterns(patterns);
+
+        // First Pattern
+        testString = "2006-10-28";
+        expected = toType(testString, patterns[0], null);
+        validConversion(converter, expected, testString);
+
+        // Second pattern
+        testString = "2006/10/18";
+        expected = toType(testString, patterns[1], null);
+        validConversion(converter, expected, testString);
+
+        // Invalid Conversion
+        invalidConversion(converter, "17/03/2006");
+        invalidConversion(converter, "17.03.2006");
+
+    }
+
+    /**
+     * Test Date Converter with no default value
+     */
+    public void testLocale() {
+
+        // Re-set the default Locale to Locale.US
+        Locale defaultLocale = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+
+        String pattern = "M/d/yy"; // SHORT style date format for US Locale
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setUseLocaleFormat(true);
+
+        // Valid String --> Type Conversion
+        String testString = "10/28/06";
+        Object expected = toType(testString, pattern, null);
+        validConversion(converter, expected, testString);
+
+        // Invalid Conversions
+        invalidConversion(converter, null);
+        invalidConversion(converter, "");
+        invalidConversion(converter, "2006-10-2X");
+        invalidConversion(converter, "10.28.06");
+        invalidConversion(converter, "10-28-06");
+        invalidConversion(converter, new Integer(2));
+
+        // Restore the default Locale
+        Locale.setDefault(defaultLocale);
+
+    }
+
+    /**
+     * Test Converter with types it can't handle
+     */
+    public void testInvalidType() {
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+
+        // Invalid Class Type
+        try {
+            converter.convert(Character.class, new Date());
+            fail("Requested Character.class conversion, expected 
ConversionException");
+        } catch (ConversionException e) {
+            // Expected result
+        }
+    }
+
+    /**
+     * Test Conversion to the required type
+     * @param converter The converter to use
+     * @param expected The expected result
+     * @param value The value to convert
+     */
+    void validConversion(Converter converter, Object expected, Object value) {
+        String valueType = (value == null ? "null" : 
value.getClass().getName());
+        String msg = "Converting '" + valueType + "' value '" + value + "'";
+        try {
+            Object result = converter.convert(getExpectedType(), value);
+            Class resultType = (result   == null ? null : result.getClass());
+            Class expectType = (expected == null ? null : expected.getClass());
+            assertEquals("TYPE "  + msg, expectType, resultType);
+            assertEquals("VALUE " + msg, expected, result);
+        } catch (Exception ex) {
+            fail(msg + " threw " + ex.toString());
+        }
+    }
+
+    /**
+     * Test Conversion to String
+     * @param converter The converter to use
+     * @param expected The expected result
+     * @param value The value to convert
+     */
+    void stringConversion(Converter converter, String expected, Object value) {
+        String valueType = (value == null ? "null" : 
value.getClass().getName());
+        String msg = "Converting '" + valueType + "' value '" + value + "' to 
String";
+        try {
+            Object result = converter.convert(String.class, value);
+            Class resultType = (result   == null ? null : result.getClass());
+            Class expectType = (expected == null ? null : expected.getClass());
+            assertEquals("TYPE "  + msg, expectType, resultType);
+            assertEquals("VALUE " + msg, expected, result);
+        } catch (Exception ex) {
+            fail(msg + " threw " + ex.toString());
+        }
+    }
+
+    /**
+     * Test Conversion Error
+     * @param converter The converter to use
+     * @param value The value to convert
+     */
+    void invalidConversion(Converter converter, Object value) {
+        String valueType = (value == null ? "null" : 
value.getClass().getName());
+        String msg = "Converting '" + valueType + "' value '" + value + "'";
+        try {
+            Object result = converter.convert(getExpectedType(), value);
+            fail(msg + ", expected ConversionException, but result = '" + 
result + "'"); 
+        } catch (ConversionException ex) {
+            // Expected Result
+        }
+    }
+
+    /**
+     * Parse a String value to the required type
+     * @param value The String value to parse
+     * @param pattern The date pattern
+     * @param locale The locale to use (or null)
+     * @return parsed Calendar value
+     */
+    Object toType(String value, String pattern, Locale locale) {
+        Calendar calendar = toCalendar(value, pattern, locale);
+        return toType(calendar);
+    }
+
+    /**
+     * Parse a String value to a Calendar
+     * @param value The String value to parse
+     * @param pattern The date pattern
+     * @param locale The locale to use (or null)
+     * @return parsed Calendar value
+     */
+    Calendar toCalendar(String value, String pattern, Locale locale) {
+        Calendar calendar = null;
+        try {
+            DateFormat format = (locale == null) 
+                           ? new SimpleDateFormat(pattern)
+                           : new SimpleDateFormat(pattern, locale);
+            format.setLenient(false);
+            format.parse(value);
+            calendar = format.getCalendar();
+        } catch (Exception e) {
+            fail("Error creating Calendar value ='"
+                    + value + ", pattern='" + pattern + "' " + e.toString());
+        }
+        return calendar;
+    }
+
+    /**
+     * Convert a Calendar to a java.util.Date
+     * @param calendar The calendar object to convert
+     * @return The converted java.util.Date
+     */
+    Date toDate(Calendar calendar) {
+        return calendar.getTime();
+    }
+
+    /**
+     * Convert a Calendar to a java.sql.Date
+     * @param calendar The calendar object to convert
+     * @return The converted java.sql.Date
+     */
+    java.sql.Date toSqlDate(Calendar calendar) {
+        return new java.sql.Date(calendar.getTimeInMillis());
+    }
+
+    /**
+     * Convert a Calendar to a java.sql.Time
+     * @param calendar The calendar object to convert
+     * @return The converted java.sql.Time
+     */
+    java.sql.Time toSqlTime(Calendar calendar) {
+        return new java.sql.Time(calendar.getTimeInMillis());
+    }
+
+    /**
+     * Convert a Calendar to a java.sql.Timestamp
+     * @param calendar The calendar object to convert
+     * @return The converted java.sql.Timestamp
+     */
+    java.sql.Timestamp toSqlTimestamp(Calendar calendar) {
+        return new java.sql.Timestamp(calendar.getTimeInMillis());
     }
 }

Added: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestCase.java?view=auto&rev=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestCase.java
 (added)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestCase.java
 Sat Nov  4 19:34:09 2006
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.beanutils.converters;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import junit.framework.TestSuite;
+
+/**
+ * Test Case for the DateConverter class.
+ *
+ * @version $Revision$
+ */
+public class DateConverterTestCase extends DateConverterTestBase {
+
+    /**
+     * Construct a new Date test case.
+     * @param name Test Name
+     */
+    public DateConverterTestCase(String name) {
+        super(name);
+    }
+
+    // ------------------------------------------------------------------------
+
+    /**
+     * Create Test Suite
+     * @return test suite
+     */
+    public static TestSuite suite() {
+        return new TestSuite(DateConverterTestCase.class);        
+    }
+
+    /** Set Up */
+    public void setUp() throws Exception {
+    }
+
+    /** Tear Down */
+    public void tearDown() throws Exception {
+    }
+
+    // ------------------------------------------------------------------------
+    
+    /**
+     * Create the Converter with no default value.
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter() {
+        return new DateConverter();
+    }
+    
+    /**
+     * Create the Converter with a default value.
+     * @param defaultValue The default value
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter(Object defaultValue) {
+        return new DateConverter(defaultValue);
+    }
+
+    /**
+     * Return the expected type
+     * @return The expected type
+     */
+    protected Class getExpectedType() {
+        return Date.class;
+    }
+
+    /**
+     * Convert from a Calendar to the appropriate Date type
+     * 
+     * @param value The Calendar value to convert
+     * @return The converted value
+     */
+    protected Object toType(Calendar value) {
+        return value.getTime();
+    }
+}
\ No newline at end of file

Propchange: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/DateConverterTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlDateConverterTestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlDateConverterTestCase.java?view=diff&rev=471352&r1=471351&r2=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlDateConverterTestCase.java
 (original)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlDateConverterTestCase.java
 Sat Nov  4 19:34:09 2006
@@ -18,9 +18,9 @@
 package org.apache.commons.beanutils.converters;
 
 import java.sql.Date;
+import java.util.Calendar;
 
 import junit.framework.TestSuite;
-import org.apache.commons.beanutils.Converter;
 
 /**
  * Test Case for the [EMAIL PROTECTED] SqlDateConverter} class.
@@ -30,24 +30,95 @@
 
 public class SqlDateConverterTestCase extends DateConverterTestBase {
 
+    /**
+     * Construct a new Date test case.
+     * @param name Test Name
+     */
     public SqlDateConverterTestCase(String name) {
         super(name);
     }
 
     // ------------------------------------------------------------------------
 
+    /**
+     * Create Test Suite
+     * @return test suite
+     */
     public static TestSuite suite() {
         return new TestSuite(SqlDateConverterTestCase.class);
     }
 
     // ------------------------------------------------------------------------
 
-    protected Converter makeConverter() {
+    /**
+     * Test default String to java.sql.Date conversion
+     */
+    public void testDefaultStringToTypeConvert() {
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setUseLocaleFormat(false);
+
+        // Valid String --> java.sql.Date Conversion
+        String testString = "2006-05-16";
+        Object expected = toType(testString, "yyyy-MM-dd", null);
+        validConversion(converter, expected, testString);
+
+        // Invalid String --> java.sql.Date Conversion
+        invalidConversion(converter, "01/01/2006");
+    }
+
+    /**
+     * Test default java.sql.Date to String conversion
+     */
+    public void testDefaultTypeToStringConvert() {
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setUseLocaleFormat(false);
+
+        // Valid String --> java.sql.Date Conversion
+        String expected  = "2006-05-16";
+        Object testVal   = toType(expected, "yyyy-MM-dd", null);
+        stringConversion(converter, expected, testVal);
+
+        Object result = converter.convert(String.class, new Integer(2));
+        assertEquals("Default toString()", "2", result);
+    }
+
+    /**
+     * Create the Converter with no default value.
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter() {
         return new SqlDateConverter();
     }
+    
+    /**
+     * Create the Converter with a default value.
+     * @param defaultValue The default value
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter(Object defaultValue) {
+        return new SqlDateConverter(defaultValue);
+    }
 
+    /**
+     * Return the expected type
+     * @return The expected type
+     */
     protected Class getExpectedType() {
         return Date.class;
+    }
+
+    /**
+     * Convert from a Calendar to the appropriate Date type
+     * 
+     * @param value The Calendar value to convert
+     * @return The converted value
+     */
+    protected Object toType(Calendar value) {
+        return new java.sql.Date(value.getTimeInMillis());
     }
 
 }

Modified: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java?view=diff&rev=471352&r1=471351&r2=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java
 (original)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java
 Sat Nov  4 19:34:09 2006
@@ -18,9 +18,10 @@
 package org.apache.commons.beanutils.converters;
 
 import java.sql.Time;
+import java.util.Calendar;
+import java.util.Locale;
 
 import junit.framework.TestSuite;
-import org.apache.commons.beanutils.Converter;
 
 /**
  * Test Case for the [EMAIL PROTECTED] SqlTimeConverter} class.
@@ -30,24 +31,116 @@
 
 public class SqlTimeConverterTestCase extends DateConverterTestBase {
 
+    /**
+     * Construct a new Date test case.
+     * @param name Test Name
+     */
     public SqlTimeConverterTestCase(String name) {
         super(name);
     }
 
     // ------------------------------------------------------------------------
 
+    /**
+     * Create Test Suite
+     * @return test suite
+     */
     public static TestSuite suite() {
         return new TestSuite(SqlTimeConverterTestCase.class);
     }
 
     // ------------------------------------------------------------------------
 
-    protected Converter makeConverter() {
+    /**
+     * Test Date Converter with no default value
+     */
+    public void testLocale() {
+
+        // Re-set the default Locale to Locale.US
+        Locale defaultLocale = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+
+        String pattern = "h:mm a"; // SHORT style time format for US Locale
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setUseLocaleFormat(true);
+
+        // Valid String --> Type Conversion
+        String testString = "3:06 pm";
+        Object expected = toType(testString, pattern, null);
+        validConversion(converter, expected, testString);
+
+        // Invalid Conversions
+        invalidConversion(converter, null);
+        invalidConversion(converter, "");
+        invalidConversion(converter, "13:05");
+        invalidConversion(converter, "11:05 p");
+        invalidConversion(converter, "11.05 pm");
+        invalidConversion(converter, new Integer(2));
+
+        // Test specified Locale
+        converter.setLocale(Locale.UK);
+        invalidConversion(converter, testString);      // Test previous value 
now fails
+        validConversion(converter, expected, "15:06"); // UK Short style is 
"HH:mm"
+
+        // Restore the default Locale
+        Locale.setDefault(defaultLocale);
+
+    }
+
+    /**
+     * Test default String to java.sql.Time conversion
+     */
+    public void testDefaultStringToTypeConvert() {
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setUseLocaleFormat(false);
+
+        // Valid String --> java.sql.Time Conversion
+        String testString = "15:36:21";
+        Object expected = toType(testString, "HH:mm:ss", null);
+        validConversion(converter, expected, testString);
+
+        // Invalid String --> java.sql.Time Conversion
+        invalidConversion(converter, "15:36");
+
+    }
+
+    /**
+     * Create the Converter with no default value.
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter() {
         return new SqlTimeConverter();
     }
+    
+    /**
+     * Create the Converter with a default value.
+     * @param defaultValue The default value
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter(Object defaultValue) {
+        return new SqlTimeConverter(defaultValue);
+    }
 
+    /**
+     * Return the expected type
+     * @return The expected type
+     */
     protected Class getExpectedType() {
         return Time.class;
+    }
+
+    /**
+     * Convert from a Calendar to the appropriate Date type
+     * 
+     * @param value The Calendar value to convert
+     * @return The converted value
+     */
+    protected Object toType(Calendar value) {
+        return new Time(value.getTimeInMillis());
     }
 
 }

Modified: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java?view=diff&rev=471352&r1=471351&r2=471352
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java
 (original)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java
 Sat Nov  4 19:34:09 2006
@@ -18,9 +18,10 @@
 package org.apache.commons.beanutils.converters;
 
 import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Locale;
 
 import junit.framework.TestSuite;
-import org.apache.commons.beanutils.Converter;
 
 /**
  * Test Case for the [EMAIL PROTECTED] SqlTimestampConverter} class.
@@ -30,24 +31,113 @@
 
 public class SqlTimestampConverterTestCase extends DateConverterTestBase {
 
+    /**
+     * Construct a new Date test case.
+     * @param name Test Name
+     */
     public SqlTimestampConverterTestCase(String name) {
         super(name);
     }
 
     // ------------------------------------------------------------------------
 
+    /**
+     * Create Test Suite
+     * @return test suite
+     */
     public static TestSuite suite() {
         return new TestSuite(SqlTimestampConverterTestCase.class);
     }
 
     // ------------------------------------------------------------------------
 
-    protected Converter makeConverter() {
+    /**
+     * Test Date Converter with no default value
+     */
+    public void testLocale() {
+
+        // Re-set the default Locale to Locale.US
+        Locale defaultLocale = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+
+        String pattern = "M/d/yy h:mm a"; // SHORT style Date & Time format 
for US Locale
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setUseLocaleFormat(true);
+
+        // Valid String --> Type Conversion
+        String testString = "3/21/06 3:06 pm";
+        Object expected = toType(testString, pattern, null);
+        validConversion(converter, expected, testString);
+
+        // Invalid Conversions
+        invalidConversion(converter, null);
+        invalidConversion(converter, "");
+        invalidConversion(converter, "13:05 pm");
+        invalidConversion(converter, "11:05 p");
+        invalidConversion(converter, "11.05 pm");
+        invalidConversion(converter, new Integer(2));
+
+        // Restore the default Locale
+        Locale.setDefault(defaultLocale);
+
+    }
+
+    /**
+     * Test default String to java.sql.Timestamp conversion
+     */
+    public void testDefaultStringToTypeConvert() {
+
+        // Create & Configure the Converter
+        DateTimeConverter converter = makeConverter();
+        converter.setUseLocaleFormat(false);
+
+        // Valid String --> java.sql.Timestamp Conversion
+        String testString = "2006-10-23 15:36:01.0";
+        Object expected = toType(testString, "yyyy-MM-dd HH:mm:ss.S", null);
+        validConversion(converter, expected, testString);
+
+        // Invalid String --> java.sql.Timestamp Conversion
+        invalidConversion(converter, "2006/09/21 15:36:01.0");
+        invalidConversion(converter, "2006-10-22");
+        invalidConversion(converter, "15:36:01");
+
+    }
+
+    /**
+     * Create the Converter with no default value.
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter() {
         return new SqlTimestampConverter();
     }
+    
+    /**
+     * Create the Converter with a default value.
+     * @param defaultValue The default value
+     * @return A new Converter
+     */
+    protected DateTimeConverter makeConverter(Object defaultValue) {
+        return new SqlTimestampConverter(defaultValue);
+    }
 
+    /**
+     * Return the expected type
+     * @return The expected type
+     */
     protected Class getExpectedType() {
         return Timestamp.class;
+    }
+
+    /**
+     * Convert from a Calendar to the appropriate Date type
+     * 
+     * @param value The Calendar value to convert
+     * @return The converted value
+     */
+    protected Object toType(Calendar value) {
+        return new Timestamp(value.getTimeInMillis());
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to