[hibernate-commits] Hibernate SVN: r17640 - in beanvalidation/tck/trunk/src/main: resources and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Wed Oct 7 04:36:02 EDT 2009
Author: hardy.ferentschik
Date: 2009-10-07 04:36:01 -0400 (Wed, 07 Oct 2009)
New Revision: 17640
Added:
beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java
beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SubClass.java
beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperClass.java
beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperConstraint.java
beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperConstraintValidator.java
Modified:
beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
beanvalidation/tck/trunk/src/main/resources/tck-audit.xml
Log:
TCK updates adding spec assertions for new ElementDescriptor API
Copied: beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java (from rev 17620, beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java)
===================================================================
--- beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java (rev 0)
+++ beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java 2009-10-07 08:36:01 UTC (rev 17640)
@@ -0,0 +1,172 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed 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.hibernate.jsr303.tck.tests.metadata;
+
+import java.lang.annotation.ElementType;
+import java.util.Set;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+import javax.validation.metadata.Scope;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.getPropertyDescriptor;
+import static org.hibernate.jsr303.tck.util.TestUtil.getValidatorUnderTest;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+public class ElementDescriptorTest extends AbstractTest {
+
+ @Test
+ @SpecAssertion(section = "5.2", id = "a")
+ public void testGetElementClass() {
+ Validator validator = getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SuperClass.class );
+ assertEquals( beanDescriptor.getElementClass(), SuperClass.class, "Wrong element class" );
+
+ ElementDescriptor elementDescriptor = beanDescriptor.getConstraintsForProperty( "myField" );
+ assertEquals( elementDescriptor.getElementClass(), String.class, "Wrong element class" );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.2", id = "b")
+ public void testGetConstraintDescriptors() {
+ ElementDescriptor descriptor = getPropertyDescriptor( SubClass.class, "myField" );
+ assertEquals( descriptor.getConstraintDescriptors().size(), 2, "There should be two constraints on myField" );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.2", id = "c")
+ public void testHasConstraints() {
+ ElementDescriptor descriptor = getPropertyDescriptor( SubClass.class, "myField" );
+ assertTrue( descriptor.hasConstraints() );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.2", id = "d")
+ public void testUnorderedAndMatchingGroups() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class );
+ assertNotNull( beanDescriptor );
+
+ Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .unorderedAndMatchingGroups( Default.class, SuperClass.BasicGroup.class )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 2 );
+
+ descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .unorderedAndMatchingGroups( SuperClass.UnusedGroup.class )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 0 );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.2", id = "d")
+ public void testUnorderedAndMatchingGroupsWithInheritance() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class );
+ assertNotNull( beanDescriptor );
+
+ Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .unorderedAndMatchingGroups( SuperClass.InheritedGroup.class )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 1 );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.2", id = "d")
+ public void testUnorderedAndMatchingGroupsWithDefaultGroupOverriding() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class );
+ assertNotNull( beanDescriptor );
+
+ Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .unorderedAndMatchingGroups( Default.class )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 1 );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.2", id = "e")
+ public void testDeclaredOn() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class );
+ assertNotNull( beanDescriptor );
+
+ Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .lookingAt( Scope.HIERARCHY )
+ .declaredOn( ElementType.TYPE )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 0 );
+
+ descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .lookingAt( Scope.HIERARCHY )
+ .declaredOn( ElementType.METHOD )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 0 );
+
+ descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .lookingAt( Scope.HIERARCHY )
+ .declaredOn( ElementType.FIELD )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 2 );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.2", id = "f")
+ public void testLookingAt() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( SubClass.class );
+ assertNotNull( beanDescriptor );
+
+ Set<ConstraintDescriptor<?>> descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .lookingAt( Scope.HIERARCHY )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 2 );
+
+ descriptors = beanDescriptor.getConstraintsForProperty( "myField" )
+ .findConstraints()
+ .lookingAt( Scope.LOCAL_ELEMENT )
+ .getConstraintDescriptors();
+ assertTrue( descriptors.size() == 1 );
+ }
+}
\ No newline at end of file
Modified: beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
===================================================================
--- beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-10-07 08:34:52 UTC (rev 17639)
+++ beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-10-07 08:36:01 UTC (rev 17640)
@@ -19,11 +19,11 @@
import javax.validation.metadata.PropertyDescriptor;
+import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
-import org.jboss.test.audit.annotations.SpecAssertion;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@@ -37,8 +37,9 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
- at Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
+ at Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class PropertyDescriptorTest extends AbstractTest {
+
@Test
@SpecAssertion(section = "5.4", id = "a")
public void testIsNotCascaded() {
Copied: beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SubClass.java (from rev 17620, beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/visibility/SubClass.java)
===================================================================
--- beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SubClass.java (rev 0)
+++ beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SubClass.java 2009-10-07 08:36:01 UTC (rev 17640)
@@ -0,0 +1,36 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed 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.hibernate.jsr303.tck.tests.metadata;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.Max;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at GroupSequence({ SubClass.class, SubClass.DefaultGroup.class })
+public class SubClass extends SuperClass {
+ @Max(value = 10, groups = SubClass.DefaultGroup.class)
+ private String myField = "1234567890";
+
+ public String yourField = "";
+
+ public interface DefaultGroup {
+ }
+}
Property changes on: beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SubClass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperClass.java (from rev 17620, beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/visibility/SuperClass.java)
===================================================================
--- beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperClass.java (rev 0)
+++ beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperClass.java 2009-10-07 08:36:01 UTC (rev 17640)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed 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.hibernate.jsr303.tck.tests.metadata;
+
+import javax.validation.constraints.NotNull;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at SuperConstraint
+public class SuperClass {
+ @NotNull(groups = BasicGroup.class)
+ private String myField = "12345678901234567890";
+
+ public String getMyField() {
+ return myField;
+ }
+
+ interface UnusedGroup {
+ }
+
+ interface BasicGroup {
+ }
+
+ interface InheritedGroup extends BasicGroup {
+ }
+}
Property changes on: beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperClass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperConstraint.java (from rev 17620, beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java)
===================================================================
--- beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperConstraint.java (rev 0)
+++ beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperConstraint.java 2009-10-07 08:36:01 UTC (rev 17640)
@@ -0,0 +1,45 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed 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.hibernate.jsr303.tck.tests.metadata;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.OverridesAttribute;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Documented
+ at Constraint(validatedBy = { })
+ at Target({ TYPE })
+ at Retention(RUNTIME)
+public @interface SuperConstraint {
+ public abstract String message() default "";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default { };
+}
\ No newline at end of file
Added: beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperConstraintValidator.java
===================================================================
--- beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperConstraintValidator.java (rev 0)
+++ beanvalidation/tck/trunk/src/main/java/org/hibernate/jsr303/tck/tests/metadata/SuperConstraintValidator.java 2009-10-07 08:36:01 UTC (rev 17640)
@@ -0,0 +1,36 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed 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.hibernate.jsr303.tck.tests.metadata;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SuperConstraintValidator implements ConstraintValidator<SuperConstraint, SuperClass> {
+
+ public void initialize(SuperConstraint constraintAnnotation) {
+ }
+
+ public boolean isValid(SuperClass value, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+}
+
+
Modified: beanvalidation/tck/trunk/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/tck/trunk/src/main/resources/tck-audit.xml 2009-10-07 08:34:52 UTC (rev 17639)
+++ beanvalidation/tck/trunk/src/main/resources/tck-audit.xml 2009-10-07 08:36:01 UTC (rev 17640)
@@ -661,6 +661,12 @@
<text>For a class level constraint a Node object is added to Path whose name is null
</text>
</assertion>
+ <assertion id="n" testable="false">
+ <text>Bean Validation implementations should ensure that a ConstraintViolation
+ implementation is Serializable provided that the root bean, the leaf bean, the
+ invalid value and keys in the Path object are Serializable objects. </text>
+ </assertion>
+
</section>
<section id="4.3.1" title="Default message interpolation">
<assertion id="a">
@@ -945,6 +951,37 @@
parameter is null</text>
</assertion>
</section>
+ <section id="5.2" title="PropertyDescriptor">
+ <assertion id="a">
+ <text>getElementClass returns either the object type for a class, or the returned type
+ for a property</text>
+ </assertion>
+ <assertion id="b">
+ <text>getConstraintDescriptors returns all the ConstraintDescriptors hosted on the given
+ element in the class hierarchy, each ConstraintDescriptor describing one of the
+ constraints declared on the given element.</text>
+ </assertion>
+ <assertion id="c">
+ <text>hasConstraints returns true if the given element (class, field or property) in the
+ class hierarchy holds at least one constraint declaration.</text>
+ </assertion>
+ <assertion id="d">
+ <text>unorderedAndMatchingGroups restricts to the ConstraintDescriptors matching the set
+ of groups passed as parameters and present on the element. Order is not respected
+ but group inheritance and inheritance via sequence (including the Default group
+ overriding at the class level) are honored.</text>
+ </assertion>
+ <assertion id="e">
+ <text>declaredOn lets you restrict the list of element types constraints are hosted
+ on.</text>
+ </assertion>
+ <assertion id="f">
+ <text>lookingAt lets you restrict which constraints are considered. Either constraints
+ belonging to the element but hosted on the class represented by BeanDescritptor
+ (Scope.LOCAL_ELEMENT), or constraints belonging to the element but hosted anywhere
+ in the class hierarchy (Scope.HIERARCHY).</text>
+ </assertion>
+ </section>
<section id="5.3" title="BeanDescriptor">
<assertion id="a">
<text>isBeanConstrained returns true if the given class (and superclasses and
More information about the hibernate-commits
mailing list