bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r999729 [3/3] - in /incubator/bval/sandbox/lang3-work: bval-jsr303/src/test/java/org/apache/bval/constraints/ bval-jsr303d/ bval-jsr303d/src/ bval-jsr303d/src/main/ bval-jsr303d/src/main/java/ bval-jsr303d/src/main/java/org/ bval-jsr303d/sr...
Date Wed, 22 Sep 2010 02:37:56 GMT
Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,532 @@
+/*
+ *  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.bval.constraints.dynamic;
+
+import static org.junit.Assert.*;
+
+import java.lang.annotation.ElementType;
+import java.util.Locale;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+
+import org.apache.bval.constraints.dynamic.Values.Labeled;
+import org.apache.bval.constraints.dynamic.Values.Strategy;
+import org.apache.bval.constraints.dynamic.Values.Rule;
+import org.apache.bval.constraints.dynamic.Values.Labeled.Item;
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.dynamic.ConstraintAppender;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+import org.apache.commons.proxy2.stub.AnnotationFactory;
+import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test the {@link Values} and {@link Values.Labeled} constraints, as well as
+ * their provided {@link ConstraintValidator}s and {@link ConstraintAppender}s.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ValuesConstraintValidationTest {
+    public static class TestBean {
+        @Values({ "foo", "bar", "baz" })
+        String fooBarOrBaz;
+
+        @Values(value = { "foo", "bar", "baz" }, rule = Rule.EXCLUDE)
+        String noneOfFooBarOrBaz;
+
+        @Values.Labeled({ @Item(label = "one", value = "1"), @Item(label = "two", value = "2"),
+            @Item(label = "three", value = "3") })
+        String oneTwoOrThree;
+
+        @Values.Labeled(value = { @Item(label = "one", value = "1"), @Item(label = "two", value = "2"),
+            @Item(label = "three", value = "3") }, rule = Rule.EXCLUDE)
+        String noneOfOneTwoOrThree;
+
+        @Values({ "FIELD", "METHOD", "TYPE" })
+        ElementType fieldMethodOrType;
+
+        @Values(value = { "FIELD", "METHOD", "TYPE" }, rule = Rule.EXCLUDE)
+        ElementType noneOfFieldMethodOrType;
+
+        @Values.Labeled({ @Item(label = "@", value = "ANNOTATION_TYPE"), @Item(label = "new", value = "CONSTRUCTOR") })
+        ElementType annotationOrConstructor;
+
+        @Values.Labeled(value = { @Item(label = "@", value = "ANNOTATION_TYPE"),
+            @Item(label = "new", value = "CONSTRUCTOR") }, rule = Rule.EXCLUDE)
+        ElementType noneOfAnnotationOrConstructor;
+    }
+
+    private Validator validator;
+    private DynamicValidatorContext validatorContext;
+    private final AnnotationFactory annotationFactory = new AnnotationFactory();
+    private TestBean testBean;
+
+    @Before
+    public void setup() {
+        DynamicValidatorFactory factory =
+            Validation
+                .byProvider(ApacheValidationProvider.class)
+                .configure()
+                .addProperty(ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                    DynamicValidatorFactory.class.getName()).buildValidatorFactory()
+                .unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        validator = validatorContext.getValidator();
+        testBean = new TestBean();
+    }
+
+    @Test
+    public void testValidateStringValues() {
+        assertNull(testBean.fooBarOrBaz);
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fooBarOrBaz = "foo";
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fooBarOrBaz = "oops";
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValidateExcludeStringValues() {
+        assertNull(testBean.noneOfFooBarOrBaz);
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.noneOfFooBarOrBaz = "oops";
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.noneOfFooBarOrBaz = "foo";
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValidateStringLabeledValues() {
+        assertNull(testBean.oneTwoOrThree);
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.oneTwoOrThree = "1";
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.oneTwoOrThree = "0";
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValidateExcludeStringLabeledValues() {
+        assertNull(testBean.noneOfOneTwoOrThree);
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.noneOfOneTwoOrThree = "0";
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.noneOfOneTwoOrThree = "1";
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValidateEnumValues() {
+        assertNull(testBean.fieldMethodOrType);
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fieldMethodOrType = ElementType.FIELD;
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fieldMethodOrType = ElementType.CONSTRUCTOR;
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValidateExcludeEnumValues() {
+        assertNull(testBean.noneOfFieldMethodOrType);
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.noneOfFieldMethodOrType = ElementType.CONSTRUCTOR;
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.noneOfFieldMethodOrType = ElementType.FIELD;
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValidateEnumLabeledValues() {
+        assertNull(testBean.annotationOrConstructor);
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.annotationOrConstructor = ElementType.CONSTRUCTOR;
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.annotationOrConstructor = ElementType.FIELD;
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValidateExcludeEnumLabeledValues() {
+        assertNull(testBean.noneOfAnnotationOrConstructor);
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.noneOfAnnotationOrConstructor = ElementType.FIELD;
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.noneOfAnnotationOrConstructor = ElementType.CONSTRUCTOR;
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValuesConstraintAccumulation() {
+        testBean.fooBarOrBaz = "bar";
+        assertEquals(0, validator.validate(testBean).size());
+
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.value()).thenReturn("foo").when(stub.rule()).thenReturn(Rule.EXCLUDE)
+                        .when(stub.strategy()).thenReturn(Strategy.MERGE);
+                }
+            }));
+
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fooBarOrBaz = "foo";
+        assertEquals(1, validator.validate(testBean).size());
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.value()).thenReturn("blah").when(stub.strategy()).thenReturn(Strategy.MERGE);
+                }
+            }));
+
+        assertEquals(1, validator.validate(testBean).size());
+        testBean.fooBarOrBaz = "blah";
+        assertEquals(0, validator.validate(testBean).size());
+
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.value()).thenReturn("foo").when(stub.strategy()).thenReturn(Strategy.MERGE);
+                }
+            }));
+
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fooBarOrBaz = "foo";
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fooBarOrBaz = "bar";
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fooBarOrBaz = "baz";
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.fooBarOrBaz = "bzzt";
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testLabeledValuesConstraintAccumulation() {
+        testBean.annotationOrConstructor = ElementType.ANNOTATION_TYPE;
+        assertEquals(0, validator.validate(testBean).size());
+
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Values.Labeled stub) {
+                    when(stub.value()).thenReturn(item(ElementType.CONSTRUCTOR, "new")).when(stub.rule())
+                        .thenReturn(Rule.EXCLUDE).when(stub.strategy()).thenReturn(Strategy.MERGE);
+                }
+            }));
+
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.annotationOrConstructor = ElementType.CONSTRUCTOR;
+        assertEquals(1, validator.validate(testBean).size());
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Values.Labeled stub) {
+                    when(stub.value()).thenReturn(item(ElementType.FIELD, ".")).when(stub.strategy())
+                        .thenReturn(Strategy.MERGE);
+                }
+            }));
+
+        assertEquals(1, validator.validate(testBean).size());
+        testBean.annotationOrConstructor = ElementType.FIELD;
+        assertEquals(0, validator.validate(testBean).size());
+
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Values.Labeled stub) {
+                    when(stub.value()).thenReturn(item(ElementType.CONSTRUCTOR, "new")).when(stub.strategy())
+                        .thenReturn(Strategy.MERGE);
+                }
+            }));
+
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.annotationOrConstructor = ElementType.CONSTRUCTOR;
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.annotationOrConstructor = ElementType.ANNOTATION_TYPE;
+        assertEquals(0, validator.validate(testBean).size());
+        testBean.annotationOrConstructor = ElementType.METHOD;
+        assertEquals(1, validator.validate(testBean).size());
+    }
+
+    @Test
+    public void testValuesConstraintAccumulationGrouping() {
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.groups()).thenReturn(X.class).when(stub.rule()).thenReturn(Rule.EXCLUDE)
+                        .when(stub.value()).thenReturn("anythingButThis").when(stub.message())
+                        .thenReturn("anything but 'anythingButThis' in group X");
+                }
+            }));
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.groups()).thenReturn(Y.class).when(stub.value()).thenReturn("onlyThis")
+                        .when(stub.message()).thenReturn("only 'onlyThis' in group Y");
+                }
+            }));
+        testBean.fooBarOrBaz = "foo";
+        assertEquals(0, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(1, validator.validate(testBean, Y.class).size());
+        assertEquals(1, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.fooBarOrBaz = "anythingButThis";
+        assertEquals(1, validator.validate(testBean).size());
+        assertEquals(1, validator.validate(testBean, X.class).size());
+        assertEquals(1, validator.validate(testBean, Y.class).size());
+        assertEquals(2, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.fooBarOrBaz = "onlyThis";
+        assertEquals(1, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(0, validator.validate(testBean, Y.class).size());
+        assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
+
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.groups()).thenReturn(Y.class).when(stub.value()).thenReturn("foo", "bar", "baz");
+                }
+            }));
+
+        testBean.fooBarOrBaz = "foo";
+        assertEquals(0, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(0, validator.validate(testBean, Y.class).size());
+        assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.fooBarOrBaz = "bar";
+        assertEquals(0, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(0, validator.validate(testBean, Y.class).size());
+        assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.fooBarOrBaz = "baz";
+        assertEquals(0, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(0, validator.validate(testBean, Y.class).size());
+        assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.fooBarOrBaz = "anythingButThis";
+        assertEquals(1, validator.validate(testBean).size());
+        assertEquals(1, validator.validate(testBean, X.class).size());
+        assertEquals(1, validator.validate(testBean, Y.class).size());
+        assertEquals(2, validator.validate(testBean, X.class, Y.class).size());
+        assertEquals(2, validator.validate(testBean, X.class, Y.class, Default.class).size());
+
+        assertEquals(2, validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("fooBarOrBaz")
+            .getConstraintDescriptors().size());
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.groups()).thenReturn(Y.class).when(stub.rule()).thenReturn(Rule.EXCLUDE)
+                        .when(stub.strategy()).thenReturn(Strategy.MERGE).when(stub.value())
+                        .thenReturn("foo", "bar", "baz");
+                }
+            }));
+
+        assertEquals(2, validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("fooBarOrBaz")
+            .getConstraintDescriptors().size());
+    }
+
+    @Test
+    public void testLabeledValuesConstraintAccumulationGrouping() {
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Labeled stub) {
+                    when(stub.groups()).thenReturn(X.class).when(stub.rule()).thenReturn(Rule.EXCLUDE)
+                        .when(stub.value()).thenReturn(item(ElementType.FIELD, ".")).when(stub.message())
+                        .thenReturn("anything but ('.'/FIELD) in group X");
+                }
+            }));
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Labeled stub) {
+                    when(stub.groups()).thenReturn(Y.class).when(stub.value())
+                        .thenReturn(item(ElementType.METHOD, "()")).when(stub.message())
+                        .thenReturn("only ('()'/METHOD) in group Y");
+                }
+            }));
+        testBean.annotationOrConstructor = ElementType.ANNOTATION_TYPE;
+        assertEquals(0, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(1, validator.validate(testBean, Y.class).size());
+        assertEquals(1, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.annotationOrConstructor = ElementType.FIELD;
+        assertEquals(1, validator.validate(testBean).size());
+        assertEquals(1, validator.validate(testBean, X.class).size());
+        assertEquals(1, validator.validate(testBean, Y.class).size());
+        assertEquals(2, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.annotationOrConstructor = ElementType.METHOD;
+        assertEquals(1, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(0, validator.validate(testBean, Y.class).size());
+        assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
+
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Labeled stub) {
+                    when(stub.groups()).thenReturn(Y.class).when(stub.value())
+                        .thenReturn(item(ElementType.ANNOTATION_TYPE, "@"), item(ElementType.CONSTRUCTOR, "new"));
+                }
+            }));
+
+        testBean.annotationOrConstructor = ElementType.ANNOTATION_TYPE;
+        assertEquals(0, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(0, validator.validate(testBean, Y.class).size());
+        assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.annotationOrConstructor = ElementType.CONSTRUCTOR;
+        assertEquals(0, validator.validate(testBean).size());
+        assertEquals(0, validator.validate(testBean, X.class).size());
+        assertEquals(0, validator.validate(testBean, Y.class).size());
+        assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
+
+        testBean.annotationOrConstructor = ElementType.FIELD;
+        assertEquals(1, validator.validate(testBean).size());
+        assertEquals(1, validator.validate(testBean, X.class).size());
+        assertEquals(1, validator.validate(testBean, Y.class).size());
+        assertEquals(2, validator.validate(testBean, X.class, Y.class).size());
+        assertEquals(2, validator.validate(testBean, X.class, Y.class, Default.class).size());
+
+        assertEquals(2,
+            validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("annotationOrConstructor")
+                .getConstraintDescriptors().size());
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Labeled stub) {
+                    when(stub.groups()).thenReturn(Y.class).when(stub.rule()).thenReturn(Rule.EXCLUDE)
+                        .when(stub.strategy()).thenReturn(Strategy.MERGE).when(stub.value())
+                        .thenReturn(item(ElementType.ANNOTATION_TYPE, "@"), item(ElementType.CONSTRUCTOR, "new"));
+                }
+            }));
+
+        assertEquals(2,
+            validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("annotationOrConstructor")
+                .getConstraintDescriptors().size());
+    }
+
+    @Test
+    public void testValuesConstraintAccumulationGroupingInheritance() {
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.groups()).thenReturn(Y.class).when(stub.value()).thenReturn("foo", "bar");
+                }
+            }));
+        assertEquals(2, validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("fooBarOrBaz")
+            .getConstraintDescriptors().size());
+        validatorContext.constrain(TestBean.class, "fooBarOrBaz",
+            annotationFactory.create(new StubConfigurer<Values>() {
+
+                @Override
+                protected void configure(Values stub) {
+                    when(stub.groups()).thenReturn(Z.class).when(stub.value()).thenReturn("foo", "bar", "baz");
+                }
+            }));
+        assertEquals(1, validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("fooBarOrBaz")
+            .getConstraintDescriptors().size());
+    }
+
+    @Test
+    public void testLabeledValuesConstraintAccumulationGroupingInheritance() {
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Labeled stub) {
+                    when(stub.groups()).thenReturn(Y.class).when(stub.value())
+                        .thenReturn(item(ElementType.ANNOTATION_TYPE, "@"));
+                }
+            }));
+        assertEquals(2,
+            validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("annotationOrConstructor")
+                .getConstraintDescriptors().size());
+        validatorContext.constrain(TestBean.class, "annotationOrConstructor",
+            annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+
+                @Override
+                protected void configure(Labeled stub) {
+                    when(stub.groups()).thenReturn(Z.class).when(stub.value())
+                        .thenReturn(item(ElementType.ANNOTATION_TYPE, "@"), item(ElementType.CONSTRUCTOR, "new"));
+                }
+            }));
+        assertEquals(1,
+            validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("annotationOrConstructor")
+                .getConstraintDescriptors().size());
+
+    }
+
+    public interface X {
+    }
+
+    public interface Y {
+    }
+
+    public interface Z extends X, Y {
+    }
+
+    private Values.Labeled.Item item(final ElementType elementType, final String label) {
+        return annotationFactory.create(new StubConfigurer<Values.Labeled.Item>() {
+
+            @Override
+            protected void configure(Item stub) {
+                when(stub.label()).thenReturn(label).when(stub.value()).thenReturn(elementType.name());
+            }
+        });
+
+    }
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.BeanDescriptorTest;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicBeanDescriptorTest extends BeanDescriptorTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCircularReferencesTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCircularReferencesTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCircularReferencesTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCircularReferencesTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.CircularReferencesTest;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicCircularReferencesTest extends CircularReferencesTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCircularReferencesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCircularReferencesTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCollectionValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCollectionValidationTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCollectionValidationTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCollectionValidationTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,150 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.ArrayList;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.constraints.Pattern;
+
+import org.apache.bval.constraints.AuthorAddressKnown;
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+import org.apache.bval.jsr303.example.Address;
+import org.apache.bval.jsr303.example.Author;
+import org.apache.bval.jsr303.example.Book;
+import org.apache.bval.jsr303.example.Country;
+import org.apache.bval.jsr303.example.Library;
+import org.apache.bval.jsr303.groups.CollectionValidationTest;
+import org.apache.bval.jsr303.util.TestUtils;
+import org.apache.commons.proxy2.stub.AnnotationFactory;
+import org.apache.commons.proxy2.stub.StubConfigurer;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicCollectionValidationTest extends CollectionValidationTest {
+
+    private final AnnotationFactory annotationFactory = new AnnotationFactory();
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+    public void testDynamicDeeplyNestedJunk() {
+        Library lib = new Library();
+        lib.setLibraryName("Leibnitz Bibliothek");
+
+        Book book1, book2, book3;
+
+        book1 = new Book();
+        book1.setTitle("History of time");
+        book1.setSubtitle("How it really works");
+        Author hawking = new Author();
+        hawking.setFirstName("Stephen");
+        hawking.setFirstName("Hawking");
+        hawking.setAddresses(new ArrayList<Address>(1));
+        Address adr = new Address();
+        adr.setAddressline1("Street 1");
+        adr.setCity("London");
+        adr.setCountry(new Country());
+        adr.getCountry().setName("England");
+        hawking.getAddresses().add(adr);
+        book1.setAuthor(hawking);
+
+        book2 = new Book();
+        Author castro = new Author();
+        castro.setFirstName("Fidel");
+        castro.setLastName("Castro Ruz");
+        book2.setAuthor(castro);
+        book2.setTitle("My life");
+
+        book3 = new Book();
+        book3.setTitle("How To Make Friends And Influence People");
+        Author blag = new Author();
+        blag.setFirstName("Blag");
+        blag.setLastName("Dahlia");
+        book3.setAuthor(blag);
+
+        lib.getTaggedBooks().put("science", book1);
+        lib.getTaggedBooks().put("politics", book2);
+        lib.getTaggedBooks().put("self-help", book3);
+
+        Set<ConstraintViolation<Library>> violations;
+
+        violations = validator.validate(lib);
+        assertTrue(violations.isEmpty());
+
+        validatorContext.constrain(Library.class, "taggedBooks[*].author", annotationFactory
+            .create(AuthorAddressKnown.class));
+
+        violations = validator.validate(lib);
+        assertEquals(2, violations.size());
+        assertNotNull(TestUtils.getViolation(violations, "taggedBooks[politics].author"));
+        assertNotNull(TestUtils.getViolation(violations, "taggedBooks[self-help].author"));
+
+        // yet show that the books themselves validate fine when not validated
+        // in the context of their containing library:
+        assertTrue(validator.validate(book2).isEmpty());
+        assertTrue(validator.validate(book3).isEmpty());
+
+        // mix different constraint levels, plus wildcard key at one level,
+        // explicit index at another:
+        validatorContext.constrain(Book.class, "author.addresses[0].addressline1", annotationFactory
+            .create(new StubConfigurer<Pattern>() {
+                /**
+                 * {@inheritDoc}
+                 */
+                @Override
+                protected void configure(Pattern stub) {
+                    when(stub.regexp()).thenReturn("[0..9]+.*");
+                }
+            }));
+
+        violations = validator.validate(lib);
+        assertEquals(3, violations.size());
+        assertNotNull(TestUtils.getViolation(violations, "taggedBooks[science].author.addresses[0].addressline1"));
+    }
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCollectionValidationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicCollectionValidationTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicComposedConstraintsTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicComposedConstraintsTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicComposedConstraintsTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicComposedConstraintsTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.ComposedConstraintsTest;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicComposedConstraintsTest extends ComposedConstraintsTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicComposedConstraintsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicComposedConstraintsTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintCompositionTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintCompositionTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintCompositionTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintCompositionTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.ConstraintCompositionTest;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicConstraintCompositionTest extends ConstraintCompositionTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintCompositionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintCompositionTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintDefinitionsTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintDefinitionsTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintDefinitionsTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintDefinitionsTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.ConstraintDefinitionsTest;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicConstraintDefinitionsTest extends ConstraintDefinitionsTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintDefinitionsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicConstraintDefinitionsTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicExceptionsContractTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicExceptionsContractTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicExceptionsContractTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicExceptionsContractTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.ExceptionsContractTest;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicExceptionsContractTest extends ExceptionsContractTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicExceptionsContractTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicExceptionsContractTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicJsr303Test.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicJsr303Test.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicJsr303Test.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicJsr303Test.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.Jsr303Test;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicJsr303Test extends Jsr303Test {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicJsr303Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicJsr303Test.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicPayloadTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicPayloadTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicPayloadTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicPayloadTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.PayloadTest;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicPayloadTest extends PayloadTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicPayloadTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicPayloadTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicTckReproducerTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicTckReproducerTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicTckReproducerTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicTckReproducerTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.TckReproducerTest;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicTckReproducerTest extends TckReproducerTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicTckReproducerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicTckReproducerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidationTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidationTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidationTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,262 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Valid;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
+
+import junit.framework.Assert;
+
+import org.apache.bval.constraints.ZipCodeCityCoherence;
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.ValidationTest;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+import org.apache.bval.jsr303.example.Address;
+import org.apache.bval.jsr303.example.Author;
+import org.apache.bval.jsr303.example.Book;
+import org.apache.bval.jsr303.example.Country;
+import org.apache.bval.jsr303.example.First;
+import org.apache.bval.jsr303.example.ZipCodeCityCarrier;
+import org.apache.bval.jsr303.util.TestUtils;
+import org.apache.commons.proxy2.stub.AnnotationFactory;
+import org.apache.commons.proxy2.stub.StubConfigurer;
+
+/**
+ * Test dynamic bean validation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicValidationTest extends ValidationTest {
+
+    private final AnnotationFactory annotationFactory = new AnnotationFactory();
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+    public void testSimpleDynamic() {
+        Author author = new Author();
+        author.setLastName("Baudelaire");
+        author.setFirstName("Chuck");
+        Book book = new Book();
+        book.setAuthor(author);
+        book.setTitle("foo");
+        Set<ConstraintViolation<Book>> errors = validator.validate(book, Book.All.class);
+        assertTrue(errors.isEmpty());
+
+        validatorContext.constrain(Book.class, "title", annotationFactory.create(new StubConfigurer<Pattern>() {
+            /**
+             * {@inheritDoc}
+             */
+            @Override
+            protected void configure(Pattern stub) {
+                when(stub.regexp()).thenReturn("[A-Za-z]*").when(stub.groups()).thenReturn(First.class);
+            }
+        }));
+
+        errors = validator.validate(book, Book.All.class);
+        assertTrue(errors.isEmpty());
+
+        book.setTitle("1001 ways to whatever");
+        errors = validator.validate(book, Book.All.class);
+        assertEquals(1, errors.size());
+        ConstraintViolation<Book> vio = errors.iterator().next();
+        assertEquals(Pattern.class, vio.getConstraintDescriptor().getAnnotation().annotationType());
+    }
+
+    public void testNestedDynamicIndexed() {
+        Author author = new Author();
+        author.setLastName("Baudelaire");
+        author.setFirstName("Chuck");
+        author.setAddresses(new ArrayList<Address>());
+        Country ham = new Country();
+        ham.setName("ham");
+        Address address0 = new Address();
+        address0.setCity("mouse");
+        address0.setCountry(ham);
+        address0.setAddressline1("100 some street");
+        Address address1 = new Address();
+        address1.setCity("mouse");
+        address1.setCountry(ham);
+        address1.setAddressline1("200 some other street");
+        author.getAddresses().add(address0);
+        author.getAddresses().add(address1);
+
+        Set<ConstraintViolation<Author>> errors = validator.validate(author);
+        assertTrue(errors.isEmpty());
+
+        validatorContext.constrain(Author.class, "addresses[*].addressline2", annotationFactory
+            .create(new StubConfigurer<Pattern>() {
+                /**
+                 * {@inheritDoc}
+                 */
+                @Override
+                protected void configure(Pattern stub) {
+                    when(stub.regexp()).thenReturn("[0..9]+.*");
+                }
+            }));
+
+        errors = validator.validate(author);
+        assertTrue(errors.isEmpty());
+
+        address1.setAddressline2("oops forgot the street number");
+
+        errors = validator.validate(author);
+        assertEquals(1, errors.size());
+
+        validatorContext.constrain(Author.class, "addresses[0].addressline2", annotationFactory.create(NotNull.class));
+
+        errors = validator.validate(author);
+        assertEquals(2, errors.size());
+    }
+
+    public void testDynamicMetadata() {
+        BeanDescriptor authorDescriptor = validator.getConstraintsForClass(Author.class);
+        PropertyDescriptor propertyDescriptor = authorDescriptor.getConstraintsForProperty("addresses[0].addressline2");
+        assertNotNull(propertyDescriptor);
+        assertEquals(String.class, propertyDescriptor.getElementClass());
+
+        for (ConstraintDescriptor<?> desc : propertyDescriptor.getConstraintDescriptors()) {
+            assertFalse(Pattern.class.equals(desc.getAnnotation().annotationType()));
+        }
+
+        validatorContext.constrain(Author.class, "addresses[*].addressline2", annotationFactory
+            .create(new StubConfigurer<Pattern>() {
+                /**
+                 * {@inheritDoc}
+                 */
+                @Override
+                protected void configure(Pattern stub) {
+                    when(stub.regexp()).thenReturn("[0..9]+.*");
+                }
+            }));
+
+        for (ConstraintDescriptor<?> desc : propertyDescriptor.getConstraintDescriptors()) {
+            assertFalse(Pattern.class.equals(desc.getAnnotation().annotationType()));
+        }
+
+        propertyDescriptor =
+            validator.getConstraintsForClass(Author.class).getConstraintsForProperty("addresses[0].addressline2");
+        assertNotNull(propertyDescriptor);
+        Iterator<ConstraintDescriptor<?>> iter = propertyDescriptor.getConstraintDescriptors().iterator();
+        ConstraintDescriptor<?> constraintDescriptor = null;
+        while (iter.hasNext()) {
+            constraintDescriptor = iter.next();
+            if (constraintDescriptor.getAnnotation().annotationType().equals(Pattern.class)) {
+                break;
+            }
+        }
+        Assert.assertTrue(constraintDescriptor != null);
+    }
+
+    public void testClearDynamicConstraints() {
+        // use this to setup:
+        testDynamicMetadata();
+        validatorContext.clearDynamicConstraints();
+        PropertyDescriptor propertyDescriptor =
+            validator.getConstraintsForClass(Author.class).getConstraintsForProperty("addresses[0].addressline2");
+        assertNotNull(propertyDescriptor);
+        for (ConstraintDescriptor<?> desc : propertyDescriptor.getConstraintDescriptors()) {
+            assertFalse(Pattern.class.equals(desc.getAnnotation().annotationType()));
+        }
+    }
+
+    public void testClassLevelDynamicConstraints() throws Exception {
+        ZipCodeCityCarrierHolder carrierHolder = new ZipCodeCityCarrierHolder(new BogusZipCodeCityCarrier());
+        assertTrue(validator.validate(carrierHolder).isEmpty());
+        assertTrue(validator.validate(carrierHolder.getCarrier()).isEmpty());
+
+        validatorContext.constrain(ZipCodeCityCarrier.class, annotationFactory.create(ZipCodeCityCoherence.class));
+        Set<ConstraintViolation<ZipCodeCityCarrierHolder>> holderErrors = validator.validate(carrierHolder);
+        assertEquals(2, holderErrors.size());
+        assertNotNull(TestUtils.getViolation(holderErrors, "carrier"));
+        assertNotNull(TestUtils.getViolation(holderErrors, "carrier.city"));
+        Set<ConstraintViolation<ZipCodeCityCarrier>> carrierErrors = validator.validate(carrierHolder.getCarrier());
+        assertEquals(2, carrierErrors.size());
+        assertNotNull(TestUtils.getViolation(carrierErrors, ""));
+        assertNotNull(TestUtils.getViolation(carrierErrors, "city"));
+    }
+
+    public static class BogusZipCodeCityCarrier implements ZipCodeCityCarrier {
+
+        /**
+         * {@inheritDoc}
+         */
+        public String getCity() {
+            return "error";
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public String getZipCode() {
+            return "error";
+        }
+    }
+
+    public static class ZipCodeCityCarrierHolder {
+        @Valid
+        private ZipCodeCityCarrier carrier;
+
+        public ZipCodeCityCarrierHolder(ZipCodeCityCarrier carrier) {
+            super();
+            this.carrier = carrier;
+        }
+
+        /**
+         * @return the carrier
+         */
+        public ZipCodeCityCarrier getCarrier() {
+            return carrier;
+        }
+
+    }
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidationTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidatorResolutionTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidatorResolutionTest.java?rev=999729&view=auto
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidatorResolutionTest.java (added)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidatorResolutionTest.java Wed Sep 22 02:37:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.bval.jsr303.dynamic;
+
+import java.util.Locale;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.ApacheValidatorConfiguration;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.ValidatorResolutionTest;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class DynamicValidatorResolutionTest extends ValidatorResolutionTest {
+
+    private DynamicValidatorContext validatorContext;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setUp() throws Exception {
+        DynamicValidatorFactory factory =
+            Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
+                ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+                DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+        ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+        validatorContext = factory.usingContext();
+        super.setUp();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Validator createValidator() {
+        return validatorContext.getValidator();
+    }
+
+}

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidatorResolutionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/bval/jsr303/dynamic/DynamicValidatorResolutionTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message