Author: hardy.ferentschik
Date: 2009-06-04 06:59:42 -0400 (Thu, 04 Jun 2009)
New Revision: 16693
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Ambigious.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Bar.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Coordinate.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Foo.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/MinMax.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/PostCodeList.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SerializableBarSubclass.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Suburb.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/invalidconstraintdefinitions/InvalidConstraintDefinitionsTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
validator resolution tests
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/invalidconstraintdefinitions/InvalidConstraintDefinitionsTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/invalidconstraintdefinitions/InvalidConstraintDefinitionsTest.java 2009-06-04
10:58:55 UTC (rev 16692)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/invalidconstraintdefinitions/InvalidConstraintDefinitionsTest.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -57,7 +57,7 @@
@Test
@SpecAssertions({
- @SpecAssertion(section = "2.1", id = "d"),
+ @SpecAssertion(section = "2.1", id = "c"),
@SpecAssertion(section = "2.1.1", id = "c"),
@SpecAssertion(section = "8.2", id = "a")
})
@@ -74,7 +74,7 @@
@Test
@SpecAssertions({
- @SpecAssertion(section = "2.1", id = "d"),
+ @SpecAssertion(section = "2.1", id = "c"),
@SpecAssertion(section = "2.1.1", id = "d"),
@SpecAssertion(section = "8.2", id = "a")
})
@@ -91,7 +91,7 @@
@Test
@SpecAssertions({
- @SpecAssertion(section = "2.1", id = "d"),
+ @SpecAssertion(section = "2.1", id = "c"),
@SpecAssertion(section = "2.1.1", id = "e"),
@SpecAssertion(section = "8.2", id = "a")
})
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Ambigious.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Ambigious.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Ambigious.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -0,0 +1,68 @@
+// $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.constraints.validatorresolution;
+
+import java.io.Serializable;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+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.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * A test constraint which can lead to a error when trying to reslove the validator.
+ *
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = {
+ Ambigious.AmbigiousValidatorForBar.class,
Ambigious.AmbigiousValidatorForSerializable.class
+})
+@Documented
+@Target({ METHOD, FIELD, TYPE })
+@Retention(RUNTIME)
+public @interface Ambigious {
+ public abstract String message() default "foobar";
+
+ public abstract Class<?>[] groups() default { };
+
+
+ public class AmbigiousValidatorForBar implements ConstraintValidator<Ambigious,
Bar> {
+
+ public void initialize(Ambigious parameters) {
+ }
+
+ public boolean isValid(Bar b, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+ }
+
+ public class AmbigiousValidatorForSerializable implements
ConstraintValidator<Ambigious, Serializable> {
+
+ public void initialize(Ambigious parameters) {
+ }
+
+ public boolean isValid(Serializable o, ConstraintValidatorContext
constraintValidatorContext) {
+ return true;
+ }
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Ambigious.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Bar.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Bar.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Bar.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -0,0 +1,37 @@
+// : Person.java 69 2008-09-08 11:05:07Z 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.constraints.validatorresolution;
+
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Bar {
+ // validating Bar actually raises an UnexpectedTypeException - @Size is not defined for
Integer
+ @Size
+ private Integer value = 0;
+
+ public Integer getValue() {
+ return value;
+ }
+
+ public void setValue(Integer value) {
+ this.value = value;
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Bar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Coordinate.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Coordinate.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Coordinate.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -0,0 +1,32 @@
+// $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.constraints.validatorresolution;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Coordinate {
+
+ long longitude;
+ long latidute;
+
+ public Coordinate(long longitude, long latidute) {
+ this.longitude = longitude;
+ this.latidute = latidute;
+ }
+}
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Coordinate.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Foo.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Foo.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Foo.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -0,0 +1,35 @@
+// : Person.java 69 2008-09-08 11:05:07Z 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.constraints.validatorresolution;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Foo {
+
+ @Ambigious
+ private Bar bar;
+
+ public Foo(Bar bar) {
+ this.bar = bar;
+ }
+
+ public Bar getBar() {
+ return bar;
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Foo.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/MinMax.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/MinMax.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/MinMax.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -0,0 +1,39 @@
+// $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.constraints.validatorresolution;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class MinMax {
+ @Min(10l)
+ @Max(20l)
+ Number number;
+
+ @Min(10l)
+ @Max(20l)
+ String numberAsString;
+
+ public MinMax(String stringNumber, Number number) {
+ this.numberAsString = stringNumber;
+ this.number = number;
+ }
+}
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/MinMax.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/PostCodeList.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/PostCodeList.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/PostCodeList.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -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.constraints.validatorresolution;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+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 java.util.Collection;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * A test constraint which can lead to a error when trying to reslove the validator.
+ *
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = {
+ PostCodeList.PostCodeListValidatorForString.class,
PostCodeList.PostCodeListValidatorForNumber.class
+})
+@Documented
+@Target({ METHOD, FIELD, TYPE })
+@Retention(RUNTIME)
+public @interface PostCodeList {
+ public abstract String message() default "foobar";
+
+ public abstract Class<?>[] groups() default { };
+
+ public class PostCodeListValidatorForNumber
+ implements ConstraintValidator<PostCodeList, Collection<? extends Number>>
{
+ public void initialize(PostCodeList constraintAnnotation) {
+ }
+
+ public boolean isValid(Collection<? extends Number> value,
ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+ }
+
+ public class PostCodeListValidatorForString implements
ConstraintValidator<PostCodeList, Collection<String>> {
+ public void initialize(PostCodeList constraintAnnotation) {
+ }
+
+ public boolean isValid(Collection<String> value, ConstraintValidatorContext
constraintValidatorContext) {
+ if ( value == null ) {
+ return true;
+ }
+ return false;
+ }
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/PostCodeList.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SerializableBarSubclass.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SerializableBarSubclass.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SerializableBarSubclass.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -0,0 +1,27 @@
+// : Person.java 69 2008-09-08 11:05:07Z 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.constraints.validatorresolution;
+
+import java.io.Serializable;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SerializableBarSubclass extends Bar implements Serializable {
+
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SerializableBarSubclass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Suburb.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Suburb.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Suburb.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -0,0 +1,95 @@
+// $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.constraints.validatorresolution;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Suburb {
+ public enum Facility {
+ SHOPPING_MALL, BUS_TERMINAL
+ }
+
+ @Size(min = 5, max = 10)
+ private String name;
+
+ @Size(min = 2, max = 2)
+ private Map<Facility, Boolean> facilities;
+
+ @Size(min = 2)
+ private Set<String> streetNames;
+
+ @Size(min = 4, max = 1000)
+ private Coordinate[] boundingBox;
+
+ @PostCodeList
+ private Collection<? extends Number> includedPostCodes;
+
+ public void setIncludedPostCodes(Collection<? extends Number> includedPostCodes)
{
+ this.includedPostCodes = includedPostCodes;
+ }
+
+ public Collection<? extends Number> getIncludedPostcodes() {
+ return includedPostCodes;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Map<Facility, Boolean> getFacilities() {
+ return facilities;
+ }
+
+ public void addFacility(Facility f, Boolean exist) {
+ if ( facilities == null ) {
+ facilities = new HashMap<Facility, Boolean>();
+ }
+ facilities.put( f, exist );
+ }
+
+ public Set<String> getStreetNames() {
+ return streetNames;
+ }
+
+ public void addStreetName(String streetName) {
+ if ( streetNames == null ) {
+ streetNames = new HashSet<String>();
+ }
+ streetNames.add( streetName );
+ }
+
+ public Coordinate[] getBoundingBox() {
+ return boundingBox;
+ }
+
+ public void setBoundingBox(Coordinate[] boundingBox) {
+ this.boundingBox = boundingBox;
+ }
+}
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Suburb.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -0,0 +1,177 @@
+// $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.constraints.validatorresolution;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.UnexpectedTypeException;
+import javax.validation.Validator;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+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.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertInvalidPropertyPaths;
+
+/**
+ * Tests for constraint validator resolution.
+ *
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class ValidatorResolutionTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.3", id = "e"),
+ @SpecAssertion(section = "2.1", id = "d")
+ })
+ public void testUnexpectedTypeInValidatorResolution() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Bar bar = new Bar();
+ try {
+ validator.validate( bar );
+ fail();
+ }
+ catch ( UnexpectedTypeException e ) {
+ // success
+ }
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.3", id = "f")
+ })
+ public void testAmbigiousValidatorResolution() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Foo foo = new Foo( new SerializableBarSubclass() );
+ try {
+ validator.validate( foo );
+ fail();
+ }
+ catch ( UnexpectedTypeException e ) {
+ // success
+ }
+ }
+
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.3", id = "d")
+ })
+ public void testResolutionOfMinMaxForDifferentTypes() {
+ Validator validator = TestUtil.getDefaultValidator();
+ MinMax minMax = new MinMax( "5", 5 );
+ Set<ConstraintViolation<MinMax>> constraintViolations = validator.validate(
minMax );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertInvalidPropertyPaths( constraintViolations, new String[] { "number",
"numberAsString" } );
+ }
+
+ @Test
+
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.3", id = "d")
+ })
+ public void testResolutionOfMultipleSizeValidators() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Suburb suburb = new Suburb();
+
+ List<Integer> postcodes = new ArrayList<Integer>();
+ postcodes.add( 12345 );
+ suburb.setIncludedPostCodes( postcodes );
+
+ // all values are null and should pass
+ Set<ConstraintViolation<Suburb>> constraintViolations = validator.validate(
suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ suburb.setName( "" );
+ constraintViolations = validator.validate( suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), Suburb.class, "", "name"
+ );
+
+ suburb.setName( "Hoegsbo" );
+ constraintViolations = validator.validate( suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ suburb.addFacility( Suburb.Facility.SHOPPING_MALL, false );
+ constraintViolations = validator.validate( suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(),
+ Suburb.class,
+ suburb.getFacilities(),
+ "facilities"
+ );
+
+ suburb.addFacility( Suburb.Facility.BUS_TERMINAL, true );
+ constraintViolations = validator.validate( suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ suburb.addStreetName( "Sikelsgatan" );
+ constraintViolations = validator.validate( suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(),
+ Suburb.class,
+ suburb.getStreetNames(),
+ "streetNames"
+ );
+
+ suburb.addStreetName( "Marklandsgatan" );
+ constraintViolations = validator.validate( suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ Coordinate[] boundingBox = new Coordinate[3];
+ boundingBox[0] = new Coordinate( 0l, 0l );
+ boundingBox[1] = new Coordinate( 0l, 1l );
+ boundingBox[2] = new Coordinate( 1l, 0l );
+ suburb.setBoundingBox( boundingBox );
+ constraintViolations = validator.validate( suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(),
+ Suburb.class,
+ suburb.getBoundingBox(),
+ "boundingBox"
+ );
+
+ boundingBox = new Coordinate[4];
+ boundingBox[0] = new Coordinate( 0l, 0l );
+ boundingBox[1] = new Coordinate( 0l, 1l );
+ boundingBox[2] = new Coordinate( 1l, 0l );
+ boundingBox[3] = new Coordinate( 1l, 1l );
+ suburb.setBoundingBox( boundingBox );
+ constraintViolations = validator.validate( suburb );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-04
10:58:55 UTC (rev 16692)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-04
10:59:42 UTC (rev 16693)
@@ -17,10 +17,17 @@
*/
package org.hibernate.jsr303.tck.util;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
-/**
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+/**
* @author Hardy Ferentschik
*/
public final class TestUtil {
@@ -31,4 +38,40 @@
public static Validator getDefaultValidator() {
return Validation.buildDefaultValidatorFactory().getValidator();
}
+
+ public static <T> void
assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations, int
expectedViolations) {
+ assertEquals( violations.size(), expectedViolations, "Wrong number of constraint
violations" );
+ }
+
+ public static <T> void
assertInvalidPropertyPaths(Set<ConstraintViolation<T>> violations, String[]
propertyPaths) {
+ List<String> propertyPathsOfViolations = new ArrayList<String>();
+ for ( ConstraintViolation<?> violation : violations ) {
+ propertyPathsOfViolations.add( violation.getPropertyPath() );
+ }
+
+ for ( String propertyPath : propertyPaths ) {
+ assertTrue(
+ propertyPathsOfViolations.contains( propertyPath ),
+ propertyPath + " should be used in at least one constraint violation"
+ );
+ }
+ }
+
+ public static <T> void assertConstraintViolation(ConstraintViolation<T>
violation, Class<T> rootBean, Object invalidValue, String propertyPath) {
+ assertEquals(
+ violation.getPropertyPath(),
+ propertyPath,
+ "Wrong propertyPath."
+ );
+ assertEquals(
+ violation.getRootBean().getClass(),
+ rootBean,
+ "Wrong root bean."
+ );
+ assertEquals(
+ violation.getInvalidValue(),
+ invalidValue,
+ "Wrong invalid value."
+ );
+ }
}
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-04
10:58:55 UTC (rev 16692)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-04
10:59:42 UTC (rev 16693)
@@ -17,21 +17,19 @@
<section id="2.1" title="Constraint Definition">
<assertion id="a">
- <text>A constraint on a JavaBean is expressed through one or more
annotations</text>
- </assertion>
- <assertion id="b">
<text>An annotation is considered a constraint definition if its
retention policy
contains RUNTIME and if the annotation itself is annotated with
javax.validation.Constraint</text>
</assertion>
- <assertion id="c">
- <text>Constraint annotations can target any of the following
ElementTypes: FIELD, METHOD, TYPE, ANNOTATION_TYPE</text>
+ <assertion id="b">
+ <text>Constraint annotations can target any of the following
ElementTypes: FIELD,
+ METHOD, TYPE, ANNOTATION_TYPE</text>
</assertion>
- <assertion id="d">
+ <assertion id="c">
<text>If a constraint definition is not valid, a
ConstraintDefinitionException is raised
either at validation time or when the metadata is requested</text>
</assertion>
- <assertion id="e">
+ <assertion id="d">
<text>Applying a constraint annotation to an incompatible type will
raise a
UnexpectedTypeException</text>
</assertion>
@@ -487,40 +485,29 @@
</section>
<section id="3.5.3" title="ConstraintValidator resolution
algorithm">
<assertion id="a">
- <text>A constraint is associated to one or more ConstraintValidator
- implementations</text>
- </assertion>
- <assertion id="b">
- <text>The ConstraintValidator executed depends on the type hosting the
constraint</text>
- </assertion>
- <assertion id="c">
- <text>For a given constraint evaluation, a single ConstraintValidator
is
- considered</text>
- </assertion>
- <assertion id="d">
<text>If the constraint declaration is hosted on a class or an
interface, the targeted
type is the class or the interface</text>
</assertion>
- <assertion id="e">
+ <assertion id="b">
<text>If the constraint is hosted on a class attribute, the type of the
attribute is the
targeted type</text>
</assertion>
- <assertion id="f">
+ <assertion id="c">
<text>If the constraint is hosted on a getter, the return type of the
getter is the
targeted type</text>
</assertion>
- <assertion id="g">
+ <assertion id="d">
<text>the ConstraintValidator chosen to validate a declared type T is
the one where the
type supported by the ConstraintValidator is a supertype of T and where
there is no
other ConstraintValidator whose supported type is a supertype of T and
not a
supertype of the chosen ConstraintValidator supported type</text>
</assertion>
- <assertion id="h">
+ <assertion id="e">
<text>If no ConstraintValidator compliant with T is found amongst the
ConstraintValidators listed by the con- straint A, a
UnexpectedTypeException is
raised</text>
</assertion>
- <assertion id="i">
+ <assertion id="f">
<text>If more than one maximally specific ConstraintValidator is found,
a
UnexpectedTypeException is raised</text>
</assertion>
@@ -1140,8 +1127,8 @@
constraint declaration</text>
</assertion>
<assertion id="b">
- <text>"message" or "groups" are not permitted
names, use the message or groups
- elements instead. Otherwise a ValidationException is raised</text>
+ <text>"message" or "groups" are not permitted
names, use the message or groups elements
+ instead. Otherwise a ValidationException is raised</text>
</assertion>
<assertion id="c">
<text>If the element represents a primitive type, a class or an enum,
the string