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