Revision: 963
          http://stripes.svn.sourceforge.net/stripes/?rev=963&view=rev
Author:   javelotinfo
Date:     2008-10-05 02:36:51 +0000 (Sun, 05 Oct 2008)

Log Message:
-----------
Fix for STS-610 with unit tests

Modified Paths:
--------------
    
branches/1.5.x/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
    
branches/1.5.x/tests/src/net/sourceforge/stripes/validation/ValidationAnnotationsTest.java

Added Paths:
-----------
    branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/
    
branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/MyIntegerTypeConverter.java
    
branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/MyStringTypeConverter.java

Modified: 
branches/1.5.x/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
===================================================================
--- 
branches/1.5.x/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
  2008-10-02 02:28:16 UTC (rev 962)
+++ 
branches/1.5.x/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
  2008-10-05 02:36:51 UTC (rev 963)
@@ -755,15 +755,15 @@
         converter = factory.getTypeConverter(declaredType, locale);
         if (validationInfo != null && validationInfo.converter() != null) {
             // If a specific converter was requested and it's the same type as 
one we'd use
-            // for the delcared type, set the return type appropriately
+            // for the declared type, set the return type appropriately
             if (converter != null && 
validationInfo.converter().isAssignableFrom(converter.getClass())) {
                 returnType = declaredType;
             }
             // Otherwise assume that it's a converter for the scalar type 
inside a collection
             else {
-                converter = factory.getInstance(validationInfo.converter(), 
locale);
                 returnType = scalarType;
             }
+            converter = factory.getInstance(validationInfo.converter(), 
locale);
         }
         // Else, if we got a converter for the declared type (e.g. Foo 
implementes List<Bar>)
         // then convert for the declared type

Added: 
branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/MyIntegerTypeConverter.java
===================================================================
--- 
branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/MyIntegerTypeConverter.java
                             (rev 0)
+++ 
branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/MyIntegerTypeConverter.java
     2008-10-05 02:36:51 UTC (rev 963)
@@ -0,0 +1,27 @@
+package net.sourceforge.stripes.extensions;
+
+import java.util.Collection;
+
+import net.sourceforge.stripes.validation.IntegerTypeConverter;
+import net.sourceforge.stripes.validation.TypeConverter;
+import net.sourceforge.stripes.validation.ValidationError;
+
+/**
+ * Converts the input string to an Integer and doubles the value. This type 
converter extends the
+ * stock IntegerTypeConverter.
+ *
+ * @author Freddy Daoud
+ */
+public class MyIntegerTypeConverter extends IntegerTypeConverter implements 
TypeConverter<Integer> {
+    @Override
+    public Integer convert(String input, Class<? extends Integer> targetType,
+        Collection<ValidationError> errors)
+    {
+        Integer result = super.convert(input, targetType, errors);
+
+        if (result != null) {
+            result = new Integer(result.intValue() * 2);
+        }
+        return result;
+    }
+}

Added: 
branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/MyStringTypeConverter.java
===================================================================
--- 
branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/MyStringTypeConverter.java
                              (rev 0)
+++ 
branches/1.5.x/tests/src/net/sourceforge/stripes/extensions/MyStringTypeConverter.java
      2008-10-05 02:36:51 UTC (rev 963)
@@ -0,0 +1,22 @@
+package net.sourceforge.stripes.extensions;
+
+import java.util.Collection;
+import java.util.Locale;
+
+import net.sourceforge.stripes.validation.TypeConverter;
+import net.sourceforge.stripes.validation.ValidationError;
+
+/**
+ * Converts the input string to upper case. This type converter does not 
extend a stock type
+ * converter.
+ *
+ * @author Freddy Daoud
+ */
+public class MyStringTypeConverter implements TypeConverter<String> {
+    public String convert(String input, Class<? extends String> targetType,
+        Collection<ValidationError> errors)
+    {
+        return input.toUpperCase();
+    }
+    public void setLocale(Locale locale) { }
+}

Modified: 
branches/1.5.x/tests/src/net/sourceforge/stripes/validation/ValidationAnnotationsTest.java
===================================================================
--- 
branches/1.5.x/tests/src/net/sourceforge/stripes/validation/ValidationAnnotationsTest.java
  2008-10-02 02:28:16 UTC (rev 962)
+++ 
branches/1.5.x/tests/src/net/sourceforge/stripes/validation/ValidationAnnotationsTest.java
  2008-10-05 02:36:51 UTC (rev 963)
@@ -4,6 +4,9 @@
 import net.sourceforge.stripes.action.ActionBean;
 import net.sourceforge.stripes.action.ActionBeanContext;
 import net.sourceforge.stripes.action.Resolution;
+import net.sourceforge.stripes.controller.StripesFilter;
+import net.sourceforge.stripes.extensions.MyIntegerTypeConverter;
+import net.sourceforge.stripes.extensions.MyStringTypeConverter;
 import net.sourceforge.stripes.mock.MockRoundtrip;
 
 import org.testng.Assert;
@@ -37,7 +40,7 @@
         MockRoundtrip trip = new 
MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
         trip.execute("validateRequiredAndIgnored");
         ActionBean actionBean = trip.getActionBean(getClass());
-        Assert.assertEquals(0, 
actionBean.getContext().getValidationErrors().size());
+        
Assert.assertEquals(actionBean.getContext().getValidationErrors().size(), 0);
     }
 
     @Validate(required=true, on="validatePublicField")
@@ -55,6 +58,52 @@
         MockRoundtrip trip = new 
MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
         trip.execute("validatePublicField");
         ActionBean actionBean = trip.getActionBean(getClass());
-        Assert.assertEquals(1, 
actionBean.getContext().getValidationErrors().size());
+        
Assert.assertEquals(actionBean.getContext().getValidationErrors().size(), 1);
     }
+
+    public Integer shouldBeDoubled;
+    @Validate(converter=IntegerTypeConverter.class) public Integer 
shouldNotBeDoubled;
+
+    public String shouldBeUpperCased;
+    @Validate(converter=StringTypeConverter.class) public String 
shouldNotBeUpperCased;
+
+    public Resolution validateTypeConverters() { return null; }
+
+    /**
+     * Tests the use of an auto-loaded type converter versus a type converter 
explicitly configured
+     * via [EMAIL PROTECTED] @Validate(converter)}, where the auto-loaded type 
converter extends the stock
+     * type converter.
+     *
+     * @see http://www.stripesframework.org/jira/browse/STS-610
+     */
+    @Test(groups="extensions")
+    public void testValidateTypeConverterExtendsStock() throws Exception {
+        MockRoundtrip trip = new 
MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
+        
StripesFilter.getConfiguration().getTypeConverterFactory().add(Integer.class, 
MyIntegerTypeConverter.class);
+        trip.addParameter("shouldBeDoubled", "42");
+        trip.addParameter("shouldNotBeDoubled", "42");
+        trip.execute("validateTypeConverters");
+        ValidationAnnotationsTest actionBean = trip.getActionBean(getClass());
+        Assert.assertEquals(actionBean.shouldBeDoubled, new Integer(84));
+        Assert.assertEquals(actionBean.shouldNotBeDoubled, new Integer(42));
+    }
+
+    /**
+     * Tests the use of an auto-loaded type converter versus a type converter 
explicitly configured
+     * via [EMAIL PROTECTED] @Validate(converter)}, where the auto-loaded type 
converter does not extend the
+     * stock type converter.
+     *
+     * @see http://www.stripesframework.org/jira/browse/STS-610
+     */
+    @Test(groups="extensions")
+    public void testValidateTypeConverterDoesNotExtendStock() throws Exception 
{
+        MockRoundtrip trip = new 
MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
+        
StripesFilter.getConfiguration().getTypeConverterFactory().add(String.class, 
MyStringTypeConverter.class);
+        trip.addParameter("shouldBeUpperCased", "test");
+        trip.addParameter("shouldNotBeUpperCased", "test");
+        trip.execute("validateTypeConverters");
+        ValidationAnnotationsTest actionBean = trip.getActionBean(getClass());
+        Assert.assertEquals(actionBean.shouldBeUpperCased, "TEST");
+        Assert.assertEquals(actionBean.shouldNotBeUpperCased, "test");
+    }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to