Author: hardy.ferentschik
Date: 2009-08-24 07:48:21 -0400 (Mon, 24 Aug 2009)
New Revision: 17399
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/CreditCard.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/FieldLevelOverridingTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/User.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/WrongFieldNameTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/CreditCard.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/PropertyLevelOverridingTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/User.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/WrongPropertyNameTest.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-FieldLevelOverridingTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-WrongFieldNameTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/validation-FieldLevelOverridingTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/validation-WrongFieldNameTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-PropertyLevelOverridingTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-WrongPropertyNameTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/validation-PropertyLevelOverridingTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/validation-WrongPropertyNameTest.xml
Modified:
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
field/property xml configuration tests
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/CreditCard.java
(from rev 17378,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CreditCard.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/CreditCard.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/CreditCard.java 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,36 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.xmlconfiguration.constraintdeclaration.fieldlevel;
+
+import javax.validation.constraints.Pattern;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CreditCard {
+ @Pattern(regexp = "[0-9]*")
+ private String number;
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+}
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/FieldLevelOverridingTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/FieldLevelOverridingTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/FieldLevelOverridingTest.java 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,119 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.xmlconfiguration.constraintdeclaration.fieldlevel;
+
+import java.util.Set;
+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 org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+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.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+@ValidationXml(value = "validation-FieldLevelOverridingTest.xml")
+@Resource(source = "user-constraints-FieldLevelOverridingTest.xml",
+ destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-FieldLevelOverridingTest.xml")
+public class FieldLevelOverridingTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "7.1.1.2", id = "a"),
+ @SpecAssertion(section = "7.1.1.2", id = "c")
+ })
+ public void testIgnoreAnnotations() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
+ assertNotNull( beanDescriptor );
+
+ PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty(
"firstname" );
+ assertNull( propDescriptor, "The annotation defined constraints should be
ignored." );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "7.1.1.2", id = "a"),
+ @SpecAssertion(section = "7.1.1.2", id = "d")
+ })
+ public void testIncludeAnnotations() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
+ assertNotNull( beanDescriptor );
+
+ PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty(
"lastname" );
+ assertNotNull( propDescriptor );
+
+ Set<ConstraintDescriptor<?>> constraintDescriptors =
propDescriptor.getConstraintDescriptors();
+ assertEquals( constraintDescriptors.size(), 2, "There should be two
constraints" );
+
+ boolean foundNotNullConstraint = false;
+ boolean foundPatternConstraint = false;
+ for ( ConstraintDescriptor<?> descriptor : constraintDescriptors ) {
+ if ( descriptor.getAnnotation() instanceof NotNull ) {
+ foundNotNullConstraint = true;
+ }
+ else if ( descriptor.getAnnotation() instanceof Pattern ) {
+ foundPatternConstraint = true;
+ }
+ else {
+ fail( "Invalid constraint for property." );
+ }
+ }
+ if ( !( foundNotNullConstraint && foundPatternConstraint ) ) {
+ fail( "Not all configured constraints discovered." );
+ }
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "7.1.1.2", id = "e")
+ })
+ public void testCascadedConfiguration() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
+ assertNotNull( beanDescriptor );
+
+ PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty(
"firstCreditCard" );
+ assertNotNull( propDescriptor );
+ assertTrue( propDescriptor.isCascaded(), "Cascaded validation is configured via
xml." );
+
+ propDescriptor = beanDescriptor.getConstraintsForProperty( "secondCreditCard"
);
+ assertNull( propDescriptor, "The @Valid annotation should be ignored." );
+ }
+}
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/User.java
(from rev 17380,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/User.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/User.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/User.java 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,69 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.xmlconfiguration.constraintdeclaration.fieldlevel;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class User {
+ @NotNull
+ private String firstname;
+
+ @NotNull
+ private String lastname;
+
+ private CreditCard firstCreditCard;
+
+ @Valid
+ private CreditCard secondCreditCard;
+
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+
+ public String getLastname() {
+ return lastname;
+ }
+
+ public void setLastname(String lastname) {
+ this.lastname = lastname;
+ }
+
+ public CreditCard getFirstCreditCard() {
+ return firstCreditCard;
+ }
+
+ public void setFirstCreditCard(CreditCard firstCreditCard) {
+ this.firstCreditCard = firstCreditCard;
+ }
+
+ public CreditCard getSecondCreditCard() {
+ return secondCreditCard;
+ }
+
+ public void setSecondCreditCard(CreditCard secondCreditCard) {
+ this.secondCreditCard = secondCreditCard;
+ }
+}
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/WrongFieldNameTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/WrongFieldNameTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/WrongFieldNameTest.java 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,58 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.xmlconfiguration.constraintdeclaration.fieldlevel;
+
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+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.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+@ValidationXml(value = "validation-WrongFieldNameTest.xml")
+@Resource(source = "user-constraints-WrongFieldNameTest.xml",
+ destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-WrongFieldNameTest.xml")
+public class WrongFieldNameTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "7.1.1.2", id = "f")
+ })
+ public void testWrongFieldNameThrowsException() {
+ try {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ validator.getConstraintsForClass( User.class );
+ }
+ catch ( ValidationException e ) {
+ // success
+ }
+ }
+}
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/CreditCard.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/CreditCard.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/CreditCard.java 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,36 @@
+// $Id: CreditCard.java 16794 2009-06-16 14:18:22Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.xmlconfiguration.constraintdeclaration.propertylevel;
+
+import javax.validation.constraints.Pattern;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CreditCard {
+ @Pattern(regexp = "[0-9]*")
+ private String number;
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+}
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/PropertyLevelOverridingTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/PropertyLevelOverridingTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/PropertyLevelOverridingTest.java 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,119 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.xmlconfiguration.constraintdeclaration.propertylevel;
+
+import java.util.Set;
+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 org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+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.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+@ValidationXml(value = "validation-PropertyLevelOverridingTest.xml")
+@Resource(source = "user-constraints-PropertyLevelOverridingTest.xml",
+ destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-PropertyLevelOverridingTest.xml")
+public class PropertyLevelOverridingTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "7.1.1.3", id = "a"),
+ @SpecAssertion(section = "7.1.1.3", id = "c")
+ })
+ public void testIgnoreAnnotations() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
+ assertNotNull( beanDescriptor );
+
+ PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty(
"firstname" );
+ assertNull( propDescriptor, "The annotation defined constraints should be
ignored." );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "7.1.1.3", id = "a"),
+ @SpecAssertion(section = "7.1.1.3", id = "d")
+ })
+ public void testIncludeAnnotations() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
+ assertNotNull( beanDescriptor );
+
+ PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty(
"lastname" );
+ assertNotNull( propDescriptor );
+
+ Set<ConstraintDescriptor<?>> constraintDescriptors =
propDescriptor.getConstraintDescriptors();
+ assertEquals( constraintDescriptors.size(), 2, "There should be two
constraints" );
+
+ boolean foundNotNullConstraint = false;
+ boolean foundPatternConstraint = false;
+ for ( ConstraintDescriptor<?> descriptor : constraintDescriptors ) {
+ if ( descriptor.getAnnotation() instanceof NotNull ) {
+ foundNotNullConstraint = true;
+ }
+ else if ( descriptor.getAnnotation() instanceof Pattern ) {
+ foundPatternConstraint = true;
+ }
+ else {
+ fail( "Invalid constraint for property." );
+ }
+ }
+ if ( !( foundNotNullConstraint && foundPatternConstraint ) ) {
+ fail( "Not all configured constraints discovered." );
+ }
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "7.1.1.3", id = "e")
+ })
+ public void testCascadedConfiguration() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class );
+ assertNotNull( beanDescriptor );
+
+ PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty(
"firstCreditCard" );
+ assertNotNull( propDescriptor );
+ assertTrue( propDescriptor.isCascaded(), "Cascaded validation is configured via
xml." );
+
+ propDescriptor = beanDescriptor.getConstraintsForProperty( "secondCreditCard"
);
+ assertNull( propDescriptor, "The @Valid annotation should be ignored." );
+ }
+}
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/User.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/User.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/User.java 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,69 @@
+// $Id: User.java 17380 2009-08-20 16:14:04Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.xmlconfiguration.constraintdeclaration.propertylevel;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class User {
+ private String firstname;
+
+ private String lastname;
+
+ private CreditCard firstCreditCard;
+
+ private CreditCard secondCreditCard;
+
+ @NotNull
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+
+ @NotNull
+ public String getLastname() {
+ return lastname;
+ }
+
+ public void setLastname(String lastname) {
+ this.lastname = lastname;
+ }
+
+ public CreditCard getFirstCreditCard() {
+ return firstCreditCard;
+ }
+
+ public void setFirstCreditCard(CreditCard firstCreditCard) {
+ this.firstCreditCard = firstCreditCard;
+ }
+
+ @Valid
+ public CreditCard getSecondCreditCard() {
+ return secondCreditCard;
+ }
+
+ public void setSecondCreditCard(CreditCard secondCreditCard) {
+ this.secondCreditCard = secondCreditCard;
+ }
+}
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/WrongPropertyNameTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/WrongPropertyNameTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/WrongPropertyNameTest.java 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,58 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.xmlconfiguration.constraintdeclaration.propertylevel;
+
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+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.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+@ValidationXml(value = "validation-WrongPropertyNameTest.xml")
+@Resource(source = "user-constraints-WrongPropertyNameTest.xml",
+ destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-WrongPropertyNameTest.xml")
+public class WrongPropertyNameTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "7.1.1.3", id = "f")
+ })
+ public void testWrongPropertyNameThrowsException() {
+ try {
+ Validator validator = TestUtil.getValidatorUnderTest();
+ validator.getConstraintsForClass( User.class );
+ }
+ catch ( ValidationException e ) {
+ // success
+ }
+ }
+}
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-FieldLevelOverridingTest.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-FieldLevelOverridingTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-FieldLevelOverridingTest.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,19 @@
+<constraint-mappings
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping
validation-mapping-1.0.xsd"
+
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+ <bean
class="org.hibernate.jsr303.tck.tests.xmlconfiguration.constraintdeclaration.fieldlevel.User"
+ ignore-annotations="false">
+ <field name="firstname" ignore-annotations="true"/>
+ <field name="lastname" ignore-annotations="false">
+ <constraint
annotation="javax.validation.constraints.Pattern">
+ <message>Last name has to start with with a capital
letter.</message>
+ <element name="regexp">^[A-Z][a-z]+</element>
+ </constraint>
+ </field>
+ <field name="firstCreditCard">
+ <valid/>
+ </field>
+ <field name="secondCreditCard"
ignore-annotations="true">
+ </field>
+ </bean>
+</constraint-mappings>
Added:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-WrongFieldNameTest.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-WrongFieldNameTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-WrongFieldNameTest.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,8 @@
+<constraint-mappings
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping
validation-mapping-1.0.xsd"
+
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+ <bean
class="org.hibernate.jsr303.tck.tests.xmlconfiguration.constraintdeclaration.fieldlevel.User"
+ ignore-annotations="false">
+ <field name="foobar" ignore-annotations="true"/>
+ </bean>
+</constraint-mappings>
Copied:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/validation-FieldLevelOverridingTest.xml
(from rev 17390,
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/validation-ClassLevelOverridingTest.xml)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/validation-FieldLevelOverridingTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/validation-FieldLevelOverridingTest.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configu...
validation-configuration-1.0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
<constraint-mapping>/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-FieldLevelOverridingTest.xml</constraint-mapping>
+</validation-config>
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/validation-WrongFieldNameTest.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/validation-WrongFieldNameTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/validation-WrongFieldNameTest.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configu...
validation-configuration-1.0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
<constraint-mapping>/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-WrongFieldNameTest.xml</constraint-mapping>
+</validation-config>
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-PropertyLevelOverridingTest.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-PropertyLevelOverridingTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-PropertyLevelOverridingTest.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,19 @@
+<constraint-mappings
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping
validation-mapping-1.0.xsd"
+
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+ <bean
class="org.hibernate.jsr303.tck.tests.xmlconfiguration.constraintdeclaration.propertylevel.User"
+ ignore-annotations="false">
+ <getter name="firstname" ignore-annotations="true"/>
+ <getter name="lastname" ignore-annotations="false">
+ <constraint
annotation="javax.validation.constraints.Pattern">
+ <message>Last name has to start with with a capital
letter.</message>
+ <element name="regexp">^[A-Z][a-z]+</element>
+ </constraint>
+ </getter>
+ <getter name="firstCreditCard">
+ <valid/>
+ </getter>
+ <getter name="secondCreditCard"
ignore-annotations="true">
+ </getter>
+ </bean>
+</constraint-mappings>
Added:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-WrongPropertyNameTest.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-WrongPropertyNameTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-WrongPropertyNameTest.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,8 @@
+<constraint-mappings
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping
validation-mapping-1.0.xsd"
+
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+ <bean
class="org.hibernate.jsr303.tck.tests.xmlconfiguration.constraintdeclaration.propertylevel.User"
+ ignore-annotations="false">
+ <getter name="foobar" ignore-annotations="true"/>
+ </bean>
+</constraint-mappings>
Added:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/validation-PropertyLevelOverridingTest.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/validation-PropertyLevelOverridingTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/validation-PropertyLevelOverridingTest.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configu...
validation-configuration-1.0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
<constraint-mapping>/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-PropertyLevelOverridingTest.xml</constraint-mapping>
+</validation-config>
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/validation-WrongPropertyNameTest.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/validation-WrongPropertyNameTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/validation-WrongPropertyNameTest.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configu...
validation-configuration-1.0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
<constraint-mapping>/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-WrongPropertyNameTest.xml</constraint-mapping>
+</validation-config>
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-08-23
10:34:35 UTC (rev 17398)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-08-24
11:48:21 UTC (rev 17399)
@@ -1116,13 +1116,10 @@
constraints</text>
</assertion>
<assertion id="e">
- <text>@Valid is considered unless the valid element is explicitly
used</text>
+ <text>The only way to disable cascading on a field marked as @Valid is
to use
+ ignore-annotations=true</text>
</assertion>
<assertion id="f">
- <text>Note that the only way to disable cascading on a field marked as
@Valid is to use
- ignore-validation=true</text>
- </assertion>
- <assertion id="g">
<text>If the name of the field does not correspond to a field in the
given bean a
ValidationException is raised</text>
</assertion>
@@ -1147,13 +1144,10 @@
constraints.</text>
</assertion>
<assertion id="e">
- <text>@Valid is considered unless the valid element is explicitly
used</text>
+ <text>The only way to disable cascading on a property marked as @Valid
is to
+ use ignore-annotations=true</text>
</assertion>
<assertion id="f">
- <text>Note that the only way to disable cascading on a property marked
as @Valid is to
- use ignore-validation=true</text>
- </assertion>
- <assertion id="g">
<text>If the name of the property does not correspond to a property in
the given bean a
ValidationException is raised</text>
</assertion>