hlship      2005/08/14 19:46:49

  Modified:    framework/src/test/org/apache/tapestry/junit
                        TapestryTestCase.java
               .        status.xml
               framework/src/java/org/apache/tapestry/form/validator
                        ValidatorFactory.java ValidatorsBindingFactory.java
                        ValidatorStrings.properties ValidatorMessages.java
                        ValidatorFactoryImpl.java
               framework/src/test/org/apache/tapestry/binding
                        BindingTestCase.java
               framework/src/test/org/apache/tapestry/form/validator
                        TestValidatorFactory.java
                        TestValidatorsBinding.java
  Log:
  TAPESTRY-417: validators: binding prefix should have way to reference the 
component's managed beans
  
  Revision  Changes    Path
  1.12      +5 -0      
jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TapestryTestCase.java
  
  Index: TapestryTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TapestryTestCase.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TapestryTestCase.java     9 May 2005 14:45:16 -0000       1.11
  +++ TapestryTestCase.java     15 Aug 2005 02:46:48 -0000      1.12
  @@ -174,4 +174,9 @@
   
           return _sharedValueConverter;
       }
  +
  +    protected IComponent newComponent()
  +    {
  +        return (IComponent) newMock(IComponent.class);
  +    }
   }
  \ No newline at end of file
  
  
  
  1.214     +1 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.213
  retrieving revision 1.214
  diff -u -r1.213 -r1.214
  --- status.xml        14 Aug 2005 20:45:36 -0000      1.213
  +++ status.xml        15 Aug 2005 02:46:48 -0000      1.214
  @@ -62,6 +62,7 @@
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-94">PropertySelection 
does not submit Palette properly</action>
         <action type="fix" dev="MB" fixes-bug="TAPESTRY-540">All For and If 
components in the non-form table family should be declared as volatile</action>
         <action type="fix" dev="MB" fixes-bug="TAPESTRY-296">Configurable 
location of Table component's page navigation links</action>
  +      <action type="fix" dev="HLS" fixes-bug="TAPESTRY-417">validators: 
binding prefix should have way to reference the component's managed 
beans</action>
       </release>
       <release version="4.0-beta-4" date="Aug 10 2005">
         <action type="fix" dev="HLS">Add getComponent() method to 
IComponent.</action>
  
  
  
  1.3       +12 -2     
jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorFactory.java
  
  Index: ValidatorFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ValidatorFactory.java     6 Aug 2005 06:58:26 -0000       1.2
  +++ ValidatorFactory.java     15 Aug 2005 02:46:48 -0000      1.3
  @@ -16,6 +16,8 @@
   
   import java.util.List;
   
  +import org.apache.tapestry.IComponent;
  +
   /**
    * Constructs [EMAIL PROTECTED] 
org.apache.tapestry.form.validator.Validator} instances from a specification. A
    * specification is a comma-seperated list of entries. Each entry is in one 
of the following forms:
  @@ -24,6 +26,7 @@
    * <li><em>name</em>=<em>value</em>
    * <li><em>name[<em>message</em>]</em>
    * <li><em>name</em>=<em>value</em>[<em>message</em>]
  + * <li>$<em>name</em>
    * </ul>
    * <p>
    * Most validator classes are <em>configurable</em>: they have a property 
that matches their
  @@ -33,9 +36,14 @@
    * <p>
    * Validators are expected to have a public no-args constructor. They are 
also expected to have a
    * <code>message</code> property which is set from the value in brackets.
  + * The message is either a literal string, or may be prefixed with a '%' 
character, to indicate
  + * a localized key, resolved using the component's message catalog.
  + * <p>
  + * When the name is prefixed with a dollary sign, it indicates a reference 
to a <em>bean</em>
  + * with the given name.
    * <p>
    * A full validator specification might be:
  - * <code>required,email,minLength=20[Email addresses must be at least 20 
characters long.]
  + * <code>required,email[%email-format],minLength=20[Email addresses must be 
at least 20 characters long.]
    * 
    * @author Howard Lewis Ship
    * @since 4.0
  @@ -46,9 +54,11 @@
        * Constructs a new (immutable) List of [EMAIL PROTECTED] Validator}, or 
returns a previously constructed
        * List.
        * 
  +     * @param component
  +     *            the component for which the list is being created
        * @param specification
        *            a string identifying which validators and their 
configuration
        * @return List of [EMAIL PROTECTED] Validator} (possibly empty)
        */
  -    public List constructValidatorList(String specification);
  +    public List constructValidatorList(IComponent component, String 
specification);
   }
  
  
  
  1.2       +1 -1      
jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorsBindingFactory.java
  
  Index: ValidatorsBindingFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorsBindingFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidatorsBindingFactory.java     20 Jun 2005 21:29:15 -0000      1.1
  +++ ValidatorsBindingFactory.java     15 Aug 2005 02:46:48 -0000      1.2
  @@ -36,7 +36,7 @@
       {
           try
           {
  -            List validators = _validatorFactory.constructValidatorList(path);
  +            List validators = _validatorFactory.constructValidatorList(root, 
path);
   
               return new ValidatorsBinding(bindingDescription, 
getValueConverter(), location,
                       validators);
  
  
  
  1.2       +3 -1      
jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorStrings.properties
  
  Index: ValidatorStrings.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorStrings.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidatorStrings.properties       20 Jun 2005 20:20:08 -0000      1.1
  +++ ValidatorStrings.properties       15 Aug 2005 02:46:48 -0000      1.2
  @@ -16,4 +16,6 @@
   needs-configuration=Validator ''{0}'' must be configured in order to be 
used. The value is configured by changing ''{0}'' to ''{0}=value''.
   not-configurable=Validator ''{0}'' is not configurable, ''{0}={1}'' should 
be changed to just ''{0}''.
   error-initializing-validator=Error initializing validator ''{0}'' (class 
{1}): {2}
  -bad-specification=Unable to parse ''{0}'' into a list of validators.
  \ No newline at end of file
  +bad-specification=Unable to parse ''{0}'' into a list of validators.
  +no-value-or-message-for-bean=Validator ''{0}'' is a reference to a managed 
bean of the component, and may not have a value or a message override specified.
  +bean-not-validator=Bean ''{0}'' does not implement the {1} interface.
  \ No newline at end of file
  
  
  
  1.2       +10 -0     
jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorMessages.java
  
  Index: ValidatorMessages.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorMessages.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidatorMessages.java    20 Jun 2005 20:20:08 -0000      1.1
  +++ ValidatorMessages.java    15 Aug 2005 02:46:48 -0000      1.2
  @@ -54,4 +54,14 @@
       {
           return _formatter.format("bad-specification", specification);
       }
  +
  +    public static String noValueOrMessageForBean(String name)
  +    {
  +        return _formatter.format("no-value-or-message-for-bean", name);
  +    }
  +
  +    public static String beanNotValidator(String name)
  +    {
  +        return _formatter.format("bean-not-validator", name, 
Validator.class.getName());
  +    }
   }
  
  
  
  1.3       +28 -23    
jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorFactoryImpl.java
  
  Index: ValidatorFactoryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/form/validator/ValidatorFactoryImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ValidatorFactoryImpl.java 6 Aug 2005 06:58:26 -0000       1.2
  +++ ValidatorFactoryImpl.java 15 Aug 2005 02:46:48 -0000      1.3
  @@ -16,13 +16,14 @@
   
   import java.util.ArrayList;
   import java.util.Collections;
  -import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
   
   import org.apache.hivemind.ApplicationRuntimeException;
   import org.apache.hivemind.HiveMind;
  +import org.apache.hivemind.util.Defense;
   import org.apache.hivemind.util.PropertyUtils;
  +import org.apache.tapestry.IComponent;
   import org.apache.tapestry.util.RegexpMatch;
   import org.apache.tapestry.util.RegexpMatcher;
   
  @@ -35,13 +36,7 @@
    */
   public class ValidatorFactoryImpl implements ValidatorFactory
   {
  -    private static final String PATTERN = 
"^\\s*(\\w+)\\s*(=\\s*(((?!,|\\[).)*))?";
  -
  -    /**
  -     * Cache of List (of Validator) keyed on specification.
  -     */
  -
  -    private Map _masterCache = new HashMap();
  +    private static final String PATTERN = 
"^\\s*(\\$?\\w+)\\s*(=\\s*(((?!,|\\[).)*))?";
   
       private RegexpMatcher _matcher = new RegexpMatcher();
   
  @@ -51,21 +46,10 @@
   
       private Map _validators;
   
  -    public synchronized List constructValidatorList(String specification)
  +    public List constructValidatorList(IComponent component, String 
specification)
       {
  -        List result = (List) _masterCache.get(specification);
  -
  -        if (result == null)
  -        {
  -            result = buildValidatorList(specification);
  -            _masterCache.put(specification, result);
  -        }
  -
  -        return result;
  -    }
  +        Defense.notNull(component, "component");
   
  -    private List buildValidatorList(String specification)
  -    {
           if (HiveMind.isBlank(specification))
               return Collections.EMPTY_LIST;
   
  @@ -113,7 +97,7 @@
                   }
               }
   
  -            Validator validator = buildValidator(name, value, message);
  +            Validator validator = buildValidator(component, name, value, 
message);
   
               result.add(validator);
   
  @@ -127,8 +111,11 @@
           return Collections.unmodifiableList(result);
       }
   
  -    private Validator buildValidator(String name, String value, String 
message)
  +    private Validator buildValidator(IComponent component, String name, 
String value, String message)
       {
  +        if (name.startsWith("$"))
  +            return extractValidatorBean(component, name, value, message);
  +
           ValidatorContribution vc = (ValidatorContribution) 
_validators.get(name);
   
           if (vc == null)
  @@ -161,6 +148,24 @@
           }
       }
   
  +    private Validator extractValidatorBean(IComponent component, String 
validatorName,
  +            String value, String message)
  +    {
  +        String beanName = validatorName.substring(1);
  +
  +        if (HiveMind.isNonBlank(value) || HiveMind.isNonBlank(message))
  +            throw new ApplicationRuntimeException(ValidatorMessages
  +                    .noValueOrMessageForBean(beanName));
  +
  +        Object bean = component.getBeans().getBean(beanName);
  +
  +        if (bean instanceof Validator)
  +            return (Validator) bean;
  +
  +        throw new 
ApplicationRuntimeException(ValidatorMessages.beanNotValidator(beanName), bean,
  +                null, null);
  +    }
  +
       public void setValidators(Map validators)
       {
           _validators = validators;
  
  
  
  1.6       +2 -8      
jakarta-tapestry/framework/src/test/org/apache/tapestry/binding/BindingTestCase.java
  
  Index: BindingTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/binding/BindingTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BindingTestCase.java      9 May 2005 14:45:16 -0000       1.5
  +++ BindingTestCase.java      15 Aug 2005 02:46:48 -0000      1.6
  @@ -14,9 +14,9 @@
   
   package org.apache.tapestry.binding;
   
  -import org.apache.hivemind.test.HiveMindTestCase;
   import org.apache.tapestry.IComponent;
   import org.apache.tapestry.coerce.ValueConverter;
  +import org.apache.tapestry.junit.TapestryTestCase;
   import org.easymock.MockControl;
   
   /**
  @@ -25,14 +25,8 @@
    * @author Howard M. Lewis Ship
    * @since 4.0
    */
  -public abstract class BindingTestCase extends HiveMindTestCase
  +public abstract class BindingTestCase extends TapestryTestCase
   {
  -
  -    protected IComponent newComponent()
  -    {
  -        return (IComponent) newMock(IComponent.class);
  -    }
  -
       protected IComponent newComponent(String extendedId)
       {
           MockControl control = newControl(IComponent.class);
  
  
  
  1.2       +195 -22   
jakarta-tapestry/framework/src/test/org/apache/tapestry/form/validator/TestValidatorFactory.java
  
  Index: TestValidatorFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/form/validator/TestValidatorFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestValidatorFactory.java 20 Jun 2005 20:20:08 -0000      1.1
  +++ TestValidatorFactory.java 15 Aug 2005 02:46:49 -0000      1.2
  @@ -20,7 +20,10 @@
   import java.util.Map;
   
   import org.apache.hivemind.ApplicationRuntimeException;
  -import org.apache.hivemind.test.HiveMindTestCase;
  +import org.apache.tapestry.IBeanProvider;
  +import org.apache.tapestry.IComponent;
  +import org.apache.tapestry.junit.TapestryTestCase;
  +import org.easymock.MockControl;
   
   /**
    * Tests for [EMAIL PROTECTED] 
org.apache.tapestry.form.validator.ValidatorFactoryImpl}.
  @@ -28,7 +31,7 @@
    * @author Howard Lewis Ship
    * @since 4.0
    */
  -public class TestValidatorFactory extends HiveMindTestCase
  +public class TestValidatorFactory extends TapestryTestCase
   {
       private Map buildContributions(String name, boolean configurable)
       {
  @@ -48,69 +51,85 @@
   
       public void testEmpty()
       {
  +        IComponent component = newComponent();
           ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
   
  -        List result = vf.constructValidatorList("");
  +        replayControls();
  +
  +        List result = vf.constructValidatorList(component, "");
   
           assertTrue(result.isEmpty());
  +
  +        verifyControls();
       }
   
       public void testSingle()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
           vf.setValidators(buildContributions("value", true));
   
  -        List result = vf.constructValidatorList("value=foo");
  +        List result = vf.constructValidatorList(component, "value=foo");
   
           ValidatorFixture fixture = (ValidatorFixture) result.get(0);
   
           assertEquals("foo", fixture.getValue());
  +
  +        verifyControls();
       }
   
       public void testMessage()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
           vf.setValidators(buildContributions("fred", false));
   
  -        List result = vf.constructValidatorList("fred[fred's message]");
  +        List result = vf.constructValidatorList(component, "fred[fred's 
message]");
   
           ValidatorFixture fixture = (ValidatorFixture) result.get(0);
   
           assertEquals("fred's message", fixture.getMessage());
  +
  +        verifyControls();
       }
   
       public void testConfigureAndMessage()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
           vf.setValidators(buildContributions("value", true));
   
  -        List result = vf.constructValidatorList("value=biff[fred's 
message]");
  +        List result = vf.constructValidatorList(component, 
"value=biff[fred's message]");
   
           ValidatorFixture fixture = (ValidatorFixture) result.get(0);
   
           assertEquals("biff", fixture.getValue());
           assertEquals("fred's message", fixture.getMessage());
  -    }
  -
  -    public void testValidatorListsCached()
  -    {
  -        ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
  -        vf.setValidators(buildContributions("value", true));
  -
  -        List result1 = vf.constructValidatorList("value=foo");
  -        List result2 = vf.constructValidatorList("value=foo");
   
  -        assertSame(result1, result2);
  +        verifyControls();
       }
   
       public void testMissingConfiguration()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
           vf.setValidators(buildContributions("fred", true));
   
           try
           {
  -            vf.constructValidatorList("fred");
  +            vf.constructValidatorList(component, "fred");
               unreachable();
           }
           catch (ApplicationRuntimeException ex)
  @@ -119,10 +138,16 @@
                       + "The value is configured by changing 'name' to 
'name=value'.", ex
                       .getMessage());
           }
  +
  +        verifyControls();
       }
   
       public void testMultiple()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           Map map = new HashMap();
           map.put("required", newContribution(false, Required.class));
           map.put("email", newContribution(false, Email.class));
  @@ -132,7 +157,9 @@
           vf.setValidators(map);
   
           List result = vf
  -                .constructValidatorList("required[EMail is 
required],email,minLength=10[EMail must be at least ten characters long]");
  +                .constructValidatorList(
  +                        component,
  +                        "required[EMail is 
required],email,minLength=10[EMail must be at least ten characters long]");
   
           assertEquals(3, result.size());
   
  @@ -145,31 +172,43 @@
   
           assertEquals(10, minLength.getMinLength());
           assertEquals("EMail must be at least ten characters long", 
minLength.getMessage());
  +
  +        verifyControls();
       }
   
       public void testUnparseable()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
           vf.setValidators(buildContributions("fred", false));
   
           try
           {
  -            vf.constructValidatorList("fred,=foo");
  +            vf.constructValidatorList(component, "fred,=foo");
           }
           catch (ApplicationRuntimeException ex)
           {
               assertEquals("Unable to parse 'fred,=foo' into a list of 
validators.", ex.getMessage());
           }
  +
  +        verifyControls();
       }
   
       public void testUnwantedConfiguration()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
           vf.setValidators(buildContributions("fred", false));
   
           try
           {
  -            vf.constructValidatorList("fred=biff");
  +            vf.constructValidatorList(component, "fred=biff");
               unreachable();
           }
           catch (ApplicationRuntimeException ex)
  @@ -177,26 +216,38 @@
               assertEquals("Validator 'fred' is not configurable, "
                       + "'fred=biff' should be changed to just 'fred'.", 
ex.getMessage());
           }
  +
  +        verifyControls();
       }
   
       public void testMissingValidator()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
           vf.setValidators(Collections.EMPTY_MAP);
   
           try
           {
  -            vf.constructValidatorList("missing");
  +            vf.constructValidatorList(component, "missing");
               unreachable();
           }
           catch (ApplicationRuntimeException ex)
           {
               assertEquals("No validator named 'missing' has been defined.", 
ex.getMessage());
           }
  +
  +        verifyControls();
       }
   
       public void testInstantiateFailure()
       {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
           Map map = new HashMap();
   
           map.put("fred", newContribution(false, Object.class));
  @@ -206,7 +257,7 @@
   
           try
           {
  -            vf.constructValidatorList("fred");
  +            vf.constructValidatorList(component, "fred");
               unreachable();
           }
           catch (ApplicationRuntimeException ex)
  @@ -216,5 +267,127 @@
                       ex.getMessage());
           }
   
  +        verifyControls();
  +    }
  +
  +    private Validator newValidator()
  +    {
  +        return (Validator) newMock(Validator.class);
  +    }
  +
  +    private IBeanProvider newBeanProvider(String beanName, Object bean)
  +    {
  +        MockControl control = newControl(IBeanProvider.class);
  +        IBeanProvider provider = (IBeanProvider) control.getMock();
  +
  +        provider.getBean(beanName);
  +        control.setReturnValue(bean);
  +
  +        return provider;
  +    }
  +
  +    private IComponent newComponent(IBeanProvider provider)
  +    {
  +        MockControl control = newControl(IComponent.class);
  +        IComponent component = (IComponent) control.getMock();
  +
  +        component.getBeans();
  +        control.setReturnValue(provider);
  +
  +        return component;
  +    }
  +
  +    public void testBeanReference()
  +    {
  +        Validator validator = newValidator();
  +        IBeanProvider provider = newBeanProvider("fred", validator);
  +        IComponent component = newComponent(provider);
  +
  +        replayControls();
  +
  +        ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
  +        vf.setValidators(Collections.EMPTY_MAP);
  +
  +        List validators = vf.constructValidatorList(component, "$fred");
  +
  +        assertEquals(1, validators.size());
  +        assertSame(validator, validators.get(0));
  +
  +        verifyControls();
  +    }
  +
  +    public void testBeanReferenceNotValidator()
  +    {
  +        Object bean = new Object();
  +        IBeanProvider provider = newBeanProvider("fred", bean);
  +        IComponent component = newComponent(provider);
  +
  +        replayControls();
  +
  +        ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
  +        vf.setValidators(Collections.EMPTY_MAP);
  +
  +        try
  +        {
  +            vf.constructValidatorList(component, "$fred");
  +            unreachable();
  +        }
  +        catch (ApplicationRuntimeException ex)
  +        {
  +            assertEquals(
  +                    "Bean 'fred' does not implement the 
org.apache.tapestry.form.validator.Validator interface.",
  +                    ex.getMessage());
  +            assertSame(bean, ex.getComponent());
  +        }
  +
  +        verifyControls();
  +    }
  +
  +    public void testBeanReferenceWithValue()
  +    {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
  +        ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
  +        vf.setValidators(Collections.EMPTY_MAP);
  +
  +        try
  +        {
  +            vf.constructValidatorList(component, "$fred=10");
  +            unreachable();
  +        }
  +        catch (ApplicationRuntimeException ex)
  +        {
  +            assertEquals(
  +                    "Validator 'fred' is a reference to a managed bean of 
the component, and may not have a value or a message override specified.",
  +                    ex.getMessage());
  +        }
  +
  +        verifyControls();
  +    }
  +
  +    public void testBeanReferenceWithMessage()
  +    {
  +        IComponent component = newComponent();
  +
  +        replayControls();
  +
  +        ValidatorFactoryImpl vf = new ValidatorFactoryImpl();
  +        vf.setValidators(Collections.EMPTY_MAP);
  +
  +        try
  +        {
  +            vf.constructValidatorList(component, "$fred[custom message]");
  +            unreachable();
  +        }
  +        catch (ApplicationRuntimeException ex)
  +        {
  +            assertEquals(
  +                    "Validator 'fred' is a reference to a managed bean of 
the component, and may not have a value or a message override specified.",
  +                    ex.getMessage());
  +        }
  +
  +        verifyControls();
       }
   }
  
  
  
  1.2       +7 -4      
jakarta-tapestry/framework/src/test/org/apache/tapestry/form/validator/TestValidatorsBinding.java
  
  Index: TestValidatorsBinding.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/form/validator/TestValidatorsBinding.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestValidatorsBinding.java        20 Jun 2005 21:29:15 -0000      1.1
  +++ TestValidatorsBinding.java        15 Aug 2005 02:46:49 -0000      1.2
  @@ -19,6 +19,7 @@
   import org.apache.hivemind.ApplicationRuntimeException;
   import org.apache.hivemind.Location;
   import org.apache.tapestry.IBinding;
  +import org.apache.tapestry.IComponent;
   import org.apache.tapestry.binding.BindingTestCase;
   import org.apache.tapestry.coerce.ValueConverter;
   import org.easymock.MockControl;
  @@ -34,6 +35,7 @@
   {
       public void testSuccess()
       {
  +        IComponent component = newComponent();
           Location l = newLocation();
           List validators = (List) newMock(List.class);
           ValueConverter vc = newValueConverter();
  @@ -41,7 +43,7 @@
           MockControl control = newControl(ValidatorFactory.class);
           ValidatorFactory vf = (ValidatorFactory) control.getMock();
   
  -        vf.constructValidatorList("required");
  +        vf.constructValidatorList(component, "required");
           control.setReturnValue(validators);
   
           replayControls();
  @@ -50,7 +52,7 @@
           factory.setValueConverter(vc);
           factory.setValidatorFactory(vf);
   
  -        IBinding binding = factory.createBinding(null, "my desc", 
"required", l);
  +        IBinding binding = factory.createBinding(component, "my desc", 
"required", l);
   
           assertSame(validators, binding.getObject());
           assertSame(l, binding.getLocation());
  @@ -61,6 +63,7 @@
   
       public void testFailure()
       {
  +        IComponent component = newComponent();
           Throwable t = new RuntimeException("Boom!");
           Location l = newLocation();
   
  @@ -69,7 +72,7 @@
           MockControl control = newControl(ValidatorFactory.class);
           ValidatorFactory vf = (ValidatorFactory) control.getMock();
   
  -        vf.constructValidatorList("required");
  +        vf.constructValidatorList(component, "required");
           control.setThrowable(t);
   
           replayControls();
  @@ -80,7 +83,7 @@
   
           try
           {
  -            factory.createBinding(null, "my desc", "required", l);
  +            factory.createBinding(component, "my desc", "required", l);
               unreachable();
           }
           catch (ApplicationRuntimeException ex)
  
  
  

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

Reply via email to