Hibernate SVN: r16843 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-21 04:39:29 -0400 (Sun, 21 Jun 2009)
New Revision: 16843
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
Log:
reorganized methods
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-19 11:45:05 UTC (rev 16842)
+++ 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)
@@ -98,27 +98,6 @@
assertTrue( !providers.isEmpty(), "There should be at least one provider" );
}
- private List<ValidationProvider> readBeanValidationServiceFile() {
- ClassLoader classloader = Thread.currentThread().getContextClassLoader();
- if ( classloader == null ) {
- classloader = BootstrapTest.class.getClassLoader();
- }
- List<ValidationProvider> providers = new ArrayList<ValidationProvider>();
- try {
-
- Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE );
- while ( providerDefinitions.hasMoreElements() ) {
- URL url = providerDefinitions.nextElement();
- addProviderToList( providers, url );
- }
- }
- catch ( Exception e ) {
- throw new RuntimeException( "Unable to load service file", e );
- }
- return providers;
- }
-
-
@Test
public void testCustomMessageInterpolatorViaConfiguration() {
Configuration<?> configuration = Validation.byDefaultProvider().configure();
@@ -178,6 +157,26 @@
);
}
+ private List<ValidationProvider> readBeanValidationServiceFile() {
+ ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ if ( classloader == null ) {
+ classloader = BootstrapTest.class.getClassLoader();
+ }
+ List<ValidationProvider> providers = new ArrayList<ValidationProvider>();
+ try {
+
+ Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE );
+ while ( providerDefinitions.hasMoreElements() ) {
+ URL url = providerDefinitions.nextElement();
+ addProviderToList( providers, url );
+ }
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to load service file", e );
+ }
+ return providers;
+ }
+
private void assertCustomMessageInterpolatorUsed(Validator validator) {
Person person = new Person();
person.setFirstName( "John" );
15 years, 5 months
Hibernate SVN: r16842 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-19 07:45:05 -0400 (Fri, 19 Jun 2009)
New Revision: 16842
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
Log:
Fixed bug in collectMetaConstraintsForPath() used by validateProperty and validateValue
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-19 11:44:15 UTC (rev 16841)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-06-19 11:45:05 UTC (rev 16842)
@@ -44,14 +44,14 @@
import org.hibernate.validation.engine.groups.GroupChain;
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.PropertyPath;
-import org.hibernate.validation.util.ReflectionHelper;
import org.hibernate.validation.metadata.BeanMetaData;
-import org.hibernate.validation.metadata.BeanMetaDataImpl;
import org.hibernate.validation.metadata.BeanMetaDataCache;
-import org.hibernate.validation.metadata.MetaConstraint;
+import org.hibernate.validation.metadata.BeanMetaDataImpl;
import org.hibernate.validation.metadata.ConstraintHelper;
+import org.hibernate.validation.metadata.MetaConstraint;
+import org.hibernate.validation.util.LoggerFactory;
+import org.hibernate.validation.util.PropertyPath;
+import org.hibernate.validation.util.ReflectionHelper;
/**
* The main Bean Validation class. This is the core processing class of Hibernate Validator.
@@ -626,9 +626,7 @@
continue;
}
}
- collectMetaConstraintsForPath(
- ( Class<T> ) type, value, propertyIter, metaConstraints
- );
+ return collectMetaConstraintsForPath( ( Class<T> ) type, value, propertyIter, metaConstraints );
}
}
}
15 years, 5 months
Hibernate SVN: r16841 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-19 07:44:15 -0400 (Fri, 19 Jun 2009)
New Revision: 16841
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyPath.java
Log:
added toString methods
Modified: 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 2009-06-19 11:38:29 UTC (rev 16840)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/PropertyPath.java 2009-06-19 11:44:15 UTC (rev 16841)
@@ -85,6 +85,14 @@
return pathList.iterator();
}
+ @Override
+ public String toString() {
+ return "PropertyPath{" +
+ "originalProperty='" + originalProperty + '\'' +
+ ", pathList=" + pathList +
+ '}';
+ }
+
public static class PathElement {
private final String value;
private final String index;
@@ -105,5 +113,13 @@
public boolean isIndexed() {
return index != null;
}
+
+ @Override
+ public String toString() {
+ return "PathElement{" +
+ "value='" + value + '\'' +
+ ", index='" + index + '\'' +
+ '}';
+ }
}
}
\ No newline at end of file
15 years, 5 months
Hibernate SVN: r16840 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-19 07:38:29 -0400 (Fri, 19 Jun 2009)
New Revision: 16840
Added:
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/ValidateValueTest.java
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.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/builtinconstraints/BuiltinConstraintsTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Person.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:
work on the tests for the different validate methods
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-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -51,7 +51,7 @@
import org.hibernate.jsr303.tck.util.TestUtil;
import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
-import static org.hibernate.jsr303.tck.util.TestUtil.assertInvalidPropertyPaths;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
/**
* @author Hardy Ferentschik
@@ -72,7 +72,7 @@
Set<ConstraintViolation<Person>> constraintViolations = validator.validate( person );
assertEquals( constraintViolations.size(), 3, "Wrong number of constraints" );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "firstName", "lastName", "personalNumber" }
);
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -54,7 +54,7 @@
import org.hibernate.jsr303.tck.util.TestUtil;
import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
-import static org.hibernate.jsr303.tck.util.TestUtil.assertInvalidPropertyPaths;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
/**
* Tests for built-in constraints. Basically juyst checks the availabiltiy of the build-in constraints.
@@ -177,7 +177,7 @@
Set<ConstraintViolation<MinDummyEntity>> constraintViolations = validator.validate( dummy );
// only the min constraints on the primitive values should fail. Object values re still null and should pass per spec
assertCorrectNumberOfViolations( constraintViolations, 4 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive" }
);
@@ -197,7 +197,7 @@
constraintViolations = validator.validate( dummy );
assertCorrectNumberOfViolations( constraintViolations, 6 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "byteObject", "intObject", "longObject", "shortObject", "bigDecimal", "bigInteger" }
);
@@ -230,7 +230,7 @@
Set<ConstraintViolation<MaxDummyEntity>> constraintViolations = validator.validate( dummy );
// only the max constraints on the primitive values should fail. Object values re still null and should pass per spec
assertCorrectNumberOfViolations( constraintViolations, 4 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive" }
);
@@ -250,7 +250,7 @@
constraintViolations = validator.validate( dummy );
assertCorrectNumberOfViolations( constraintViolations, 6 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "byteObject", "intObject", "longObject", "shortObject", "bigDecimal", "bigInteger" }
);
@@ -278,7 +278,7 @@
Set<ConstraintViolation<DecimalMinDummyEntity>> constraintViolations = validator.validate( dummy );
// only the min constraints on the primitive values should fail. Object values re still null and should pass per spec
assertCorrectNumberOfViolations( constraintViolations, 4 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive" }
);
@@ -298,7 +298,7 @@
constraintViolations = validator.validate( dummy );
assertCorrectNumberOfViolations( constraintViolations, 6 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "byteObject", "intObject", "longObject", "shortObject", "bigDecimal", "bigInteger" }
);
@@ -331,7 +331,7 @@
Set<ConstraintViolation<DecimalMaxDummyEntity>> constraintViolations = validator.validate( dummy );
// only the max constraints on the primitive values should fail. Object values re still null and should pass per spec
assertCorrectNumberOfViolations( constraintViolations, 4 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive" }
);
@@ -351,7 +351,7 @@
constraintViolations = validator.validate( dummy );
assertCorrectNumberOfViolations( constraintViolations, 6 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "byteObject", "intObject", "longObject", "shortObject", "bigDecimal", "bigInteger" }
);
@@ -395,7 +395,7 @@
constraintViolations = validator.validate( dummy );
assertCorrectNumberOfViolations( constraintViolations, 5 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "collection", "map", "string", "integerArray", "intArray" }
);
@@ -426,7 +426,7 @@
Set<ConstraintViolation<DigitsDummyEntity>> constraintViolations = validator.validate( dummy );
// only the max constraints on the primitive values should fail. Object values re still null and should pass per spec
assertCorrectNumberOfViolations( constraintViolations, 4 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive" }
);
@@ -446,7 +446,7 @@
constraintViolations = validator.validate( dummy );
assertCorrectNumberOfViolations( constraintViolations, 6 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "byteObject", "intObject", "longObject", "shortObject", "bigDecimal", "bigInteger" }
);
@@ -482,7 +482,7 @@
constraintViolations = validator.validate( dummy );
assertCorrectNumberOfViolations( constraintViolations, 2 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "date", "calendar" }
);
@@ -514,7 +514,7 @@
constraintViolations = validator.validate( dummy );
assertCorrectNumberOfViolations( constraintViolations, 2 );
- assertInvalidPropertyPaths(
+ assertCorrectPropertyPaths(
constraintViolations,
new String[] { "date", "calendar" }
);
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-06-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -35,7 +35,7 @@
import org.hibernate.jsr303.tck.util.TestUtil;
import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
-import static org.hibernate.jsr303.tck.util.TestUtil.assertInvalidPropertyPaths;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
/**
* Tests for constraint validator resolution.
@@ -93,7 +93,7 @@
MinMax minMax = new MinMax( "5", 5 );
Set<ConstraintViolation<MinMax>> constraintViolations = validator.validate( minMax );
assertCorrectNumberOfViolations( constraintViolations, 2 );
- assertInvalidPropertyPaths( constraintViolations, new String[] { "number", "numberAsString" } );
+ assertCorrectPropertyPaths( constraintViolations, new String[] { "number", "numberAsString" } );
}
@Test
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java 2009-06-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -34,7 +34,6 @@
private List<Actor> playedWith = new ArrayList<Actor>();
public Actor() {
-
}
public Actor(String firstName, String lastName) {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java 2009-06-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -60,7 +60,7 @@
this.zipCode = zipCode;
}
- @Size(max = 30)
+ @Size(max = 30, message = "City name cannot be longer than 30 characters.")
@NotNull
public String getCity() {
return city;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Person.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Person.java 2009-06-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Person.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -28,6 +28,6 @@
String getMiddleName();
- @NotNull
+ @NotNull(message = "Everyone has a last name.")
String getLastName();
}
\ No newline at end of file
Added: 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 (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -0,0 +1,178 @@
+// $Id: ValidateTest.java 16824 2009-06-17 20:57:08Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validation;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+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.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintType;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessage;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+
+/**
+ * Tests for the implementation of <code>Validator</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class ValidatePropertyTest extends AbstractTest {
+
+ //TODO Needs verification
+ @Test
+ @SuppressWarnings("NullArgumentToVariableArgMethod")
+ public void testPassingNullAsGroup() {
+ Validator validator = TestUtil.getDefaultValidator();
+ Customer customer = new Customer();
+
+ try {
+ validator.validateProperty( customer, "firstName", null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
+ }
+
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "e")
+ public void testIllegalArgumentExceptionIsThrownForNullValue() {
+ Validator validator = TestUtil.getDefaultValidator();
+ try {
+ validator.validateProperty( null, "firstName" );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
+ }
+
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "e")
+ 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
+ }
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.1.1", id = "d"),
+ @SpecAssertion(section = "4.1.1", id = "c")
+ })
+ public void testValidateProperty() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Address address = new Address();
+ address.setAddressline1( null );
+ address.setAddressline2( null );
+ String townInNorthWales = "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch";
+ address.setCity( townInNorthWales );
+
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validateProperty( address, "city" );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+
+ ConstraintViolation<Address> violation = constraintViolations.iterator().next();
+ assertCorrectConstraintType( violation, Size.class );
+ assertConstraintViolation( violation, Address.class, townInNorthWales, "city" );
+ assertCorrectConstraintViolationMessage( violation, "City name cannot be longer than 30 characters." );
+
+ address.setCity( "London" );
+ constraintViolations = validator.validateProperty( address, "city" );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.1.1", id = "d"),
+ @SpecAssertion(section = "4.1.1", id = "c")
+ })
+ public void testValidatePropertyWithIndexedPath() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Actor clint = new Actor( "Clint", "Eastwood" );
+ Actor morgan = new Actor( "Morgan", null );
+ Actor charlie = new Actor( "Charlie", "Sheen" );
+
+ clint.addPlayedWith( charlie );
+ charlie.addPlayedWith( clint );
+ charlie.addPlayedWith( morgan );
+ morgan.addPlayedWith( charlie );
+ morgan.addPlayedWith( clint );
+ clint.addPlayedWith( morgan );
+
+ String property = "playedWith[0].playedWith[1].lastName";
+ Set<ConstraintViolation<Actor>> constraintViolations = validator.validateProperty(
+ clint, property
+ );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+
+ ConstraintViolation<Actor> violation = constraintViolations.iterator().next();
+ assertCorrectConstraintType( violation, NotNull.class );
+ assertConstraintViolation( violation, Actor.class, null, property );
+ assertCorrectConstraintViolationMessage( violation, "Everyone has a last name." );
+ }
+}
\ No newline at end of file
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java (from rev 16839, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -0,0 +1,444 @@
+// $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.validation;
+
+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.ConstraintDescriptor;
+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 org.jboss.test.audit.annotations.SpecAssertion;
+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.jsr303.tck.util.TestUtil;
+
+/**
+ * Tests for the implementation of <code>Validator</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class ValidateTest extends AbstractTest {
+
+
+ @Test
+ public void testWrongMethodName() {
+ 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"
+ );
+ }
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNullParamterToValidatorImplConstructor() {
+ TestUtil.getDefaultValidator().getConstraintsForClass( null );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testValidateWithNull() {
+ Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( null );
+ }
+
+ @Test
+ @SuppressWarnings("NullArgumentToVariableArgMethod")
+ public void testPassingNullAsGroup() {
+ Validator validator = TestUtil.getDefaultValidator();
+ Customer customer = new Customer();
+ try {
+ validator.validate( customer, null );
+ }
+ 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
+ public void testValidateWithNullProperty() {
+ Validator validator = TestUtil.getDefaultValidator();
+ try {
+ validator.validate( null );
+ fail();
+ }
+ 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();
+
+ Address address = new Address();
+ address.setAddressline1( null );
+ address.setAddressline2( null );
+ address.setCity( "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch" ); //town in North Wales
+
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
+ assertEquals(
+ constraintViolations.size(),
+ 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
+ public void testValidateSet() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Customer customer = new Customer();
+ customer.setFirstName( "John" );
+ customer.setLastName( "Doe" );
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+
+ Order order = new Order();
+ customer.addOrder( order );
+
+ constraintViolations = validator.validate( customer );
+ ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+ org.testng.Assert.assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
+ org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
+ assertEquals( "orders[].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+ }
+
+ @Test
+ public void testMultiValueConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Engine engine = new Engine();
+ engine.setSerialNumber( "mail(a)foobar.com" );
+ Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
+ assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
+
+ engine.setSerialNumber( "ABCDEFGH1234" );
+ constraintViolations = validator.validate( engine );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+ engine.setSerialNumber( "ABCD-EFGH-1234" );
+ constraintViolations = validator.validate( engine );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
+ @Test
+ public void testGraphValidation() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Actor clint = new Actor( "Clint", "Eastwood" );
+ Actor morgan = new Actor( "Morgan", null );
+ Actor charlie = new Actor( "Charlie", "Sheen" );
+
+ clint.addPlayedWith( charlie );
+ charlie.addPlayedWith( clint );
+ charlie.addPlayedWith( morgan );
+ morgan.addPlayedWith( charlie );
+ morgan.addPlayedWith( clint );
+ clint.addPlayedWith( morgan );
+
+
+ Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+ assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
+ org.testng.Assert.assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
+ org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
+ assertEquals(
+ constraintViolation.getPropertyPath(), "playedWith[0].playedWith[1].lastName", "Wrong propertyName"
+ );
+ }
+
+ @Test
+ public void testValidateValue() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
+ Customer.class, "orders[0].orderNumber", null
+ );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+ 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(), null, "Wrong root entity" );
+ assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
+ assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
+ assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+ constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
+ @Test
+ public void testValidateValueWithInvalidPropertyPath() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ try {
+ validator.validateValue( Customer.class, "", null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ assertEquals( "Invalid property path.", e.getMessage() );
+ }
+
+ try {
+ validator.validateValue( Customer.class, "foobar", null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ assertEquals( "Invalid property path.", e.getMessage() );
+ }
+
+ try {
+ validator.validateValue( Customer.class, "orders[0].foobar", null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ assertEquals( "Invalid property path.", e.getMessage() );
+ }
+ }
+
+ @Test
+ public void testValidateProperty() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Customer customer = new Customer();
+ Order order = new Order();
+ customer.addOrder( order );
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validateProperty(
+ customer, "orders[0].orderNumber"
+ );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+ ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+ org.testng.Assert.assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
+ org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
+ assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+ order.setOrderNumber( 1234 );
+ constraintViolations = validator.validateProperty( customer, "orderList[0].orderNumber" );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
+ @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();
+
+ Customer customer = new Customer();
+ customer.setFirstName( "Foo" );
+ customer.setLastName( "Bar" );
+
+ Order order = new Order();
+ customer.addOrder( order );
+
+ Set<ConstraintViolation<Person>> constraintViolations = validator.validate( ( Person ) customer );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+ TestUtil.assertConstraintViolation(
+ constraintViolations.iterator().next(),
+ Customer.class,
+ null,
+ "orders[].orderNumber"
+ );
+
+ order.setOrderNumber( 123 );
+
+ constraintViolations = validator.validate( ( Person ) customer );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
+ @Test
+ public void testObjectTraversion() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Customer customer = new Customer();
+ customer.setFirstName( "John" );
+ customer.setLastName( "Doe" );
+
+ for ( int i = 0; i < 100; i++ ) {
+ Order order = new Order();
+ customer.addOrder( order );
+ }
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validate(
+ customer, Default.class, First.class, Second.class, Last.class
+ );
+ assertEquals( constraintViolations.size(), 100, "Wrong number of constraints" );
+ }
+
+ /**
+ * HV-120
+ */
+ @Test
+ public void testConstraintDescriptorWithoutExplicitGroup() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
+ PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderNumber" );
+ Set<ConstraintDescriptor<?>> descriptors = propertyDescriptor.getConstraintDescriptors();
+
+ assertEquals( descriptors.size(), 1, "There should be only one constraint descriptor" );
+ ConstraintDescriptor<?> descriptor = descriptors.iterator().next();
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 1, "There should be only one group" );
+ assertEquals(
+ groups.iterator().next(),
+ Default.class,
+ "The declared constraint does not explicitly define a group, hence Default is expected"
+ );
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -0,0 +1,188 @@
+// $Id: ValidateTest.java 16824 2009-06-17 20:57:08Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validation;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+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.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * Tests for the implementation of <code>Validator</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class ValidateValueTest extends AbstractTest {
+
+
+ @Test
+ @SuppressWarnings("NullArgumentToVariableArgMethod")
+ public void testPassingNullAsGroup() {
+ Validator validator = TestUtil.getDefaultValidator();
+ Customer customer = new Customer();
+ try {
+ validator.validate( customer, null );
+ }
+ 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
+ public void testValidateWithNullProperty() {
+ Validator validator = TestUtil.getDefaultValidator();
+ try {
+ validator.validate( null );
+ fail();
+ }
+ 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
+ public void testMultipleValidationMethods() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Address address = new Address();
+ address.setAddressline1( null );
+ address.setAddressline2( null );
+ address.setCity( "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch" ); //town in North Wales
+
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
+ assertEquals(
+ constraintViolations.size(),
+ 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
+ public void testValidateValue() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
+ Customer.class, "orders[0].orderNumber", null
+ );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+ 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(), null, "Wrong root entity" );
+ assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
+ assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
+ assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+ constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
+ assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ }
+
+ @Test
+ public void testValidateValueWithInvalidPropertyPath() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ try {
+ validator.validateValue( Customer.class, "", null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ assertEquals( "Invalid property path.", e.getMessage() );
+ }
+
+ try {
+ validator.validateValue( Customer.class, "foobar", null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ assertEquals( "Invalid property path.", e.getMessage() );
+ }
+
+ try {
+ validator.validateValue( Customer.class, "orders[0].foobar", null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ assertEquals( "Invalid property path.", e.getMessage() );
+ }
+ }
+}
\ No newline at end of file
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java 2009-06-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -1,444 +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.validation;
-
-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.ConstraintDescriptor;
-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 org.jboss.test.audit.annotations.SpecAssertion;
-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.jsr303.tck.util.TestUtil;
-
-/**
- * Tests for the implementation of <code>Validator</code>.
- *
- * @author Hardy Ferentschik
- */
-@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
-public class ValidatorImplTest extends AbstractTest {
-
-
- @Test
- public void testWrongMethodName() {
- 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"
- );
- }
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testNullParamterToValidatorImplConstructor() {
- TestUtil.getDefaultValidator().getConstraintsForClass( null );
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testValidateWithNull() {
- Validator validator = TestUtil.getDefaultValidator();
- validator.validate( null );
- }
-
- @Test
- @SuppressWarnings("NullArgumentToVariableArgMethod")
- public void testPassingNullAsGroup() {
- Validator validator = TestUtil.getDefaultValidator();
- Customer customer = new Customer();
- try {
- validator.validate( customer, null );
- }
- 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
- public void testValidateWithNullProperty() {
- Validator validator = TestUtil.getDefaultValidator();
- try {
- validator.validate( null );
- fail();
- }
- 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();
-
- Address address = new Address();
- address.setAddressline1( null );
- address.setAddressline2( null );
- address.setCity( "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch" ); //town in North Wales
-
- Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 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
- public void testValidateSet() {
- Validator validator = TestUtil.getDefaultValidator();
-
- Customer customer = new Customer();
- customer.setFirstName( "John" );
- customer.setLastName( "Doe" );
-
- Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
-
- Order order = new Order();
- customer.addOrder( order );
-
- constraintViolations = validator.validate( customer );
- ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
- assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
- org.testng.Assert.assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
- org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
- assertEquals( "orders[].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
- }
-
- @Test
- public void testMultiValueConstraint() {
- Validator validator = TestUtil.getDefaultValidator();
-
- Engine engine = new Engine();
- engine.setSerialNumber( "mail(a)foobar.com" );
- Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
- assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
-
- engine.setSerialNumber( "ABCDEFGH1234" );
- constraintViolations = validator.validate( engine );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
- engine.setSerialNumber( "ABCD-EFGH-1234" );
- constraintViolations = validator.validate( engine );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @Test
- public void testGraphValidation() {
- Validator validator = TestUtil.getDefaultValidator();
-
- Actor clint = new Actor( "Clint", "Eastwood" );
- Actor morgan = new Actor( "Morgan", null );
- Actor charlie = new Actor( "Charlie", "Sheen" );
-
- clint.addPlayedWith( charlie );
- charlie.addPlayedWith( clint );
- charlie.addPlayedWith( morgan );
- morgan.addPlayedWith( charlie );
- morgan.addPlayedWith( clint );
- clint.addPlayedWith( morgan );
-
-
- Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
- ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
- org.testng.Assert.assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
- org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
- assertEquals(
- constraintViolation.getPropertyPath(), "playedWith[0].playedWith[1].lastName", "Wrong propertyName"
- );
- }
-
- @Test
- public void testValidateValue() {
- Validator validator = TestUtil.getDefaultValidator();
-
- Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
- Customer.class, "orders[0].orderNumber", null
- );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
- 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(), null, "Wrong root entity" );
- assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
- assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
- assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
-
- constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @Test
- public void testValidateValueWithInvalidPropertyPath() {
- Validator validator = TestUtil.getDefaultValidator();
-
- try {
- validator.validateValue( Customer.class, "", null );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- assertEquals( "Invalid property path.", e.getMessage() );
- }
-
- try {
- validator.validateValue( Customer.class, "foobar", null );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- assertEquals( "Invalid property path.", e.getMessage() );
- }
-
- try {
- validator.validateValue( Customer.class, "orders[0].foobar", null );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- assertEquals( "Invalid property path.", e.getMessage() );
- }
- }
-
- @Test
- public void testValidateProperty() {
- Validator validator = TestUtil.getDefaultValidator();
-
- Customer customer = new Customer();
- Order order = new Order();
- customer.addOrder( order );
-
- Set<ConstraintViolation<Customer>> constraintViolations = validator.validateProperty(
- customer, "orders[0].orderNumber"
- );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
- ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
- assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
- org.testng.Assert.assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
- org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
- assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
-
- order.setOrderNumber( 1234 );
- constraintViolations = validator.validateProperty( customer, "orderList[0].orderNumber" );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @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();
-
- Customer customer = new Customer();
- customer.setFirstName( "Foo" );
- customer.setLastName( "Bar" );
-
- Order order = new Order();
- customer.addOrder( order );
-
- Set<ConstraintViolation<Person>> constraintViolations = validator.validate( ( Person ) customer );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
- TestUtil.assertConstraintViolation(
- constraintViolations.iterator().next(),
- Customer.class,
- null,
- "orders[].orderNumber"
- );
-
- order.setOrderNumber( 123 );
-
- constraintViolations = validator.validate( ( Person ) customer );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @Test
- public void testObjectTraversion() {
- Validator validator = TestUtil.getDefaultValidator();
-
- Customer customer = new Customer();
- customer.setFirstName( "John" );
- customer.setLastName( "Doe" );
-
- for ( int i = 0; i < 100; i++ ) {
- Order order = new Order();
- customer.addOrder( order );
- }
-
- Set<ConstraintViolation<Customer>> constraintViolations = validator.validate(
- customer, Default.class, First.class, Second.class, Last.class
- );
- assertEquals( constraintViolations.size(), 100, "Wrong number of constraints" );
- }
-
- /**
- * HV-120
- */
- @Test
- public void testConstraintDescriptorWithoutExplicitGroup() {
- Validator validator = TestUtil.getDefaultValidator();
-
- BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
- PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderNumber" );
- Set<ConstraintDescriptor<?>> descriptors = propertyDescriptor.getConstraintDescriptors();
-
- assertEquals( descriptors.size(), 1, "There should be only one constraint descriptor" );
- ConstraintDescriptor<?> descriptor = descriptors.iterator().next();
- Set<Class<?>> groups = descriptor.getGroups();
- assertTrue( groups.size() == 1, "There should be only one group" );
- assertEquals(
- groups.iterator().next(),
- Default.class,
- "The declared constraint does not explicitly define a group, hence Default is expected"
- );
- }
-}
\ No newline at end of file
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-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-19 11:38:29 UTC (rev 16840)
@@ -80,7 +80,7 @@
}
}
- public static <T> void assertInvalidPropertyPaths(Set<ConstraintViolation<T>> violations, String[] propertyPaths) {
+ public static <T> void assertCorrectPropertyPaths(Set<ConstraintViolation<T>> violations, String[] propertyPaths) {
List<String> propertyPathsOfViolations = new ArrayList<String>();
for ( ConstraintViolation<?> violation : violations ) {
propertyPathsOfViolations.add( violation.getPropertyPath() );
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-18 17:18:35 UTC (rev 16839)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-19 11:38:29 UTC (rev 16840)
@@ -4,12 +4,12 @@
name="JSR-303: Bean Validation" version="Revised Public Review Draft">
<section id="2.1" title="Constraint Definition">
- <assertion id="a">
+ <assertion id="a" testable="false">
<text>An annotation is considered a constraint definition if its retention policy
contains RUNTIME and if the annotation itself is annotated with
javax.validation.Constraint</text>
</assertion>
- <assertion id="b">
+ <assertion id="b" testable="false">
<text>Constraint annotations can target any of the following ElementTypes: FIELD,
METHOD, TYPE, ANNOTATION_TYPE</text>
</assertion>
@@ -54,10 +54,6 @@
annotations in a special way. Each element in the value array are processed by the
Bean Validation implementation as regular constraint annotations.</text>
</assertion>
- <assertion id="b">
- <text>The annotation must have retention RUNTIME and can be applied on a type, field,
- property or an other annotation</text>
- </assertion>
</section>
<section id="2.3" title="Constraint composition">
<assertion id="a">
@@ -65,8 +61,8 @@
target element and this recursively</text>
</assertion>
<assertion id="b">
- <text>Note that the main annotation and its constraint validation implementation is
- also applied</text>
+ <text>Note that the main annotation and its constraint validation implementation is also
+ applied</text>
</assertion>
<assertion id="c">
<text>By default, each failing constraint generates an error report</text>
@@ -104,8 +100,7 @@
</assertion>
<assertion id="k">
<text>A composing constraint can itself be a composed constraint. In this case,
- attribute values are overridden recursively according to the described
- rules</text>
+ attribute values are overridden recursively according to the described rules</text>
</assertion>
<assertion id="l">
<text>If a constraint is used more than once as a composing constraint, the multi value
@@ -158,7 +153,8 @@
<text>isValid implementations must be thread-safe</text>
</assertion>
<assertion id="i">
- <text>If the property is of an unanticipated type, an UnexpectedTypeException is raised</text>
+ <text>If the property is of an unanticipated type, an UnexpectedTypeException is
+ raised</text>
</assertion>
<assertion id="j">
<text>If an exception occurs either in the initialize or isValid method, the runtime
@@ -172,8 +168,8 @@
<assertion id="l">
<text>By default, each invalid constraint leads to the generation of one error object
represented by a ConstraintViolation object. This object is build from the default
- error message as defined by the constraint declaration and the context in which
- the constraint declaration is placed on (bean, property, attribute)</text>
+ error message as defined by the constraint declaration and the context in which the
+ constraint declaration is placed on (bean, property, attribute)</text>
</assertion>
<assertion id="m">
<text>The ConstraintValidatorContext methods let the constraint implementation disable
@@ -378,7 +374,7 @@
</section>
<section id="3.4.3" title="Redefining the Default group for a class">
<assertion id="a">
- <text>To redefine Default for a class, place a @GroupSequence annotation on the class.
+ <text>To redefine Default for a class, place a @GroupSequence annotation on the class.
this sequence expresses the sequence of groups that does substitute Default for this
class.</text>
</assertion>
@@ -498,32 +494,44 @@
</section>
<section id="4.1.1" title="Validation methods">
<assertion id="a">
- <text>validate(T object, Class... groups) is used to validate a given ob- ject</text>
+ <text>validate(T object, Class... groups) is used to validate a given object</text>
</assertion>
<assertion id="b">
- <text>A Set containing all ConstraintViolation ob- jects representing the failing
+ <text>An IllegalArgumentException is thrown if object is null when validate() is
+ called.</text>
+ </assertion>
+ <assertion id="c">
+ <text>A Set containing all ConstraintViolation objects representing the failing
constraints is returned, an empty Set is returned otherwise</text>
</assertion>
- <assertion id="c">
+ <assertion id="d">
<text>validateProperty(T object, String propertyName, Class... groups) validates a given
field or property of an object</text>
</assertion>
- <assertion id="d">
+ <assertion id="e">
+ <text>An IllegalArgumentException is thrown if object is null or propertyName is null
+ empty or invalid when validateProperty() is called.</text>
+ </assertion>
+ <assertion id="f">
<text>The property name is the JavaBeans property name (as defined by the JavaBeans
Introspector class)</text>
</assertion>
- <assertion id="e">
- <text>@Valid is not honored by this method</text>
+ <assertion id="g">
+ <text>@Valid is not honored by validateProperty()</text>
</assertion>
- <assertion id="f">
+ <assertion id="h">
<text>validateValue(Class beanType, String propertyName, Object value, Class... groups)
validates the property referenced by propertyName present on beanType or any of its
superclasses, if the property value were value.</text>
</assertion>
- <assertion id="g">
- <text>@Valid is not honored by this method</text>
+ <assertion id="i">
+ <text>An IllegalArgumentException is thrown if object is null or propertyName is null
+ empty or invalid when validateValue() is called.</text>
</assertion>
- <assertion id="h">
+ <assertion id="j">
+ <text>@Valid is not honored by validateValue()</text>
+ </assertion>
+ <assertion id="k">
<text>If some unrecoverable failure happens during validation, a ValidationException is
raised.</text>
</assertion>
@@ -863,7 +871,7 @@
<text>ValidatorFactory is a thread-safe object that should be built once per deployment
unit</text>
</assertion>
- <assertion id="b" testable="false" >
+ <assertion id="b" testable="false">
<text>Validator is thread-safe too and should be considered a lightweight object</text>
</assertion>
</section>
15 years, 5 months
Hibernate SVN: r16839 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-18 13:18:35 -0400 (Thu, 18 Jun 2009)
New Revision: 16839
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
Log:
Made sure null instance returned from validator factory throws ValidationException
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-18 17:17:48 UTC (rev 16838)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-06-18 17:18:35 UTC (rev 16839)
@@ -180,6 +180,11 @@
constraintValidator = ( ConstraintValidator<A, V> ) constraintFactory.getInstance(
validatorClass
);
+ if ( constraintValidator == null ) {
+ throw new ValidationException(
+ "Constraint factory returned null when trying to create instance of " + validatorClass.getName()
+ );
+ }
constraintValidatorCache.put( validatorClass, constraintValidator );
}
else {
15 years, 5 months
Hibernate SVN: r16838 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-18 13:17:48 -0400 (Thu, 18 Jun 2009)
New Revision: 16838
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java
Log:
Made sure RuntimeException during Validator creating is wrapped
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java 2009-06-18 17:17:16 UTC (rev 16837)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.java 2009-06-18 17:17:48 UTC (rev 16838)
@@ -25,6 +25,7 @@
* Default <code>ConstraintValidatorFactory</code> using a no-arg constructor.
*
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class ConstraintValidatorFactoryImpl implements ConstraintValidatorFactory {
@@ -41,5 +42,8 @@
catch ( IllegalAccessException e ) {
throw new ValidationException( "Unable to instanciate " + key, e );
}
+ catch ( RuntimeException e ) {
+ throw new ValidationException( "Unable to instanciate " + key, e );
+ }
}
}
15 years, 5 months
Hibernate SVN: r16837 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-18 13:17:16 -0400 (Thu, 18 Jun 2009)
New Revision: 16837
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java
Log:
cleanup
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-18 17:16:55 UTC (rev 16836)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java 2009-06-18 17:17:16 UTC (rev 16837)
@@ -18,7 +18,6 @@
package org.hibernate.validation;
import javax.validation.Configuration;
-import javax.validation.ValidationException;
import javax.validation.ValidatorFactory;
import javax.validation.spi.BootstrapState;
import javax.validation.spi.ConfigurationState;
@@ -37,7 +36,6 @@
public class HibernateValidationProvider implements ValidationProvider<HibernateValidatorConfiguration> {
public HibernateValidatorConfiguration createSpecializedConfiguration(BootstrapState state) {
- //cast protected by isSuitable call
return HibernateValidatorConfiguration.class.cast( new ConfigurationImpl( this ) );
}
15 years, 5 months
Hibernate SVN: r16836 - in beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests: validation/customconstraint and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-18 13:16:55 -0400 (Thu, 18 Jun 2009)
New Revision: 16836
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraintValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Negative.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java
Log:
added test for ConstraintValidatorFactory
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java 2009-06-18 16:29:46 UTC (rev 16835)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -24,6 +24,7 @@
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public abstract class BoundariesConstraintValidator<T extends Annotation> implements ConstraintValidator<T, Integer> {
public static boolean initializeCalled = false;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java 2009-06-18 16:29:46 UTC (rev 16835)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -39,6 +39,7 @@
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
@Classes(TestUtil.class)
@@ -147,6 +148,4 @@
@Negative
public int temprature;
}
-
-
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Negative.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Negative.java 2009-06-18 16:29:46 UTC (rev 16835)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Negative.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -17,23 +17,24 @@
*/
package org.hibernate.jsr303.tck.tests.validation.customconstraint;
-import java.lang.annotation.Target;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Target;
import javax.validation.Constraint;
/**
* @author Emmanuel Bernard
*/
-@Constraint( validatedBy = { PositiveConstraintValidator.class })
+@Constraint(validatedBy = { NegativeConstraintValidator.class })
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
public @interface Negative {
public abstract String message() default "{validation.negative}";
- public abstract Class<?>[] groups() default {};
+
+ public abstract Class<?>[] groups() default { };
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java 2009-06-18 16:29:46 UTC (rev 16835)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -21,10 +21,11 @@
import javax.validation.ConstraintValidatorContext;
/**
- * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
-public abstract class NegativeConstraintValidator implements ConstraintValidator<Negative, Integer> {
- protected void initialize(int low, int high) {
+public class NegativeConstraintValidator implements ConstraintValidator<Negative, Integer> {
+
+ public void initialize(Negative constraintAnnotation) {
throw new RuntimeException( "Throwing a RuntimeException from NegativeConstraintValidator.initialize" );
}
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/CustomConstraintValidatorTest.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -0,0 +1,85 @@
+// $Id: CustomConstraintValidatorTest.java 16835 2009-06-18 16:29:46Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validatorfactory;
+
+import javax.validation.Configuration;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import static org.testng.Assert.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 CustomConstraintValidatorTest extends AbstractTest {
+
+ @SpecAssertion(section = "2.5", id = "a")
+ @Test
+ public void testDefaultConstructorInValidatorCalled() {
+ Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( new Dummy() );
+ assertTrue(
+ MyConstraintValidator.defaultConstructorCalled,
+ "The no-arg default constructor should have been called."
+ );
+ }
+
+ @SpecAssertion(section = "2.5", id = "b")
+ @Test(expectedExceptions = ValidationException.class)
+ public void testRuntimeExceptionInValidatorCreationIsWrapped() {
+ Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( new SecondDummy() );
+ }
+
+ @SpecAssertion(section = "2.5", id = "c")
+ @Test(expectedExceptions = ValidationException.class)
+ public void testValidationExceptionIsThrownInCaseFactoryReturnsNull() {
+ Configuration<?> config = Validation.byDefaultProvider().configure().constraintValidatorFactory(
+ new ConstraintValidatorFactory() {
+ public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
+ return null;
+ }
+ }
+ );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ validator.validate( new SecondDummy() );
+ }
+
+ public static class Dummy {
+ @MyConstraint
+ public int value;
+ }
+
+ public static class SecondDummy {
+ @MySecondConstraint
+ public int value;
+ }
+}
\ No newline at end of file
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraint.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -0,0 +1,40 @@
+// $Id: MyConstraint.java 16835 2009-06-18 16:29:46Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validatorfactory;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = { MyConstraintValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface MyConstraint {
+ public abstract String message() default "my constraint failed";
+
+ public abstract Class<?>[] groups() default { };
+}
\ No newline at end of file
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraintValidator.java (from rev 16835, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraintValidator.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraintValidator.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -0,0 +1,40 @@
+// $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.validatorfactory;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class MyConstraintValidator implements ConstraintValidator<MyConstraint, Integer> {
+
+ public static boolean defaultConstructorCalled = false;
+
+ public MyConstraintValidator() {
+ defaultConstructorCalled = true;
+ }
+
+ public void initialize(MyConstraint constraintAnnotation) {
+ }
+
+ public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MyConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraint.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -0,0 +1,40 @@
+// $Id: MyConstraint.java 16835 2009-06-18 16:29:46Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validatorfactory;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = { MySecondConstraintValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface MySecondConstraint {
+ public abstract String message() default "my second constraint failed.";
+
+ public abstract Class<?>[] groups() default { };
+}
\ No newline at end of file
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validatorfactory/MySecondConstraintValidator.java 2009-06-18 17:16:55 UTC (rev 16836)
@@ -0,0 +1,38 @@
+// $Id: MyConstraintValidator.java 16835 2009-06-18 16:29:46Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validatorfactory;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class MySecondConstraintValidator implements ConstraintValidator<MySecondConstraint, Integer> {
+
+ public MySecondConstraintValidator() {
+ throw new RuntimeException( "Runtime exception in validator creation" );
+ }
+
+ public void initialize(MySecondConstraint constraintAnnotation) {
+ }
+
+ public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+}
\ No newline at end of file
15 years, 5 months
Hibernate SVN: r16835 - in beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests: validation and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-18 12:29:46 -0400 (Thu, 18 Jun 2009)
New Revision: 16835
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Negative.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Positive.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/PositiveConstraintValidator.java
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/BoundariesConstraintValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/CustomConstraintValidatorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Negative.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/NegativeConstraintValidator.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Positive.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/PositiveConstraintValidator.java
Log:
package refactoring
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/BoundariesConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/BoundariesConstraintValidator.java 2009-06-18 16:25:46 UTC (rev 16834)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/BoundariesConstraintValidator.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -1,58 +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.constraints.customconstraint;
-
-import java.lang.annotation.Annotation;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.ValidationException;
-
-/**
- * @author Emmanuel Bernard
- */
-public abstract class BoundariesConstraintValidator<T extends Annotation> implements ConstraintValidator<T, Integer> {
- public static boolean initializeCalled = false;
- public static int isValidCalls = 0;
- public static boolean throwRuntimeExceptionFromInitalize = false;
- public static boolean throwRuntimeExceptionFromIsValid = false;
-
- private int low;
- private int high;
-
- protected void initialize(int low, int high) {
- initializeCalled = true;
- if ( throwRuntimeExceptionFromInitalize ) {
- throwRuntimeExceptionFromInitalize = false;
- throw new RuntimeException( "Throwing a RuntimeException from BoundariesConstraintValidator.initialize" );
- }
- this.low = low;
- this.high = high;
- }
-
- public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
- if ( !initializeCalled ) {
- throw new ValidationException( "initialize() must be called before the usage of isValid()" );
- }
- if ( throwRuntimeExceptionFromIsValid ) {
- throwRuntimeExceptionFromIsValid = false;
- throw new RuntimeException( "Throwing a RuntimeException from BoundariesConstraintValidator.isValid" );
- }
- isValidCalls++;
- return value >= low && value <= high;
- }
-}
\ No newline at end of file
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/CustomConstraintValidatorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/CustomConstraintValidatorTest.java 2009-06-18 16:25:46 UTC (rev 16834)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/CustomConstraintValidatorTest.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -1,152 +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.constraints.customconstraint;
-
-import java.util.Set;
-import javax.validation.ConstraintViolation;
-import javax.validation.UnexpectedTypeException;
-import javax.validation.ValidationException;
-import javax.validation.Validator;
-import javax.validation.metadata.PropertyDescriptor;
-
-import org.jboss.test.audit.annotations.SpecAssertion;
-import org.jboss.test.audit.annotations.SpecAssertions;
-import org.jboss.testharness.AbstractTest;
-import org.jboss.testharness.impl.packaging.Artifact;
-import org.jboss.testharness.impl.packaging.ArtifactType;
-import org.jboss.testharness.impl.packaging.Classes;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
-
-import org.hibernate.jsr303.tck.util.TestUtil;
-
-/**
- * @author Emmanuel Bernard
- */
-@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
-public class CustomConstraintValidatorTest extends AbstractTest {
-
- @Test
- @SpecAssertions({
- @SpecAssertion(section = "2.4", id = "a"),
- @SpecAssertion(section = "2.4", id = "b"),
- @SpecAssertion(section = "2.4", id = "e")
- })
- public void testRightValidatorIsSlectedAndInializedCalled() {
- Validator validator = TestUtil.getDefaultValidator();
- Shoe shoe = new Shoe();
- shoe.size = -2;
- final PropertyDescriptor propertyDescriptor = validator.getConstraintsForClass( Shoe.class )
- .getConstraintsForProperty( "size" );
- assertNotNull( propertyDescriptor );
-
- BoundariesConstraintValidator.isValidCalls = 0;
- final Set<ConstraintViolation<Shoe>> constraintViolations = validator.validate( shoe );
- assertEquals( 1, constraintViolations.size() );
- assertTrue(
- BoundariesConstraintValidator.isValidCalls == 1,
- "Ensure the right validator implementation class was picked."
- );
- assertTrue(
- BoundariesConstraintValidator.initializeCalled,
- "Check initilize was called. Note this is not really ensuring that it was called before isValid. That is done in the actual implementation of the validator."
- );
- }
-
- @Test
- @SpecAssertions({
- @SpecAssertion(section = "2.4", id = "a"),
- @SpecAssertion(section = "2.4", id = "b"),
- @SpecAssertion(section = "2.4", id = "f")
- })
- public void testIsValidIsCalledForEachValidation() {
- Validator validator = TestUtil.getDefaultValidator();
- Shoe shoe = new Shoe();
- shoe.size = -2;
-
- BoundariesConstraintValidator.isValidCalls = 0;
- validator.validate( shoe );
- assertTrue(
- BoundariesConstraintValidator.isValidCalls == 1,
- "Ensure is valid hasbeen called."
- );
-
- validator.validate( shoe );
- assertTrue(
- BoundariesConstraintValidator.isValidCalls == 2,
- "Ensure is valid hasbeen called."
- );
-
- validator.validateProperty( shoe, "size" );
- assertTrue(
- BoundariesConstraintValidator.isValidCalls == 3,
- "Ensure is valid hasbeen called."
- );
-
- validator.validateValue( Shoe.class, "size", 41 );
- assertTrue(
- BoundariesConstraintValidator.isValidCalls == 4,
- "Ensure is valid hasbeen called."
- );
- }
-
-
- @SpecAssertion(section = "2.4", id = "i")
- @Test(expectedExceptions = UnexpectedTypeException.class)
- public void testUnexpectedTypeExceptionIsRaisedForInvalidType() {
- Validator validator = TestUtil.getDefaultValidator();
- validator.validate( new OddShoe() );
- }
-
- @SpecAssertion(section = "2.4", id = "j")
- @Test(expectedExceptions = ValidationException.class)
- public void testRuntimeExceptionFromIsValidIsWrapped() {
- Validator validator = TestUtil.getDefaultValidator();
- Shoe shoe = new Shoe();
- shoe.size = -2;
- BoundariesConstraintValidator.throwRuntimeExceptionFromIsValid = true;
- validator.validate( shoe );
- }
-
- @SpecAssertion(section = "2.4", id = "j")
- @Test(expectedExceptions = ValidationException.class)
- public void testRuntimeExceptionFromInitializeIsWrapped() {
- Validator validator = TestUtil.getDefaultValidator();
- validator.validate( new Freezer() );
- }
-
- public static class Shoe {
- @Positive
- public int size;
- }
-
- public static class OddShoe {
- @Positive
- public String size;
- }
-
- public static class Freezer {
- @Negative
- public int temprature;
- }
-
-
-}
\ No newline at end of file
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Negative.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Negative.java 2009-06-18 16:25:46 UTC (rev 16834)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Negative.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -1,39 +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.constraints.customconstraint;
-
-import java.lang.annotation.Target;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import javax.validation.Constraint;
-
-/**
- * @author Emmanuel Bernard
- */
-@Constraint( validatedBy = { PositiveConstraintValidator.class })
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
-@Retention(RUNTIME)
-@Documented
-public @interface Negative {
- public abstract String message() default "{validation.negative}";
- public abstract Class<?>[] groups() default {};
-}
\ No newline at end of file
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/NegativeConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/NegativeConstraintValidator.java 2009-06-18 16:25:46 UTC (rev 16834)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/NegativeConstraintValidator.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -1,35 +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.constraints.customconstraint;
-
-import java.lang.annotation.Annotation;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Emmanuel Bernard
- */
-public abstract class NegativeConstraintValidator implements ConstraintValidator<Negative, Integer> {
- protected void initialize(int low, int high) {
- throw new RuntimeException( "Throwing a RuntimeException from NegativeConstraintValidator.initialize" );
- }
-
- public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
- return true;
- }
-}
\ No newline at end of file
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Positive.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Positive.java 2009-06-18 16:25:46 UTC (rev 16834)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Positive.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -1,39 +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.constraints.customconstraint;
-
-import java.lang.annotation.Target;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Documented;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-import javax.validation.Constraint;
-
-/**
- * @author Emmanuel Bernard
- */
-@Constraint( validatedBy = { PositiveConstraintValidator.class })
-@Target({ METHOD, FIELD, ANNOTATION_TYPE })
-@Retention(RUNTIME)
-@Documented
-public @interface Positive {
- public abstract String message() default "{validation.positive}";
- public abstract Class<?>[] groups() default {};
-}
\ No newline at end of file
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/PositiveConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/PositiveConstraintValidator.java 2009-06-18 16:25:46 UTC (rev 16834)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/PositiveConstraintValidator.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -1,27 +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.constraints.customconstraint;
-
-/**
- * @author Emmanuel Bernard
- */
-public class PositiveConstraintValidator extends BoundariesConstraintValidator<Positive> {
- public void initialize(Positive constraintAnnotation) {
- super.initialize( 0, Integer.MAX_VALUE );
- }
-}
\ No newline at end of file
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java (from rev 16832, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/BoundariesConstraintValidator.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -0,0 +1,58 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validation.customconstraint;
+
+import java.lang.annotation.Annotation;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class BoundariesConstraintValidator<T extends Annotation> implements ConstraintValidator<T, Integer> {
+ public static boolean initializeCalled = false;
+ public static int isValidCalls = 0;
+ public static boolean throwRuntimeExceptionFromInitalize = false;
+ public static boolean throwRuntimeExceptionFromIsValid = false;
+
+ private int low;
+ private int high;
+
+ protected void initialize(int low, int high) {
+ initializeCalled = true;
+ if ( throwRuntimeExceptionFromInitalize ) {
+ throwRuntimeExceptionFromInitalize = false;
+ throw new RuntimeException( "Throwing a RuntimeException from BoundariesConstraintValidator.initialize" );
+ }
+ this.low = low;
+ this.high = high;
+ }
+
+ public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
+ if ( !initializeCalled ) {
+ throw new ValidationException( "initialize() must be called before the usage of isValid()" );
+ }
+ if ( throwRuntimeExceptionFromIsValid ) {
+ throwRuntimeExceptionFromIsValid = false;
+ throw new RuntimeException( "Throwing a RuntimeException from BoundariesConstraintValidator.isValid" );
+ }
+ isValidCalls++;
+ return value >= low && value <= high;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/BoundariesConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java (from rev 16832, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/CustomConstraintValidatorTest.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -0,0 +1,152 @@
+// $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.validation.customconstraint;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.UnexpectedTypeException;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.metadata.PropertyDescriptor;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class CustomConstraintValidatorTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "2.4", id = "a"),
+ @SpecAssertion(section = "2.4", id = "b"),
+ @SpecAssertion(section = "2.4", id = "e")
+ })
+ public void testRightValidatorIsSlectedAndInializedCalled() {
+ Validator validator = TestUtil.getDefaultValidator();
+ Shoe shoe = new Shoe();
+ shoe.size = -2;
+ final PropertyDescriptor propertyDescriptor = validator.getConstraintsForClass( Shoe.class )
+ .getConstraintsForProperty( "size" );
+ assertNotNull( propertyDescriptor );
+
+ BoundariesConstraintValidator.isValidCalls = 0;
+ final Set<ConstraintViolation<Shoe>> constraintViolations = validator.validate( shoe );
+ assertEquals( 1, constraintViolations.size() );
+ assertTrue(
+ BoundariesConstraintValidator.isValidCalls == 1,
+ "Ensure the right validator implementation class was picked."
+ );
+ assertTrue(
+ BoundariesConstraintValidator.initializeCalled,
+ "Check initilize was called. Note this is not really ensuring that it was called before isValid. That is done in the actual implementation of the validator."
+ );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "2.4", id = "a"),
+ @SpecAssertion(section = "2.4", id = "b"),
+ @SpecAssertion(section = "2.4", id = "f")
+ })
+ public void testIsValidIsCalledForEachValidation() {
+ Validator validator = TestUtil.getDefaultValidator();
+ Shoe shoe = new Shoe();
+ shoe.size = -2;
+
+ BoundariesConstraintValidator.isValidCalls = 0;
+ validator.validate( shoe );
+ assertTrue(
+ BoundariesConstraintValidator.isValidCalls == 1,
+ "Ensure is valid hasbeen called."
+ );
+
+ validator.validate( shoe );
+ assertTrue(
+ BoundariesConstraintValidator.isValidCalls == 2,
+ "Ensure is valid hasbeen called."
+ );
+
+ validator.validateProperty( shoe, "size" );
+ assertTrue(
+ BoundariesConstraintValidator.isValidCalls == 3,
+ "Ensure is valid hasbeen called."
+ );
+
+ validator.validateValue( Shoe.class, "size", 41 );
+ assertTrue(
+ BoundariesConstraintValidator.isValidCalls == 4,
+ "Ensure is valid hasbeen called."
+ );
+ }
+
+
+ @SpecAssertion(section = "2.4", id = "i")
+ @Test(expectedExceptions = UnexpectedTypeException.class)
+ public void testUnexpectedTypeExceptionIsRaisedForInvalidType() {
+ Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( new OddShoe() );
+ }
+
+ @SpecAssertion(section = "2.4", id = "j")
+ @Test(expectedExceptions = ValidationException.class)
+ public void testRuntimeExceptionFromIsValidIsWrapped() {
+ Validator validator = TestUtil.getDefaultValidator();
+ Shoe shoe = new Shoe();
+ shoe.size = -2;
+ BoundariesConstraintValidator.throwRuntimeExceptionFromIsValid = true;
+ validator.validate( shoe );
+ }
+
+ @SpecAssertion(section = "2.4", id = "j")
+ @Test(expectedExceptions = ValidationException.class)
+ public void testRuntimeExceptionFromInitializeIsWrapped() {
+ Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( new Freezer() );
+ }
+
+ public static class Shoe {
+ @Positive
+ public int size;
+ }
+
+ public static class OddShoe {
+ @Positive
+ public String size;
+ }
+
+ public static class Freezer {
+ @Negative
+ public int temprature;
+ }
+
+
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/CustomConstraintValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Negative.java (from rev 16832, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Negative.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Negative.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Negative.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validation.customconstraint;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import javax.validation.Constraint;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Constraint( validatedBy = { PositiveConstraintValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface Negative {
+ public abstract String message() default "{validation.negative}";
+ 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/validation/customconstraint/Negative.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java (from rev 16832, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/NegativeConstraintValidator.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -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.validation.customconstraint;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class NegativeConstraintValidator implements ConstraintValidator<Negative, Integer> {
+ protected void initialize(int low, int high) {
+ throw new RuntimeException( "Throwing a RuntimeException from NegativeConstraintValidator.initialize" );
+ }
+
+ public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/NegativeConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Positive.java (from rev 16812, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/Positive.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Positive.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Positive.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.validation.customconstraint;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import javax.validation.Constraint;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Constraint( validatedBy = { PositiveConstraintValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface Positive {
+ public abstract String message() default "{validation.positive}";
+ 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/validation/customconstraint/Positive.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/PositiveConstraintValidator.java (from rev 16832, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/PositiveConstraintValidator.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/PositiveConstraintValidator.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/PositiveConstraintValidator.java 2009-06-18 16:29:46 UTC (rev 16835)
@@ -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.validation.customconstraint;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class PositiveConstraintValidator extends BoundariesConstraintValidator<Positive> {
+ public void initialize(Positive constraintAnnotation) {
+ super.initialize( 0, Integer.MAX_VALUE );
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/PositiveConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
15 years, 5 months