[hibernate-commits] Hibernate SVN: r16695 - in beanvalidation/trunk/validation-tck/src: main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition and 5 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jun 4 10:59:34 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-04 10:59:34 -0400 (Thu, 04 Jun 2009)
New Revision: 16695

Added:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Address.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchAddress.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeConstraintValidator.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanAddress.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcode.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcodeConstraintValidator.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/AlwaysValid.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/AlwaysValidList.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/Person.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/StandaloneContainersImpl.java
Removed:
   beanvalidation/trunk/validation-tck/src/test/java/org/hibernate/jsr303/tck/tests/StandaloneContainersImpl.java
   beanvalidation/trunk/validation-tck/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/default/beans.xml
Modified:
   beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
Added tests for constraint composistion; added a default implementation for the test harness standalone container

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Address.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Address.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Address.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,73 @@
+// $Id: Address.java 16156 2009-03-13 09:46:38Z 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.constraints.constraintcomposition;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Address {
+	@NotNull
+	@Size(max = 30)
+	private String addressline1;
+
+	@NotNull
+	@Size(max = 30)
+	private String addressline2;
+
+	private String zipCode;
+
+	private String city;
+
+	public String getAddressline1() {
+		return addressline1;
+	}
+
+	public void setAddressline1(String addressline1) {
+		this.addressline1 = addressline1;
+	}
+
+	public String getAddressline2() {
+		return addressline2;
+	}
+
+	public void setAddressline2(String addressline2) {
+		this.addressline2 = addressline2;
+	}
+
+	public String getZipCode() {
+		return zipCode;
+	}
+
+	public void setZipCode(String zipCode) {
+		this.zipCode = zipCode;
+	}
+
+	@Size(max = 30)
+	@NotNull
+	public String getCity() {
+		return city;
+	}
+
+	public void setCity(String city) {
+		this.city = city;
+	}
+}
+

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,130 @@
+// $Id: ConstraintCompositionTest.java 16249 2009-04-02 12:10:40Z 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.constraints.constraintcomposition;
+
+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 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.assertCorrectNumberOfViolations;
+
+/**
+ * Tests for composing constraints.
+ *
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes(TestUtil.class)
+public class ConstraintCompositionTest extends AbstractTest {
+
+	@Test
+	public void testComposition() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		FrenchAddress address = new FrenchAddress();
+		address.setAddressline1( "10 rue des Treuils" );
+		address.setAddressline2( "BP 12 " );
+		address.setCity( "Bordeaux" );
+		Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
+		assertConstraintViolation(
+				constraintViolations.iterator().next(),
+				FrenchAddress.class,
+				null,
+				"zipCode"
+		);
+
+
+		address.setZipCode( "abc" );
+		constraintViolations = validator.validate( address );
+		assertCorrectNumberOfViolations( constraintViolations, 3 );
+		for ( ConstraintViolation<FrenchAddress> violation : constraintViolations ) {
+			assertConstraintViolation(
+					violation,
+					FrenchAddress.class,
+					"abc",
+					"zipCode"
+			);
+
+		}
+
+
+		address.setZipCode( "123" );
+		constraintViolations = validator.validate( address );
+		assertCorrectNumberOfViolations( constraintViolations, 2 );
+		for ( ConstraintViolation<FrenchAddress> violation : constraintViolations ) {
+			assertConstraintViolation(
+					violation,
+					FrenchAddress.class,
+					"123",
+					"zipCode"
+			);
+
+		}
+
+		address.setZipCode( "33023" );
+		constraintViolations = validator.validate( address );
+		assertCorrectNumberOfViolations( constraintViolations, 0 );
+	}
+
+	@Test
+	public void testNestedComposition() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		GermanAddress address = new GermanAddress();
+		address.setAddressline1( "Rathausstrasse 5" );
+		address.setAddressline2( "3ter Stock" );
+		address.setCity( "Karlsruhe" );
+		Set<ConstraintViolation<GermanAddress>> constraintViolations = validator.validate( address );
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
+		assertConstraintViolation(
+				constraintViolations.iterator().next(),
+				GermanAddress.class,
+				null,
+				"zipCode"
+		);
+	}
+
+	@Test
+	public void testOnlySingleConstraintViolation() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		GermanAddress address = new GermanAddress();
+		address.setAddressline1( "Rathausstrasse 5" );
+		address.setAddressline2( "3ter Stock" );
+		address.setCity( "Karlsruhe" );
+		address.setZipCode( "abc" );
+		// actually three composing constraints fail, but due to @ReportAsSingleViolation only one will be reported.
+		Set<ConstraintViolation<GermanAddress>> constraintViolations = validator.validate( address );
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
+		assertConstraintViolation(
+				constraintViolations.iterator().next(),
+				GermanAddress.class,
+				"abc",
+				"zipCode"
+		);
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchAddress.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchAddress.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchAddress.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,29 @@
+// $Id: FrenchAddress.java 16156 2009-03-13 09:46:38Z 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.constraints.constraintcomposition;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class FrenchAddress extends Address {
+
+	@FrenchZipcode
+	public String getZipCode() {
+		return super.getZipCode();
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,60 @@
+// $Id: FrenchZipcode.java 16264 2009-04-06 15:10:53Z 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.constraints.constraintcomposition;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.OverridesAttribute;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at NotNull
+ at Size
+// first pattern just duplicates the length of 5 characters, the second pattern is just to proof that parameters can be overridden.
+ at Pattern.List({ @Pattern(regexp = "....."), @Pattern(regexp = "bar") })
+ at Constraint(validatedBy = FrenchZipcodeConstraintValidator.class)
+ at Documented
+ at Target({ METHOD, FIELD, TYPE })
+ at Retention(RUNTIME)
+public @interface FrenchZipcode {
+	String message() default "Wrong zipcode";
+
+	Class<?>[] groups() default { };
+
+	@OverridesAttribute.List({
+			@OverridesAttribute(constraint = Size.class, name = "min"),
+			@OverridesAttribute(constraint = Size.class, name = "max")
+	}) int size() default 5;
+
+	@OverridesAttribute(constraint = Size.class,
+			name = "message") String sizeMessage() default "A french zip code has a length of 5";
+
+
+	@OverridesAttribute(constraint = Pattern.class, name = "regexp", constraintIndex = 2) String regex() default "\\d*";
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeConstraintValidator.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeConstraintValidator.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,34 @@
+// $Id: FrenchZipcodeConstraintValidator.java 15829 2009-01-29 05:20:27Z epbernard $
+/*
+* 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.constraintcomposition;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class FrenchZipcodeConstraintValidator implements ConstraintValidator<FrenchZipcode, String> {
+
+	public void initialize(FrenchZipcode parameters) {
+	}
+
+	public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
+		return true;
+	}
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanAddress.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanAddress.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanAddress.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,29 @@
+// $Id: GermanAddress.java 16156 2009-03-13 09:46:38Z 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.constraints.constraintcomposition;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class GermanAddress extends Address {
+
+	@GermanZipcode
+	public String getZipCode() {
+		return super.getZipCode();
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcode.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcode.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcode.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,45 @@
+// $Id: GermanZipcode.java 15875 2009-02-03 23:25:10Z epbernard $
+/*
+* 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.constraintcomposition;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.ReportAsSingleViolation;
+
+/**
+ * Constraint used to test nested composing constraints.
+ *
+ * @author Hardy Ferentschik
+ */
+ at FrenchZipcode
+ at Constraint(validatedBy = GermanZipcodeConstraintValidator.class)
+ at Documented
+ at Target({ METHOD, FIELD, TYPE })
+ at Retention(RUNTIME)
+ at ReportAsSingleViolation
+public @interface GermanZipcode {
+	public abstract String message() default "Falsche Postnummer.";
+
+	public abstract Class<?>[] groups() default { };
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcodeConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcodeConstraintValidator.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcodeConstraintValidator.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,34 @@
+// $Id: GermanZipcodeConstraintValidator.java 15829 2009-01-29 05:20:27Z epbernard $
+/*
+* 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.constraintcomposition;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class GermanZipcodeConstraintValidator implements ConstraintValidator<GermanZipcode, String> {
+
+	public void initialize(GermanZipcode parameters) {
+	}
+
+	public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
+		return true;
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/AlwaysValid.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/AlwaysValid.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/AlwaysValid.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,57 @@
+// $Id: ValidProperty.java 16691 2009-06-04 09:18:14Z 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.constraints.constraintdefinition;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Documented
+ at Constraint(validatedBy = AlwaysValid.StaticConstraintValidator.class)
+ at Target({ TYPE, METHOD, FIELD })
+ at Retention(RUNTIME)
+public @interface AlwaysValid {
+	public abstract String message() default "default message";
+
+	public abstract Class<?>[] groups() default { };
+
+	public abstract boolean alwaysValid();
+
+	public class StaticConstraintValidator implements ConstraintValidator<AlwaysValid, Object> {
+
+		boolean valid;
+
+		public void initialize(AlwaysValid parameters) {
+			valid = parameters.alwaysValid();
+		}
+
+		public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
+			return valid;
+		}
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/AlwaysValidList.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/AlwaysValidList.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/AlwaysValidList.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,36 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.constraints.constraintdefinition;
+
+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;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ at Retention(RUNTIME)
+ at Documented
+		@interface AlwaysValidList {
+	AlwaysValid[] value();
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/ConstraintDefinitionsTest.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,85 @@
+// $Id: InvalidConstraintDefinitionsTest.java 16693 2009-06-04 10:59:42Z 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.constraints.constraintdefinition;
+
+import java.util.Set;
+import javax.validation.ConstraintDescriptor;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+
+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 org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes(TestUtil.class)
+public class ConstraintDefinitionsTest extends AbstractTest {
+
+	@Test
+	@SpecAssertions({
+			@SpecAssertion(section = "2.1.1", id = "a"),
+			@SpecAssertion(section = "2.2", id = "a")
+	})
+	public void testConstraintWithCustomAttributes() {
+
+		Validator validator = TestUtil.getDefaultValidator();
+		Set<ConstraintDescriptor<?>> descriptors = validator.getConstraintsForClass( Person.class )
+				.getConstraintsForProperty( "lastName" )
+				.getConstraintDescriptors();
+
+		assertEquals( descriptors.size(), 2, "There should be two constraints on the lastName property." );
+		for ( ConstraintDescriptor<?> descriptor : descriptors ) {
+			assertEquals(
+					descriptor.getAnnotation().annotationType().getName(),
+					AlwaysValid.class.getName(),
+					"Wrong annotation type."
+			);
+		}
+
+		Set<ConstraintViolation<Person>> constraintViolations = validator.validate( new Person( "John", "Doe" ) );
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
+	}
+
+	@Test
+	@SpecAssertion(section = "2.1.1", id = "f")
+	public void testDefaultGroupAssumedWhenNoGroupsSpecified() {
+
+		Validator validator = TestUtil.getDefaultValidator();
+		ConstraintDescriptor<?> descriptor = validator.getConstraintsForClass( Person.class )
+				.getConstraintsForProperty( "firstName" )
+				.getConstraintDescriptors()
+				.iterator()
+				.next();
+
+		Set<Class<?>> groups = descriptor.getGroups();
+		assertEquals( groups.size(), 1, "The group set should only contain one entry." );
+		assertEquals( groups.iterator().next(), Default.class, "The Default group should be returned." );
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/Person.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/Person.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintdefinition/Person.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -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.constraints.constraintdefinition;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Person {
+	@NotNull
+	private String firstName;
+
+	// a little bit of a catch 22 here
+	@AlwaysValidList({
+			@AlwaysValid(alwaysValid = true),
+			@AlwaysValid(alwaysValid = false)
+	})
+	private String lastName;
+
+	public Person(String firstName, String lastName) {
+		this.firstName = firstName;
+		this.lastName = lastName;
+	}
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/StandaloneContainersImpl.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/StandaloneContainersImpl.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/StandaloneContainersImpl.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -0,0 +1,107 @@
+// $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.util;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.testharness.api.DeploymentException;
+import org.jboss.testharness.spi.StandaloneContainers;
+
+
+public class StandaloneContainersImpl implements StandaloneContainers {
+
+	public void deploy(Iterable<Class<?>> classes) throws DeploymentException {
+	}
+
+	public void undeploy() {
+	}
+
+	public void setup() {
+	}
+
+	public void cleanup() {
+	}
+
+	public void deploy(Iterable<Class<?>> classes, Iterable<URL> validationXmls) throws DeploymentException {
+		if ( validationXmls == null || !validationXmls.iterator().hasNext() ) {
+			Thread.currentThread()
+					.setContextClassLoader( new IgnoringValidationXmlClassLoader() );
+			return;
+		}
+
+		URL validationXmlUrl = validationXmls.iterator().next();
+		Thread.currentThread()
+				.setContextClassLoader( new CustomValidationXmlClassLoader( validationXmlUrl.getPath() ) );
+	}
+
+
+	private static class CustomValidationXmlClassLoader extends ClassLoader {
+		private final String customValidationXmlPath;
+
+		CustomValidationXmlClassLoader(String pathToCustomValidationXml) {
+			super( CustomValidationXmlClassLoader.class.getClassLoader() );
+			customValidationXmlPath = pathToCustomValidationXml;
+		}
+
+		public InputStream getResourceAsStream(String path) {
+			InputStream in;
+			if ( "META-INF/validation.xml".equals( path ) ) {
+				if ( customValidationXmlPath.contains( ".jar!" ) ) {
+					path = customValidationXmlPath.substring( customValidationXmlPath.indexOf( "!" ) + 2 );
+					in = super.getResourceAsStream( path );
+				}
+				else {
+					in = loadFromDisk();
+				}
+			}
+			else {
+				in = super.getResourceAsStream( path );
+			}
+			return in;
+		}
+
+		private InputStream loadFromDisk() {
+			InputStream in;
+			try {
+				in = new BufferedInputStream( new FileInputStream( customValidationXmlPath ) );
+			}
+			catch ( IOException ioe ) {
+				String msg = "Unble to load " + customValidationXmlPath + " from  disk";
+				throw new RuntimeException( msg );
+			}
+			return in;
+		}
+	}
+
+	private static class IgnoringValidationXmlClassLoader extends ClassLoader {
+		IgnoringValidationXmlClassLoader() {
+			super( IgnoringValidationXmlClassLoader.class.getClassLoader() );
+		}
+
+		public InputStream getResourceAsStream(String path) {
+			if ( "META-INF/validation.xml".equals( path ) ) {
+				return null;
+			}
+			return super.getResourceAsStream( path );
+		}
+	}
+}

Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-06-04 11:00:14 UTC (rev 16694)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-06-04 14:59:34 UTC (rev 16695)
@@ -55,7 +55,7 @@
         </assertion>
         <assertion id="f">
             <text>If no group is specified when declaring the constraint on an element, the Default
-                group is considered declared. </text>
+                group is considered declared.</text>
         </assertion>
     </section>
 
@@ -73,11 +73,11 @@
     </section>
     <section id="2.3" title="Constraint composition">
         <assertion id="a">
-            <text>Each constraint annotation hosted on a constraint an- notation is applied to the
+            <text>Each constraint annotation hosted on a constraint annotation is applied to the
                 target element and this recursively</text>
         </assertion>
         <assertion id="b">
-            <text>Note that the main annotation and its constraint valid- ation implementation is
+            <text>Note that the main annotation and its constraint validation implementation is
                 also applied</text>
         </assertion>
         <assertion id="c">
@@ -504,7 +504,7 @@
         </assertion>
         <assertion id="e">
             <text>If no ConstraintValidator compliant with T is found amongst the
-                ConstraintValidators listed by the con- straint A, a UnexpectedTypeException is
+                ConstraintValidators listed by the constraint A, a UnexpectedTypeException is
                 raised</text>
         </assertion>
         <assertion id="f">
@@ -1167,7 +1167,7 @@
         </assertion>
         <assertion id="c">
             <text>If set to true, the list of ConstraintValidators described in XML are concatenated
-                to the list of Con- straintValidator described on the annotation to form a new array
+                to the list of ConstraintValidator described on the annotation to form a new array
                 of ConstraintValidator evaluated</text>
         </assertion>
         <assertion id="d">

Deleted: beanvalidation/trunk/validation-tck/src/test/java/org/hibernate/jsr303/tck/tests/StandaloneContainersImpl.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/test/java/org/hibernate/jsr303/tck/tests/StandaloneContainersImpl.java	2009-06-04 11:00:14 UTC (rev 16694)
+++ beanvalidation/trunk/validation-tck/src/test/java/org/hibernate/jsr303/tck/tests/StandaloneContainersImpl.java	2009-06-04 14:59:34 UTC (rev 16695)
@@ -1,40 +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;
-
-import java.net.URL;
-
-import org.jboss.testharness.api.DeploymentException;
-import org.jboss.testharness.spi.StandaloneContainers;
-
-public class StandaloneContainersImpl implements StandaloneContainers {
-	public void deploy(Iterable<Class<?>> classes) throws DeploymentException {
-	}
-
-	public void undeploy() {
-	}
-
-	public void setup() {
-	}
-
-	public void cleanup() {
-	}
-
-	public void deploy(Iterable<Class<?>> classes, Iterable<URL> beansXmls) throws DeploymentException {
-	}
-}

Deleted: beanvalidation/trunk/validation-tck/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/default/beans.xml
===================================================================




More information about the hibernate-commits mailing list