Hibernate SVN: r16853 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-22 09:53:50 -0400 (Mon, 22 Jun 2009)
New Revision: 16853
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
Log:
minor
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-22 13:41:18 UTC (rev 16852)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-06-22 13:53:50 UTC (rev 16853)
@@ -38,7 +38,7 @@
*
* @throws IllegalArgumentException if object is null
* or if null is passed to the varargs groups
- * @throws ValidationException if a non recoverable error happens
+ * @throws ValidationException if a non recoverable error happens
* during the validation process
*/
<T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups);
15 years, 5 months
Hibernate SVN: r16852 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-22 09:41:18 -0400 (Mon, 22 Jun 2009)
New Revision: 16852
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
Log:
HV-173 Made sure that the value is case to Object[]
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-22 11:37:29 UTC (rev 16851)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-22 13:41:18 UTC (rev 16852)
@@ -193,8 +193,6 @@
return Collections.emptyList();
}
- //FIXME if context not accessible do not call isTraversable??
-
// process all groups breadth-first
Iterator<Group> groupIterator = groupChain.getGroupIterator();
while ( groupIterator.hasNext() ) {
@@ -282,7 +280,6 @@
}
//this method must always be called after validateConstraints for the same context
- //TODO define a validate that calls validateConstraints and then validateCascadedConstraints
private <T> void validateCascadedConstraints(ExecutionContext<T> context) {
List<Member> cascadedMembers = getBeanMetaData( context.peekCurrentBeanType() )
.getCascadedMembers();
@@ -323,7 +320,7 @@
context.markCurrentPropertyAsIterable();
}
else if ( TypeUtils.isArray( type ) ) {
- List<?> arrayList = Arrays.asList( value );
+ List<?> arrayList = Arrays.asList( ( Object[] ) value );
iter = arrayList.iterator();
context.markCurrentPropertyAsIterable();
}
15 years, 5 months
Hibernate SVN: r16851 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/tests/validation/graphnavigation and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-22 07:37:29 -0400 (Mon, 22 Jun 2009)
New Revision: 16851
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
some more tests mappings. Cleanup
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-06-22 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-06-22 11:37:29 UTC (rev 16851)
@@ -63,6 +63,8 @@
}
}
+
+
@Test
@SpecAssertion(section = "4.1.1", id = "e")
public void testIllegalArgumentExceptionIsThrownForNullValue() {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-06-22 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-06-22 11:37:29 UTC (rev 16851)
@@ -26,11 +26,11 @@
import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.metadata.PropertyDescriptor;
+import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
-import org.jboss.test.audit.annotations.SpecAssertion;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -47,23 +47,36 @@
@Classes(TestUtil.class)
public class ValidateTest extends AbstractTest {
-
@Test
- public void testWrongMethodName() {
+ @SpecAssertion(section = "5.1", id = "a")
+ public void testValidatedPropertyDoesNotFollowJavaBeansConvention() {
try {
Boy boy = new Boy();
TestUtil.getDefaultValidator().validate( boy );
fail();
}
catch ( ValidationException e ) {
- assertEquals(
- "Annotated methods must follow the JavaBeans naming convention. age() does not.",
- e.getMessage(),
- "Wrong error message"
- );
+ // success
}
}
+ @Test
+ @SpecAssertion(section = "5.1", id = "a")
+ public void testBasicValidation() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Customer customer = new Customer();
+ customer.setFirstName( "John" );
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+ customer.setLastName( "Doe" );
+
+ constraintViolations = validator.validate( customer );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullParamterToValidatorImplConstructor() {
TestUtil.getDefaultValidator().getConstraintsForClass( null );
@@ -86,22 +99,6 @@
catch ( IllegalArgumentException e ) {
// success
}
-
- try {
- validator.validateProperty( customer, "firstName", null );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
-
- try {
- validator.validateValue( Customer.class, "firstName", "foobar", null );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
}
@Test
@@ -114,42 +111,9 @@
catch ( IllegalArgumentException e ) {
// success
}
-
- try {
- validator.validateProperty( null, "firstName" );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
-
- try {
- validator.validateValue( null, "firstName", "foobar" );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
}
@Test
- @SpecAssertion(section = "5.1", id="a")
- public void testBasicValidation() {
- Validator validator = TestUtil.getDefaultValidator();
-
- Customer customer = new Customer();
- customer.setFirstName( "John" );
-
- Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
- customer.setLastName( "Doe" );
-
- constraintViolations = validator.validate( customer );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @Test
public void testMultipleValidationMethods() {
Validator validator = TestUtil.getDefaultValidator();
@@ -164,27 +128,6 @@
3,
"we should have been 2 not null violation for addresslines and one length violation for city"
);
-
- constraintViolations = validator.validateProperty( address, "city" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "only city should be validated"
- );
-
- constraintViolations = validator.validateProperty( address, "city" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "only city should be validated"
- );
-
- constraintViolations = validator.validateValue( Address.class, "city", "Paris" );
- assertEquals(
- constraintViolations.size(),
- 0,
- "Paris should be a valid city name."
- );
}
@Test
@@ -331,50 +274,6 @@
}
@Test
- public void testValidatePropertyWithInvalidPropertyPath() {
- Validator validator = TestUtil.getDefaultValidator();
-
- Customer customer = new Customer();
- Order order = new Order();
- customer.addOrder( order );
-
- try {
- validator.validateProperty( customer, "orders[].orderNumber" );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
-
- try {
- validator.validateProperty( customer, "" );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
-
- try {
- validator.validateProperty( customer, "foobar" );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
-
- try {
- validator.validateProperty( customer, "orders[].foobar" );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
- }
-
- /**
- * HV-108
- */
- @Test
public void testValidationIsPolymorphic() {
Validator validator = TestUtil.getDefaultValidator();
@@ -420,9 +319,6 @@
assertEquals( constraintViolations.size(), 100, "Wrong number of constraints" );
}
- /**
- * HV-120
- */
@Test
public void testConstraintDescriptorWithoutExplicitGroup() {
Validator validator = TestUtil.getDefaultValidator();
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java 2009-06-22 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java 2009-06-22 11:37:29 UTC (rev 16851)
@@ -17,22 +17,21 @@
*/
package org.hibernate.jsr303.tck.tests.validation.graphnavigation;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
-import javax.validation.Validation;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
-import org.jboss.testharness.AbstractTest;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
/**
@@ -43,6 +42,10 @@
public class GraphNavigationTest extends AbstractTest {
@Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.1", id = "a"),
+ @SpecAssertion(section = "3.5.1", id = "b")
+ })
public void testGraphNavigationDeterminism() {
// build the test object graph
User user = new User( "John", "Doe" );
@@ -70,22 +73,17 @@
Set<ConstraintViolation<Order>> constraintViolations = validator.validate( order );
assertEquals( constraintViolations.size(), 3, "Wrong number of constraints" );
-
- List<String> expectedErrorMessages = new ArrayList<String>();
- expectedErrorMessages.add( "shippingAddress.addressline1" );
- expectedErrorMessages.add( "customer.addresses[0].addressline1" );
- expectedErrorMessages.add( "billingAddress.inhabitant.addresses[0].addressline1" );
-
- for ( ConstraintViolation<Order> violation : constraintViolations ) {
- if ( expectedErrorMessages.contains( violation.getPropertyPath() ) ) {
- expectedErrorMessages.remove( violation.getPropertyPath() );
- }
- }
-
- assertTrue( expectedErrorMessages.size() == 0, "All error messages should have occured once" );
+ assertCorrectPropertyPaths(
+ constraintViolations, new String[] {
+ "shippingAddress.addressline1",
+ "customer.addresses[0].addressline1",
+ "billingAddress.inhabitant.addresses[0].addressline1"
+ }
+ );
}
@Test
+ @SpecAssertion(section = "3.5.1", id = "d")
public void testNoEndlessLoop() {
User john = new User( "John", null );
john.knows( john );
@@ -124,7 +122,7 @@
public void testFullGraphValidationBeforeNextGroupInSequence() {
Parent p = new Parent();
p.setChild( new Child() );
- Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
+ Validator validator = TestUtil.getDefaultValidator();
Set<ConstraintViolation<Parent>> errors = validator.validate( p, ProperOrder.class );
assertEquals( 1, errors.size() );
assertEquals( "child.name", errors.iterator().next().getPropertyPath() );
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java 2009-06-22 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java 2009-06-22 11:37:29 UTC (rev 16851)
@@ -48,13 +48,4 @@
// success
}
}
-
-//
-// @Test
-// public void testNoDefinedConstraints() {
-// Validator validator = getValidatorWithCustomConfiguration( "org/hibernate/validation/engine/xmlconfiguration/validation.xmlconfiguration" );
-// assertFalse(
-// validator.getConstraintsForClass( Order.class ).isBeanConstrained(), "Bean should be unsonstrained"
-// );
-// }
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-22 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-22 11:37:29 UTC (rev 16851)
@@ -416,7 +416,7 @@
<section id="3.5.1" title="Object graph validation ">
<assertion id="a">
<text>The @Valid annotation on a given association (i.e. object reference or collection,
- array, Iterable of objects), dic- tates the Bean Validator implementation to apply
+ array, Iterable of objects), dictates the Bean Validator implementation to apply
recursively the bean validation routine on (each of) the associated object(s)</text>
</assertion>
<assertion id="b">
@@ -444,11 +444,11 @@
</assertion>
<assertion id="c">
<text>If an exception occurs when the TraversableResolver is called, the exception is
- wrapped into a ValidationEx- ception</text>
+ wrapped into a ValidationException</text>
</assertion>
<assertion id="d">
<text>if Java Persistence is available in the runtime environment, a property is
- considered reachable if Java Persist- ence considers the property as loaded</text>
+ considered reachable if Java Persistence considers the property as loaded</text>
</assertion>
<assertion id="d">
<text>if Java Persistence is not available in the runtime environment, all properties
@@ -577,7 +577,7 @@
</assertion>
<assertion id="g">
<text>the name of the association property (field name or Java Bean property name) is
- concatenated to the prop- ertyPath.</text>
+ concatenated to the propertyPath.</text>
</assertion>
<assertion id="h">
<text>if the association is a List or an array, the index value surrounded by square
15 years, 5 months
Hibernate SVN: r16850 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-22 07:00:33 -0400 (Mon, 22 Jun 2009)
New Revision: 16850
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java
Log:
minor remove static from interface definition
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-22 10:59:55 UTC (rev 16849)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java 2009-06-22 11:00:33 UTC (rev 16850)
@@ -57,7 +57,7 @@
/**
* Information related to the interpolation context
*/
- static interface Context {
+ interface Context {
/**
* @return ConstraintDescriptor corresponding to the constraint being validated
*/
15 years, 5 months
Hibernate SVN: r16849 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-22 06:59:55 -0400 (Mon, 22 Jun 2009)
New Revision: 16849
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java
Log:
Made sure that the implicit group for a class implementing an interface only applies for the class, not the interface.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanDescriptorImpl.java 2009-06-22 10:59:08 UTC (rev 16848)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanDescriptorImpl.java 2009-06-22 10:59:55 UTC (rev 16849)
@@ -21,6 +21,9 @@
}
public PropertyDescriptor getConstraintsForProperty(String propertyName) {
+ if ( propertyName == null ) {
+ throw new IllegalArgumentException( "The property name cannot be null" );
+ }
return metadataBean.getPropertyDescriptor( propertyName );
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java 2009-06-22 10:59:08 UTC (rev 16848)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java 2009-06-22 10:59:55 UTC (rev 16849)
@@ -331,7 +331,7 @@
@SuppressWarnings("unchecked")
private <A extends Annotation> ConstraintDescriptorImpl buildConstraintDescriptor(Class<?> clazz, A annotation) {
ConstraintDescriptorImpl constraintDescriptor;
- if ( clazz.isInterface() ) {
+ if ( clazz.isInterface() && !clazz.equals( beanClass)) {
constraintDescriptor = new ConstraintDescriptorImpl( annotation, constraintHelper, clazz );
}
else {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java 2009-06-22 10:59:08 UTC (rev 16848)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/ConstraintDescriptorImpl.java 2009-06-22 10:59:55 UTC (rev 16849)
@@ -93,7 +93,10 @@
public ConstraintDescriptorImpl(T annotation, ConstraintHelper constraintHelper, Class<?> implicitGroup) {
this( annotation, constraintHelper );
- this.groups.add( implicitGroup );
+ // if the constraint is part of the Default group it is automatically part of the implicit group as well
+ if ( groups.contains( Default.class ) ) {
+ this.groups.add( implicitGroup );
+ }
}
15 years, 5 months
Hibernate SVN: r16848 - in validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation: metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-22 06:59:08 -0400 (Mon, 22 Jun 2009)
New Revision: 16848
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Customer.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Order.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Person.java
Log:
ElemetDescriptor tests. Moved back from TCK.
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Customer.java (from rev 16842, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Customer.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Customer.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Customer.java 2009-06-22 10:59:08 UTC (rev 16848)
@@ -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.validation.metadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.Valid;
+
+/**
+ * @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
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java 2009-06-22 10:59:08 UTC (rev 16848)
@@ -0,0 +1,87 @@
+// $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.metadata;
+
+import java.util.Set;
+import javax.validation.Validator;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+
+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.util.TestUtil;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ElementDescriptorTest {
+
+
+ @Test
+ public void testGetTypeForConstrainedBean() {
+ Validator validator = TestUtil.getValidator();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
+ assertEquals( beanDescriptor.getType(), Customer.class, "Wrong type." );
+ }
+
+ @Test
+ public void testGetTypeForConstrainedProperty() {
+ ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
+ assertEquals( elementDescriptor.getType(), Integer.class, "Wrong type." );
+ }
+
+ /**
+ * HV-95
+ */
+ @Test
+ public void testElementDescriptorForProperty() {
+ ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
+ Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
+ assertTrue( constraintDescriptors.size() == 1, "There should be a descriptor" );
+ }
+
+ /**
+ * HV-95
+ */
+ @Test
+ public void testElementDescriptorImmutable() {
+ ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
+ Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
+
+ try {
+ constraintDescriptors.add( null );
+ fail( "Set should be immutable" );
+ }
+ catch ( UnsupportedOperationException e ) {
+ // success
+ }
+
+ try {
+ constraintDescriptors.remove( null );
+ fail( "Set should be immutable" );
+ }
+ catch ( UnsupportedOperationException e ) {
+ // success
+ }
+ }
+}
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Order.java (from rev 16842, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Order.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Order.java 2009-06-22 10:59:08 UTC (rev 16848)
@@ -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.validation.metadata;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Order {
+ @NotNull(message = "Order number must be specified")
+ Integer orderNumber;
+
+ public Integer getOrderNumber() {
+ return orderNumber;
+ }
+
+ public void setOrderNumber(Integer orderNumber) {
+ this.orderNumber = orderNumber;
+ }
+}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Person.java (from rev 16842, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Person.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Person.java 2009-06-22 10:59:08 UTC (rev 16848)
@@ -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.validation.metadata;
+
+import org.hibernate.validation.constraints.NotEmpty;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Person {
+ @NotEmpty(groups = PersonValidation.class)
+ String getFirstName();
+
+ String getMiddleName();
+
+ @NotEmpty
+ String getLastName();
+
+ public interface PersonValidation {
+ }
+}
\ No newline at end of file
15 years, 5 months
Hibernate SVN: r16847 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/util and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-22 06:57:54 -0400 (Mon, 22 Jun 2009)
New Revision: 16847
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java
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/ConstraintDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.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
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
Metadata tests
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-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java 2009-06-22 10:57:54 UTC (rev 16847)
@@ -132,17 +132,16 @@
assertNull( beanDescriptor.getConstraintsForProperty( "foobar" ), "There should be no descriptor" );
}
- /**
- * @todo Is this corect or should we get a IllegalArgumentException
- */
- @Test
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
public void testGetConstraintsForNullProperty() {
Validator validator = TestUtil.getDefaultValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
- assertNull( beanDescriptor.getConstraintsForProperty( null ), "There should be no descriptor" );
+ beanDescriptor.getConstraintsForProperty( null );
}
@Test
+ @SpecAssertion(section = "5.3", id = "b")
public void testGetConstrainedProperties() {
Validator validator = TestUtil.getDefaultValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
@@ -156,6 +155,15 @@
}
@Test
+ @SpecAssertion(section = "5.3", id = "b")
+ public void testGetConstrainedPropertiesForUnconstraintEntity() {
+ Validator validator = TestUtil.getDefaultValidator();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( UnconstraintEntity.class );
+ Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
+ assertEquals( constraintProperties.size(), 0, "We should get the empty set." );
+ }
+
+ @Test(enabled = false)
public void testGetConstrainedPropertiesImmutable() {
Validator validator = TestUtil.getDefaultValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
@@ -176,12 +184,4 @@
// success
}
}
-
- @Test
- public void testGetConstrainedPropertiesForUnconstraintEntity() {
- Validator validator = TestUtil.getDefaultValidator();
- BeanDescriptor beanDescriptor = validator.getConstraintsForClass( UnconstraintEntity.class );
- Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
- assertEquals( constraintProperties.size(), 0, "We should get the empty set." );
- }
}
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-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java 2009-06-22 10:57:54 UTC (rev 16847)
@@ -17,21 +17,21 @@
*/
package org.hibernate.jsr303.tck.tests.metadata;
-import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Set;
import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
import javax.validation.groups.Default;
import javax.validation.metadata.ConstraintDescriptor;
import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import org.testng.annotations.Test;
@@ -48,6 +48,107 @@
public class ConstraintDescriptorTest extends AbstractTest {
@Test
+ public void testReportAsSingleViolation() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+ assertFalse( descriptor.isReportAsSingleViolation() );
+
+ descriptor = getConstraintDescriptor( Person.class, "firstName" );
+ assertTrue( descriptor.isReportAsSingleViolation() );
+ }
+
+ @Test
+ public void testEmptyComposingConstraints() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+ assertTrue( descriptor.getComposingConstraints().isEmpty() );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "5.5", id = "a"),
+ @SpecAssertion(section = "5.5", id = "c")
+ })
+ public void testAnnotationAndMapParamtersReflectParamterOverriding() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class, "firstName" );
+ Set<ConstraintDescriptor<?>> composingDescriptors = descriptor.getComposingConstraints();
+ assertEquals( composingDescriptors.size(), 2, "Wrong number of composing constraints" );
+ for ( ConstraintDescriptor<?> desc : composingDescriptors ) {
+ if ( desc.getAnnotation().annotationType().equals( Size.class ) ) {
+ Size sizeAnn = ( Size ) desc.getAnnotation();
+ assertEquals( sizeAnn.min(), 5, "The min parameter should reflect the overriden parameter" );
+ assertEquals(
+ desc.getAttributes().get( "min" ), 5, "The min parameter should reflect the overriden parameter"
+ );
+ }
+ else if ( desc.getAnnotation().annotationType().equals( NotNull.class ) ) {
+ }
+ else {
+ fail( "Unexpected annotation." );
+ }
+ }
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "b")
+ public void testGetAttributesFromConstraintDescriptor() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+ Map<String, Object> attributes = descriptor.getAttributes();
+ assertTrue( attributes.containsKey( "message" ) );
+ assertTrue( attributes.containsKey( "groups" ) );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "d")
+ public void testGetGroups() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class, "firstName" );
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 1 );
+ assertEquals( groups.iterator().next(), Person.PersonValidation.class, "Wrong group" );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "d")
+ public void testGetGroupsOnInterface() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class, "lastName" );
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 1 );
+ assertEquals( groups.iterator().next(), Default.class, "Wrong group" );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "d")
+ public void testGetGroupsWithImplcitGroup() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Man.class, "lastName" );
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 2 );
+ for ( Class<?> group : groups ) {
+ if ( !( group.equals( Default.class ) || group.equals( Person.class ) ) ) {
+ fail( "Invalid group." );
+ }
+ }
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "e")
+ public void testDefaultGroupIsReturnedIfNoGroupSpecifiedInDeclaration() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 1 );
+ assertEquals( groups.iterator().next(), Default.class, "Wrong group" );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "f")
+ public void testComposingConstraints() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class, "firstName" );
+ Set<ConstraintDescriptor<?>> composingDescriptors = descriptor.getComposingConstraints();
+ assertEquals( composingDescriptors.size(), 2, "Wrong number of composing constraints" );
+ for ( ConstraintDescriptor<?> desc : composingDescriptors ) {
+ assertTrue( desc.getGroups().size() == 1 );
+ assertEquals( desc.getGroups().iterator().next(), Person.PersonValidation.class, "Wrong group" );
+ }
+ }
+
+ @Test(enabled = false)
public void testConstraintDescriptorImmutable() {
ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
@@ -84,64 +185,6 @@
}
}
- @Test
- public void testReportAsSingleViolation() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
- assertFalse( descriptor.isReportAsSingleViolation() );
-
- descriptor = getConstraintDescriptor( Person.class, "firstName" );
- assertTrue( descriptor.isReportAsSingleViolation() );
- }
-
- @Test
- public void testComposingConstraints() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
- assertTrue( descriptor.getComposingConstraints().isEmpty() );
- }
-
- /**
- * @todo Is getComposingConstraints() recursive and hence the result should be 4?
- */
- @Test
- public void testEmptyComposingConstraints() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class, "firstName" );
- assertEquals( descriptor.getComposingConstraints().size(), 2, "Wrong number of composing constraints" );
- }
-
- @Test
- public void testGetAnnotation() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
- Annotation annotation = descriptor.getAnnotation();
- assertNotNull( annotation );
- assertTrue( annotation instanceof NotNull );
- }
-
- @Test
- @SpecAssertion(section = "5.5", id = "e")
- public void testDefaultGroupIsReturnedIfNoGroupSpecifiedInDeclaration() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
- Set<Class<?>> groups = descriptor.getGroups();
- assertTrue( groups.size() == 1 );
- assertEquals( groups.iterator().next(), Default.class, "Wrong group" );
- }
-
-// @Test
-// public void testGetConstraintValidatorClasses() {
-// Set<ConstraintDescriptor<?>> descriptors = getConstraintDescriptorsFor( Order.class, "orderNumber" );
-// assertTrue( descriptors.size() == 1, "There should only by one descriptor." );
-// ConstraintDescriptor<?> descriptor = descriptors.iterator().next();
-// assertEquals( descriptor.getConstraintValidatorClasses().get( 0 ), InvertedNotNullValidator.class, "Wrong classes" );
-// }
-
- @Test
- @SpecAssertion(section = "5.5", id = "b")
- public void testGetAttributesFromConstraintDescriptor() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
- Map<String, Object> attributes = descriptor.getAttributes();
- assertTrue( attributes.containsKey( "message" ) );
- assertTrue( attributes.containsKey( "groups" ) );
- }
-
private ConstraintDescriptor<?> getConstraintDescriptor(Class<?> clazz, String property) {
Set<ConstraintDescriptor<?>> descriptors = getConstraintDescriptorsFor( clazz, property );
assertTrue( descriptors.size() == 1, "There should only by one descriptor." );
Deleted: 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-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java 2009-06-22 10:57:54 UTC (rev 16847)
@@ -1,92 +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.jsr303.tck.tests.metadata;
-
-import java.util.Set;
-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;
-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;
-
-/**
- * @author Hardy Ferentschik
- */
-@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
-public class ElementDescriptorTest extends AbstractTest {
-
-
- @Test
- public void testGetTypeForConstrainedBean() {
- Validator validator = TestUtil.getDefaultValidator();
- BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
- assertEquals( beanDescriptor.getType(), Customer.class, "Wrong type." );
- }
-
- @Test
- public void testGetTypeForConstrainedProperty() {
- ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
- assertEquals( elementDescriptor.getType(), Integer.class, "Wrong type." );
- }
-
- /**
- * HV-95
- */
- @Test
- public void testElementDescriptorForProperty() {
- ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
- Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
- assertTrue( constraintDescriptors.size() == 1, "There should be a descriptor" );
- }
-
- /**
- * HV-95
- */
- @Test
- public void testElementDescriptorImmutable() {
- ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
- Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
-
- try {
- constraintDescriptors.add( null );
- fail( "Set should be immutable" );
- }
- catch ( UnsupportedOperationException e ) {
- // success
- }
-
- try {
- constraintDescriptors.remove( null );
- fail( "Set should be immutable" );
- }
- catch ( UnsupportedOperationException e ) {
- // success
- }
- }
-}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java 2009-06-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java 2009-06-22 10:57:54 UTC (rev 16847)
@@ -24,6 +24,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.OverridesAttribute;
import javax.validation.ReportAsSingleViolation;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@@ -32,14 +33,17 @@
* @author Emmanuel Bernard
*/
@Documented
-@Constraint(validatedBy = {})
+@Constraint(validatedBy = { })
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
@ReportAsSingleViolation
@NotNull
-@Size(min=1)
+@Size
public @interface NotEmpty {
public abstract String message() default "{org.hibernate.validation.constraints.NotEmpty.message}";
public abstract Class<?>[] groups() default { };
+
+ @OverridesAttribute(constraint = Size.class, name = "min")
+ public abstract int min() default 5;
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java 2009-06-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java 2009-06-22 10:57:54 UTC (rev 16847)
@@ -23,7 +23,7 @@
* @author Hardy Ferentschik
*/
public class Order {
- @NotNull
+ @NotNull(message = "Order number must be specified")
Integer orderNumber;
public Integer getOrderNumber() {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java 2009-06-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java 2009-06-22 10:57:54 UTC (rev 16847)
@@ -21,11 +21,14 @@
* @author Hardy Ferentschik
*/
public interface Person {
- @NotEmpty
+ @NotEmpty(groups = PersonValidation.class)
String getFirstName();
String getMiddleName();
@NotEmpty
String getLastName();
+
+ public interface PersonValidation {
+ }
}
\ No newline at end of file
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-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-06-22 10:57:54 UTC (rev 16847)
@@ -23,6 +23,7 @@
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.test.audit.annotations.SpecAssertion;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@@ -39,12 +40,14 @@
@Classes(TestUtil.class)
public class PropertyDescriptorTest extends AbstractTest {
@Test
+ @SpecAssertion(section = "5.4", id = "a")
public void testIsNotCascaded() {
PropertyDescriptor descriptor = getPropertyDescriptor( Order.class, "orderNumber" );
assertFalse( descriptor.isCascaded(), "Should not be cascaded" );
}
@Test
+ @SpecAssertion(section = "5.4", id = "a")
public void testIsCascaded() {
PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, "orderList" );
assertTrue( descriptor.isCascaded(), "Should be cascaded" );
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-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-22 10:57:54 UTC (rev 16847)
@@ -112,7 +112,6 @@
);
}
-
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String property) {
Validator validator = getDefaultValidator();
return validator.getConstraintsForClass( clazz ).getConstraintsForProperty( property );
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-22 09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-22 10:57:54 UTC (rev 16847)
@@ -387,7 +387,7 @@
must contain the group A</text>
</assertion>
<assertion id="d">
- <text>If a @GroupSequence rede- fining the Default group for a class A does not contain
+ <text>If a @GroupSequence redefining the Default group for a class A does not contain
the group A, a GroupDefinitionException is raised when the class is validated or
when its metadata is requested</text>
</assertion>
@@ -921,8 +921,7 @@
returned</text>
</assertion>
<assertion id="f">
- <text>The groups of a composing constraint are the groups of the composed con-
- straint</text>
+ <text>The groups of a composing constraint are the groups of the composed constraint</text>
</assertion>
</section>
<section id="6" title="Built-in Constraint definitions">
@@ -1106,7 +1105,7 @@
</section>
<section id="7.1.1.4" title="Constraint declaration">
<assertion id="a">
- <text>The name attribute is mandatory and repres- ents the name of the element in the
+ <text>The name attribute is mandatory and represents the name of the element in the
constraint declaration</text>
</assertion>
<assertion id="b">
15 years, 5 months
Hibernate SVN: r16846 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-22 05:36:49 -0400 (Mon, 22 Jun 2009)
New Revision: 16846
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
Log:
adjust some IAE groups cannot be null
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-21 09:37:10 UTC (rev 16845)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-06-22 09:36:49 UTC (rev 16846)
@@ -37,6 +37,7 @@
* @return constraint violations or an empty Set if none
*
* @throws IllegalArgumentException if object is null
+ * or if null is passed to the varargs groups
* @throws ValidationException if a non recoverable error happens
* during the validation process
*/
@@ -55,6 +56,7 @@
*
* @throws IllegalArgumentException if object is null, if propertyName null, empty
* or not a valid object property
+ * or if null is passed to the varargs groups
* @throws ValidationException if a non recoverable error happens
* during the validation process
*/
@@ -79,6 +81,7 @@
*
* @throws IllegalArgumentException if object is null, if propertyName null, empty
* or not a valid object property
+ * or if null is passed to the varargs groups
* @throws ValidationException if a non recoverable error happens
* during the validation process
*/
15 years, 5 months
Hibernate SVN: r16845 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-21 05:37:10 -0400 (Sun, 21 Jun 2009)
New Revision: 16845
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java
Log:
Made sure the right type of exceptions are thrown when the default group is re-defined.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java 2009-06-21 09:36:16 UTC (rev 16844)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/metadata/BeanMetaDataImpl.java 2009-06-21 09:37:10 UTC (rev 16845)
@@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.validation.GroupDefinitionException;
import javax.validation.GroupSequence;
import javax.validation.Valid;
import javax.validation.ValidationException;
@@ -138,17 +139,22 @@
public void setDefaultGroupSequence(List<Class<?>> groupSequence) {
defaultGroupSequence = new ArrayList<Class<?>>();
+ boolean groupSequenceContainsDefault = false;
for ( Class<?> group : groupSequence ) {
if ( group.getName().equals( beanClass.getName() ) ) {
defaultGroupSequence.add( Default.class );
+ groupSequenceContainsDefault = true;
}
else if ( group.getName().equals( Default.class.getName() ) ) {
- throw new ValidationException( "'Default.class' cannot appear in default group sequence list." );
+ throw new GroupDefinitionException( "'Default.class' cannot appear in default group sequence list." );
}
else {
defaultGroupSequence.add( group );
}
}
+ if ( !groupSequenceContainsDefault ) {
+ throw new GroupDefinitionException( beanClass.getName() + " must be part of the redefined default group sequence." );
+ }
if ( log.isTraceEnabled() ) {
log.trace(
"Members of the default group sequence for bean {} are: {}",
15 years, 5 months
Hibernate SVN: r16844 - in beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests: constraints and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-21 05:36:16 -0400 (Sun, 21 Jun 2009)
New Revision: 16844
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.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/DefaultGroupRedefinitionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java
Log:
Updated and mapped the tests for default group re-definition
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-06-21 08:39:29 UTC (rev 16843)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-06-21 09:36:16 UTC (rev 16844)
@@ -99,11 +99,13 @@
}
@Test
+ @SpecAssertion(section = "4.3.2", id = "b")
public void testCustomMessageInterpolatorViaConfiguration() {
- Configuration<?> configuration = Validation.byDefaultProvider().configure();
- configuration.messageInterpolator( new DummyMessageInterpolator() );
+ ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+ Validator validator = factory.usingContext()
+ .messageInterpolator( new DummyMessageInterpolator() )
+ .getValidator();
- Validator validator = configuration.buildValidatorFactory().getValidator();
assertCustomMessageInterpolatorUsed( validator );
}
@@ -175,7 +177,7 @@
throw new RuntimeException( "Unable to load service file", e );
}
return providers;
- }
+ }
private void assertCustomMessageInterpolatorUsed(Validator validator) {
Person person = new Person();
Deleted: 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 2009-06-21 08:39:29 UTC (rev 16843)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java 2009-06-21 09:36:16 UTC (rev 16844)
@@ -1,12 +0,0 @@
-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
Modified: 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 2009-06-21 08:39:29 UTC (rev 16843)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java 2009-06-21 09:36:16 UTC (rev 16844)
@@ -12,7 +12,7 @@
@GroupSequence({ Car.class, Car.Test.class })
public class Car {
@Pattern(regexp = ".*", groups = Default.class)
- @Size(min = 2, max = 20, groups = Car.Test.class)
+ @Size(min = 2, max = 20, groups = Car.Test.class, message = "Car type has to be betweeb {min} and {max} characters.")
private String type;
public String getType() {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java 2009-06-21 08:39:29 UTC (rev 16843)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java 2009-06-21 09:36:16 UTC (rev 16844)
@@ -20,13 +20,15 @@
import java.lang.annotation.Annotation;
import java.util.Set;
import javax.validation.ConstraintViolation;
-import javax.validation.ValidationException;
+import javax.validation.GroupDefinitionException;
+import javax.validation.GroupSequence;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import javax.validation.metadata.BeanDescriptor;
import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
@@ -37,9 +39,12 @@
import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessage;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
/**
- * Tests for the group and group sequence feature.
+ * Tests for redifining the default group sequence.
*
* @author Hardy Ferentschik
*/
@@ -64,7 +69,8 @@
);
ConstraintViolation<Address> violation = constraintViolations.iterator().next();
- TestUtil.assertConstraintViolation( violation, Address.class, null, "zipcode" );
+ assertConstraintViolation( violation, Address.class, null, "zipcode" );
+ assertCorrectConstraintViolationMessage( violation, "may not be null" );
address.setZipcode( "41841" );
@@ -77,7 +83,8 @@
);
violation = constraintViolations.iterator().next();
- TestUtil.assertConstraintViolation( violation, Address.class, address, "" );
+ assertConstraintViolation( violation, Address.class, address, "" );
+ assertCorrectConstraintViolationMessage( violation, "Zip code is not coherent." );
}
@Test(enabled = false)
@@ -102,68 +109,66 @@
}
@Test
- public void testRedefiningDefaultGroup2() {
+ @SpecAssertion(section = "3.4.3", id = "a")
+ public void testValidatingAgainstRedefinedDefaultGroup() {
Car car = new Car();
car.setType( "A" );
Validator validator = TestUtil.getDefaultValidator();
+ // if the group sequence would not be properly redefined there would be no error when validating default.
+
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"
- );
+ assertCorrectNumberOfViolations(constraintViolations, 1);
+ assertCorrectConstraintViolationMessage( constraintViolations.iterator().next(), "Car type has to be betweeb 2 and 20 characters." );
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"
- );
+ assertCorrectNumberOfViolations(constraintViolations, 1);
+ assertCorrectConstraintViolationMessage( constraintViolations.iterator().next(), "Car type has to be betweeb 2 and 20 characters.");
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"
- );
+ assertCorrectNumberOfViolations(constraintViolations, 1);
+ assertCorrectConstraintViolationMessage( constraintViolations.iterator().next(), "Car type has to be betweeb 2 and 20 characters.");
}
@Test
- public void testInvalidRedefinitionOfDefaultGroup() {
- Address address = new AddressWithInvalidGroupSequence();
+ @SpecAssertions({
+ @SpecAssertion(section = "3.4.3", id = "c"),
+ @SpecAssertion(section = "3.4.3", id = "d")
+ })
+ public void testGroupSequenceContainingDefault() {
+ Address address = new AddressWithDefaultInGroupSequence();
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"
- );
+ catch ( GroupDefinitionException e ) {
+ // success
}
}
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.4.3", id = "c"),
+ @SpecAssertion(section = "3.4.3", id = "d")
+ })
+ public void testGroupSequenceWithNoImplicitDefaultGroup() {
+ Address address = new AddressWithNoImplicitDefaultGroupSequence();
+ Validator validator = TestUtil.getDefaultValidator();
+ try {
+ validator.validate( address );
+ fail( "A valid group sequence definiton must contain the class itself as implicit default group." );
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+ }
+
private void assertAssertionType(Set<ConstraintViolation<Address>> violations) {
for ( ConstraintViolation<Address> violation : violations ) {
// cast is required for JDK 5 - at least on Mac OS X
- Annotation ann = (Annotation) violation.getConstraintDescriptor().getAnnotation();
+ Annotation ann = ( Annotation ) violation.getConstraintDescriptor().getAnnotation();
assertEquals(
NotNull.class,
ann.annotationType(),
@@ -171,4 +176,14 @@
);
}
}
+
+ @GroupSequence({ Default.class, Address.HighLevelCoherence.class })
+ public class AddressWithDefaultInGroupSequence extends Address {
+
+ }
+
+ @GroupSequence({ Address.HighLevelCoherence.class })
+ public class AddressWithNoImplicitDefaultGroupSequence extends Address {
+
+ }
}
\ No newline at end of file
Modified: 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 2009-06-21 08:39:29 UTC (rev 16843)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java 2009-06-21 09:36:16 UTC (rev 16844)
@@ -16,7 +16,7 @@
@Documented
@Constraint(validatedBy = ZipCodeCoherenceValidator.class)
public @interface ZipCodeCoherenceChecker {
- public abstract String message() default "{validator.zipCodeCoherenceChecker}";
+ public abstract String message() default "Zip code is not coherent.";
public abstract Class<?>[] groups() default { };
}
\ No newline at end of file
15 years, 5 months