Repository: bval Updated Branches: refs/heads/bv2 f1e8de164 -> 92c64b3ce
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/xml/MetaConstraint.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/MetaConstraint.java b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/MetaConstraint.java deleted file mode 100644 index 1826a55..0000000 --- a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/MetaConstraint.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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.jsr.xml; - -import org.apache.bval.ConstructorAccess; -import org.apache.bval.util.AccessStrategy; -import org.apache.bval.util.FieldAccess; -import org.apache.bval.util.MethodAccess; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; - -/** - * Description: hold parsed information from xml to complete MetaBean later<br/> - */ -//TODO move this guy up to org.apache.bval.jsr or org.apache.bval.jsr.model -//to decouple ApacheValidatorFactory from xml package and allow others to consume MetaConstraint -public class MetaConstraint<T, A extends Annotation> { - - /** The member the constraint was defined on. */ - private final Member member; - - /** The class of the bean hosting this constraint. */ - private final Class<T> beanClass; - - /** constraint annotation (proxy) */ - private final A annotation; - - private Integer index; // for parameters - - private final AccessStrategy accessStrategy; - - /** - * Create a new MetaConstraint instance. - * @param beanClass The class in which the constraint is defined on - * @param member The member on which the constraint is defined on, {@code null} if it is a class constraint} - * @param annotation - */ - public MetaConstraint(Class<T> beanClass, Member member, A annotation) { - this.member = member; - this.beanClass = beanClass; - this.annotation = annotation; - if (member != null) { - accessStrategy = createAccessStrategy(member); - /*TODO: see if can really be removed - if (accessStrategy == null || accessStrategy.getPropertyName() == null) { // can happen if method does not follow the bean convention - throw new ValidationException("Annotated method does not follow the JavaBeans naming convention: " + member); - } - */ - } else { - this.accessStrategy = null; - } - } - - private static AccessStrategy createAccessStrategy(Member member) { - if (member instanceof Method) { - return new MethodAccess((Method) member); - } else if (member instanceof Field) { - return new FieldAccess((Field) member); - } else if (member instanceof Constructor<?>) { - return new ConstructorAccess((Constructor<?>) member); - } else { - return null; // class level - } - } - - /** - * Get the bean class of this constraint. - * @return Class - */ - public Class<T> getBeanClass() { - return beanClass; - } - - /** - * Get the member to which this constraint applies. - * @return Member - */ - public Member getMember() { - return member; - } - - /** - * Get the annotation that defines this constraint. - * @return Annotation - */ - public A getAnnotation() { - return annotation; - } - - /** - * Get the access strategy used for the associated property. - * @return {@link AccessStrategy} - */ - public AccessStrategy getAccessStrategy() { - return accessStrategy; - } - - public Integer getIndex() { - return index; - } - - public void setIndex(final int index) { - this.index = index; - } -} http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/xml/SchemaManager.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/SchemaManager.java b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/SchemaManager.java index a502b7e..5a79b63 100644 --- a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/SchemaManager.java +++ b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/SchemaManager.java @@ -276,7 +276,6 @@ public class SchemaManager { schemaRewriter.setContentHandler(unmarshallerHandler); xmlReader.parse(input); - schemaValidator.validate(); @SuppressWarnings("unchecked") http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/test/java/org/apache/bval/jsr/ConstraintValidatorContextTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/ConstraintValidatorContextTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/ConstraintValidatorContextTest.java deleted file mode 100644 index 5aa1de9..0000000 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/ConstraintValidatorContextTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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.jsr; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import javax.validation.ConstraintValidatorContext; -import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder; - -import org.apache.bval.jsr.util.PathImpl; -import org.apache.bval.model.ValidationListener; -import org.apache.bval.model.ValidationListener.Error; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; - -/** - * Checks to validate the correct implementation of - * {@link ConstraintValidatorContext} and its sub-interfaces. - * - * @author Carlos Vara - */ -@RunWith(MockitoJUnitRunner.class) -public class ConstraintValidatorContextTest { - - private ConstraintValidatorContextImpl cvc; - private ConstraintViolationBuilder cvb; - - @Mock - private GroupValidationContext<ValidationListener> groupValidationContext; - - /** - * {@inheritDoc} - */ - @Before - public void setUp() throws Exception { - Mockito.when(groupValidationContext.getPropertyPath()).thenAnswer(new Answer<PathImpl>() { - - @Override - public PathImpl answer(InvocationOnMock invocation) throws Throwable { - return PathImpl.createPathFromString(""); - } - }); - this.cvc = new ConstraintValidatorContextImpl(groupValidationContext, null); - this.cvc.disableDefaultConstraintViolation(); - this.cvb = cvc.buildConstraintViolationWithTemplate("dummy.msg.tpl"); - } - - @Test - public void testPerson1() { - cvb.addNode("person").addNode(null).inIterable().atIndex(1).addConstraintViolation(); - final Error error = cvc.getErrorMessages().iterator().next(); - final PathImpl errorPath = (PathImpl) error.getOwner(); - assertEquals("Incorrect path created", "person[1]", errorPath.toString()); - } - - @Test - public void testPersonLawyerName() { - cvb.addNode("person").addNode("name").inIterable().atKey("john").addConstraintViolation(); - Error error = cvc.getErrorMessages().iterator().next(); - PathImpl errorPath = (PathImpl) error.getOwner(); - assertEquals("Incorrect path created", "person[john].name", errorPath.toString()); - } - - @Test - public void test0Name() { - cvb.addNode(null).addNode("name").inIterable().atIndex(0).addNode(null).inIterable().addConstraintViolation(); - Error error = cvc.getErrorMessages().iterator().next(); - PathImpl errorPath = (PathImpl) error.getOwner(); - assertEquals("Incorrect path created", "[0].name[]", errorPath.toString()); - } - - @Test - public void testEmptyIndex() { - cvb.addNode(null).addNode(null).inIterable().addConstraintViolation(); - Error error = cvc.getErrorMessages().iterator().next(); - PathImpl errorPath = (PathImpl) error.getOwner(); - assertEquals("Incorrect path created", "[]", errorPath.toString()); - } - - @Test - public void testRootPath() { - // Adding only nulls should still give a root path - cvb.addNode(null).addNode(null).addNode(null).addNode(null).addConstraintViolation(); - Error error = cvc.getErrorMessages().iterator().next(); - PathImpl errorPath = (PathImpl) error.getOwner(); - assertTrue("Created path must be a root path", errorPath.isRootPath()); - } - -} http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java index d5cf4f2..d6651b3 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java @@ -20,8 +20,10 @@ package org.apache.bval.jsr.groups; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; -import java.util.List; +import java.util.Arrays; +import java.util.Collections; import java.util.Set; import javax.validation.ConstraintViolation; @@ -29,15 +31,14 @@ import javax.validation.GroupSequence; import javax.validation.constraints.NotNull; import org.apache.bval.jsr.ApacheValidatorFactory; -import org.apache.bval.jsr.JsrFeatures; import org.apache.bval.jsr.ValidationTestBase; +import org.apache.bval.jsr.descriptor.BeanD; import org.apache.bval.jsr.example.Author; import org.apache.bval.jsr.example.Book; import org.apache.bval.jsr.example.First; import org.apache.bval.jsr.example.Last; import org.apache.bval.jsr.example.Second; import org.apache.bval.jsr.util.TestUtils; -import org.apache.bval.model.MetaBean; import org.junit.Test; /** @@ -47,44 +48,34 @@ public class GroupSequenceTest extends ValidationTestBase { @Test public void testGroupSequence1() { - MetaBean metaBean = - ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder().findForClass(GInterface1.class); - List<Group> gseq = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE); - assertNotNull(gseq); - assertEquals(1, gseq.size()); - assertEquals(Group.DEFAULT, gseq.get(0)); + BeanD bean = (BeanD) ApacheValidatorFactory.getDefault().usingContext().getValidator() + .getConstraintsForClass(GInterface1.class); + + assertEquals(Collections.singletonList(GInterface1.class), bean.getGroupSequence()); } @Test public void testGroupSequence2() { - MetaBean metaBean = - ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder().findForClass(GClass1.class); - List<Group> gseq = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE); - assertNotNull(gseq); - assertEquals(1, gseq.size()); - assertEquals(Group.DEFAULT, gseq.get(0)); + BeanD bean = (BeanD) ApacheValidatorFactory.getDefault().usingContext().getValidator() + .getConstraintsForClass(GClass1.class); + + assertNull(bean.getGroupSequence()); } @Test public void testGroupSequence3() { - MetaBean metaBean = - ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder().findForClass(GClass2.class); - List<Group> gseq = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE); - assertNotNull(gseq); - assertEquals(2, gseq.size()); - assertEquals(new Group(GClass1.class), gseq.get(0)); - assertEquals(Group.DEFAULT, gseq.get(1)); + BeanD bean = (BeanD) ApacheValidatorFactory.getDefault().usingContext().getValidator() + .getConstraintsForClass(GClass2.class); + + assertEquals(Arrays.asList(GClass1.class, GClass2.class), bean.getGroupSequence()); } @Test public void testGroupSequence4() { - MetaBean metaBean = - ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder().findForClass(GClass3.class); - List<Group> gseq = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE); - assertNotNull(gseq); - assertEquals(2, gseq.size()); - assertEquals(Group.DEFAULT, gseq.get(0)); - assertEquals(new Group(GClass1.class), gseq.get(1)); + BeanD bean = (BeanD) ApacheValidatorFactory.getDefault().usingContext().getValidator() + .getConstraintsForClass(GClass3.class); + + assertEquals(Arrays.asList(GClass3.class, GClass1.class), bean.getGroupSequence()); } @Test http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/test/java/org/apache/bval/jsr/util/EnumerationConverterTestCase.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/util/EnumerationConverterTestCase.java b/bval-jsr/src/test/java/org/apache/bval/jsr/util/EnumerationConverterTestCase.java deleted file mode 100644 index 4f15606..0000000 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/util/EnumerationConverterTestCase.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.jsr.util; - -import static org.junit.Assert.assertEquals; - -import org.apache.commons.beanutils.Converter; -import org.junit.Test; - -/** - * EnumerationConverter tester. - * - * $Id: EnumerationConverterTestCase.java 1161648 2011-08-25 17:14:15Z - * romanstumm $ - */ -public final class EnumerationConverterTestCase { - - @Test - public void testEnum() { - Converter converter = EnumerationConverter.getInstance(); - - Thread.State expected = Thread.State.TERMINATED; - Thread.State actual = (Thread.State) converter.convert(Thread.State.class, Thread.State.TERMINATED.name()); - assertEquals(expected, actual); - } - -} http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-tck/work-tests-suite.xml ---------------------------------------------------------------------- diff --git a/bval-tck/work-tests-suite.xml b/bval-tck/work-tests-suite.xml index 3bb8b11..8bc248c 100644 --- a/bval-tck/work-tests-suite.xml +++ b/bval-tck/work-tests-suite.xml @@ -21,7 +21,8 @@ think to add -Dvalidation.provider=org.apache.bval.jsr.ApacheValidationProvider <suite name="tmp" verbose="1"> <test name="tmp"> <classes> - <class name="org.hibernate.beanvalidation.tck.tests.xmlconfiguration.groupconversion.containerelement.XmlBasedContainerElementGroupConversionValidationTest"/> +<!-- <class name="org.hibernate.beanvalidation.tck.tests.xmlconfiguration.groupconversion.containerelement.XmlBasedContainerElementGroupConversionValidationTest"/> --> + <class name="org.hibernate.beanvalidation.tck.tests.validation.CustomPropertyPathTest"/> <!-- <class name="org.hibernate.beanvalidation.tck.tests.util.ConstraintViolationAssertTest"/> -->
