Hibernate SVN: r16794 - in beanvalidation/trunk: validation-tck/src/main/java and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-16 10:18:22 -0400 (Tue, 16 Jun 2009)
New Revision: 16794
Added:
beanvalidation/trunk/validation-tck/src/main/java/First/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Address.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Animal.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Auditable.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Author.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Billable.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Book.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/BuyInOneClick.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java
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/constraints/groups/CyclicGroupSequence.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence1.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence2.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultAlias.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Dictonary.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/First.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Last.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Optional.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Order.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Second.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/User.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Bar.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Foo.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/InheritanceTest.java
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
Log:
added group tests from hibernat validator implementation.
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-06-16 14:17:45 UTC (rev 16793)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -102,15 +102,18 @@
*/
BeanDescriptor getConstraintsForClass(Class<?> clazz);
- /**
+ /**
* Return an object of the specified type to allow access to the
* provider-specific API. If the Bean Validation provider
* implementation does not support the specified class, the
* ValidationException is thrown.
- * @param type the class of the object to be returned.
+ *
+ * @param type the class of the object to be returned.
+ *
* @return an instance of the specified class
+ *
* @throws ValidationException if the provider does not
- * support the call.
+ * support the call.
*/
public <T> T unwrap(Class<T> type);
}
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Address.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Address.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Address.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,64 @@
+package org.hibernate.jsr303.tck.tests.constraints.groups;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.validation.groups.Default;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@GroupSequence({ Address.class, Address.HighLevelCoherence.class })
+@ZipCodeCoherenceChecker(groups = Address.HighLevelCoherence.class)
+public class Address {
+ @NotNull
+ @Size(max = 50)
+ private String street;
+
+ @NotNull
+ @Size(max = 5)
+ private String zipcode;
+
+ @NotNull
+ @Size(max = 30)
+ private String city;
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public String getZipcode() {
+ return zipcode;
+ }
+
+ public void setZipcode(String zipcode) {
+ this.zipcode = zipcode;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ /**
+ * Check conherence on the overall object
+ * Needs basic checking to be green first
+ */
+ public interface HighLevelCoherence {
+ }
+
+ /**
+ * Check both basic constraints and high level ones.
+ * High level constraints are not checked if basic constraints fail.
+ */
+ @GroupSequence(value = { Default.class, HighLevelCoherence.class })
+ public interface Complete {
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Address.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,12 @@
+package org.hibernate.jsr303.tck.tests.constraints.groups;
+
+import javax.validation.GroupSequence;
+import javax.validation.groups.Default;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@GroupSequence({ Default.class, AddressWithInvalidGroupSequence.HighLevelCoherence.class })
+public class AddressWithInvalidGroupSequence extends Address {
+
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Animal.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Animal.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Animal.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,52 @@
+// $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.groups;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Animal {
+ public enum Domain {
+ PROKARYOTA, EUKARYOTA
+ }
+
+ @Size(min= 1, groups = { First.class, Second.class })
+ private String name;
+
+ @NotNull(groups = First.class)
+ private Domain domain;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Domain getDomain() {
+ return domain;
+ }
+
+ public void setDomain(Domain domain) {
+ this.domain = domain;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Animal.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Auditable.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Auditable.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Auditable.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,37 @@
+// $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.groups;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Auditable {
+ @NotNull
+ String getCreationDate();
+
+ @NotNull
+ String getLastUpdate();
+
+ @NotNull
+ String getLastModifier();
+
+ @NotNull
+ String getLastReader();
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Auditable.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Author.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Author.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Author.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,59 @@
+// $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.groups;
+
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Author {
+
+ @Size(min = 1, groups = Last.class)
+ private String firstName;
+
+ @Size(min = 1, groups = First.class)
+ private String lastName;
+
+ @Size(max = 20, groups = Last.class)
+ private String company;
+
+ 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 String getCompany() {
+ return company;
+ }
+
+ public void setCompany(String company) {
+ this.company = company;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Author.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Billable.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Billable.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Billable.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,9 @@
+package org.hibernate.jsr303.tck.tests.constraints.groups;
+
+/**
+ * Validation group checking whether user is billable.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface Billable {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Billable.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Book.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Book.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Book.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,67 @@
+// $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.groups;
+
+import javax.validation.GroupSequence;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Book {
+ @NotNull(groups = First.class)
+ @Size(min = 1, groups = First.class)
+ private String title;
+
+ @Size(max = 30, groups = Second.class)
+ private String subtitle;
+
+ @Valid
+ @NotNull(groups = First.class)
+ private Author author;
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getSubtitle() {
+ return subtitle;
+ }
+
+ public void setSubtitle(String subtitle) {
+ this.subtitle = subtitle;
+ }
+
+ public Author getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(Author author) {
+ this.author = author;
+ }
+
+ @GroupSequence(value = { First.class, Second.class, Last.class })
+ public interface All {
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Book.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/BuyInOneClick.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/BuyInOneClick.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/BuyInOneClick.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,11 @@
+package org.hibernate.jsr303.tck.tests.constraints.groups;
+
+import javax.validation.groups.Default;
+
+/**
+ * Customer can buy without being harrassed by the checking-out process.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface BuyInOneClick extends Default, Billable {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/BuyInOneClick.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,29 @@
+package org.hibernate.jsr303.tck.tests.constraints.groups;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import javax.validation.groups.Default;
+
+/**
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+@GroupSequence({ Car.class, Car.Test.class })
+public class Car {
+ @Pattern(regexp = ".*", groups = Default.class)
+ @Size(min = 2, max = 20, groups = Car.Test.class)
+ private String type;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public interface Test {
+
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: 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/constraints/groups/CreditCard.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CreditCard.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,34 @@
+// $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.groups;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CreditCard {
+
+ private String number;
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CreditCard.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,27 @@
+// $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.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@GroupSequence(value = CyclicGroupSequence.class)
+public interface CyclicGroupSequence {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence1.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence1.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence1.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,27 @@
+// $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.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@GroupSequence(value = CyclicGroupSequence2.class)
+public interface CyclicGroupSequence1 {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence1.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence2.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence2.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence2.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,27 @@
+// $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.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@GroupSequence(value = CyclicGroupSequence1.class)
+public interface CyclicGroupSequence2 {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/CyclicGroupSequence2.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultAlias.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultAlias.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultAlias.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,24 @@
+// $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.groups;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface DefaultAlias {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultAlias.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Dictonary.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Dictonary.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Dictonary.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,56 @@
+// $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.groups;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Dictonary extends Book {
+ @NotNull(groups = Translate.class)
+ @Size(min = 1, groups = Translate.class)
+ private String translatesTo;
+
+ @NotNull(groups = Translate.class)
+ @Size(min = 1, groups = Translate.class)
+ private String translatesFrom;
+
+ public String getTranslatesTo() {
+ return translatesTo;
+ }
+
+ public void setTranslatesTo(String translatesTo) {
+ this.translatesTo = translatesTo;
+ }
+
+ public String getTranslatesFrom() {
+ return translatesFrom;
+ }
+
+ public void setTranslatesFrom(String translatesFrom) {
+ this.translatesFrom = translatesFrom;
+ }
+
+ /**
+ * Translator related constraints
+ */
+ public interface Translate {
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Dictonary.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/First.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/First.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/First.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,24 @@
+// $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.groups;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface First {
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/First.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,414 @@
+// $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.groups;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+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.hibernate.jsr303.tck.util.TestUtil;
+
+
+/**
+ * Tests for the group and group sequence feature.
+ *
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class GroupTest extends AbstractTest {
+
+ @Test
+ public void testGroups() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Author author = new Author();
+ author.setLastName( "" );
+ author.setFirstName( "" );
+ Book book = new Book();
+ book.setTitle( "" );
+ book.setAuthor( author );
+
+ Set<ConstraintViolation<Book>> constraintViolations = validator.validate(
+ book, First.class, Second.class, Last.class
+ );
+ assertEquals( constraintViolations.size(), 3, "Wrong number of constraints" );
+
+ author.setFirstName( "Gavin" );
+ author.setLastName( "King" );
+
+ constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+ ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
+ assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
+ assertEquals( "title", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+ book.setTitle( "Hibernate Persistence with JPA" );
+ book.setSubtitle( "Revised Edition of Hibernate in Action" );
+
+ constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ constraintViolation = constraintViolations.iterator().next();
+ assertEquals( "size must be between 0 and 30", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
+ assertEquals( constraintViolation.getInvalidValue(), book.getSubtitle(), "Wrong value" );
+ assertEquals( "subtitle", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+ book.setSubtitle( "Revised Edition" );
+ author.setCompany( "JBoss a divison of RedHat" );
+
+ constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+ constraintViolation = constraintViolations.iterator().next();
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertEquals( "size must be between 0 and 20", constraintViolation.getMessage() );
+ assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
+ assertEquals( constraintViolation.getInvalidValue(), author.getCompany(), "Wrong value" );
+ assertEquals( "author.company", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+ author.setCompany( "JBoss" );
+
+ constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
+ @Test
+ public void testGroupSequence() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Author author = new Author();
+ author.setLastName( "" );
+ author.setFirstName( "" );
+ Book book = new Book();
+ book.setAuthor( author );
+
+ Set<ConstraintViolation<Book>> constraintViolations = validator.validate( book, Book.All.class );
+ assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
+
+ author.setFirstName( "Gavin" );
+ author.setLastName( "King" );
+
+ constraintViolations = validator.validate( book, Book.All.class );
+ ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
+ assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
+ assertEquals( "title", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+ book.setTitle( "Hibernate Persistence with JPA" );
+ book.setSubtitle( "Revised Edition of Hibernate in Action" );
+
+ constraintViolations = validator.validate( book, Book.All.class );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+ book.setSubtitle( "Revised Edition" );
+ author.setCompany( "JBoss a divison of RedHat" );
+
+ constraintViolations = validator.validate( book, Book.All.class );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+ author.setCompany( "JBoss" );
+
+ constraintViolations = validator.validate( book, Book.All.class );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
+ @Test
+ public void testGroupSequences() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Dictonary dictonary = new Dictonary();
+ dictonary.setTitle( "English - German" );
+ Author author = new Author();
+ author.setLastName( "-" );
+ author.setFirstName( "-" );
+ author.setCompany( "Langenscheidt Publ." );
+ dictonary.setAuthor( author );
+
+ Set<ConstraintViolation<Dictonary>> constraintViolations = validator.validate( dictonary, DefaultAlias.class );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
+ @Test
+ public void testValidationFailureInMultipleGroups() {
+ Validator validator = TestUtil.getDefaultValidator();
+ Animal elepfant = new Animal();
+ elepfant.setName( "" );
+ elepfant.setDomain( Animal.Domain.EUKARYOTA );
+
+ Set<ConstraintViolation<Animal>> constraintViolations = validator.validate(
+ elepfant, First.class, Second.class
+ );
+ assertEquals(
+ constraintViolations.size(),
+ 1,
+ "The should be two invalid constraints since the same propertyName gets validated in both groups"
+ );
+ }
+
+ @Test
+ public void testValidateAgainstDifferentGroups() {
+ User user = new User();
+
+ // all fields per default null. Depending on the validation groups there should be a different amount
+ // of constraint failures.
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
+ assertEquals(
+ constraintViolations.size(),
+ 2,
+ "There should be two violations against the implicit default group"
+ );
+
+ constraintViolations = validator.validate( user, Default.class );
+ assertEquals(
+ constraintViolations.size(),
+ 2,
+ "There should be two violations against the explicit defualt group"
+ );
+
+ constraintViolations = validator.validate( user, Billable.class );
+ assertEquals(
+ constraintViolations.size(),
+ 1,
+ "There should be one violation against Billable"
+ );
+
+ constraintViolations = validator.validate( user, Default.class, Billable.class );
+ assertEquals(
+ constraintViolations.size(),
+ 3,
+ "There should be 3 violation against Default and Billable"
+ );
+
+ constraintViolations = validator.validate( user, BuyInOneClick.class );
+ assertEquals(
+ constraintViolations.size(),
+ 3,
+ "Three violations expected since BuyInOneClick extends Default and Billable"
+ );
+
+ constraintViolations = validator.validate( user, BuyInOneClick.class, Billable.class );
+ assertEquals(
+ constraintViolations.size(),
+ 3,
+ "BuyInOneClick already contains all other groups. Adding Billable does not change the number of violations"
+ );
+
+ constraintViolations = validator.validate( user, BuyInOneClick.class, Default.class );
+ assertEquals(
+ constraintViolations.size(),
+ 3,
+ "BuyInOneClick already contains all other groups. Adding Default does not change the number of violations"
+ );
+
+ constraintViolations = validator.validate( user, BuyInOneClick.class, Default.class, Billable.class );
+ assertEquals(
+ constraintViolations.size(),
+ 3,
+ "BuyInOneClick already contains all other groups. Adding Billable and Default does not change the number of violations"
+ );
+
+ constraintViolations = validator.validate( user, Billable.class, Billable.class );
+ assertEquals(
+ constraintViolations.size(),
+ 1,
+ "Adding the same group twice is still only leads to a single violation"
+ );
+ }
+
+ /**
+ * HV-85
+ */
+ @Test
+ public void testGroupSequenceFollowedByGroup() {
+ User user = new User();
+ user.setFirstname( "Foo" );
+ user.setLastname( "Bar" );
+ user.setPhoneNumber( "+46 123-456" );
+
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
+ user, BuyInOneClick.class, Optional.class
+ );
+ assertEquals(
+ constraintViolations.size(),
+ 2,
+ "There should be two violations against the implicit default group"
+ );
+
+ for ( ConstraintViolation<User> constraintViolation : constraintViolations ) {
+ if ( constraintViolation.getPropertyPath().equals( "defaultCreditCard" ) ) {
+ TestUtil.assertConstraintViolation(
+ constraintViolation,
+ User.class,
+ null,
+ "defaultCreditCard"
+ );
+ }
+ else if ( constraintViolation.getPropertyPath().equals( "phoneNumber" ) ) {
+ TestUtil.assertConstraintViolation(
+ constraintViolation,
+ User.class,
+ "+46 123-456",
+ "phoneNumber"
+ );
+ }
+ else {
+ fail( "Unexpected violation" );
+ }
+ }
+ }
+
+ /**
+ * HV-113
+ */
+ @Test
+ public void testRedefiningDefaultGroup() {
+ Address address = new Address();
+ address.setStreet( "Guldmyntgatan" );
+ address.setCity( "Gothenborg" );
+
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
+ assertEquals(
+ constraintViolations.size(),
+ 1,
+ "There should only be one violation for zipcode"
+ );
+
+ ConstraintViolation<Address> violation = constraintViolations.iterator().next();
+ TestUtil.assertConstraintViolation( violation, Address.class, null, "zipcode" );
+
+ address.setZipcode( "41841" );
+
+ // now the second group in the re-defined default group causes an error
+ constraintViolations = validator.validate( address );
+ assertEquals(
+ constraintViolations.size(),
+ 1,
+ "There should only be one violation for zipcode"
+ );
+
+ violation = constraintViolations.iterator().next();
+ TestUtil.assertConstraintViolation( violation, Address.class, address, "" );
+ }
+
+ /**
+ * HV-113
+ */
+ @Test
+ public void testRedefiningDefaultGroup2() {
+ Car car = new Car();
+ car.setType( "A" );
+
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
+ assertEquals(
+ constraintViolations.size(),
+ 1,
+ "There should be one violations due to the re-defintion of the default group"
+ );
+ assertEquals(
+ "size must be between 2 and 20",
+ constraintViolations.iterator().next().getMessage(),
+ "Wrong constraint"
+ );
+
+ constraintViolations = validator.validateProperty( car, "type" );
+ assertEquals(
+ constraintViolations.size(),
+ 1,
+ "There should be one violations due to the re-defintion of the default group"
+ );
+ assertEquals(
+ "size must be between 2 and 20",
+ constraintViolations.iterator().next().getMessage(),
+ "Wrong constraint"
+ );
+
+ constraintViolations = validator.validateValue( Car.class, "type", "A" );
+ assertEquals(
+ constraintViolations.size(),
+ 1,
+ "There should be one violations due to the re-defintion of the default group"
+ );
+ assertEquals(
+ "size must be between 2 and 20",
+ constraintViolations.iterator().next().getMessage(),
+ "Wrong constraint"
+ );
+ }
+
+ /**
+ * HV-113
+ */
+ @Test
+ public void testInvalidRedefinitionOfDefaultGroup() {
+ Address address = new AddressWithInvalidGroupSequence();
+ Validator validator = TestUtil.getDefaultValidator();
+ try {
+ validator.validate( address );
+ fail( "It shoud not be allowed to have Default.class in the group sequence of a class." );
+ }
+ catch ( ValidationException e ) {
+ assertEquals(
+ "'Default.class' cannot appear in default group sequence list.", e.getMessage(), "Wrong message"
+ );
+ }
+ }
+
+ /**
+ * HV-115
+ */
+ @Test
+ public void testImplicitGroup() {
+ Validator validator = TestUtil.getDefaultValidator();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
+ assertTrue( beanDescriptor.isBeanConstrained() );
+
+ Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
+ assertTrue( constraintProperties.size() == 5, "Each of the properties should have at least one constraint." );
+
+ Order order = new Order();
+ Set<ConstraintViolation<Order>> violations = validator.validate( order );
+ assertTrue( violations.size() == 5, "All 5 NotNull constraints should fail." );
+
+ // use implicit group Auditable
+ violations = validator.validate( order, Auditable.class );
+ assertTrue( violations.size() == 4, "All 4 NotNull constraints on Auditable should fail." );
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/GroupTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Last.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Last.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Last.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,24 @@
+// $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.groups;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Last {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Last.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Optional.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Optional.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Optional.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,9 @@
+package org.hibernate.jsr303.tck.tests.constraints.groups;
+
+/**
+ * Validation group checking whether user is billable.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface Optional {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Optional.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Order.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Order.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Order.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,54 @@
+// $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.groups;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Order implements Auditable {
+ private String creationDate;
+ private String lastUpdate;
+ private String lastModifier;
+ private String lastReader;
+ private String orderNumber;
+
+ public String getCreationDate() {
+ return this.creationDate;
+ }
+
+ public String getLastUpdate() {
+ return this.lastUpdate;
+ }
+
+ public String getLastModifier() {
+ return this.lastModifier;
+ }
+
+ public String getLastReader() {
+ return this.lastReader;
+ }
+
+ @NotNull
+ @Size(min = 10, max = 10)
+ public String getOrderNumber() {
+ return this.orderNumber;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Order.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Second.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Second.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Second.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,24 @@
+// $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.groups;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Second {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Second.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/User.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/User.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/User.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,58 @@
+package org.hibernate.jsr303.tck.tests.constraints.groups;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.groups.Default;
+
+
+/**
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+@GroupSequence({ User.class })
+public class User {
+ @NotNull
+ private String firstname;
+
+ @NotNull(groups = Default.class)
+ private String lastname;
+
+ @Pattern(regexp = "[0-9 -]?", groups = Optional.class)
+ private String phoneNumber;
+
+ @NotNull(groups = { Billable.class, BuyInOneClick.class })
+ private CreditCard defaultCreditCard;
+
+ 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 getDefaultCreditCard() {
+ return defaultCreditCard;
+ }
+
+ public void setDefaultCreditCard(CreditCard defaultCreditCard) {
+ this.defaultCreditCard = defaultCreditCard;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/User.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,22 @@
+package org.hibernate.jsr303.tck.tests.constraints.groups;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+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;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Target({ TYPE, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+@Constraint(validatedBy = ZipCodeCoherenceValidator.class)
+public @interface ZipCodeCoherenceChecker {
+ public abstract String message() default "{validator.zipCodeCoherenceChecker}";
+
+ public abstract Class<?>[] groups() default { };
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceValidator.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceValidator.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,34 @@
+// $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.groups;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ZipCodeCoherenceValidator implements ConstraintValidator<ZipCodeCoherenceChecker, Address> {
+
+ public void initialize(ZipCodeCoherenceChecker parameters) {
+ }
+
+ public boolean isValid(Address value, ConstraintValidatorContext constraintValidatorContext) {
+ return false;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Bar.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Bar.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Bar.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,24 @@
+// $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.inheritance;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Bar extends Foo {
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/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/inheritance/Foo.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Foo.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/Foo.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -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.constraints.inheritance;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Foo {
+ @NotNull
+ private String foo;
+
+ public String getFoo() {
+ return foo;
+ }
+
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/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/inheritance/InheritanceTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/InheritanceTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/InheritanceTest.java 2009-06-16 14:18:22 UTC (rev 16794)
@@ -0,0 +1,60 @@
+// $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.inheritance;
+
+import java.lang.annotation.Annotation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
+
+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.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class InheritanceTest extends AbstractTest {
+
+ @Test
+ public void testIsBeanConstrained() {
+ Validator validator = TestUtil.getDefaultValidator();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Bar.class );
+
+ assertFalse( beanDescriptor.hasConstraints(), "There should be no direct constraints on the specified bean." );
+ assertTrue( beanDescriptor.isBeanConstrained(), "Bean should be constrainted " );
+
+ assertTrue( beanDescriptor.getConstraintsForProperty( "foo" ) != null );
+ PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "foo" );
+ Annotation constraintAnnotation = ( Annotation ) propDescriptor.getConstraintDescriptors()
+ .iterator()
+ .next().getAnnotation();
+ assertTrue(
+ constraintAnnotation.annotationType() == NotNull.class
+ );
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/inheritance/InheritanceTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
15 years, 6 months
Hibernate SVN: r16793 - in validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine: groups and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-16 10:17:45 -0400 (Tue, 16 Jun 2009)
New Revision: 16793
Removed:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/AddressWithInvalidGroupSequence.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Animal.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Auditable.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Author.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Billable.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Book.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/BuyInOneClick.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Car.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/CreditCard.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Dictonary.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Optional.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Order.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/User.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/inheritance/
Log:
moving group tests into tck
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/AddressWithInvalidGroupSequence.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/AddressWithInvalidGroupSequence.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/AddressWithInvalidGroupSequence.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,12 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.groups.Default;
-
-/**
- * @author Emmanuel Bernard
- */
-@GroupSequence({ Default.class, AddressWithInvalidGroupSequence.HighLevelCoherence.class })
-public class AddressWithInvalidGroupSequence extends Address {
-
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Animal.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Animal.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Animal.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,55 +0,0 @@
-// $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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Second;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Animal {
- public enum Domain {
- PROKARYOTA, EUKARYOTA
- }
-
- @NotEmpty(groups = { First.class, Second.class })
- private String name;
-
- @NotNull(groups = First.class)
- private Domain domain;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Domain getDomain() {
- return domain;
- }
-
- public void setDomain(Domain domain) {
- this.domain = domain;
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Auditable.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Auditable.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Auditable.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,37 +0,0 @@
-// $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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-
-/**
- * @author Hardy Ferentschik
- */
-public interface Auditable {
- @NotNull
- String getCreationDate();
-
- @NotNull
- String getLastUpdate();
-
- @NotNull
- String getLastModifier();
-
- @NotNull
- String getLastReader();
-}
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Author.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Author.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Author.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,64 +0,0 @@
-// $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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.Length;
-import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Last;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Author {
-
- @NotEmpty(groups = Last.class)
- private String firstName;
-
- @NotEmpty(groups = First.class)
- private String lastName;
-
- @Length(max = 20, groups = Last.class)
- private String company;
-
- 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 String getCompany() {
- return company;
- }
-
- public void setCompany(String company) {
- this.company = company;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Billable.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Billable.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Billable.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,9 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-/**
- * Validation group checking whether user is billable.
- *
- * @author Emmanuel Bernard
- */
-public interface Billable {
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Book.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Book.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Book.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,71 +0,0 @@
-// $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.validation.engine.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.Length;
-import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Last;
-import org.hibernate.validation.engine.Second;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Book {
- @NotEmpty(groups = First.class)
- private String title;
-
- @Length(max = 30, groups = Second.class)
- private String subtitle;
-
- @Valid
- @NotNull(groups = First.class)
- private Author author;
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getSubtitle() {
- return subtitle;
- }
-
- public void setSubtitle(String subtitle) {
- this.subtitle = subtitle;
- }
-
- public Author getAuthor() {
- return author;
- }
-
- public void setAuthor(Author author) {
- this.author = author;
- }
-
- @GroupSequence(value = { First.class, Second.class, Last.class })
- public interface All {
- }
-}
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/BuyInOneClick.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/BuyInOneClick.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/BuyInOneClick.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,11 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-import javax.validation.groups.Default;
-
-/**
- * Customer can buy without being harrassed by the checking-out process.
- *
- * @author Emmanuel Bernard
- */
-public interface BuyInOneClick extends Default, Billable {
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Car.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Car.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Car.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,30 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.constraints.Pattern;
-import javax.validation.groups.Default;
-
-import org.hibernate.validation.constraints.Length;
-
-/**
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-@GroupSequence({ Car.class, Car.Test.class })
-public class Car {
- @Pattern(regexp = ".*", groups = Default.class)
- @Length(min = 2, max = 20, groups = Car.Test.class)
- private String type;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public interface Test {
-
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/CreditCard.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/CreditCard.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/CreditCard.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,34 +0,0 @@
-// $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.validation.engine.groups;
-
-/**
- * @author Hardy Ferentschik
- */
-public class CreditCard {
-
- private String number;
-
- public String getNumber() {
- return number;
- }
-
- public void setNumber(String number) {
- this.number = number;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Dictonary.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Dictonary.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Dictonary.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,57 +0,0 @@
-// $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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.NotEmpty;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Dictonary extends Book {
- @NotNull(groups = Translate.class)
- @NotEmpty(groups = Translate.class)
- private String translatesTo;
-
- @NotNull(groups = Translate.class)
- @NotEmpty(groups = Translate.class)
- private String translatesFrom;
-
- public String getTranslatesTo() {
- return translatesTo;
- }
-
- public void setTranslatesTo(String translatesTo) {
- this.translatesTo = translatesTo;
- }
-
- public String getTranslatesFrom() {
- return translatesFrom;
- }
-
- public void setTranslatesFrom(String translatesFrom) {
- this.translatesFrom = translatesFrom;
- }
-
- /**
- * Translator related constraints
- */
- public interface Translate {
- }
-}
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,415 +0,0 @@
-// $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.validation.engine.groups;
-
-import java.util.Set;
-import javax.validation.metadata.BeanDescriptor;
-import javax.validation.ConstraintViolation;
-import javax.validation.metadata.PropertyDescriptor;
-import javax.validation.ValidationException;
-import javax.validation.Validator;
-import javax.validation.groups.Default;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-import org.testng.annotations.Test;
-
-import org.hibernate.validation.engine.DefaultAlias;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Last;
-import org.hibernate.validation.engine.Second;
-import org.hibernate.validation.util.TestUtil;
-import static org.hibernate.validation.util.TestUtil.assertConstraintViolation;
-
-/**
- * Tests for the group and group sequence feature.
- *
- * @author Hardy Ferentschik
- */
-public class GroupTest {
-
- @Test
- public void testGroups() {
- Validator validator = TestUtil.getValidator();
-
- Author author = new Author();
- author.setLastName( "" );
- author.setFirstName( "" );
- Book book = new Book();
- book.setTitle( "" );
- book.setAuthor( author );
-
- Set<ConstraintViolation<Book>> constraintViolations = validator.validate(
- book, First.class, Second.class, Last.class
- );
- assertEquals( constraintViolations.size(), 3, "Wrong number of constraints" );
-
- author.setFirstName( "Gavin" );
- author.setLastName( "King" );
-
- constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
- ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
- assertEquals( "may not be empty", constraintViolation.getMessage(), "Wrong message" );
- assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
- assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
- assertEquals( "title", constraintViolation.getPropertyPath(), "Wrong propertyName" );
-
- book.setTitle( "Hibernate Persistence with JPA" );
- book.setSubtitle( "Revised Edition of Hibernate in Action" );
-
- constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
- constraintViolation = constraintViolations.iterator().next();
- assertEquals( "length must be between 0 and 30", constraintViolation.getMessage(), "Wrong message" );
- assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
- assertEquals( constraintViolation.getInvalidValue(), book.getSubtitle(), "Wrong value" );
- assertEquals( "subtitle", constraintViolation.getPropertyPath(), "Wrong propertyName" );
-
- book.setSubtitle( "Revised Edition" );
- author.setCompany( "JBoss a divison of RedHat" );
-
- constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
- constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
- assertEquals( "length must be between 0 and 20", constraintViolation.getMessage() );
- assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
- assertEquals( constraintViolation.getInvalidValue(), author.getCompany(), "Wrong value" );
- assertEquals( "author.company", constraintViolation.getPropertyPath(), "Wrong propertyName" );
-
- author.setCompany( "JBoss" );
-
- constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @Test
- public void testGroupSequence() {
- Validator validator = TestUtil.getValidator();
-
- Author author = new Author();
- author.setLastName( "" );
- author.setFirstName( "" );
- Book book = new Book();
- book.setAuthor( author );
-
- Set<ConstraintViolation<Book>> constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
-
- author.setFirstName( "Gavin" );
- author.setLastName( "King" );
-
- constraintViolations = validator.validate( book, Book.All.class );
- ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
- assertEquals( "may not be empty", constraintViolation.getMessage(), "Wrong message" );
- assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
- assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
- assertEquals( "title", constraintViolation.getPropertyPath(), "Wrong propertyName" );
-
- book.setTitle( "Hibernate Persistence with JPA" );
- book.setSubtitle( "Revised Edition of Hibernate in Action" );
-
- constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
- book.setSubtitle( "Revised Edition" );
- author.setCompany( "JBoss a divison of RedHat" );
-
- constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
- author.setCompany( "JBoss" );
-
- constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @Test
- public void testGroupSequences() {
- Validator validator = TestUtil.getValidator();
-
- Dictonary dictonary = new Dictonary();
- dictonary.setTitle( "English - German" );
- Author author = new Author();
- author.setLastName( "-" );
- author.setFirstName( "-" );
- author.setCompany( "Langenscheidt Publ." );
- dictonary.setAuthor( author );
-
- Set<ConstraintViolation<Dictonary>> constraintViolations = validator.validate( dictonary, DefaultAlias.class );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @Test
- public void testValidationFailureInMultipleGroups() {
- Validator validator = TestUtil.getValidator();
- Animal elepfant = new Animal();
- elepfant.setName( "" );
- elepfant.setDomain( Animal.Domain.EUKARYOTA );
-
- Set<ConstraintViolation<Animal>> constraintViolations = validator.validate(
- elepfant, First.class, Second.class
- );
- assertEquals(
- constraintViolations.size(),
- 1,
- "The should be two invalid constraints since the same propertyName gets validated in both groups"
- );
- }
-
- @Test
- public void testValidateAgainstDifferentGroups() {
- User user = new User();
-
- // all fields per default null. Depending on the validation groups there should be a different amount
- // of constraint failures.
- Validator validator = TestUtil.getValidator();
-
- Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
- assertEquals(
- constraintViolations.size(),
- 2,
- "There should be two violations against the implicit default group"
- );
-
- constraintViolations = validator.validate( user, Default.class );
- assertEquals(
- constraintViolations.size(),
- 2,
- "There should be two violations against the explicit defualt group"
- );
-
- constraintViolations = validator.validate( user, Billable.class );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violation against Billable"
- );
-
- constraintViolations = validator.validate( user, Default.class, Billable.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "There should be 3 violation against Default and Billable"
- );
-
- constraintViolations = validator.validate( user, BuyInOneClick.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "Three violations expected since BuyInOneClick extends Default and Billable"
- );
-
- constraintViolations = validator.validate( user, BuyInOneClick.class, Billable.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "BuyInOneClick already contains all other groups. Adding Billable does not change the number of violations"
- );
-
- constraintViolations = validator.validate( user, BuyInOneClick.class, Default.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "BuyInOneClick already contains all other groups. Adding Default does not change the number of violations"
- );
-
- constraintViolations = validator.validate( user, BuyInOneClick.class, Default.class, Billable.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "BuyInOneClick already contains all other groups. Adding Billable and Default does not change the number of violations"
- );
-
- constraintViolations = validator.validate( user, Billable.class, Billable.class );
- assertEquals(
- constraintViolations.size(),
- 1,
- "Adding the same group twice is still only leads to a single violation"
- );
- }
-
- /**
- * HV-85
- */
- @Test
- public void testGroupSequenceFollowedByGroup() {
- User user = new User();
- user.setFirstname( "Foo" );
- user.setLastname( "Bar" );
- user.setPhoneNumber( "+46 123-456" );
-
- Validator validator = TestUtil.getValidator();
-
- Set<ConstraintViolation<User>> constraintViolations = validator.validate(
- user, BuyInOneClick.class, Optional.class
- );
- assertEquals(
- constraintViolations.size(),
- 2,
- "There should be two violations against the implicit default group"
- );
-
- for ( ConstraintViolation<User> constraintViolation : constraintViolations ) {
- if ( constraintViolation.getPropertyPath().equals( "defaultCreditCard" ) ) {
- assertConstraintViolation(
- constraintViolation,
- "may not be null",
- User.class,
- null,
- "defaultCreditCard"
- );
- }
- else if ( constraintViolation.getPropertyPath().equals( "phoneNumber" ) ) {
- assertConstraintViolation(
- constraintViolation,
- "must match \"[0-9 -]?\"",
- User.class,
- "+46 123-456",
- "phoneNumber"
- );
- }
- else {
- fail( "Unexpected violation" );
- }
- }
- }
-
- /**
- * HV-113
- */
- @Test
- public void testRedefiningDefaultGroup() {
- Address address = new Address();
- address.setStreet( "Guldmyntgatan" );
- address.setCity( "Gothenborg" );
-
- Validator validator = TestUtil.getValidator();
-
- Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should only be one violation for zipcode"
- );
-
- ConstraintViolation<Address> violation = constraintViolations.iterator().next();
- assertConstraintViolation( violation, "may not be null", address.getClass(), null, "zipcode" );
-
- address.setZipcode( "41841" );
-
- // now the second group in the re-defined default group causes an error
- constraintViolations = validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should only be one violation for zipcode"
- );
-
- violation = constraintViolations.iterator().next();
- assertConstraintViolation( violation, "{validator.zipCodeCoherenceChecker}", address.getClass(), address, "" );
- }
-
- /**
- * HV-113
- */
- @Test
- public void testRedefiningDefaultGroup2() {
- Car car = new Car();
- car.setType( "A" );
-
- Validator validator = TestUtil.getValidator();
-
- Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default group"
- );
- assertEquals(
- "length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
-
- constraintViolations = validator.validateProperty( car, "type" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default group"
- );
- assertEquals(
- "length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
-
- constraintViolations = validator.validateValue( Car.class, "type", "A" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default group"
- );
- assertEquals(
- "length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
- }
-
- /**
- * HV-113
- */
- @Test
- public void testInvalidRedefinitionOfDefaultGroup() {
- Address address = new AddressWithInvalidGroupSequence();
- Validator validator = TestUtil.getValidator();
- try {
- validator.validate( address );
- fail( "It shoud not be allowed to have Default.class in the group sequence of a class." );
- }
- catch ( ValidationException e ) {
- assertEquals(
- "'Default.class' cannot appear in default group sequence list.", e.getMessage(), "Wrong message"
- );
- }
- }
-
- /**
- * HV-115
- */
- @Test
- public void testImplicitGroup() {
- Validator validator = TestUtil.getValidator();
- BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
- assertTrue( beanDescriptor.isBeanConstrained() );
-
- Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
- assertTrue( constraintProperties.size() == 5, "Each of the properties should have at least one constraint." );
-
- Order order = new Order();
- Set<ConstraintViolation<Order>> violations = validator.validate( order );
- assertTrue( violations.size() == 5, "All 5 NotNull constraints should fail." );
-
- // use implicit group Auditable
- violations = validator.validate( order, Auditable.class );
- assertTrue( violations.size() == 4, "All 4 NotNull constraints on Auditable should fail." );
- }
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Optional.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Optional.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Optional.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,9 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-/**
- * Validation group checking whether user is billable.
- *
- * @author Emmanuel Bernard
- */
-public interface Optional {
-}
\ No newline at end of file
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Order.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Order.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Order.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,54 +0,0 @@
-// $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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Order implements Auditable {
- private String creationDate;
- private String lastUpdate;
- private String lastModifier;
- private String lastReader;
- private String orderNumber;
-
- public String getCreationDate() {
- return this.creationDate;
- }
-
- public String getLastUpdate() {
- return this.lastUpdate;
- }
-
- public String getLastModifier() {
- return this.lastModifier;
- }
-
- public String getLastReader() {
- return this.lastReader;
- }
-
- @NotNull
- @Size(min = 10, max = 10)
- public String getOrderNumber() {
- return this.orderNumber;
- }
-}
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/User.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/User.java 2009-06-16 13:21:53 UTC (rev 16792)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/User.java 2009-06-16 14:17:45 UTC (rev 16793)
@@ -1,58 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Pattern;
-import javax.validation.groups.Default;
-
-
-/**
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-@GroupSequence({ User.class })
-public class User {
- @NotNull
- private String firstname;
-
- @NotNull(groups = Default.class)
- private String lastname;
-
- @Pattern(regexp = "[0-9 -]?", groups = Optional.class)
- private String phoneNumber;
-
- @NotNull(groups = { Billable.class, BuyInOneClick.class })
- private CreditCard defaultCreditCard;
-
- 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 getDefaultCreditCard() {
- return defaultCreditCard;
- }
-
- public void setDefaultCreditCard(CreditCard defaultCreditCard) {
- this.defaultCreditCard = defaultCreditCard;
- }
-
- public String getPhoneNumber() {
- return phoneNumber;
- }
-
- public void setPhoneNumber(String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
-}
\ No newline at end of file
15 years, 6 months
Hibernate SVN: r16792 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validation/util and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-16 09:21:53 -0400 (Tue, 16 Jun 2009)
New Revision: 16792
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyPath.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyPathTest.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyIterator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyIteratorTest.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/package.html
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
Log:
HV-163
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -17,8 +17,8 @@
*/
package org.hibernate.validation.engine;
+import javax.validation.ConstraintViolation;
import javax.validation.metadata.ConstraintDescriptor;
-import javax.validation.ConstraintViolation;
/**
* @author Emmanuel Bernard
@@ -35,7 +35,7 @@
private final Class<T> rootBeanClass;
- public ConstraintViolationImpl(String messageTemplate, String interpolatedMessage, Class<T> rootBeanClass,
+ public ConstraintViolationImpl(String messageTemplate, String interpolatedMessage, Class<T> rootBeanClass,
T rootBean, Object leafBeanInstance, Object value,
String propertyPath, ConstraintDescriptor constraintDescriptor) {
this.rawMessage = messageTemplate;
@@ -93,6 +93,7 @@
}
@Override
+ @SuppressWarnings("SimplifiableIfStatement")
public boolean equals(Object o) {
if ( this == o ) {
return true;
@@ -112,6 +113,9 @@
if ( rootBean != null ? !rootBean.equals( that.rootBean ) : that.rootBean != null ) {
return false;
}
+ if ( leafBeanInstance != null ? !leafBeanInstance.equals( that.leafBeanInstance ) : that.leafBeanInstance != null ) {
+ return false;
+ }
if ( value != null ? !value.equals( that.value ) : that.value != null ) {
return false;
}
@@ -122,9 +126,10 @@
@Override
public int hashCode() {
int result = interpolatedMessage != null ? interpolatedMessage.hashCode() : 0;
+ result = 31 * result + ( propertyPath != null ? propertyPath.hashCode() : 0 );
result = 31 * result + ( rootBean != null ? rootBean.hashCode() : 0 );
+ result = 31 * result + ( leafBeanInstance != null ? leafBeanInstance.hashCode() : 0 );
result = 31 * result + ( value != null ? value.hashCode() : 0 );
- result = 31 * result + ( propertyPath != null ? propertyPath.hashCode() : 0 );
return result;
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -253,7 +253,7 @@
}
}
- public void markCurrentPropertyAsIndexed() {
+ public void markCurrentPropertyAsIterable() {
String property = peekProperty();
property += "[]";
propertyPath.remove( propertyPath.size() - 1 );
@@ -284,6 +284,7 @@
return buildPath( propertyPath.size() - 2 );
}
+ @SuppressWarnings("SimplifiableIfStatement")
public boolean isValidationRequired(MetaConstraint metaConstraint) {
if ( !metaConstraint.getGroupList().contains( currentGroup ) ) {
return false;
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -28,14 +28,14 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.validation.metadata.BeanDescriptor;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.ConstraintViolation;
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
+import javax.validation.ValidationException;
import javax.validation.Validator;
-import javax.validation.ValidationException;
import javax.validation.groups.Default;
+import javax.validation.metadata.BeanDescriptor;
import com.googlecode.jtype.TypeUtils;
import org.slf4j.Logger;
@@ -45,7 +45,7 @@
import org.hibernate.validation.engine.groups.GroupChainGenerator;
import org.hibernate.validation.engine.resolver.SingleThreadCachedTraversableResolver;
import org.hibernate.validation.util.LoggerFactory;
-import org.hibernate.validation.util.PropertyIterator;
+import org.hibernate.validation.util.PropertyPath;
import org.hibernate.validation.util.ReflectionHelper;
/**
@@ -125,7 +125,7 @@
GroupChain groupChain = determineGroupExecutionOrder( groups );
List<ConstraintViolation<T>> failingConstraintViolations = new ArrayList<ConstraintViolation<T>>();
- validateProperty( object, new PropertyIterator( propertyName ), failingConstraintViolations, groupChain );
+ validateProperty( object, new PropertyPath( propertyName ), failingConstraintViolations, groupChain );
return new HashSet<ConstraintViolation<T>>( failingConstraintViolations );
}
@@ -140,7 +140,7 @@
GroupChain groupChain = determineGroupExecutionOrder( groups );
List<ConstraintViolation<T>> failingConstraintViolations = new ArrayList<ConstraintViolation<T>>();
- validateValue( beanType, value, new PropertyIterator( propertyName ), failingConstraintViolations, groupChain );
+ validateValue( beanType, value, new PropertyPath( propertyName ), failingConstraintViolations, groupChain );
return new HashSet<ConstraintViolation<T>>( failingConstraintViolations );
}
@@ -152,7 +152,7 @@
}
public <T> T unwrap(Class<T> type) {
- throw new ValidationException( "Type " + type + " not supported");
+ throw new ValidationException( "Type " + type + " not supported" );
}
private void sanityCheckPropertyPath(String propertyName) {
@@ -288,7 +288,8 @@
Object value = ReflectionHelper.getValue( member, context.peekCurrentBean() );
if ( value != null ) {
Iterator<?> iter = createIteratorForCascadedValue( context, type, value );
- validateCascadedConstraint( context, iter );
+ boolean isIndexable = isIndexable( type );
+ validateCascadedConstraint( context, iter, isIndexable );
}
}
context.popProperty();
@@ -309,17 +310,17 @@
Iterator<?> iter;
if ( ReflectionHelper.isIterable( type ) ) {
iter = ( ( Iterable<?> ) value ).iterator();
- context.markCurrentPropertyAsIndexed();
+ context.markCurrentPropertyAsIterable();
}
else if ( ReflectionHelper.isMap( type ) ) {
Map<?, ?> map = ( Map<?, ?> ) value;
iter = map.values().iterator();
- context.markCurrentPropertyAsIndexed();
+ context.markCurrentPropertyAsIterable();
}
else if ( TypeUtils.isArray( type ) ) {
List<?> arrayList = Arrays.asList( value );
iter = arrayList.iterator();
- context.markCurrentPropertyAsIndexed();
+ context.markCurrentPropertyAsIterable();
}
else {
List<Object> list = new ArrayList<Object>();
@@ -329,8 +330,30 @@
return iter;
}
+ /**
+ * Called when processing cascaded constraints. This methods inspects the type of the cascaded constraints and in case
+ * of a list or array creates an iterator in order to validate each element.
+ *
+ * @param type the type of the cascaded field or property.
+ *
+ * @return An iterator over the value of a cascaded property.
+ */
+ private boolean isIndexable(Type type) {
+ boolean isIndexable = false;
+ if ( ReflectionHelper.isList( type ) ) {
+ isIndexable = true;
+ }
+ else if ( ReflectionHelper.isMap( type ) ) {
+ isIndexable = true;
+ }
+ else if ( TypeUtils.isArray( type ) ) {
+ isIndexable = true;
+ }
+ return isIndexable;
+ }
+
@SuppressWarnings("RedundantArrayCreation")
- private <T> void validateCascadedConstraint(ExecutionContext<T> context, Iterator<?> iter) {
+ private <T> void validateCascadedConstraint(ExecutionContext<T> context, Iterator<?> iter, boolean isIndexable) {
Object actualValue;
String propertyIndex;
int i = 0;
@@ -346,7 +369,9 @@
}
if ( !context.isAlreadyValidated( actualValue ) ) {
- context.setPropertyIndex( propertyIndex );
+ if ( isIndexable ) {
+ context.setPropertyIndex( propertyIndex );
+ }
context.pushCurrentBean( actualValue );
GroupChain groupChain = groupChainGenerator.getGroupChainFor( Arrays.asList( new Class<?>[] { context.getCurrentGroup() } ) );
validateInContext( context, groupChain );
@@ -356,13 +381,15 @@
}
}
- private <T> void validateProperty(T object, PropertyIterator propertyIter, List<ConstraintViolation<T>> failingConstraintViolations, GroupChain groupChain) {
+ private <T> void validateProperty(T object, PropertyPath propertyPath, List<ConstraintViolation<T>> failingConstraintViolations, GroupChain groupChain) {
@SuppressWarnings("unchecked")
final Class<T> beanType = ( Class<T> ) object.getClass();
Set<MetaConstraint<T, ?>> metaConstraints = new HashSet<MetaConstraint<T, ?>>();
- Object hostingBeanInstance = collectMetaConstraintsForPath( beanType, object, propertyIter, metaConstraints );
+ Object hostingBeanInstance = collectMetaConstraintsForPath(
+ beanType, object, propertyPath.iterator(), metaConstraints
+ );
if ( hostingBeanInstance == null ) {
throw new IllegalArgumentException( "Invalid property path." );
@@ -379,7 +406,13 @@
while ( groupIterator.hasNext() ) {
Group group = groupIterator.next();
validatePropertyForGroup(
- object, propertyIter, failingConstraintViolations, metaConstraints, hostingBeanInstance, group, cachedResolver
+ object,
+ propertyPath,
+ failingConstraintViolations,
+ metaConstraints,
+ hostingBeanInstance,
+ group,
+ cachedResolver
);
}
@@ -389,7 +422,13 @@
int numberOfConstraintViolationsBefore = failingConstraintViolations.size();
for ( Group group : sequence ) {
validatePropertyForGroup(
- object, propertyIter, failingConstraintViolations, metaConstraints, hostingBeanInstance, group, cachedResolver
+ object,
+ propertyPath,
+ failingConstraintViolations,
+ metaConstraints,
+ hostingBeanInstance,
+ group,
+ cachedResolver
);
if ( failingConstraintViolations.size() > numberOfConstraintViolationsBefore ) {
@@ -401,7 +440,7 @@
private <T> void validatePropertyForGroup(
T object,
- PropertyIterator propertyIter,
+ PropertyPath propertyIter,
List<ConstraintViolation<T>> failingConstraintViolations,
Set<MetaConstraint<T, ?>> metaConstraints,
Object hostingBeanInstance,
@@ -443,9 +482,9 @@
}
@SuppressWarnings("unchecked")
- private <T> void validateValue(Class<T> beanType, Object value, PropertyIterator propertyIter, List<ConstraintViolation<T>> failingConstraintViolations, GroupChain groupChain) {
+ private <T> void validateValue(Class<T> beanType, Object value, PropertyPath propertyPath, List<ConstraintViolation<T>> failingConstraintViolations, GroupChain groupChain) {
Set<MetaConstraint<T, ?>> metaConstraints = new HashSet<MetaConstraint<T, ?>>();
- collectMetaConstraintsForPath( beanType, null, propertyIter, metaConstraints );
+ collectMetaConstraintsForPath( beanType, null, propertyPath.iterator(), metaConstraints );
if ( metaConstraints.size() == 0 ) {
return;
@@ -461,7 +500,7 @@
validateValueForGroup(
beanType,
value,
- propertyIter,
+ propertyPath,
failingConstraintViolations,
metaConstraints,
group,
@@ -478,7 +517,7 @@
validateValueForGroup(
beanType,
value,
- propertyIter,
+ propertyPath,
failingConstraintViolations,
metaConstraints,
group,
@@ -495,7 +534,7 @@
private <T> void validateValueForGroup(
Class<T> beanType,
Object value,
- PropertyIterator propertyIter,
+ PropertyPath propertyIter,
List<ConstraintViolation<T>> failingConstraintViolations,
Set<MetaConstraint<T, ?>> metaConstraints,
Group group,
@@ -546,22 +585,23 @@
* @return Returns the bean hosting the constraints which match the specified property path.
*/
@SuppressWarnings("unchecked")
- private <T> Object collectMetaConstraintsForPath(Class<T> clazz, Object value, PropertyIterator propertyIter, Set<MetaConstraint<T, ?>> metaConstraints) {
- propertyIter.split();
+ private <T> Object collectMetaConstraintsForPath(Class<T> clazz, Object value, Iterator<PropertyPath.PathElement> propertyIter, Set<MetaConstraint<T, ?>> metaConstraints) {
+ PropertyPath.PathElement elem = propertyIter.next();
final BeanMetaData<T> metaData = getBeanMetaData( clazz );
if ( !propertyIter.hasNext() ) {
+
//use metadata first as ReflectionHelper#containsMember is slow
//TODO store some metadata here?
- if ( metaData.getPropertyDescriptor( propertyIter.getHead() ) == null
- && !ReflectionHelper.containsMember( clazz, propertyIter.getHead() ) ) {
+ if ( metaData.getPropertyDescriptor( elem.value() ) == null
+ && !ReflectionHelper.containsMember( clazz, elem.value() ) ) {
//TODO better error report
throw new IllegalArgumentException( "Invalid property path." );
}
List<MetaConstraint<T, ? extends Annotation>> metaConstraintList = metaData.geMetaConstraintList();
for ( MetaConstraint<T, ?> metaConstraint : metaConstraintList ) {
- if ( metaConstraint.getPropertyName().equals( propertyIter.getHead() ) ) {
+ if ( metaConstraint.getPropertyName().equals( elem.value() ) ) {
metaConstraints.add( metaConstraint );
}
}
@@ -569,13 +609,13 @@
else {
List<Member> cascadedMembers = metaData.getCascadedMembers();
for ( Member m : cascadedMembers ) {
- if ( ReflectionHelper.getPropertyName( m ).equals( propertyIter.getHead() ) ) {
+ if ( ReflectionHelper.getPropertyName( m ).equals( elem.value() ) ) {
Type type = ReflectionHelper.typeOf( m );
value = value == null ? null : ReflectionHelper.getValue( m, value );
- if ( propertyIter.isIndexed() ) {
+ if ( elem.isIndexed() ) {
type = ReflectionHelper.getIndexedType( type );
value = value == null ? null : ReflectionHelper.getIndexedValue(
- value, propertyIter.getIndex()
+ value, elem.getIndex()
);
if ( type == null ) {
continue;
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyIterator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyIterator.java 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyIterator.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -1,102 +0,0 @@
-// $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.validation.util;
-
-/**
- * @author Hardy Ferentschik
- */
-
-/**
- * Helper class to iterate over a property. After constructing an instance of this class one can with
- * successive calls to <code>split()</code> split the property into a head and tail section. The head will contain the
- * property up to the first '.' and tail the rest. If head is an indexed value it is further seperated into its actual
- * value and index. For example, <code>new PropertyNavigator("order[2].orderNumer").split()</code> will result into:
- * <ul>
- * <li> <code>getHead() == "order"</code> </li>
- * <li> <code>getIndex() == "2"</code> </li>
- * <li> <code>getTail() == "orderNumber"</code> </li>
- * </ul>.
- */
-public class PropertyIterator {
- final String originalProperty;
- String head;
- String index;
- String tail;
-
- public PropertyIterator(String property) {
- this.originalProperty = property;
- if ("".equals( property ) ) {
- this.tail = null;
- } else {
- this.tail = property;
- }
- }
-
- public boolean hasNext() {
- return tail != null;
- }
-
- /**
- * Splits the property at the next '.'
- *
- * @todo Add error handling in case the property uses wrong characters or has unbalanced []
- */
- public void split() {
-
- if ( tail == null ) {
- return;
- }
-
- String[] tokens = tail.split( "\\.", 2 ); // split the property at the first .
-
- head = tokens[0];
- index = null;
-
- if ( head.contains( "[" ) ) {
- head = tokens[0].substring( 0, tokens[0].indexOf( "[" ) );
- index = tokens[0].substring( tokens[0].indexOf( "[" ) + 1, tokens[0].indexOf( "]" ) );
- }
-
- if ( tokens.length > 1 ) {
- tail = tokens[1];
- }
- else {
- tail = null;
- }
- }
-
- public String getOriginalProperty() {
- return originalProperty;
- }
-
- public String getHead() {
- return head;
- }
-
- public String getTail() {
- return tail;
- }
-
- public String getIndex() {
- return index;
- }
-
- public boolean isIndexed() {
- return index != null;
- }
-}
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyPath.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyPath.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyPath.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -0,0 +1,109 @@
+// $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.validation.util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+/**
+ * Helper class to iterate over a property path.
+ *
+ * @author Hardy Ferentschik
+ */
+public class PropertyPath implements Iterable<PropertyPath.PathElement> {
+
+ /**
+ * Regular expression used to split the path into its elements.
+ *
+ * @see <a href="http://www.regexplanet.com/simple/index.jsp">Regular expression tester</a>
+ */
+ private static final Pattern pathPattern = Pattern.compile( "(\\w+)(\\[(\\w+)\\])?(\\.(.*))*" );
+
+ final String originalProperty;
+
+ final List<PathElement> pathList = new ArrayList<PathElement>();
+
+ /**
+ * Constructs a new {@code PropertyPath}.
+ *
+ * @param property The string representation of the property path.
+ *
+ * @throws IllegalArgumentException in case {@code property == null} or {@code property} cannot be parsed.
+ */
+ public PropertyPath(String property) {
+ if ( property == null ) {
+ throw new IllegalArgumentException( "null is not allowed as property path." );
+ }
+
+ this.originalProperty = property;
+ if ( property.length() > 0 ) {
+ parseProperty( property );
+ }
+ }
+
+ private void parseProperty(String property) {
+ String tmp = property;
+ do {
+ Matcher matcher = pathPattern.matcher( tmp );
+ if ( matcher.matches() ) {
+ String value = matcher.group( 1 );
+ String index = matcher.group( 3 );
+ PathElement elem = new PathElement( value, index );
+ pathList.add( elem );
+ tmp = matcher.group( 5 );
+ }
+ else {
+ throw new IllegalArgumentException( "Unable to parse property path " + property );
+ }
+ } while ( tmp != null );
+ }
+
+ public String getOriginalProperty() {
+ return originalProperty;
+ }
+
+ public Iterator<PathElement> iterator() {
+ return pathList.iterator();
+ }
+
+ public static class PathElement {
+ private final String value;
+ private final String index;
+
+ private PathElement(String value, String index) {
+ this.value = value;
+ this.index = index;
+ }
+
+ public String value() {
+ return value;
+ }
+
+ public String getIndex() {
+ return index;
+ }
+
+ public boolean isIndexed() {
+ return index != null;
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyPath.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -243,7 +243,7 @@
* @return Returns <code>true</code> if <code>type</code> is a iterable type, <code>false</code> otherwise.
*/
public static boolean isIterable(Type type) {
- if ( type instanceof Class && isIterableClass( ( Class ) type ) ) {
+ if ( type instanceof Class && extendsOrImplements( ( Class ) type, Iterable.class ) ) {
return true;
}
if ( type instanceof ParameterizedType ) {
@@ -262,7 +262,7 @@
* @return Returns <code>true</code> if <code>type</code> is implementing <code>Map</code>, <code>false</code> otherwise.
*/
public static boolean isMap(Type type) {
- if ( type instanceof Class && isMapClass( ( Class ) type ) ) {
+ if ( type instanceof Class && extendsOrImplements( ( Class ) type, Map.class ) ) {
return true;
}
if ( type instanceof ParameterizedType ) {
@@ -276,6 +276,25 @@
}
/**
+ * @param type the type to check.
+ *
+ * @return Returns <code>true</code> if <code>type</code> is implementing <code>List</code>, <code>false</code> otherwise.
+ */
+ public static boolean isList(Type type) {
+ if ( type instanceof Class && extendsOrImplements( ( Class ) type, List.class ) ) {
+ return true;
+ }
+ if ( type instanceof ParameterizedType ) {
+ return isList( ( ( ParameterizedType ) type ).getRawType() );
+ }
+ if ( type instanceof WildcardType ) {
+ Type[] upperBounds = ( ( WildcardType ) type ).getUpperBounds();
+ return upperBounds.length != 0 && isList( upperBounds[0] );
+ }
+ return false;
+ }
+
+ /**
* Tries to retrieve the indexed value from the specified object.
*
* @param value The object from which to retrieve the indexed value. The object has to be non <code>null</null> and
@@ -438,7 +457,9 @@
* Returns the autoboxed type of a primitive type.
*
* @param primitiveType the primitive type
- * @return the autoboxed type of a primitive type.
+ *
+ * @return the autoboxed type of a primitive type.
+ *
* @throws IllegalArgumentException in case the parameter {@code primitiveType} does not represent a primitive type.
*/
public static Class<?> boxedTyp(Type primitiveType) {
@@ -494,28 +515,16 @@
}
/**
- * Checks whether the specified class parameter is an instance of a collection class.
+ * Checks whether the specified {@code clazz} extends or inherits the specified super class or interface.
*
- * @param clazz <code>Class</code> to check.
+ * @param clazz @{code Class} to check.
+ * @param superClassOrInterface The super class/interface {@code clazz}.
*
- * @return <code>true</code> is <code>clazz</code> is instance of a collection class, <code>false</code> otherwise.
+ * @return {@code true} if {@code clazz} extends or implements {@code superClassOrInterface}, {@code false} otherwise.
*/
- private static boolean isIterableClass(Class<?> clazz) {
+ private static boolean extendsOrImplements(Class<?> clazz, Class<?> superClassOrInterface) {
List<Class<?>> classes = new ArrayList<Class<?>>();
computeClassHierarchy( clazz, classes );
- return classes.contains( Iterable.class );
+ return classes.contains( superClassOrInterface );
}
-
- /**
- * Checks whether the specified class parameter is an instance of a collection class.
- *
- * @param clazz <code>Class</code> to check.
- *
- * @return <code>true</code> is <code>clazz</code> is instance of a collection class, <code>false</code> otherwise.
- */
- private static boolean isMapClass(Class<?> clazz) {
- List<Class<?>> classes = new ArrayList<Class<?>>();
- computeClassHierarchy( clazz, classes );
- return classes.contains( Map.class );
- }
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/package.html 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/package.html 2009-06-16 13:21:53 UTC (rev 16792)
@@ -21,6 +21,6 @@
-->
</head>
<body>
-This package contains helper independend helper classes.
+This package contains independend helper classes.
</body>
</html>
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -17,13 +17,10 @@
*/
package org.hibernate.validation.engine;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
import javax.validation.Valid;
-import org.hibernate.validation.engine.Order;
-import org.hibernate.validation.engine.Person;
-
/**
* @author Hardy Ferentschik
*/
@@ -34,14 +31,14 @@
private String lastName;
@Valid
- private List<Order> orderList = new ArrayList<Order>();
+ private Set<Order> orders = new HashSet<Order>();
public void addOrder(Order order) {
- orderList.add( order );
+ orders.add( order );
}
- public List<Order> getOrderList() {
- return orderList;
+ public Set<Order> getOrders() {
+ return orders;
}
public String getFirstName() {
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -159,7 +159,7 @@
assertEquals(
constraintViolations.size(),
3,
- "we should have been 2 not null violation for addresslines and one lenth violation for city"
+ "we should have been 2 not null violation for addresslines and one length violation for city"
);
constraintViolations = validator.validateProperty( address, "city" );
@@ -185,7 +185,7 @@
}
@Test
- public void testValidateList() {
+ public void testValidateSet() {
Validator validator = TestUtil.getValidator();
Customer customer = new Customer();
@@ -204,7 +204,7 @@
assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
- assertEquals( "orderList[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+ assertEquals( "orders[].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
}
@Test
@@ -248,7 +248,7 @@
assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
assertEquals(
- "playedWith[0].playedWith[1].lastName", constraintViolation.getPropertyPath(), "Wrong propertyName"
+ constraintViolation.getPropertyPath(), "playedWith[0].playedWith[1].lastName", "Wrong propertyName"
);
}
@@ -257,7 +257,7 @@
Validator validator = TestUtil.getValidator();
Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
- Customer.class, "orderList[0].orderNumber", null
+ Customer.class, "orders[0].orderNumber", null
);
assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
@@ -267,9 +267,9 @@
assertEquals( constraintViolation.getRootBean(), null, "Wrong root entity" );
assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
- assertEquals( "orderList[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+ assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
- constraintViolations = validator.validateValue( Customer.class, "orderList[0].orderNumber", 1234 );
+ constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
}
@@ -294,7 +294,7 @@
}
try {
- validator.validateValue( Customer.class, "orderList[0].foobar", null );
+ validator.validateValue( Customer.class, "orders[0].foobar", null );
fail();
}
catch ( IllegalArgumentException e ) {
@@ -311,7 +311,7 @@
customer.addOrder( order );
Set<ConstraintViolation<Customer>> constraintViolations = validator.validateProperty(
- customer, "orderList[0].orderNumber"
+ customer, "orders[0].orderNumber"
);
assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
@@ -320,7 +320,7 @@
assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
- assertEquals( "orderList[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+ assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
order.setOrderNumber( 1234 );
constraintViolations = validator.validateProperty( customer, "orderList[0].orderNumber" );
@@ -336,11 +336,11 @@
customer.addOrder( order );
try {
- validator.validateProperty( customer, "orderList[1].orderNumber" );
+ validator.validateProperty( customer, "orders[].orderNumber" );
fail();
}
catch ( IllegalArgumentException e ) {
- assertEquals( "Invalid property path.", e.getMessage() );
+ // success
}
try {
@@ -348,7 +348,7 @@
fail();
}
catch ( IllegalArgumentException e ) {
- assertEquals( "Invalid property path.", e.getMessage() );
+ // success
}
try {
@@ -356,15 +356,15 @@
fail();
}
catch ( IllegalArgumentException e ) {
- assertEquals( "Invalid property path.", e.getMessage() );
+ // success
}
try {
- validator.validateProperty( customer, "orderList[0].foobar" );
+ validator.validateProperty( customer, "orders[].foobar" );
fail();
}
catch ( IllegalArgumentException e ) {
- assertEquals( "Invalid property path.", e.getMessage() );
+ // success
}
}
@@ -392,7 +392,7 @@
"may not be null",
Customer.class,
null,
- "orderList[0].orderNumber"
+ "orders[].orderNumber"
);
order.setOrderNumber( 123 );
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyIteratorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyIteratorTest.java 2009-06-16 10:50:53 UTC (rev 16791)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyIteratorTest.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -1,89 +0,0 @@
-// $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.validation.util;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
-
-/**
- * @author Hardy Ferentschik
- */
-public class PropertyIteratorTest {
-
- @Test
- public void testSplit() {
- String property = "order[3].deliveryAddress.addressline[1]";
- PropertyIterator propIter = new PropertyIterator( property );
-
- assertTrue( propIter.hasNext() );
-
- propIter.split();
- assertTrue( propIter.hasNext() );
- assertEquals( "order", propIter.getHead() );
- assertTrue( propIter.isIndexed() );
- assertEquals( "3", propIter.getIndex() );
- assertEquals( "deliveryAddress.addressline[1]", propIter.getTail() );
- assertEquals( property, propIter.getOriginalProperty() );
-
- propIter.split();
- assertTrue( propIter.hasNext() );
- assertEquals( "deliveryAddress", propIter.getHead() );
- assertFalse( propIter.isIndexed() );
- assertEquals( null, propIter.getIndex() );
- assertEquals( "addressline[1]", propIter.getTail() );
- assertEquals( property, propIter.getOriginalProperty() );
-
- propIter.split();
- assertFalse( propIter.hasNext() );
- assertEquals( "addressline", propIter.getHead() );
- assertTrue( propIter.isIndexed() );
- assertEquals( "1", propIter.getIndex() );
- assertEquals( null, propIter.getTail() );
- assertEquals( property, propIter.getOriginalProperty() );
- }
-
- @Test
- public void testNull() {
- PropertyIterator propIter = new PropertyIterator( null );
- assertFalse( propIter.hasNext() );
-
- propIter.split();
- assertFalse( propIter.hasNext() );
- assertEquals( null, propIter.getHead() );
- assertFalse( propIter.isIndexed() );
- assertEquals( null, propIter.getIndex() );
- assertEquals( null, propIter.getTail() );
- assertEquals( null, propIter.getOriginalProperty() );
- }
-
- @Test
- public void testEmptyString() {
- PropertyIterator propIter = new PropertyIterator( "" );
- assertFalse( propIter.hasNext() );
-
- propIter.split();
- assertFalse( propIter.hasNext() );
- assertEquals( null, propIter.getHead() );
- assertFalse( propIter.isIndexed() );
- assertEquals( null, propIter.getIndex() );
- assertEquals( null, propIter.getTail() );
- assertEquals( "", propIter.getOriginalProperty() );
- }
-}
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyPathTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyPathTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyPathTest.java 2009-06-16 13:21:53 UTC (rev 16792)
@@ -0,0 +1,92 @@
+// $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.validation.util;
+
+import java.util.Iterator;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class PropertyPathTest {
+
+ @Test
+ public void testParsing() {
+ String property = "order[3].deliveryAddress.addressline[1]";
+ PropertyPath path = new PropertyPath( property );
+ Iterator<PropertyPath.PathElement> propIter = path.iterator();
+
+ assertTrue( propIter.hasNext() );
+
+ PropertyPath.PathElement elem = propIter.next();
+ assertTrue( propIter.hasNext() );
+ assertEquals( "order", elem.value() );
+ assertTrue( elem.isIndexed() );
+ assertEquals( "3", elem.getIndex() );
+ assertEquals( property, path.getOriginalProperty() );
+
+ assertTrue( propIter.hasNext() );
+ elem = propIter.next();
+ assertEquals( "deliveryAddress", elem.value() );
+ assertFalse( elem.isIndexed() );
+ assertEquals( null, elem.getIndex() );
+
+ assertTrue( propIter.hasNext() );
+ elem = propIter.next();
+ assertEquals( "addressline", elem.value() );
+ assertTrue( elem.isIndexed() );
+ assertEquals( "1", elem.getIndex() );
+
+ assertFalse( propIter.hasNext() );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNull() {
+ new PropertyPath( null );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testUnbalancedBraces() {
+ new PropertyPath( "foo[.bar" );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testIndexInMiddleOfProperty() {
+ new PropertyPath( "f[1]oo.bar" );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testTrailingPathSeperator() {
+ new PropertyPath( "foo.bar." );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testLeadingPathSeperator() {
+ new PropertyPath( ".foo.bar" );
+ }
+
+ @Test
+ public void testEmptyString() {
+ PropertyPath path = new PropertyPath( "" );
+ assertFalse( path.iterator().hasNext() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyPathTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
15 years, 6 months
Hibernate SVN: r16791 - in beanvalidation/trunk/validation-tck: src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-16 06:50:53 -0400 (Tue, 16 Jun 2009)
New Revision: 16791
Modified:
beanvalidation/trunk/validation-tck/pom.xml
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
Log:
Updated the testharness after API changes
Modified: beanvalidation/trunk/validation-tck/pom.xml
===================================================================
--- beanvalidation/trunk/validation-tck/pom.xml 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/pom.xml 2009-06-16 10:50:53 UTC (rev 16791)
@@ -46,7 +46,7 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
- <version>1.0.CR2</version>
+ <version>1.0.CR3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/CustomProviderResolverTest.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -21,9 +21,9 @@
import java.util.List;
import javax.validation.Configuration;
import javax.validation.Validation;
+import javax.validation.ValidationException;
import javax.validation.ValidationProviderResolver;
import javax.validation.ValidatorFactory;
-import javax.validation.ValidationException;
import javax.validation.bootstrap.ProviderSpecificBootstrap;
import javax.validation.spi.ValidationProvider;
@@ -31,12 +31,9 @@
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.IntegrationTest;
-import org.jboss.testharness.impl.packaging.Resource;
import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.assertEquals;
-import org.testng.annotations.Test;
import static org.testng.FileAssert.fail;
+import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
@@ -44,7 +41,6 @@
* @author Hardy Ferentschik
* @todo Review these tests. These tests are actually testing functionality within Validation. They should maybe be moved to
* the Bean Validation API itself!?
- *
*/
@Artifact(artifactType = ArtifactType.JSR303)
@Classes(TestUtil.class)
@@ -54,8 +50,8 @@
public void testCustomResolverAndType() {
ValidationProviderResolver resolver = new ValidationProviderResolver() {
- public List<ValidationProvider> getValidationProviders() {
- List<ValidationProvider> list = new ArrayList<ValidationProvider>();
+ public List<ValidationProvider<?>> getValidationProviders() {
+ List<ValidationProvider<?>> list = new ArrayList<ValidationProvider<?>>();
list.add( new TCKValidationProvider() );
return list;
}
@@ -63,20 +59,20 @@
TCKValidatorConfiguration configuration = Validation
- .byProvider( TCKValidatorConfiguration.class )
+ .byProvider( TCKValidationProvider.class )
.providerResolver( resolver )
.configure();
ValidatorFactory factory = configuration.buildValidatorFactory();
- assertTrue(factory instanceof TCKValidationProvider.DummyValidatorFactory);
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
}
@Test
public void testCustomResolver() {
ValidationProviderResolver resolver = new ValidationProviderResolver() {
- public List<ValidationProvider> getValidationProviders() {
- List<ValidationProvider> list = new ArrayList<ValidationProvider>();
+ public List<ValidationProvider<?>> getValidationProviders() {
+ List<ValidationProvider<?>> list = new ArrayList<ValidationProvider<?>>();
list.add( new TCKValidationProvider() );
return list;
}
@@ -87,21 +83,21 @@
.providerResolver( resolver )
.configure();
ValidatorFactory factory = configuration.buildValidatorFactory();
- assertTrue(factory instanceof TCKValidationProvider.DummyValidatorFactory);
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
}
@Test
public void testFailingCustomResolver() {
ValidationProviderResolver resolver = new ValidationProviderResolver() {
- public List<ValidationProvider> getValidationProviders() {
- return new ArrayList<ValidationProvider>();
+ public List<ValidationProvider<?>> getValidationProviders() {
+ return new ArrayList<ValidationProvider<?>>();
}
};
final ProviderSpecificBootstrap<TCKValidatorConfiguration> providerSpecificBootstrap =
Validation
- .byProvider( TCKValidatorConfiguration.class )
+ .byProvider( TCKValidationProvider.class )
.providerResolver( resolver );
try {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -49,7 +49,7 @@
@SpecAssertion(section = "4.4.4.2", id = "a")
})
public void testGetFactoryByProviderSpecifiedProgrammatically() {
- TCKValidatorConfiguration configuration = Validation.byProvider( TCKValidatorConfiguration.class ).configure();
+ TCKValidatorConfiguration configuration = Validation.byProvider( TCKValidationProvider.class ).configure();
ValidatorFactory factory = configuration.buildValidatorFactory();
assertNotNull( factory );
assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -19,7 +19,6 @@
import javax.validation.Configuration;
import javax.validation.MessageInterpolator;
-import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
@@ -30,26 +29,12 @@
/**
* @author Hardy Ferentschik
*/
-public class TCKValidationProvider implements ValidationProvider {
+public class TCKValidationProvider implements ValidationProvider<TCKValidatorConfiguration> {
- /**
- * {@inheritDoc}
- */
- public boolean isSuitable(Class<? extends Configuration<?>> builderClass) {
- return builderClass == TCKValidatorConfiguration.class;
+ public TCKValidatorConfiguration createSpecializedConfiguration(BootstrapState state) {
+ return TCKValidatorConfiguration.class.cast( new TCKValidatorConfiguration( this ) );
}
- public <T extends Configuration<T>> T createSpecializedConfiguration(BootstrapState state, Class<T> configurationClass) {
- if ( !isSuitable( configurationClass ) ) {
- throw new ValidationException(
- "Illegal call to createSpecializedConfiguration() for a non suitable provider"
- );
- }
- //cast protected by isSuitable call
- return configurationClass.cast( new TCKValidatorConfiguration( this ) );
- }
-
-
public Configuration<?> createGenericConfiguration(BootstrapState state) {
return new TCKValidatorConfiguration( this );
}
@@ -61,15 +46,19 @@
public static class DummyValidatorFactory implements ValidatorFactory {
public Validator getValidator() {
- return null;
+ throw new UnsupportedOperationException();
}
public ValidatorContext usingContext() {
- return null;
+ throw new UnsupportedOperationException();
}
public MessageInterpolator getMessageInterpolator() {
- return null;
+ throw new UnsupportedOperationException();
}
+
+ public <T> T unwrap(Class<T> type) {
+ throw new UnsupportedOperationException();
+ }
}
}
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -21,9 +21,9 @@
import java.util.Arrays;
import java.util.List;
import java.util.Set;
-import javax.validation.BeanDescriptor;
+import javax.validation.metadata.BeanDescriptor;
import javax.validation.ConstraintDefinitionException;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -18,7 +18,7 @@
package org.hibernate.jsr303.tck.tests.constraints.constraintdefinition;
import java.util.Set;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.validation.groups.Default;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -18,8 +18,8 @@
package org.hibernate.jsr303.tck.tests.metadata;
import java.util.Set;
-import javax.validation.BeanDescriptor;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import javax.validation.Validator;
import org.jboss.testharness.AbstractTest;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -20,7 +20,7 @@
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Set;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -18,9 +18,9 @@
package org.hibernate.jsr303.tck.tests.metadata;
import java.util.Set;
-import javax.validation.BeanDescriptor;
-import javax.validation.ConstraintDescriptor;
-import javax.validation.ElementDescriptor;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
import javax.validation.Validator;
import static org.testng.Assert.assertEquals;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-06-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -17,7 +17,7 @@
*/
package org.hibernate.jsr303.tck.tests.metadata;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
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-16 02:56:04 UTC (rev 16790)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-16 10:50:53 UTC (rev 16791)
@@ -21,10 +21,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
-import javax.validation.ElementDescriptor;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import javax.validation.Validation;
import javax.validation.Validator;
15 years, 6 months
Hibernate SVN: r16790 - beanvalidation/trunk/validation-api/src/main/java/javax/validation/bootstrap and 7 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-15 22:56:04 -0400 (Mon, 15 Jun 2009)
New Revision: 16790
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Configuration.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ValidationProviderResolver.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/bootstrap/ProviderSpecificBootstrap.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/ValidationProvider.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationBootstrapParameters.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationXmlParser.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/resolver/CachedTraversableResolverTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
Log:
BVAL-164 Validation.byProvider now accept the provider implementation class
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Configuration.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Configuration.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Configuration.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -43,10 +43,11 @@
* <p/>
* The provider is selected in the following way:
* <ul>
- * <li>if a specific <code>Configuration</code> subclass is requested programmatically using
- * <code>Validation.byProvider(Class)</code>, find the first provider matching it</li>
- * <li>if a specific <code>Configuration</code> subclass is defined in <i>META-INF/validation.xml</i>,
- * find the first provider matching it </li>
+ * <li>if a specific provider is requested programmatically using
+ * <code>Validation.byProvider(Class)</code>, find the first provider implementing
+ * the provider class requested and use it</li>
+ * <li>if a specific provider is requested in <i>META-INF/validation.xml</i>,
+ * find the first provider implementing the provider class requested and use it</li>
* <li>otherwise, use the first provider returned by the <code>ValidationProviderResolver<code></li>
* </ul>
* <p/>
@@ -128,7 +129,7 @@
* <p/>
* It is more appropriate to use, if available, the type-safe equivalent provided
* by a specific provider via its <code>Configuration<code> subclass.
- * <code>ValidatorFactory factory = Validation.byProvider(ACMEConfiguration.class)
+ * <code>ValidatorFactory factory = Validation.byProvider(ACMEPrivoder.class)
* .configure()
* .providerSpecificProperty(ACMEState.FAST)
* .buildValidatorFactory();
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -69,13 +69,12 @@
* <p/>
* <li>
* The third approach allows you to specify explicitly and in
- * a type safe fashion the expected provider by
- * using its specific <code>Configuration</code> sub-interface.
+ * a type safe fashion the expected provider.
*
* Optionally you can choose a custom <code>ValidationProviderResolver</code>.
* <pre>
* ACMEConfiguration configuration = Validation
- * .byProvider(ACMEConfiguration.class)
+ * .byProvider(ACMEProvider.class)
* .providerResolver( new MyResolverStrategy() ) // optionally set the provider resolver
* .configure();
* ValidatorFactory factory = configuration.buildValidatorFactory();
@@ -127,7 +126,7 @@
* </pre>
* The provider can be specified in the XML configuration. If the XML
* configuration does not exsist or if no provider is specified,
- * the first available provider will be returned.
+ * the first available provider will be returned.
*
* @return instance building a generic <code>Configuration</code>
* compliant with the bootstrap state provided.
@@ -144,34 +143,34 @@
* <p/>
* <pre>
* ACMEConfiguration configuration =
- * Validation.byProvider(ACMEConfiguration.class)
+ * Validation.byProvider(ACMEProvider.class)
* .providerResolver( new MyResolverStrategy() )
* .configure();
* </pre>,
* where <code>ACMEConfiguration</code> is the
* <code>Configuration</code> sub interface uniquely identifying the
- * ACME Bean Validation provider.
+ * ACME Bean Validation provider. and ACMEProvider is the ValidationProvider
+ * implementation of the ACME provider.
*
- * @param configurationType the <code>Configuration</code> sub interface
- * uniquely defining the targeted provider.
+ * @param providerType the <code>ValidationProvider</code> implementation type
*
* @return instance building a provider specific <code>Configuration</code>
* sub interface implementation.
*/
- public static <T extends Configuration<T>>
- ProviderSpecificBootstrap<T> byProvider(Class<T> configurationType) {
- return new ProviderSpecificBootstrapImpl<T>( configurationType );
+ public static <T extends Configuration<T>, U extends ValidationProvider<T>>
+ ProviderSpecificBootstrap<T> byProvider(Class<U> providerType) {
+ return new ProviderSpecificBootstrapImpl<T, U>( providerType );
}
//private class, not exposed
- private static class ProviderSpecificBootstrapImpl<T extends Configuration<T>>
+ private static class ProviderSpecificBootstrapImpl<T extends Configuration<T>, U extends ValidationProvider<T>>
implements ProviderSpecificBootstrap<T> {
- private final Class<T> configurationType;
+ private final Class<U> validationProviderClass;
private ValidationProviderResolver resolver;
- public ProviderSpecificBootstrapImpl(Class<T> configurationType) {
- this.configurationType = configurationType;
+ public ProviderSpecificBootstrapImpl(Class<U> validationProviderClass) {
+ this.validationProviderClass = validationProviderClass;
}
/**
@@ -194,11 +193,12 @@
* @return a Configuration sub interface implementation
*/
public T configure() {
- if ( configurationType == null ) {
+ if ( validationProviderClass == null ) {
throw new ValidationException(
"builder is mandatory. Use Validation.byDefaultProvider() to use the generic provider discovery mechanism"
);
}
+ //used mostly as a BootstrapState
GenericBootstrapImpl state = new GenericBootstrapImpl();
if ( resolver == null ) {
resolver = state.getDefaultValidationProviderResolver();
@@ -208,11 +208,13 @@
state.providerResolver( resolver );
}
for ( ValidationProvider provider : resolver.getValidationProviders() ) {
- if ( provider.isSuitable( configurationType ) ) {
- return provider.createSpecializedConfiguration( state, configurationType );
+ if ( validationProviderClass.isAssignableFrom( provider.getClass() ) ) {
+ ValidationProvider<T> specificProvider = validationProviderClass.cast( provider );
+ return specificProvider.createSpecializedConfiguration( state );
+
}
}
- throw new ValidationException( "Unable to find provider: " + configurationType );
+ throw new ValidationException( "Unable to find provider: " + validationProviderClass );
}
}
@@ -268,24 +270,24 @@
//cache per classloader for an appropriate discovery
//keep them in a weak hashmap to avoid memory leaks and allow proper hot redeployment
//TODO use a WeakConcurrentHashMap
- private static final Map<ClassLoader, List<ValidationProvider>> providersPerClassloader =
- new WeakHashMap<ClassLoader, List<ValidationProvider>>();
+ private static final Map<ClassLoader, List<ValidationProvider<?>>> providersPerClassloader =
+ new WeakHashMap<ClassLoader, List<ValidationProvider<?>>>();
private static final String SERVICES_FILE = "META-INF/services/" + ValidationProvider.class.getName();
- public List<ValidationProvider> getValidationProviders() {
+ public List<ValidationProvider<?>> getValidationProviders() {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
if ( classloader == null ) {
classloader = DefaultValidationProviderResolver.class.getClassLoader();
}
- List<ValidationProvider> providers;
+ List<ValidationProvider<?>> providers;
synchronized ( providersPerClassloader ) {
providers = providersPerClassloader.get( classloader );
}
if ( providers == null ) {
- providers = new ArrayList<ValidationProvider>();
+ providers = new ArrayList<ValidationProvider<?>>();
String name = null;
try {
Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE );
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ValidationProviderResolver.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ValidationProviderResolver.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ValidationProviderResolver.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -21,7 +21,7 @@
import javax.validation.spi.ValidationProvider;
/**
- * Determine the list of Bean Validation providers available in the runtime environment
+ * Determines the list of Bean Validation providers available in the runtime environment
* <p/>
* Bean Validation providers are identified by the presence of
* META-INF/services/javax.validation.spi.ValidationProvider
@@ -41,5 +41,5 @@
*
* @return list of validation providers.
*/
- List<ValidationProvider> getValidationProviders();
+ List<ValidationProvider<?>> getValidationProviders();
}
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/bootstrap/ProviderSpecificBootstrap.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/bootstrap/ProviderSpecificBootstrap.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/bootstrap/ProviderSpecificBootstrap.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -2,15 +2,18 @@
import javax.validation.ValidationProviderResolver;
import javax.validation.Configuration;
+import javax.validation.spi.ValidationProvider;
/**
* Defines the state used to bootstrap Bean Validation and
- * creates a provider specific Configuration. The specific Configuration
- * sub interface uniquely identifies a provider.
+ * creates a provider specific Configuration <code>T</code>.
* <p/>
- * The requested provider is the first provider suitable for T (as defined in
- * {@link javax.validation.spi.ValidationProvider#isSuitable(Class)}). The
- * list of providers evaluated is returned by {@link ValidationProviderResolver}.
+ * The specific Configuration is linked to the provider via the generic
+ * parameter of the ValidationProvider implementation.
+ * <p/>
+ * The requested provider is the first provider instance assignable to
+ * the requested provider type (known when ProviderSpecificBootstrap is built).
+ * The list of providers evaluated is returned by {@link ValidationProviderResolver}.
* If no ValidationProviderResolver is defined, the
* default ValidationProviderResolver strategy is used.
*
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/ValidationProvider.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/ValidationProvider.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/ValidationProvider.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -26,38 +26,26 @@
* Implementations must have a public no-arg constructor. The construction of a provider
* should be as "lightweight" as possible.
*
+ * <code>T</code> represents the provider specific Configuration subclass
+ * which typically host provider's additional configuration methods.
+ *
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
-public interface ValidationProvider {
- /**
- * Return true if <code>configurationClass</code> is the uniquely identifying
- * Configuration subclass for this provider
- *
- * @param configurationClass targeted configuration class.
- *
- * @return <code>true</code> if <code>configurationClass</code> is the Bean Validation Provider
- * sub-interface for Configuration
- */
- boolean isSuitable(Class<? extends Configuration<?>> configurationClass);
+public interface ValidationProvider<T extends Configuration<T>> {
/**
- * Returns a Configuration instance implementing the
- * <code>configurationClass</code> interface.
+ * Returns a Configuration instance implementing <code>T</code>,
+ * the <code>Configuration</code> subinterface.
* The returned Configuration instance must use the current provider (<code>this</code>)
* to build the ValidatorFactory instance.
* <p/>
- * This method can only be called on providers returning true on
- * <code>#isSuitable(configurationClass)</code>
*
- * @param configurationClass the Configuration class type
* @param state bootstrap state
*
* @return specific Configuration implementation
*/
- <T extends Configuration<T>> T createSpecializedConfiguration(
- BootstrapState state,
- Class<T> configurationClass);
+ T createSpecializedConfiguration(BootstrapState state);
/**
* Returns a Configuration instance. This instance is not bound to
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -34,20 +34,11 @@
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
-public class HibernateValidationProvider implements ValidationProvider {
+public class HibernateValidationProvider implements ValidationProvider<HibernateValidatorConfiguration> {
- public boolean isSuitable(Class<? extends Configuration<?>> builderClass) {
- return builderClass == HibernateValidatorConfiguration.class;
- }
-
- public <T extends Configuration<T>> T createSpecializedConfiguration(BootstrapState state, Class<T> configurationClass) {
- if ( !isSuitable( configurationClass ) ) {
- throw new ValidationException(
- "Illegal call to createSpecializedConfiguration() for a non suitable provider"
- );
- }
+ public HibernateValidatorConfiguration createSpecializedConfiguration(BootstrapState state) {
//cast protected by isSuitable call
- return configurationClass.cast( new ConfigurationImpl( this ) );
+ return HibernateValidatorConfiguration.class.cast( new ConfigurationImpl( this ) );
}
public Configuration<?> createGenericConfiguration(BootstrapState state) {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -119,19 +119,20 @@
factory = validationBootstrapParameters.provider.buildValidatorFactory( this );
}
else {
- if ( validationBootstrapParameters.providerClass != null ) {
+ final Class<? extends ValidationProvider<?>> providerClass = validationBootstrapParameters.providerClass;
+ if ( providerClass != null ) {
for ( ValidationProvider provider : providerResolver.getValidationProviders() ) {
- if ( provider.isSuitable( validationBootstrapParameters.providerClass ) ) {
+ if ( providerClass.isAssignableFrom( provider.getClass() ) ) {
factory = provider.buildValidatorFactory( this );
break;
}
}
if ( factory == null ) {
- throw new ValidationException( "Unable to find provider: " + validationBootstrapParameters.providerClass );
+ throw new ValidationException( "Unable to find provider: " + providerClass );
}
}
else {
- List<ValidationProvider> providers = providerResolver.getValidationProviders();
+ List<ValidationProvider<?>> providers = providerResolver.getValidationProviders();
assert providers.size() != 0; // I run therefore I am
factory = providers.get( 0 ).buildValidatorFactory( this );
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationBootstrapParameters.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationBootstrapParameters.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationBootstrapParameters.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -36,7 +36,7 @@
public MessageInterpolator messageInterpolator;
public TraversableResolver traversableResolver;
public ValidationProvider provider;
- public Class<? extends Configuration<?>> providerClass = null;
+ public Class<? extends ValidationProvider<?>> providerClass = null;
public final Map<String, String> configProperties = new HashMap<String, String>();
public final Set<InputStream> mappings = new HashSet<InputStream>();
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationXmlParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationXmlParser.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/ValidationXmlParser.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -24,6 +24,7 @@
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
import javax.validation.ValidationException;
+import javax.validation.spi.ValidationProvider;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
@@ -192,7 +193,7 @@
String providerClassName = config.getDefaultProvider();
if ( providerClassName != null ) {
try {
- xmlParamters.providerClass = ( Class<? extends Configuration<?>> ) ReflectionHelper.classForName(
+ xmlParamters.providerClass = ( Class<? extends ValidationProvider<?>> ) ReflectionHelper.classForName(
providerClassName, this.getClass()
);
log.info( "Using {} as validation provider.", providerClassName );
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -38,6 +38,7 @@
import org.hibernate.validation.engine.HibernateValidatorConfiguration;
import org.hibernate.validation.engine.ValidatorFactoryImpl;
import org.hibernate.validation.engine.Customer;
+import org.hibernate.validation.HibernateValidationProvider;
/**
* Tests the Bean Validation bootstrapping.
@@ -49,7 +50,7 @@
@Test
public void testBootstrapAsServiceWithBuilder() {
HibernateValidatorConfiguration configuration = Validation
- .byProvider( HibernateValidatorConfiguration.class )
+ .byProvider( HibernateValidationProvider.class )
.configure();
assertDefaultBuilderAndFactory( configuration );
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/resolver/CachedTraversableResolverTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/resolver/CachedTraversableResolverTest.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/resolver/CachedTraversableResolverTest.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -30,6 +30,7 @@
import static org.testng.Assert.*;
import org.hibernate.validation.engine.HibernateValidatorConfiguration;
+import org.hibernate.validation.HibernateValidationProvider;
/**
* @author Emmanuel Bernard
@@ -39,7 +40,7 @@
@Test
public void testCache() {
TraversableResolver resolver = new AskOnceTR();
- ValidatorFactory factory = Validation.byProvider( HibernateValidatorConfiguration.class )
+ ValidatorFactory factory = Validation.byProvider( HibernateValidationProvider.class )
.configure().traversableResolver( resolver )
.buildValidatorFactory();
Suit suit = new Suit();
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-06-15 21:41:42 UTC (rev 16789)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-06-16 02:56:04 UTC (rev 16790)
@@ -31,6 +31,7 @@
import static org.testng.Assert.assertTrue;
import org.hibernate.validation.engine.HibernateValidatorConfiguration;
+import org.hibernate.validation.HibernateValidationProvider;
/**
* Tests for the <code>ReflectionHelper</code>.
@@ -48,7 +49,7 @@
public static Validator getValidator() {
if ( hibernateValidator == null ) {
HibernateValidatorConfiguration configuration = Validation
- .byProvider( HibernateValidatorConfiguration.class )
+ .byProvider( HibernateValidationProvider.class )
.configure();
hibernateValidator = configuration.buildValidatorFactory().getValidator();
}
@@ -66,7 +67,7 @@
Thread.currentThread().setContextClassLoader( new CustomValidationXmlClassLoader( path ) );
HibernateValidatorConfiguration configuration = Validation
- .byProvider( HibernateValidatorConfiguration.class )
+ .byProvider( HibernateValidationProvider.class )
.configure();
return configuration.buildValidatorFactory().getValidator();
}
@@ -78,7 +79,7 @@
Thread.currentThread().setContextClassLoader( new IgnoringValidationXmlClassLoader() );
HibernateValidatorConfiguration configuration = Validation
- .byProvider( HibernateValidatorConfiguration.class )
+ .byProvider( HibernateValidationProvider.class )
.configure();
return configuration.buildValidatorFactory().getValidator();
}
15 years, 6 months
Hibernate SVN: r16789 - beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-15 17:41:42 -0400 (Mon, 15 Jun 2009)
New Revision: 16789
Added:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintPayload.java
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java
Log:
BVAL-163 constraint payload
Added: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintPayload.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintPayload.java (rev 0)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintPayload.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -0,0 +1,15 @@
+package javax.validation;
+
+/**
+ * Payload type that can be attached to a given
+ * constraint declaration.
+ * Payloads are typically used to carry on metadata information
+ * consumed by a validation client.
+ *
+ * Use of payloads is not considered portable.
+ *
+ * @author Emmanuel Bernard
+ * @author Gerhard Petracek
+ */
+public interface ConstraintPayload {
+}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be false.
@@ -43,6 +44,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* Defines several @AssertFalse annotations on the same element
* @see javax.validation.constraints.AssertFalse
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be true.
@@ -43,6 +44,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* Defines several @AssertTrue annotations on the same element
* @see AssertTrue
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be a number whose value must be lower or
@@ -54,6 +55,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* The String representation of the max value according to the
* BigDecimal string representation
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be a number whose value must be higher or
@@ -54,6 +55,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* The String representation of the min value according to the
* BigDecimal string representation
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be a number within accepted range
@@ -51,6 +52,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* @return maximum number of integral digits accepted for this number.
*/
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be a date in the future.
@@ -51,6 +52,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* Defines several @Future annotations on the same element
* @see {@link Future}
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be a number whose value must be lower or
@@ -53,6 +54,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* @return value the element must be lower or equal to
*/
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be a number whose value must be higher or
@@ -53,6 +54,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* @return value the element must be higher or equal to
*/
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must not be <code>null</code>.
@@ -41,6 +42,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* Defines several @NotNull annotations on the same element
* @see javax.validation.constraints.NotNull
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be null.
@@ -41,6 +42,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* Defines several @Null annotations on the same element
* @see javax.validation.constraints.Null
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element must be a date in the past.
@@ -51,6 +52,8 @@
Class<?>[] groups() default { };
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* Defines several @Past annotations on the same element
* @see {@link Past}
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated String must match the following regular expression.
@@ -61,6 +62,11 @@
Class<?>[] groups() default { };
/**
+ * @return The payload associated to the constraint
+ */
+ Class<? extends ConstraintPayload>[] payload() default {};
+
+ /**
* Possible Regexp flags
*/
public static enum Flag {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -25,6 +25,7 @@
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
/**
* The annotated element size must be between the specified boundaries (included).
@@ -46,8 +47,11 @@
@Constraint(validatedBy = {})
public @interface Size {
String message() default "{javax.validation.constraints.Size.message}";
+
Class<?>[] groups() default {};
+ Class<? extends ConstraintPayload>[] payload() default {};
+
/**
* @return size the element must be higher or equal to
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java 2009-06-15 18:03:30 UTC (rev 16788)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java 2009-06-15 21:41:42 UTC (rev 16789)
@@ -28,6 +28,7 @@
import java.util.SortedMap;
import java.util.TreeSet;
import javax.validation.ValidationException;
+import javax.validation.ConstraintPayload;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
@@ -136,6 +137,12 @@
return new Class<?>[] { Default.class };
}
+ public Class<? extends ConstraintPayload>[] payload() {
+ @SuppressWarnings( "unchecked")
+ Class<? extends ConstraintPayload>[] classes = new Class[] { };
+ return classes;
+ }
+
public Class<? extends Annotation> annotationType() {
return this.getClass();
}
15 years, 6 months
Hibernate SVN: r16788 - beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-15 14:03:30 -0400 (Mon, 15 Jun 2009)
New Revision: 16788
Added:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/BeanDescriptor.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ConstraintDescriptor.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ElementDescriptor.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/PropertyDescriptor.java
Removed:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolation.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaData.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ElementDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MessageInterpolatorContext.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PropertyDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/custom/CustomConstraintValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/inheritance/InheritanceTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
Log:
Move metadata classes to the metadata package (BeanDescriptor, ElementDescriptor, PropertyDescriptor, ConstraintDescriptor)
Deleted: beanvalidation/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -1,59 +0,0 @@
-// $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 javax.validation;
-
-import java.util.Set;
-
-/**
- * Describe a constrained Java Bean and the constraints associated to it.
- *
- * @author Emmanuel Bernard
- */
-public interface BeanDescriptor extends ElementDescriptor {
- /**
- * Returns true if the bean involves validation:
- * <ul>
- * <li> a constraint is hosted on the bean itself </li>
- * <li> a constraint is hosted on one of the bean properties </li>
- * <li> or a bean property is marked for cascade (@Valid) </li>
- * </ul>
- *
- * @return <code>true</code> if the bean involves validation, <code>false</code> otherwise.
- */
- boolean isBeanConstrained();
-
- /**
- * Return the property descriptor for a given property.
- * Return <code>null</code> if the property does not exist or has no
- * constraint nor is marked as cascaded (see {@link #getConstrainedProperties()} )
- * <p/>
- * The returned object (and associated objects including ConstraintDescriptors)
- * are immutable.
- *
- * @param propertyName property evaludated
- *
- * @return the property descriptor for a given property.
- */
- PropertyDescriptor getConstraintsForProperty(String propertyName);
-
- /**
- * @return the property descriptors having at least one constraint defined or which are marked
- * as cascaded (@Valid) or an empty set.
- */
- Set<PropertyDescriptor> getConstrainedProperties();
-}
Deleted: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -1,85 +0,0 @@
-// $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 javax.validation;
-
-import java.lang.annotation.Annotation;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Describes a single constraint and its composing constraints.
- * T is the constraint's annotation type.
- *
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-public interface ConstraintDescriptor<T extends Annotation> {
- /**
- * Returns the annotation describing the constraint declaration.
- * If a composing constraint, attribute values are reflecting
- * the overridden attributes of the composing constraint
- *
- * @return The annotation for this constraint.
- */
- T getAnnotation();
-
- /**
- * The Set of groups the constraint is applied on.
- * If the constraint declares no group, a set with only the <code>Default</code>
- * group is returned.
- *
- * @return The groups the constraint is applied on.
- */
- Set<Class<?>> getGroups();
-
- /**
- * Immutable list of the constraint validation implementation classes.
- *
- * @return list of the constraint validation implementation classes.
- */
- List<Class<? extends ConstraintValidator<T, ?>>>
- getConstraintValidatorClasses();
-
- /**
- * Returns a map containing the annotation attribute names as keys and the
- * annotation attribute values as value.
- * If this constraint is used as part of a composed constraint, attribute
- * values are reflecting the overridden attribute of the composing constraint.
- *
- * @return a map containing the annotation attribute names as keys
- * and the annotation attribute values as value.
- */
- Map<String, Object> getAttributes();
-
- /**
- * Return a set of composing <code>ConstraintDescriptor</code>s where each
- * descriptor describes a composing constraint. <code>ConstraintDescriptor</code>
- * instances of composing constraints reflect overridden attribute values in
- * {@link #getAttributes()} and {@link #getAnnotation()}.
- *
- * @return a set of <code>ConstraintDescriptor<code> objects or an empty set
- * in case there are no composing constraints.
- */
- Set<ConstraintDescriptor<?>> getComposingConstraints();
-
- /**
- * @return true if the constraint is annotated with @ReportAsSingleViolation
- */
- boolean isReportAsSingleViolation();
-}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolation.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolation.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolation.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -17,7 +17,7 @@
*/
package javax.validation;
-import java.util.Set;
+import javax.validation.metadata.ConstraintDescriptor;
/**
* Describe a constraint violation. This object describe the error context as
Deleted: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -1,49 +0,0 @@
-// $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 javax.validation;
-
-import java.util.Set;
-
-/**
- * Describes a validated element (class, field or property).
- *
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-public interface ElementDescriptor {
-
- /**
- * @return <code>true</code> if at least one constraint declaration is present on the element, <code>false</code> otherwise.
- */
- boolean hasConstraints();
-
- /**
- * @return Statically defined returned type.
- *
- * @todo should it be Type or even completly removed
- */
- Class<?> getType();
-
- /**
- * Return all constraint descriptors for this element or an
- * empty Set if none are present.
- *
- * @return Set of constraint descriptors for this element
- */
- Set<ConstraintDescriptor<?>> getConstraintDescriptors();
-}
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -18,6 +18,7 @@
package javax.validation;
import java.util.Locale;
+import javax.validation.metadata.ConstraintDescriptor;
/**
* Interpolate a given constraint error message.
Deleted: beanvalidation/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -1,23 +0,0 @@
-package javax.validation;
-
-/**
- * Describes a Java Bean property hosting validation constraints.
- *
- * Constraints placed on the attribute and the getter of a given property
- * are all referenced by this object.
- *
- * @author Emmanuel Bernard
- */
-public interface PropertyDescriptor extends ElementDescriptor {
- /**
- * Is the property marked by the <code>@Valid</code> annotation.
- * @return <code>true</code> if the annotation is present, <code>false</code> otherwise.
- */
- boolean isCascaded();
-
- /**
- * Name of the property acording to the Java Bean specification.
- * @return property name.
- */
- String getPropertyName();
-}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -18,6 +18,7 @@
package javax.validation;
import java.util.Set;
+import javax.validation.metadata.BeanDescriptor;
/**
* Validate bean instances. Implementations of this interface must be thread-safe.
Copied: beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/BeanDescriptor.java (from rev 16786, beanvalidation/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java)
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/BeanDescriptor.java (rev 0)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/BeanDescriptor.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -0,0 +1,59 @@
+// $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 javax.validation.metadata;
+
+import java.util.Set;
+
+/**
+ * Describe a constrained Java Bean and the constraints associated to it.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface BeanDescriptor extends ElementDescriptor {
+ /**
+ * Returns true if the bean involves validation:
+ * <ul>
+ * <li> a constraint is hosted on the bean itself </li>
+ * <li> a constraint is hosted on one of the bean properties </li>
+ * <li> or a bean property is marked for cascade (@Valid) </li>
+ * </ul>
+ *
+ * @return <code>true</code> if the bean involves validation, <code>false</code> otherwise.
+ */
+ boolean isBeanConstrained();
+
+ /**
+ * Return the property descriptor for a given property.
+ * Return <code>null</code> if the property does not exist or has no
+ * constraint nor is marked as cascaded (see {@link #getConstrainedProperties()} )
+ * <p/>
+ * The returned object (and associated objects including ConstraintDescriptors)
+ * are immutable.
+ *
+ * @param propertyName property evaludated
+ *
+ * @return the property descriptor for a given property.
+ */
+ PropertyDescriptor getConstraintsForProperty(String propertyName);
+
+ /**
+ * @return the property descriptors having at least one constraint defined or which are marked
+ * as cascaded (@Valid) or an empty set.
+ */
+ Set<PropertyDescriptor> getConstrainedProperties();
+}
Property changes on: beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/BeanDescriptor.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ConstraintDescriptor.java (from rev 16786, beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java)
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ConstraintDescriptor.java (rev 0)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ConstraintDescriptor.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -0,0 +1,86 @@
+// $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 javax.validation.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.validation.ConstraintValidator;
+
+/**
+ * Describes a single constraint and its composing constraints.
+ * T is the constraint's annotation type.
+ *
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+public interface ConstraintDescriptor<T extends Annotation> {
+ /**
+ * Returns the annotation describing the constraint declaration.
+ * If a composing constraint, attribute values are reflecting
+ * the overridden attributes of the composing constraint
+ *
+ * @return The annotation for this constraint.
+ */
+ T getAnnotation();
+
+ /**
+ * The Set of groups the constraint is applied on.
+ * If the constraint declares no group, a set with only the <code>Default</code>
+ * group is returned.
+ *
+ * @return The groups the constraint is applied on.
+ */
+ Set<Class<?>> getGroups();
+
+ /**
+ * Immutable list of the constraint validation implementation classes.
+ *
+ * @return list of the constraint validation implementation classes.
+ */
+ List<Class<? extends ConstraintValidator<T, ?>>>
+ getConstraintValidatorClasses();
+
+ /**
+ * Returns a map containing the annotation attribute names as keys and the
+ * annotation attribute values as value.
+ * If this constraint is used as part of a composed constraint, attribute
+ * values are reflecting the overridden attribute of the composing constraint.
+ *
+ * @return a map containing the annotation attribute names as keys
+ * and the annotation attribute values as value.
+ */
+ Map<String, Object> getAttributes();
+
+ /**
+ * Return a set of composing <code>ConstraintDescriptor</code>s where each
+ * descriptor describes a composing constraint. <code>ConstraintDescriptor</code>
+ * instances of composing constraints reflect overridden attribute values in
+ * {@link #getAttributes()} and {@link #getAnnotation()}.
+ *
+ * @return a set of <code>ConstraintDescriptor<code> objects or an empty set
+ * in case there are no composing constraints.
+ */
+ Set<ConstraintDescriptor<?>> getComposingConstraints();
+
+ /**
+ * @return true if the constraint is annotated with @ReportAsSingleViolation
+ */
+ boolean isReportAsSingleViolation();
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ConstraintDescriptor.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ElementDescriptor.java (from rev 16786, beanvalidation/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java)
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ElementDescriptor.java (rev 0)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ElementDescriptor.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -0,0 +1,49 @@
+// $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 javax.validation.metadata;
+
+import java.util.Set;
+
+/**
+ * Describes a validated element (class, field or property).
+ *
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+public interface ElementDescriptor {
+
+ /**
+ * @return <code>true</code> if at least one constraint declaration is present on the element, <code>false</code> otherwise.
+ */
+ boolean hasConstraints();
+
+ /**
+ * @return Statically defined returned type.
+ *
+ * @todo should it be Type or even completly removed
+ */
+ Class<?> getType();
+
+ /**
+ * Return all constraint descriptors for this element or an
+ * empty Set if none are present.
+ *
+ * @return Set of constraint descriptors for this element
+ */
+ Set<ConstraintDescriptor<?>> getConstraintDescriptors();
+}
Property changes on: beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/ElementDescriptor.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/PropertyDescriptor.java (from rev 16786, beanvalidation/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java)
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/PropertyDescriptor.java (rev 0)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/PropertyDescriptor.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -0,0 +1,23 @@
+package javax.validation.metadata;
+
+/**
+ * Describes a Java Bean property hosting validation constraints.
+ *
+ * Constraints placed on the attribute and the getter of a given property
+ * are all referenced by this object.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface PropertyDescriptor extends ElementDescriptor {
+ /**
+ * Is the property marked by the <code>@Valid</code> annotation.
+ * @return <code>true</code> if the annotation is present, <code>false</code> otherwise.
+ */
+ boolean isCascaded();
+
+ /**
+ * Name of the property acording to the Java Bean specification.
+ * @return property name.
+ */
+ String getPropertyName();
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-api/src/main/java/javax/validation/metadata/PropertyDescriptor.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanDescriptorImpl.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanDescriptorImpl.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -1,8 +1,8 @@
package org.hibernate.validation.engine;
import java.util.Set;
-import javax.validation.BeanDescriptor;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
/**
* @author Emmanuel Bernard
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaData.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaData.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaData.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -21,8 +21,8 @@
import java.lang.reflect.Member;
import java.util.List;
import java.util.Set;
-import javax.validation.BeanDescriptor;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
/**
* Interface defining the meta data about the constraints defined in a given bean.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -30,9 +30,9 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.validation.BeanDescriptor;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import javax.validation.GroupSequence;
-import javax.validation.PropertyDescriptor;
import javax.validation.Valid;
import javax.validation.ValidationException;
import javax.validation.groups.Default;
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -30,7 +30,7 @@
import java.util.Set;
import javax.validation.Constraint;
import javax.validation.ConstraintDefinitionException;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintValidator;
import javax.validation.OverridesAttribute;
import javax.validation.ReportAsSingleViolation;
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -24,7 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.ConstraintViolation;
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorContextImpl.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -19,7 +19,7 @@
import java.util.ArrayList;
import java.util.List;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintValidatorContext;
/**
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -17,7 +17,7 @@
*/
package org.hibernate.validation.engine;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
/**
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ElementDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ElementDescriptorImpl.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ElementDescriptorImpl.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -20,8 +20,8 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-import javax.validation.ConstraintDescriptor;
-import javax.validation.ElementDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
/**
* Describe a validated element (class, field or property).
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -28,7 +28,7 @@
import java.lang.reflect.Member;
import java.lang.reflect.Field;
import java.lang.annotation.ElementType;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.ConstraintViolation;
import javax.validation.MessageInterpolator;
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MessageInterpolatorContext.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MessageInterpolatorContext.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MessageInterpolatorContext.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -1,6 +1,6 @@
package org.hibernate.validation.engine;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.MessageInterpolator;
/**
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -20,18 +20,15 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.reflect.Field;
-import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
-import com.googlecode.jtype.TypeUtils;
-
import org.hibernate.validation.util.ReflectionHelper;
/**
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PropertyDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PropertyDescriptorImpl.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/PropertyDescriptorImpl.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -17,7 +17,7 @@
*/
package org.hibernate.validation.engine;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
/**
* Describe a validated element (class, field or property).
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -28,7 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.validation.BeanDescriptor;
+import javax.validation.metadata.BeanDescriptor;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.ConstraintViolation;
import javax.validation.MessageInterpolator;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/custom/CustomConstraintValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/custom/CustomConstraintValidatorTest.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/custom/CustomConstraintValidatorTest.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -21,7 +21,7 @@
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ConstraintViolation;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -18,10 +18,10 @@
package org.hibernate.validation.engine;
import java.util.Set;
-import javax.validation.BeanDescriptor;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.groups.Default;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -18,9 +18,9 @@
package org.hibernate.validation.engine.groups;
import java.util.Set;
-import javax.validation.BeanDescriptor;
+import javax.validation.metadata.BeanDescriptor;
import javax.validation.ConstraintViolation;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.groups.Default;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/inheritance/InheritanceTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/inheritance/InheritanceTest.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/inheritance/InheritanceTest.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -18,8 +18,8 @@
package org.hibernate.validation.engine.inheritance;
import java.lang.annotation.Annotation;
-import javax.validation.BeanDescriptor;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-06-15 17:54:38 UTC (rev 16787)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-06-15 18:03:30 UTC (rev 16788)
@@ -19,10 +19,10 @@
import java.io.InputStream;
import java.util.Set;
-import javax.validation.ConstraintDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
-import javax.validation.ElementDescriptor;
-import javax.validation.PropertyDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import javax.validation.Validation;
import javax.validation.Validator;
15 years, 6 months
Hibernate SVN: r16787 - in beanvalidation/trunk/validation-api/src/main/java/javax/validation: constraints and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-15 13:54:38 -0400 (Mon, 15 Jun 2009)
New Revision: 16787
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java
Log:
Minor
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-06-15 13:34:25 UTC (rev 16786)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-06-15 17:54:38 UTC (rev 16787)
@@ -167,7 +167,7 @@
private static class ProviderSpecificBootstrapImpl<T extends Configuration<T>>
implements ProviderSpecificBootstrap<T> {
- private Class<T> configurationType;
+ private final Class<T> configurationType;
private ValidationProviderResolver resolver;
public ProviderSpecificBootstrapImpl(Class<T> configurationType) {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java 2009-06-15 13:34:25 UTC (rev 16786)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java 2009-06-15 17:54:38 UTC (rev 16787)
@@ -108,7 +108,7 @@
CANON_EQ(java.util.regex.Pattern.CANON_EQ);
//JDK flag value
- private int value;
+ private final int value;
private Flag(int value) {
this.value = value;
15 years, 6 months
Hibernate SVN: r16786 - in validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation: engine and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-15 09:34:25 -0400 (Mon, 15 Jun 2009)
New Revision: 16786
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java
Log:
Tests updates
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-06-15 09:39:23 UTC (rev 16785)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-06-15 13:34:25 UTC (rev 16786)
@@ -37,7 +37,7 @@
import org.hibernate.validation.engine.ConstraintValidatorFactoryImpl;
import org.hibernate.validation.engine.HibernateValidatorConfiguration;
import org.hibernate.validation.engine.ValidatorFactoryImpl;
-import org.hibernate.validation.engine.metadata.Customer;
+import org.hibernate.validation.engine.Customer;
/**
* Tests the Bean Validation bootstrapping.
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java 2009-06-15 13:34:25 UTC (rev 16786)
@@ -0,0 +1,70 @@
+// $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.validation.engine;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.Valid;
+
+import org.hibernate.validation.engine.Order;
+import org.hibernate.validation.engine.Person;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Customer implements Person {
+
+ private String firstName;
+ private String middleName;
+ private String lastName;
+
+ @Valid
+ private List<Order> orderList = new ArrayList<Order>();
+
+ public void addOrder(Order order) {
+ orderList.add( order );
+ }
+
+ public List<Order> getOrderList() {
+ return orderList;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ public void setMiddleName(String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-06-15 09:39:23 UTC (rev 16785)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-06-15 13:34:25 UTC (rev 16786)
@@ -32,7 +32,6 @@
import static org.testng.Assert.fail;
import org.testng.annotations.Test;
-import org.hibernate.validation.engine.metadata.Customer;
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.TestUtil;
import static org.hibernate.validation.util.TestUtil.assertConstraintViolation;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java 2009-06-15 09:39:23 UTC (rev 16785)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java 2009-06-15 13:34:25 UTC (rev 16786)
@@ -24,10 +24,11 @@
import javax.validation.ConstraintValidator;
import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.Test;
-import org.hibernate.validation.constraints.composition.FrenchZipcode;
-import org.hibernate.validation.constraints.composition.FrenchZipcodeConstraintValidator;
+import org.hibernate.validation.constraints.custom.Positive;
+import org.hibernate.validation.constraints.custom.PositiveConstraintValidator;
/**
* Tests for message resolution.
@@ -38,11 +39,13 @@
@Test
public void testTypeDiscovery() {
- List<Class<? extends ConstraintValidator<FrenchZipcode, ?>>> validators =
- new ArrayList<Class<? extends ConstraintValidator<FrenchZipcode, ?>>>();
- validators.add( FrenchZipcodeConstraintValidator.class );
+ List<Class<? extends ConstraintValidator<Positive, ?>>> validators =
+ new ArrayList<Class<? extends ConstraintValidator<Positive, ?>>>();
+ validators.add( PositiveConstraintValidator.class );
Map<Type, Class<? extends ConstraintValidator<?, ?>>> validatorsTypes = ValidatorTypeHelper
.getValidatorsTypes( validators );
- assertEquals( FrenchZipcodeConstraintValidator.class, validatorsTypes.get( String.class ) );
+
+ assertEquals( validatorsTypes.get( Integer.class ), PositiveConstraintValidator.class );
+ assertNull( validatorsTypes.get( String.class ) );
}
}
\ No newline at end of file
15 years, 6 months
Hibernate SVN: r16785 - search/trunk/hibernate-search-archetype/src/main/resources/META-INF/maven.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-15 05:39:23 -0400 (Mon, 15 Jun 2009)
New Revision: 16785
Added:
search/trunk/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
Log:
new config file for the archetye. The old format via archetype.xml is obsolete
Added: search/trunk/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
===================================================================
--- search/trunk/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml (rev 0)
+++ search/trunk/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml 2009-06-15 09:39:23 UTC (rev 16785)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?><archetype-descriptor name="hibernate-validator-quickstart">
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.xml</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/test/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</archetype-descriptor>
Property changes on: search/trunk/hibernate-search-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
15 years, 6 months