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